From 1a2241c40e10193c5ff7008a7b7b36cc1d855d96 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Tue, 25 Mar 2025 15:55:45 +0900 Subject: initial commit --- lib/roles/table/add-role-dialog.tsx | 308 ++++++++++++++++++++++++++++++++++++ 1 file changed, 308 insertions(+) create mode 100644 lib/roles/table/add-role-dialog.tsx (limited to 'lib/roles/table/add-role-dialog.tsx') diff --git a/lib/roles/table/add-role-dialog.tsx b/lib/roles/table/add-role-dialog.tsx new file mode 100644 index 00000000..365daf29 --- /dev/null +++ b/lib/roles/table/add-role-dialog.tsx @@ -0,0 +1,308 @@ +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { Check, ChevronsUpDown, Loader } from "lucide-react" +import { cn } from "@/lib/utils" +import { toast } from "sonner" + +import { createRoleSchema, type CreateRoleSchema } from "../validations" +import { createRole } from "../services" +import { Textarea } from "@/components/ui/textarea" +import { Company } from "@/db/schema/companies" +import { getAllCompanies } from "@/lib/admin-users/service" +import { + Popover, + PopoverTrigger, + PopoverContent, +} from "@/components/ui/popover" +import { + Command, + CommandInput, + CommandList, + CommandGroup, + CommandItem, + CommandEmpty, +} from "@/components/ui/command" + + + +const domainOptions = [ + { value: "partners", label: "협력업체" }, + { value: "evcp", label: "삼성중공업" }, +] + +export function AddRoleDialog() { + const [open, setOpen] = React.useState(false) + const [isAddPending, startAddTransition] = React.useTransition() + const [companies, setCompanies] = React.useState([]) // 회사 목록 + + React.useEffect(() => { + getAllCompanies().then((res) => { + setCompanies(res) + }) + }, []) + + // react-hook-form 세팅 + const form = useForm({ + resolver: zodResolver(createRoleSchema), + defaultValues: { + name: "", + domain: "evcp", // 기본값 + description: "", + // companyId: null, // optional + }, + }) + + async function onSubmit(data: CreateRoleSchema) { + startAddTransition(async () => { + const result = await createRole(data) + if (result.error) { + toast.error(`에러: ${result.error}`) + return + } + form.reset() + setOpen(false) + toast.success("Role added") + }) + } + + function handleDialogOpenChange(nextOpen: boolean) { + if (!nextOpen) { + form.reset() + } + setOpen(nextOpen) + } + + // domain이 partners일 경우 companyId 입력 필드 보이게 + const selectedDomain = form.watch("domain") + + return ( + + + + + + + + Create New Role + + 새 Role 정보를 입력하고 Create 버튼을 누르세요. + + + +
+ +
+ {/* 1) Role Name */} + ( + + Role Name + + + + + + )} + /> + + {/* 2) Description */} + ( + + Role Description + +