690326:2139 Fixing Refactor ADR-019 Naming convention uuid #07
This commit is contained in:
@@ -38,7 +38,7 @@ import { SearchContractDto, CreateContractDto, UpdateContractDto } from '@/types
|
||||
import { AxiosError } from 'axios';
|
||||
|
||||
interface _Project {
|
||||
id: string; // ADR-019: uuid exposed as 'id'
|
||||
id: string; // ADR-019: uuid exposed as 'id' (string)
|
||||
projectCode: string;
|
||||
projectName: string;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ const useProjectsList = () => {
|
||||
export default function ContractsPage() {
|
||||
const [search, setSearch] = useState('');
|
||||
const { data: contracts, isLoading } = useContracts({ search: search || undefined });
|
||||
const { data: projects } = useProjectsList();
|
||||
const { data: projects } = useProjectsList() as { data: _Project[] | undefined };
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -286,7 +286,9 @@ export default function ContractsPage() {
|
||||
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{editingUuid ? 'Edit Contract' : 'New Contract'}</DialogTitle>
|
||||
<DialogTitle>
|
||||
{editingUuid ? `Edit Contract: ${watch('contractCode') || '...'}` : 'New Contract'}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
@@ -296,13 +298,12 @@ export default function ContractsPage() {
|
||||
<SelectValue placeholder="Select Project" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{(projects as { id?: number; uuid?: string; projectCode: string; projectName: string }[])?.map(
|
||||
(p) => (
|
||||
<SelectItem key={p.uuid || p.id} value={String(p.id || p.uuid)}>
|
||||
{p.projectCode} - {p.projectName}
|
||||
</SelectItem>
|
||||
)
|
||||
)}
|
||||
{projects?.map((p) => (
|
||||
// ADR-019: Project exposes UUID as 'id' (string)
|
||||
<SelectItem key={p.id} value={p.id}>
|
||||
{p.projectCode} - {p.projectName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.projectId && <p className="text-sm text-red-500">{errors.projectId.message}</p>}
|
||||
|
||||
@@ -16,10 +16,10 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
|
||||
import { useProjects, useCorrespondenceTypes, useContracts, useDisciplines } from '@/hooks/use-master-data';
|
||||
|
||||
interface ProjectItem {
|
||||
id: number | string;
|
||||
publicId?: string; // ADR-019: exposed as 'id' in API responses
|
||||
publicId: string; // ADR-019: UUID from API
|
||||
projectName: string;
|
||||
projectCode: string;
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
import { ManualOverrideForm } from '@/components/numbering/manual-override-form';
|
||||
@@ -38,7 +38,7 @@ export default function NumberingPage() {
|
||||
useEffect(() => {
|
||||
if (projects.length > 0 && !selectedProjectId) {
|
||||
const first = projects[0] as ProjectItem;
|
||||
setSelectedProjectId(String(first.publicId ?? first.id));
|
||||
setSelectedProjectId(String(first.publicId));
|
||||
}
|
||||
}, [projects, selectedProjectId]);
|
||||
|
||||
@@ -48,7 +48,7 @@ export default function NumberingPage() {
|
||||
const [isTesting, setIsTesting] = useState(false);
|
||||
const [testTemplate, setTestTemplate] = useState<NumberingTemplate | null>(null);
|
||||
|
||||
const selectedProject = (projects as ProjectItem[]).find((p) => String(p.publicId ?? p.id) === selectedProjectId);
|
||||
const selectedProject = (projects as ProjectItem[]).find((p) => String(p.publicId) === selectedProjectId);
|
||||
const selectedProjectName = selectedProject?.projectName || 'Unknown Project';
|
||||
|
||||
// Master Data
|
||||
@@ -116,7 +116,7 @@ export default function NumberingPage() {
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{(projects as ProjectItem[]).map((project) => (
|
||||
<SelectItem key={String(project.publicId ?? project.id)} value={String(project.publicId ?? project.id)}>
|
||||
<SelectItem key={project.publicId} value={project.publicId}>
|
||||
{project.projectCode} - {project.projectName}
|
||||
</SelectItem>
|
||||
))}
|
||||
|
||||
@@ -33,8 +33,7 @@ import {
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
|
||||
interface Project {
|
||||
uuid: string;
|
||||
id?: number; // Excluded from API responses (ADR-019)
|
||||
id: string; // ADR-019: uuid exposed as 'id'
|
||||
projectCode: string;
|
||||
projectName: string;
|
||||
isActive: boolean;
|
||||
@@ -72,7 +71,7 @@ export default function ProjectsPage() {
|
||||
|
||||
const confirmDelete = () => {
|
||||
if (projectToDelete) {
|
||||
deleteProject.mutate(projectToDelete.uuid, {
|
||||
deleteProject.mutate(projectToDelete.id, {
|
||||
onSuccess: () => {
|
||||
setDeleteDialogOpen(false);
|
||||
setProjectToDelete(null);
|
||||
@@ -146,7 +145,7 @@ export default function ProjectsPage() {
|
||||
];
|
||||
|
||||
const handleEdit = (project: Project) => {
|
||||
setEditingUuid(project.uuid);
|
||||
setEditingUuid(project.id);
|
||||
reset({
|
||||
projectCode: project.projectCode,
|
||||
projectName: project.projectName,
|
||||
|
||||
@@ -21,6 +21,18 @@ export default function DisciplinesPage() {
|
||||
header: 'Code',
|
||||
cell: ({ row }) => <span className="font-mono font-bold">{row.getValue('disciplineCode')}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'contract',
|
||||
header: 'Contract',
|
||||
cell: ({ row }) => {
|
||||
const contract = row.original.contract;
|
||||
return contract ? (
|
||||
<span className="text-sm">{contract.contractName} ({contract.contractCode})</span>
|
||||
) : (
|
||||
<span className="text-muted-foreground text-sm">-</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'codeNameTh',
|
||||
header: 'Name (TH)',
|
||||
@@ -44,9 +56,9 @@ export default function DisciplinesPage() {
|
||||
},
|
||||
];
|
||||
|
||||
const contractOptions = contracts.map((c: { id: number; contractCode: string; contractName: string }) => ({
|
||||
const contractOptions = contracts.map((c: { id?: number; publicId?: string; contractCode: string; contractName: string }) => ({
|
||||
label: `${c.contractName} (${c.contractCode})`,
|
||||
value: String(c.id),
|
||||
value: String(c.publicId ?? c.id ?? ''),
|
||||
}));
|
||||
|
||||
return (
|
||||
@@ -86,8 +98,8 @@ export default function DisciplinesPage() {
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Contracts</SelectItem>
|
||||
{contracts.map((c: { id: number; contractCode: string; contractName: string }) => (
|
||||
<SelectItem key={c.id} value={String(c.id)}>
|
||||
{contracts.map((c: { id?: number; publicId?: string; contractCode: string; contractName: string }) => (
|
||||
<SelectItem key={String(c.publicId ?? c.id ?? '')} value={String(c.publicId ?? c.id ?? '')}>
|
||||
{c.contractName} ({c.contractCode})
|
||||
</SelectItem>
|
||||
))}
|
||||
|
||||
@@ -21,6 +21,18 @@ export default function RfaTypesPage() {
|
||||
header: 'Code',
|
||||
cell: ({ row }) => <span className="font-mono font-bold">{row.getValue('typeCode')}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'contract',
|
||||
header: 'Contract',
|
||||
cell: ({ row }) => {
|
||||
const contract = row.original.contract;
|
||||
return contract ? (
|
||||
<span className="text-sm">{contract.contractName} ({contract.contractCode})</span>
|
||||
) : (
|
||||
<span className="text-muted-foreground text-sm">-</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'typeNameTh',
|
||||
header: 'Name (TH)',
|
||||
@@ -48,9 +60,9 @@ export default function RfaTypesPage() {
|
||||
},
|
||||
];
|
||||
|
||||
const contractOptions = contracts.map((c: { id: number | string; contract_name?: string; contract_code?: string; contractName?: string; contractCode?: string }) => ({
|
||||
const contractOptions = contracts.map((c: { id?: number; publicId?: string; contract_name?: string; contract_code?: string; contractName?: string; contractCode?: string }) => ({
|
||||
label: `${c.contractName || c.contract_name} (${c.contractCode || c.contract_code})`,
|
||||
value: String(c.id),
|
||||
value: String(c.publicId ?? c.id ?? ''),
|
||||
}));
|
||||
|
||||
return (
|
||||
@@ -87,8 +99,8 @@ export default function RfaTypesPage() {
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Contracts</SelectItem>
|
||||
{contracts.map((c: { id: number | string; contract_name?: string; contract_code?: string; contractName?: string; contractCode?: string }) => (
|
||||
<SelectItem key={c.id} value={String(c.id)}>
|
||||
{contracts.map((c: { id?: number; publicId?: string; contract_name?: string; contract_code?: string; contractName?: string; contractCode?: string }) => (
|
||||
<SelectItem key={String(c.publicId ?? c.id ?? '')} value={String(c.publicId ?? c.id ?? '')}>
|
||||
{c.contractName || c.contract_name} ({c.contractCode || c.contract_code})
|
||||
</SelectItem>
|
||||
))}
|
||||
@@ -104,11 +116,11 @@ export default function RfaTypesPage() {
|
||||
required: true,
|
||||
options: contractOptions,
|
||||
},
|
||||
{ name: 'type_code', label: 'Code', type: 'text', required: true },
|
||||
{ name: 'type_name_th', label: 'Name (TH)', type: 'text', required: true },
|
||||
{ name: 'type_name_en', label: 'Name (EN)', type: 'text' },
|
||||
{ name: 'typeCode', label: 'Code', type: 'text', required: true },
|
||||
{ name: 'typeNameTh', label: 'Name (TH)', type: 'text', required: true },
|
||||
{ name: 'typeNameEn', label: 'Name (EN)', type: 'text' },
|
||||
{ name: 'remark', label: 'Remark', type: 'textarea' },
|
||||
{ name: 'is_active', label: 'Active', type: 'checkbox' },
|
||||
{ name: 'isActive', label: 'Active', type: 'checkbox' },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -16,9 +16,9 @@ export default function TagsPage() {
|
||||
|
||||
const projectOptions = [
|
||||
{ label: 'Global (All Projects)', value: '__none__' },
|
||||
...(projectsData || []).map((p: { id: number | string; projectName?: string; projectCode?: string }) => ({
|
||||
label: (p.projectName || p.projectCode || `Project ${p.id}`) as string,
|
||||
value: String(p.id), // p.id = UUID string via serialization
|
||||
...(projectsData || []).map((p: { id?: number; publicId?: string; projectName?: string; projectCode?: string }) => ({
|
||||
label: (p.projectName || p.projectCode || `Project ${p.publicId || p.id}`) as string,
|
||||
value: String(p.publicId ?? p.id ?? ''), // ADR-019: publicId is the UUID exposed in API
|
||||
})),
|
||||
];
|
||||
|
||||
|
||||
@@ -16,6 +16,13 @@ export interface Discipline {
|
||||
codeNameEn: string;
|
||||
codeNameTh?: string;
|
||||
isActive: boolean;
|
||||
contract?: {
|
||||
id?: number;
|
||||
publicId?: string;
|
||||
contractCode: string;
|
||||
contractName: string;
|
||||
};
|
||||
contractId?: number | string;
|
||||
}
|
||||
|
||||
export interface RfaType {
|
||||
@@ -25,6 +32,13 @@ export interface RfaType {
|
||||
typeNameEn?: string;
|
||||
remark?: string;
|
||||
isActive: boolean;
|
||||
contract?: {
|
||||
id?: number;
|
||||
publicId?: string;
|
||||
contractCode: string;
|
||||
contractName: string;
|
||||
};
|
||||
contractId?: number | string;
|
||||
}
|
||||
|
||||
export interface Tag {
|
||||
|
||||
Reference in New Issue
Block a user