This commit is contained in:
@@ -50,14 +50,13 @@ import { SearchContractDto, CreateContractDto, UpdateContractDto } from "@/types
|
|||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
|
|
||||||
interface Project {
|
interface Project {
|
||||||
id: number;
|
id: string; // ADR-019: uuid exposed as 'id'
|
||||||
projectCode: string;
|
projectCode: string;
|
||||||
projectName: string;
|
projectName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Contract {
|
interface Contract {
|
||||||
uuid: string;
|
id: string; // ADR-019: uuid exposed as 'id'
|
||||||
id?: number; // Excluded from API responses (ADR-019)
|
|
||||||
contractCode: string;
|
contractCode: string;
|
||||||
contractName: string;
|
contractName: string;
|
||||||
projectId: number;
|
projectId: number;
|
||||||
@@ -65,6 +64,7 @@ interface Contract {
|
|||||||
startDate?: string;
|
startDate?: string;
|
||||||
endDate?: string;
|
endDate?: string;
|
||||||
project?: {
|
project?: {
|
||||||
|
id: string; // ADR-019: project uuid exposed as 'id'
|
||||||
projectCode: string;
|
projectCode: string;
|
||||||
projectName: string;
|
projectName: string;
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ export default function ContractsPage() {
|
|||||||
|
|
||||||
const confirmDelete = () => {
|
const confirmDelete = () => {
|
||||||
if (contractToDelete) {
|
if (contractToDelete) {
|
||||||
deleteContract.mutate(contractToDelete.uuid, {
|
deleteContract.mutate(contractToDelete.id, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
setDeleteDialogOpen(false);
|
setDeleteDialogOpen(false);
|
||||||
setContractToDelete(null);
|
setContractToDelete(null);
|
||||||
@@ -213,9 +213,9 @@ export default function ContractsPage() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const handleEdit = (contract: Contract) => {
|
const handleEdit = (contract: Contract) => {
|
||||||
setEditingUuid(contract.uuid);
|
setEditingUuid(contract.id);
|
||||||
// ADR-019: projectId might be a number or a UUID string from the entity response
|
// ADR-019: project.id is the project's UUID (exposed via @Expose)
|
||||||
const pId = String((contract as any).id || (contract as any).projectId || "");
|
const pId = contract.project?.id || '';
|
||||||
reset({
|
reset({
|
||||||
contractCode: contract.contractCode,
|
contractCode: contract.contractCode,
|
||||||
contractName: contract.contractName,
|
contractName: contract.contractName,
|
||||||
@@ -242,10 +242,11 @@ export default function ContractsPage() {
|
|||||||
|
|
||||||
const onSubmit = (data: ContractFormData) => {
|
const onSubmit = (data: ContractFormData) => {
|
||||||
// ADR-019: Resolve projectId (ID or UUID)
|
// ADR-019: Resolve projectId (ID or UUID)
|
||||||
|
// ADR-019: projectId is now a UUID string — backend resolveProjectId handles both
|
||||||
const submitData = {
|
const submitData = {
|
||||||
...data,
|
...data,
|
||||||
projectId: isNaN(Number(data.projectId)) ? data.projectId : Number(data.projectId),
|
projectId: data.projectId,
|
||||||
} as any;
|
};
|
||||||
|
|
||||||
if (editingUuid) {
|
if (editingUuid) {
|
||||||
updateContract.mutate({ uuid: editingUuid, data: submitData });
|
updateContract.mutate({ uuid: editingUuid, data: submitData });
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const masterDataKeys = {
|
|||||||
all: ['masterData'] as const,
|
all: ['masterData'] as const,
|
||||||
organizations: () => [...masterDataKeys.all, 'organizations'] as const,
|
organizations: () => [...masterDataKeys.all, 'organizations'] as const,
|
||||||
correspondenceTypes: () => [...masterDataKeys.all, 'correspondenceTypes'] as const,
|
correspondenceTypes: () => [...masterDataKeys.all, 'correspondenceTypes'] as const,
|
||||||
disciplines: (contractId?: number) => [...masterDataKeys.all, 'disciplines', contractId] as const,
|
disciplines: (contractId?: number | string) => [...masterDataKeys.all, 'disciplines', contractId] as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useOrganizations(params?: SearchOrganizationDto) {
|
export function useOrganizations(params?: SearchOrganizationDto) {
|
||||||
@@ -74,7 +74,7 @@ export function useDeleteOrganization() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useDisciplines(contractId?: number) {
|
export function useDisciplines(contractId?: number | string) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: masterDataKeys.disciplines(contractId),
|
queryKey: masterDataKeys.disciplines(contractId),
|
||||||
queryFn: () => masterDataService.getDisciplines(contractId),
|
queryFn: () => masterDataService.getDisciplines(contractId),
|
||||||
@@ -88,10 +88,10 @@ export function useProjects(isActive: boolean = true) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useContracts(projectId: number = 1) {
|
export function useContracts(projectId?: number | string) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['contracts', projectId],
|
queryKey: ['contracts', projectId ?? 'all'],
|
||||||
queryFn: () => contractService.getAll({ projectId }),
|
queryFn: () => contractService.getAll(projectId ? { projectId } : undefined),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export interface CreateContractDto {
|
export interface CreateContractDto {
|
||||||
contractCode: string;
|
contractCode: string;
|
||||||
contractName: string;
|
contractName: string;
|
||||||
projectId: number;
|
projectId: number | string;
|
||||||
description?: string;
|
description?: string;
|
||||||
startDate?: string;
|
startDate?: string;
|
||||||
endDate?: string;
|
endDate?: string;
|
||||||
@@ -11,7 +11,7 @@ export type UpdateContractDto = Partial<CreateContractDto>;
|
|||||||
|
|
||||||
export interface SearchContractDto {
|
export interface SearchContractDto {
|
||||||
search?: string;
|
search?: string;
|
||||||
projectId?: number;
|
projectId?: number | string;
|
||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user