690328:2128 Fixing Refactor uuid by Kimi #12
This commit is contained in:
@@ -81,12 +81,12 @@ export default function DisciplinesPage() {
|
||||
queryKey={['disciplines', selectedContractId ?? 'all']}
|
||||
fetchFn={async () => {
|
||||
const items = await masterDataService.getDisciplines(selectedContractId ? selectedContractId : undefined);
|
||||
// ADR-019: Map contractId INT → contract UUID for edit mode select matching
|
||||
// ADR-019: Map contract.publicId UUID for edit mode select matching
|
||||
return items.map((item) => {
|
||||
const rec = item as Discipline & { contract?: { id?: number; uuid?: string }; contractId?: number | string };
|
||||
const rec = item as Discipline & { contract?: { publicId?: string }; contractId?: number | string };
|
||||
return {
|
||||
...item,
|
||||
contractId: rec.contract?.id || rec.contract?.uuid || String(rec.contractId),
|
||||
contractId: rec.contract?.publicId || (rec.contractId ? String(rec.contractId) : null),
|
||||
} as Discipline;
|
||||
});
|
||||
}}
|
||||
|
||||
@@ -84,12 +84,12 @@ export default function RfaTypesPage() {
|
||||
queryKey={['rfa-types', selectedContractId ?? 'all']}
|
||||
fetchFn={async () => {
|
||||
const items = await masterDataService.getRfaTypes(selectedContractId ? selectedContractId : undefined);
|
||||
// ADR-019: Map contractId INT → contract UUID for edit mode select matching
|
||||
// ADR-019: Map contract.publicId UUID for edit mode select matching
|
||||
return items.map((item) => {
|
||||
const rec = item as RfaType & { contract?: { id?: number | string; uuid?: string }; contract_id?: number | string };
|
||||
const rec = item as RfaType & { contract?: { publicId?: string }; contractId?: number | string };
|
||||
return {
|
||||
...item,
|
||||
contractId: rec.contract?.id || rec.contract?.uuid || (rec.contract_id ? String(rec.contract_id) : null),
|
||||
contractId: rec.contract?.publicId || (rec.contractId ? String(rec.contractId) : null),
|
||||
} as RfaType;
|
||||
});
|
||||
}}
|
||||
|
||||
@@ -46,8 +46,8 @@ export function TemplateEditor({
|
||||
onCancel,
|
||||
}: TemplateEditorProps) {
|
||||
const [format, setFormat] = useState(template?.formatTemplate || '');
|
||||
const [typeId, setTypeId] = useState<string>(template?.correspondenceTypeId?.toString() || '');
|
||||
const [disciplineId, setDisciplineId] = useState<string>(template?.disciplineId?.toString() || '0');
|
||||
const [typeId, setTypeId] = useState<string>(template?.correspondenceTypeId ? String(template.correspondenceTypeId) : '');
|
||||
const [disciplineId, setDisciplineId] = useState<string>(template?.disciplineId ? String(template.disciplineId) : '0');
|
||||
const [reset, setReset] = useState(template?.resetSequenceYearly ?? true);
|
||||
|
||||
const [preview, setPreview] = useState('');
|
||||
@@ -64,7 +64,7 @@ export function TemplateEditor({
|
||||
// Dynamic context based on selection (optional visual enhancement)
|
||||
if (v.key === '{TYPE}' && typeId) {
|
||||
const t = correspondenceTypes.find(
|
||||
(ct) => ct.id?.toString() === typeId
|
||||
(ct) => String(ct.publicId) === typeId
|
||||
);
|
||||
if (t) replacement = t.typeCode;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ export function TemplateEditor({
|
||||
<SelectItem value="__default__">Default (All Types)</SelectItem>
|
||||
{correspondenceTypes.map((type) => {
|
||||
return (
|
||||
<SelectItem key={type.publicId} value={type.publicId.toString()}>
|
||||
<SelectItem key={type.publicId} value={String(type.publicId)}>
|
||||
{type.typeCode} - {type.typeName}
|
||||
</SelectItem>
|
||||
);
|
||||
@@ -142,7 +142,7 @@ export function TemplateEditor({
|
||||
<SelectContent>
|
||||
<SelectItem value="0">All Disciplines</SelectItem>
|
||||
{disciplines.map((d) => (
|
||||
<SelectItem key={d.publicId} value={d.publicId.toString()}>
|
||||
<SelectItem key={d.publicId} value={String(d.publicId)}>
|
||||
{d.disciplineCode} - {d.codeNameEn || d.codeNameTh}
|
||||
</SelectItem>
|
||||
))}
|
||||
|
||||
@@ -25,7 +25,7 @@ import { Contract } from '@/types/contract';
|
||||
const rfaSchema = z.object({
|
||||
projectId: z.string().min(1, 'Project is required'), // ADR-019: UUID
|
||||
contractId: z.string().min(1, 'Contract is required'),
|
||||
disciplineId: z.number({ message: 'Discipline is required' }).min(1, 'Discipline is required'),
|
||||
disciplineId: z.union([z.string().min(1, 'Discipline is required'), z.number().min(1, 'Discipline is required')]),
|
||||
rfaTypeId: z.string().min(1, 'Type is required'), // ADR-019: UUID
|
||||
subject: z.string().min(5, 'Subject must be at least 5 characters'),
|
||||
description: z.string().optional(),
|
||||
@@ -165,7 +165,7 @@ export function RFAForm() {
|
||||
defaultValues: {
|
||||
projectId: '',
|
||||
contractId: '',
|
||||
disciplineId: 0,
|
||||
disciplineId: '',
|
||||
rfaTypeId: '',
|
||||
subject: '',
|
||||
description: '',
|
||||
@@ -366,7 +366,7 @@ export function RFAForm() {
|
||||
onValueChange={(val) => {
|
||||
setValue('projectId', val);
|
||||
setValue('contractId', '');
|
||||
setValue('disciplineId', 0);
|
||||
setValue('disciplineId', '');
|
||||
setValue('rfaTypeId', '');
|
||||
setValue('shopDrawingRevisionIds', []);
|
||||
setValue('asBuiltDrawingRevisionIds', []);
|
||||
@@ -402,7 +402,7 @@ export function RFAForm() {
|
||||
value={selectedContractId || undefined}
|
||||
onValueChange={(val) => {
|
||||
setValue('contractId', val);
|
||||
setValue('disciplineId', 0);
|
||||
setValue('disciplineId', '');
|
||||
setValue('rfaTypeId', '');
|
||||
setValue('shopDrawingRevisionIds', []);
|
||||
setValue('asBuiltDrawingRevisionIds', []);
|
||||
@@ -434,8 +434,8 @@ export function RFAForm() {
|
||||
<div>
|
||||
<Label>Discipline *</Label>
|
||||
<Select
|
||||
value={selectedDisciplineId > 0 ? String(selectedDisciplineId) : undefined}
|
||||
onValueChange={(val) => setValue('disciplineId', Number(val))}
|
||||
value={selectedDisciplineId ? String(selectedDisciplineId) : undefined}
|
||||
onValueChange={(val) => setValue('disciplineId', val)}
|
||||
disabled={!selectedContractId || isLoadingDisciplines}
|
||||
>
|
||||
<SelectTrigger>
|
||||
|
||||
Reference in New Issue
Block a user