diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-10-15 12:52:11 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-10-15 12:52:11 +0000 |
| commit | b54f6f03150dd78d86db62201b6386bf14b72394 (patch) | |
| tree | b3092bb34805fdc65eee5282e86a9fb90ba20d6e /lib/owner-companies/owner-company-user-form.tsx | |
| parent | c1bd1a2f499ee2f0742170021b37dab410983ab7 (diff) | |
(대표님) 커버, 데이터룸, 파일매니저, 담당자할당 등
Diffstat (limited to 'lib/owner-companies/owner-company-user-form.tsx')
| -rw-r--r-- | lib/owner-companies/owner-company-user-form.tsx | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/lib/owner-companies/owner-company-user-form.tsx b/lib/owner-companies/owner-company-user-form.tsx new file mode 100644 index 00000000..52253607 --- /dev/null +++ b/lib/owner-companies/owner-company-user-form.tsx @@ -0,0 +1,125 @@ +// app/(admin)/owner-companies/_components/owner-company-user-form.tsx +"use client"; + +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import * as z from "zod"; +import { Button } from "@/components/ui/button"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { useRouter } from "next/navigation"; +import { toast } from "sonner"; +import { createOwnerCompanyUser } from "./service"; + +const formSchema = z.object({ + name: z.string().min(1, "이름을 입력해주세요"), + email: z.string().email("올바른 이메일을 입력해주세요"), + phone: z.string().optional(), +}); + +type FormValues = z.infer<typeof formSchema>; + +interface OwnerCompanyUserFormProps { + companyId: number; +} + +export function OwnerCompanyUserForm({ companyId }: OwnerCompanyUserFormProps) { + const router = useRouter(); + + const form = useForm<FormValues>({ + resolver: zodResolver(formSchema), + defaultValues: { + name: "", + email: "", + phone: "", + }, + }); + + async function onSubmit(values: FormValues) { + try { + const result = await createOwnerCompanyUser(companyId, values); + + if (result.success) { + toast.success("사용자가 등록되었습니다"); + router.push(`/evcp/data-room/owner-companies/${companyId}/users`); + router.refresh(); + } else { + toast.error(result.error || "오류가 발생했습니다"); + } + } catch (error) { + toast.error("오류가 발생했습니다"); + } + } + + return ( + <Form {...form}> + <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6"> + <FormField + control={form.control} + name="name" + render={({ field }) => ( + <FormItem> + <FormLabel>이름 *</FormLabel> + <FormControl> + <Input placeholder="홍길동" {...field} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="email" + render={({ field }) => ( + <FormItem> + <FormLabel>이메일 *</FormLabel> + <FormControl> + <Input + type="email" + placeholder="user@company.com" + {...field} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="phone" + render={({ field }) => ( + <FormItem> + <FormLabel>전화번호</FormLabel> + <FormControl> + <Input placeholder="+82-10-1234-5678" {...field} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <div className="flex gap-2"> + <Button + type="button" + variant="outline" + onClick={() => router.back()} + > + 취소 + </Button> + <Button type="submit" disabled={form.formState.isSubmitting}> + {form.formState.isSubmitting ? "처리 중..." : "등록"} + </Button> + </div> + </form> + </Form> + ); +}
\ No newline at end of file |
