diff options
Diffstat (limited to 'lib/vendor-candidates/table/update-candidate-sheet.tsx')
| -rw-r--r-- | lib/vendor-candidates/table/update-candidate-sheet.tsx | 112 |
1 files changed, 105 insertions, 7 deletions
diff --git a/lib/vendor-candidates/table/update-candidate-sheet.tsx b/lib/vendor-candidates/table/update-candidate-sheet.tsx index c475210b..3d278126 100644 --- a/lib/vendor-candidates/table/update-candidate-sheet.tsx +++ b/lib/vendor-candidates/table/update-candidate-sheet.tsx @@ -1,7 +1,6 @@ "use client" import * as React from "react" -import { vendorCandidates, VendorCandidates } from "@/db/schema/vendors" import { zodResolver } from "@hookform/resolvers/zod" import { Check, ChevronsUpDown, Loader } from "lucide-react" import { useForm } from "react-hook-form" @@ -38,6 +37,7 @@ import { SheetTitle, } from "@/components/ui/sheet" import { Input } from "@/components/ui/input" +import { Textarea } from "@/components/ui/textarea" import { Popover, PopoverContent, @@ -51,9 +51,11 @@ import { CommandItem, CommandList, } from "@/components/ui/command" +import { useSession } from "next-auth/react" // next-auth 세션 훅 import { updateVendorCandidateSchema, UpdateVendorCandidateSchema } from "../validations" import { updateVendorCandidate } from "../service" +import { vendorCandidates,VendorCandidatesWithVendorInfo} from "@/db/schema" // Register locales for countries i18nIsoCountries.registerLocale(enLocale) @@ -69,47 +71,65 @@ const countryArray = Object.entries(countryMap).map(([code, label]) => ({ interface UpdateCandidateSheetProps extends React.ComponentPropsWithRef<typeof Sheet> { - candidate: VendorCandidates | null + candidate: VendorCandidatesWithVendorInfo | null } export function UpdateCandidateSheet({ candidate, ...props }: UpdateCandidateSheetProps) { const [isUpdatePending, startUpdateTransition] = React.useTransition() + const { data: session, status } = useSession() // Set default values from candidate data when the component receives a new candidate + React.useEffect(() => { if (candidate) { form.reset({ id: candidate.id, companyName: candidate.companyName, - contactEmail: candidate.contactEmail, + taxId: candidate.taxId, + contactEmail: candidate.contactEmail || "", // null을 빈 문자열로 변환 contactPhone: candidate.contactPhone || "", + address: candidate.address || "", country: candidate.country || "", source: candidate.source || "", + items: candidate.items, + remark: candidate.remark || "", status: candidate.status, }) } }, [candidate]) + const form = useForm<UpdateVendorCandidateSchema>({ resolver: zodResolver(updateVendorCandidateSchema), defaultValues: { id: candidate?.id || 0, companyName: candidate?.companyName || "", + taxId: candidate?.taxId || "", contactEmail: candidate?.contactEmail || "", contactPhone: candidate?.contactPhone || "", + address: candidate?.address || "", country: candidate?.country || "", source: candidate?.source || "", + items: candidate?.items || "", + remark: candidate?.remark || "", status: candidate?.status || "COLLECTED", }, }) function onSubmit(input: UpdateVendorCandidateSchema) { startUpdateTransition(async () => { + + if (!session?.user?.id) { + toast.error("인증 오류. 로그인 정보를 찾을 수 없습니다.") + return + } + const userId = Number(session.user.id) + if (!candidate) return const { error } = await updateVendorCandidate({ ...input, - }) + }, userId) if (error) { toast.error(error) @@ -124,7 +144,7 @@ export function UpdateCandidateSheet({ candidate, ...props }: UpdateCandidateShe return ( <Sheet {...props}> - <SheetContent className="flex flex-col gap-6 sm:max-w-md"> + <SheetContent className="flex flex-col gap-6 sm:max-w-md overflow-y-auto"> <SheetHeader className="text-left"> <SheetTitle>Update Vendor Candidate</SheetTitle> <SheetDescription> @@ -142,7 +162,7 @@ export function UpdateCandidateSheet({ candidate, ...props }: UpdateCandidateShe name="companyName" render={({ field }) => ( <FormItem> - <FormLabel>Company Name</FormLabel> + <FormLabel>Company Name <span className="text-red-500">*</span></FormLabel> <FormControl> <Input placeholder="Enter company name" @@ -155,6 +175,25 @@ export function UpdateCandidateSheet({ candidate, ...props }: UpdateCandidateShe )} /> + {/* Tax ID Field */} + <FormField + control={form.control} + name="taxId" + render={({ field }) => ( + <FormItem> + <FormLabel>Tax ID</FormLabel> + <FormControl> + <Input + placeholder="Enter tax ID" + {...field} + disabled={isUpdatePending} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + {/* Contact Email Field */} <FormField control={form.control} @@ -194,6 +233,25 @@ export function UpdateCandidateSheet({ candidate, ...props }: UpdateCandidateShe )} /> + {/* Address Field */} + <FormField + control={form.control} + name="address" + render={({ field }) => ( + <FormItem> + <FormLabel>Address</FormLabel> + <FormControl> + <Input + placeholder="Enter company address" + {...field} + disabled={isUpdatePending} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + {/* Country Field */} <FormField control={form.control} @@ -266,7 +324,7 @@ export function UpdateCandidateSheet({ candidate, ...props }: UpdateCandidateShe name="source" render={({ field }) => ( <FormItem> - <FormLabel>Source</FormLabel> + <FormLabel>Source <span className="text-red-500">*</span></FormLabel> <FormControl> <Input placeholder="Where this candidate was found" @@ -279,6 +337,46 @@ export function UpdateCandidateSheet({ candidate, ...props }: UpdateCandidateShe )} /> + {/* Items Field */} + <FormField + control={form.control} + name="items" + render={({ field }) => ( + <FormItem> + <FormLabel>Items <span className="text-red-500">*</span></FormLabel> + <FormControl> + <Textarea + placeholder="List of items or products this vendor provides" + className="min-h-[80px]" + {...field} + disabled={isUpdatePending} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* Remark Field */} + <FormField + control={form.control} + name="remark" + render={({ field }) => ( + <FormItem> + <FormLabel>Remark</FormLabel> + <FormControl> + <Textarea + placeholder="Additional notes or comments" + className="min-h-[80px]" + {...field} + disabled={isUpdatePending} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + {/* Status Field */} <FormField control={form.control} |
