diff options
Diffstat (limited to 'components/ship-vendor-document/edit-revision-dialog.tsx')
| -rw-r--r-- | components/ship-vendor-document/edit-revision-dialog.tsx | 137 |
1 files changed, 43 insertions, 94 deletions
diff --git a/components/ship-vendor-document/edit-revision-dialog.tsx b/components/ship-vendor-document/edit-revision-dialog.tsx index 2b8735e7..9ca4c65d 100644 --- a/components/ship-vendor-document/edit-revision-dialog.tsx +++ b/components/ship-vendor-document/edit-revision-dialog.tsx @@ -31,17 +31,23 @@ import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" -import { - Edit, - FileText, - Loader2, +import { + Edit, + FileText, + Loader2, AlertTriangle, Trash2, - CheckCircle, - Clock + CheckCircle } from "lucide-react" import { toast } from "sonner" import { updateRevisionAction, deleteRevisionAction } from "@/lib/vendor-document-list/enhanced-document-service" // ✅ 서버 액션 import +import { + createEditRevisionSchema, + getUsageOptions, + getUsageTypeOptions, + getRevisionGuide, + B3RevisionInput +} from "./revision-validation" /* ------------------------------------------------------------------------------------------------- * Schema & Types @@ -84,88 +90,16 @@ interface AttachmentInfo { updatedAt: Date } -// drawingKind에 따른 동적 스키마 생성 (수정용) -const createEditRevisionSchema = (drawingKind: string) => { - const baseSchema = { - usage: z.string().min(1, "Please select a usage"), - revision: z.string().min(1, "Please enter a revision").max(50, "Revision must be 50 characters or less"), // ✅ revision 필드 추가 - comment: z.string().optional(), - } - // B3인 경우에만 usageType 필드 추가 - if (drawingKind === 'B3') { - return z.object({ - ...baseSchema, - usageType: z.string().min(1, "Please select a usage type"), - }) - } else { - return z.object({ - ...baseSchema, - usageType: z.string().optional(), - }) - } -} -// drawingKind에 따른 용도 옵션 -const getUsageOptions = (drawingKind: string) => { - switch (drawingKind) { - case 'B3': - return [ - { value: "Approval", label: "Approval" }, - { value: "Working", label: "Working" }, - { value: "Comments", label: "Comments" }, - ] - case 'B4': - return [ - { value: "Pre", label: "Pre" }, - { value: "Working", label: "Working" }, - ] - case 'B5': - return [ - { value: "Pre", label: "Pre" }, - { value: "Working", label: "Working" }, - ] - default: - return [ - { value: "Pre", label: "Pre" }, - { value: "Working", label: "Working" }, - ] - } -} -// B3 전용 용도 타입 옵션 -const getUsageTypeOptions = (usage: string) => { - switch (usage) { - case 'Approval': - return [ - { value: "Full", label: "Full" }, - { value: "Partial", label: "Partial" }, - ] - case 'Working': - return [ - { value: "Full", label: "Full" }, - { value: "Partial", label: "Partial" }, - ] - case 'Comments': - return [ - { value: "Comments", label: "Comments" }, - ] - default: - return [] - } -} - -// ✅ 리비전 가이드 생성 (NewRevisionDialog와 동일) -const getRevisionGuide = () => { - return "Enter in R01, R02, R03... format" -} interface EditRevisionDialogProps { open: boolean onOpenChange: (open: boolean) => void revision: RevisionInfo | null drawingKind?: string - onSuccess: (action: 'update' | 'delete', result?: any) => void + onSuccess: (action: 'update' | 'delete', result?: unknown) => void } /* ------------------------------------------------------------------------------------------------- @@ -302,8 +236,8 @@ export function EditRevisionDialog({ // ✅ 리비전 가이드 텍스트 const revisionGuide = React.useMemo(() => { - return getRevisionGuide() - }, []) + return getRevisionGuide(drawingKind) + }, [drawingKind]) // revision이 변경될 때 폼 데이터 초기화 React.useEffect(() => { @@ -324,7 +258,6 @@ export function EditRevisionDialog({ form.setValue("usageType", "Comments") } else { // Comments가 아닌 경우, 초기 로드가 아니라면 초기화 - const currentValue = form.getValues("usageType") if (revision && watchedUsage !== revision.usage) { form.setValue("usageType", "") } @@ -471,15 +404,31 @@ export function EditRevisionDialog({ <FormItem> <FormLabel className="required">Revision</FormLabel> <FormControl> - <Input - placeholder={revisionGuide} - disabled={!canEdit} - {...field} - /> + {drawingKind === 'B3' ? ( + <B3RevisionInput + value={field.value} + onChange={field.onChange} + error={form.formState.errors.revision?.message} + /> + ) : ( + <> + <Input + placeholder={revisionGuide.placeholder} + disabled={!canEdit} + {...field} + onChange={(e) => { + const upperValue = e.target.value.toUpperCase() + if (upperValue.length <= 3) { + field.onChange(upperValue) + } + }} + /> + <div className="text-xs text-muted-foreground mt-1"> + {revisionGuide.helpText} + </div> + </> + )} </FormControl> - <div className="text-xs text-muted-foreground mt-1"> - {revisionGuide} - </div> <FormMessage /> </FormItem> )} @@ -495,7 +444,7 @@ export function EditRevisionDialog({ <Select onValueChange={field.onChange} value={field.value} disabled={!canEdit}> <FormControl> <SelectTrigger> - <SelectValue placeholder="Select usage" /> + <SelectValue placeholder='Select usage' /> </SelectTrigger> </FormControl> <SelectContent> @@ -526,7 +475,7 @@ export function EditRevisionDialog({ > <FormControl> <SelectTrigger> - <SelectValue placeholder="Select usage type" /> + <SelectValue placeholder='Select usage type' /> </SelectTrigger> </FormControl> <SelectContent> @@ -539,7 +488,7 @@ export function EditRevisionDialog({ </Select> {watchedUsage === "Comments" && ( <div className="text-xs text-muted-foreground mt-1"> - Automatically set to "Comments" for this usage + Automatically set to "Comments" for this usage </div> )} <FormMessage /> @@ -574,7 +523,7 @@ export function EditRevisionDialog({ <div className="space-y-2"> <FormLabel>Attachments ({revision.attachments.length})</FormLabel> <div className="space-y-2 max-h-32 overflow-y-auto border rounded-lg p-3"> - {revision.attachments.map((file, index) => ( + {revision.attachments.map((file) => ( <div key={file.id} className="flex items-center justify-between p-2 bg-muted/50 rounded text-sm" |
