diff options
Diffstat (limited to 'components/knox/approval/ApprovalSubmit.tsx')
| -rw-r--r-- | components/knox/approval/ApprovalSubmit.tsx | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/components/knox/approval/ApprovalSubmit.tsx b/components/knox/approval/ApprovalSubmit.tsx index bfe66981..d9ccc785 100644 --- a/components/knox/approval/ApprovalSubmit.tsx +++ b/components/knox/approval/ApprovalSubmit.tsx @@ -104,7 +104,7 @@ import { UserSelector, type UserSelectItem, } from "@/components/common/user/user-selector"; -import { useSession } from "next-auth/react"; +// next-auth 세션 의존 제거 // UserSelector에서 반환되는 사용자에 epId가 포함될 수 있으므로 확장 타입 정의 interface ExtendedUserSelectItem extends UserSelectItem { @@ -531,8 +531,8 @@ function SortableApprovalGroup({ export default function ApprovalSubmit({ onSubmitSuccess, -}: ApprovalSubmitProps) { - const { data: session } = useSession(); + currentUser, +}: ApprovalSubmitProps & { currentUser?: { id: number | string; name: string | null | undefined; email: string; epId?: string | null } }) { const [isSubmitting, setIsSubmitting] = useState(false); const [submitResult, setSubmitResult] = useState<{ apInfId: string; @@ -687,29 +687,28 @@ export default function ApprovalSubmit({ }); }; - // 로그인 사용자를 첫 번째 결재자로 보장하는 effect + // 로그인 사용자를 첫 번째 결재자로 보장하는 effect (prop만 사용) useEffect(() => { - if (!session?.user) return; - - const currentEmail = session.user.email ?? ""; - const currentEpId = (session.user as { epId?: string }).epId; - const currentUserId = session.user.id ?? undefined; + if (!currentUser?.email) return; + const effectiveEmail = currentUser.email; + const effectiveEpId = currentUser.epId ?? undefined; + const effectiveUserId = currentUser.id as string | number | undefined; let currentAplns = form.getValues("aplns"); // 이미 포함되어 있는지 확인 (epId 또는 email 기준) const selfIndex = currentAplns.findIndex( - (a) => (currentEpId && a.epId === currentEpId) || a.emailAddress === currentEmail, + (a) => (effectiveEpId && a.epId === effectiveEpId) || a.emailAddress === effectiveEmail, ); if (selfIndex === -1) { // 맨 앞에 상신자 추가 const newSelf: FormData["aplns"][number] = { id: generateUniqueId(), - epId: currentEpId, - userId: currentUserId ? currentUserId.toString() : undefined, - emailAddress: currentEmail, - name: session.user.name ?? undefined, + epId: effectiveEpId, + userId: effectiveUserId ? effectiveUserId.toString() : undefined, + emailAddress: effectiveEmail, + name: currentUser?.name ?? undefined, role: "0", // 기안 seq: "0", opinion: "", @@ -722,7 +721,7 @@ export default function ApprovalSubmit({ currentAplns = currentAplns.map((apln, idx) => ({ ...apln, seq: idx.toString() })); form.setValue("aplns", currentAplns, { shouldValidate: false, shouldDirty: true }); - }, [session, form]); + }, [currentUser, form]); // dnd-kit sensors const sensors = useSensors( @@ -856,19 +855,19 @@ export default function ApprovalSubmit({ setSubmitResult(null); try { - // 세션 정보 확인 - if (!session?.user) { - toast.error("로그인이 필요합니다."); + // 사용자 정보 (prop 전용) + if (!currentUser) { + toast.error("사용자 정보를 불러올 수 없습니다."); return; } - const currentEmail = session.user.email ?? ""; - const currentEpId = (session.user as { epId?: string }).epId; - const currentUserId = session.user.id ?? ""; + const effectiveEmail = currentUser.email; + const effectiveEpId = currentUser.epId ?? undefined; + const effectiveUserId = String(currentUser.id ?? ""); - debugLog("Current User", session.user); + debugLog("Current User", { email: effectiveEmail, epId: effectiveEpId, userId: effectiveUserId }); - if (!currentEpId) { + if (!effectiveEpId) { toast.error("사용자 정보가 올바르지 않습니다."); return; } @@ -920,9 +919,9 @@ export default function ApprovalSubmit({ const response = isSecure ? await submitSecurityApproval(submitRequest) : await submitApproval(submitRequest, { - userId: currentUserId, - epId: currentEpId, - emailAddress: currentEmail, + userId: effectiveUserId, + epId: effectiveEpId, + emailAddress: effectiveEmail, }); debugLog("Submit Response", response); |
