From a4ceade24d28af0bde985bf750017efc02f053ff Mon Sep 17 00:00:00 2001 From: 0-Zz-ang Date: Thu, 13 Nov 2025 11:36:15 +0900 Subject: (박서영)준법설문조사 RedFlag관련 요청사항 반영 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compliance/table/red-flag-managers-dialog.tsx | 203 ++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 lib/compliance/table/red-flag-managers-dialog.tsx (limited to 'lib/compliance/table/red-flag-managers-dialog.tsx') diff --git a/lib/compliance/table/red-flag-managers-dialog.tsx b/lib/compliance/table/red-flag-managers-dialog.tsx new file mode 100644 index 00000000..08244f9e --- /dev/null +++ b/lib/compliance/table/red-flag-managers-dialog.tsx @@ -0,0 +1,203 @@ +"use client"; + +import * as React from "react"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { Label } from "@/components/ui/label"; +import { AlertCircle, Users } from "lucide-react"; +import { toast } from "sonner"; +import { useRouter } from "next/navigation"; +import { UserSelector, UserSelectItem } from "@/components/common/user/user-selector"; +import { + getOrCreateRedFlagManagers, + updateRedFlagManagers +} from "@/lib/compliance/services"; + +export function RedFlagManagersDialog() { + const [open, setOpen] = React.useState(false); + const [isLoading, setIsLoading] = React.useState(false); + const [isFetching, setIsFetching] = React.useState(false); + const router = useRouter(); + + // 담당자 state + const [managerId, setManagerId] = React.useState(null); + const [purchasingManager, setPurchasingManager] = React.useState([]); + const [complianceManager, setComplianceManager] = React.useState([]); + + // 다이얼로그 열릴 때 현재 담당자 정보 가져오기 + React.useEffect(() => { + if (open) { + loadManagers(); + } + }, [open]); + + const loadManagers = async () => { + setIsFetching(true); + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const managers: any = await getOrCreateRedFlagManagers(); + + if (managers) { + setManagerId(managers.id); + + // 구매기획 담당자 설정 + if (managers.purchasingManager) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const pm: any = managers.purchasingManager; + setPurchasingManager([{ + id: pm.id, + name: pm.name, + email: pm.email, + epId: pm.epId, + deptCode: pm.deptCode, + deptName: pm.deptName, + imageUrl: pm.imageUrl, + domain: pm.domain, + }]); + } + + // 준법 담당자 설정 + if (managers.complianceManager) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const cm: any = managers.complianceManager; + setComplianceManager([{ + id: cm.id, + name: cm.name, + email: cm.email, + epId: cm.epId, + deptCode: cm.deptCode, + deptName: cm.deptName, + imageUrl: cm.imageUrl, + domain: cm.domain, + }]); + } + } + } catch (error) { + console.error("Error loading red flag managers:", error); + toast.error("담당자 정보를 불러오는 중 오류가 발생했습니다."); + } finally { + setIsFetching(false); + } + }; + + const handleSave = async () => { + if (!managerId) { + toast.error("담당자 정보를 불러오지 못했습니다."); + return; + } + + setIsLoading(true); + try { + await updateRedFlagManagers(managerId, { + purchasingManagerId: purchasingManager[0]?.id || null, + complianceManagerId: complianceManager[0]?.id || null, + }); + + toast.success("레드플래그 담당자가 저장되었습니다."); + setOpen(false); + router.refresh(); + } catch (error) { + console.error("Error saving red flag managers:", error); + toast.error("담당자 저장 중 오류가 발생했습니다."); + } finally { + setIsLoading(false); + } + }; + + return ( + + + + + + + + + 레드플래그 담당자 관리 + + + 레드플래그 발생 시 알림을 받을 담당자를 지정합니다. + + + + {isFetching ? ( +
+
+ 담당자 정보를 불러오는 중... +
+
+ ) : ( +
+ {/* 구매기획 담당자 */} +
+ + +

+ 레드플래그 발생 시 알림을 받을 구매기획 담당자를 지정합니다. +

+
+ + {/* 준법 담당자 */} +
+ + +

+ 레드플래그 발생 시 알림을 받을 준법 담당자를 지정합니다. +

+
+
+ )} + + + + + +
+
+ ); +} + -- cgit v1.2.3