260330:1011 Addied correspondence_revieion_attcahments table table #01
This commit is contained in:
@@ -53,7 +53,9 @@ export function CorrespondenceDetail({ data, selectedRevisionId }: Correspondenc
|
||||
const subject = currentRevision?.subject || '-';
|
||||
const description = currentRevision?.description || '-';
|
||||
const status = currentRevision?.status?.statusCode || 'UNKNOWN';
|
||||
const attachments = currentRevision?.attachments || [];
|
||||
// [FIX v1.8.1] flatten attachmentLinks จาก junction table แทน attachments โดยตรง
|
||||
const attachments =
|
||||
currentRevision?.attachmentLinks?.map((link) => link.attachment) ?? [];
|
||||
const importance = (currentRevision?.details?.importance as string) || 'NORMAL';
|
||||
const canEditMetadata = hasPermission('correspondence.edit');
|
||||
const privilegedEditableStatuses = ['SUBCSC', 'SUBOWN', 'IN_REVIEW_CSC'];
|
||||
@@ -294,10 +296,15 @@ export function CorrespondenceDetail({ data, selectedRevisionId }: Correspondenc
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<FileText className="h-5 w-5 text-primary" />
|
||||
<span className="text-sm font-medium">{file.name}</span>
|
||||
<span className="text-sm font-medium">{file.originalFilename}</span>
|
||||
</div>
|
||||
<Button variant="ghost" size="sm" asChild>
|
||||
<a href={file.url} target="_blank" rel="noopener noreferrer">
|
||||
<a
|
||||
href={file.filePath}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label={`Download ${file.originalFilename}`}
|
||||
>
|
||||
<Download className="h-4 w-4" />
|
||||
</a>
|
||||
</Button>
|
||||
|
||||
@@ -24,7 +24,9 @@ import { toast } from 'sonner';
|
||||
// Updated Zod Schema with all required fields
|
||||
const correspondenceSchema = z.object({
|
||||
projectId: z.string().min(1, 'Please select a Project'),
|
||||
contractId: z.string().min(1, 'Please select a Contract'),
|
||||
// [FIX v1.8.1] contractId optional เพราะ correspondences ไม่มี contract_id โดยตรง
|
||||
// จะ auto-populate จาก discipline เฉพาะ UI เท่านั้น
|
||||
contractId: z.string().optional(),
|
||||
documentTypeId: z.number().min(1, 'Please select a Document Type'),
|
||||
disciplineId: z.number().optional(),
|
||||
subject: z.string().min(5, 'Subject must be at least 5 characters'),
|
||||
@@ -66,6 +68,12 @@ interface DisciplineOption {
|
||||
id: number;
|
||||
disciplineCode: string;
|
||||
codeNameEn?: string;
|
||||
// [FIX v1.8.1] บาง API ส่ง contract relation มาด้วย → ใช้ resolve contractId
|
||||
contract?: {
|
||||
publicId?: string;
|
||||
contractName?: string;
|
||||
contractCode?: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface InitialCorrespondenceData {
|
||||
@@ -168,7 +176,8 @@ export function CorrespondenceForm({
|
||||
projectId:
|
||||
normalizePublicId(initialData?.project?.publicId) ??
|
||||
normalizePublicId(initialData?.projectId),
|
||||
contractId: normalizePublicId(initialData?.contract?.publicId),
|
||||
// [FIX v1.8.1] correspondences ไม่มี contract_id โดยตรง → จะ auto-populate จาก discipline useEffect
|
||||
contractId: undefined,
|
||||
documentTypeId: initialData?.correspondenceTypeId || undefined,
|
||||
disciplineId: initialData?.disciplineId || undefined,
|
||||
subject: currentRev?.subject || currentRev?.title || '',
|
||||
@@ -241,6 +250,21 @@ export function CorrespondenceForm({
|
||||
}
|
||||
}, [contractId, setValue]);
|
||||
|
||||
// [FIX v1.8.1] Auto-populate contractId จาก discipline เมื่อ edit mode
|
||||
// disciplines API ส่ง contract relation มาด้วย ถ้ามี discipline
|
||||
useEffect(() => {
|
||||
if (!initialData?.disciplineId) return;
|
||||
if (disciplines.length === 0) return;
|
||||
// ถ้ามี contractId ใน form แล้ว ไม่ต้อง override
|
||||
const currentContractId = watch('contractId');
|
||||
if (currentContractId) return;
|
||||
|
||||
const matched = disciplines.find((d) => d.id === initialData.disciplineId);
|
||||
if (matched?.contract?.publicId) {
|
||||
setValue('contractId', matched.contract.publicId);
|
||||
}
|
||||
}, [initialData?.disciplineId, disciplines, setValue, watch]);
|
||||
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
|
||||
const onSubmit = async (data: FormData) => {
|
||||
|
||||
@@ -6,13 +6,20 @@ export interface Organization {
|
||||
|
||||
export interface Attachment {
|
||||
publicId: string; // ADR-019: public identifier
|
||||
name: string;
|
||||
url: string;
|
||||
size?: number;
|
||||
type?: string;
|
||||
originalFilename: string;
|
||||
storedFilename?: string;
|
||||
fileSize?: number;
|
||||
mimeType?: string;
|
||||
filePath?: string;
|
||||
createdAt?: string;
|
||||
}
|
||||
|
||||
// [FIX v1.8.1] ประเภทข้อมูล junction table correspondence_revision_attachments
|
||||
export interface AttachmentLink {
|
||||
isMainDocument: boolean;
|
||||
attachment: Attachment;
|
||||
}
|
||||
|
||||
// Used in List View mainly
|
||||
export interface CorrespondenceRevision {
|
||||
publicId: string; // ADR-019: public identifier
|
||||
@@ -34,7 +41,8 @@ export interface CorrespondenceRevision {
|
||||
statusName: string;
|
||||
};
|
||||
details?: Record<string, unknown> | null;
|
||||
attachments?: Attachment[];
|
||||
// [FIX v1.8.1] ไฟล์แนบผ่าน junction table (correspondence_revision_attachments)
|
||||
attachmentLinks?: AttachmentLink[];
|
||||
createdAt: string;
|
||||
|
||||
// Nested Relation from Backend Refactor
|
||||
|
||||
Reference in New Issue
Block a user