"use client"; import React, { useEffect, useState } from "react"; import { getMySubstitutes } from "@/lib/api/substitute"; /** * ProfileModal 내부 read-only 섹션: 내가 위임한 / 나를 대무 중인 관계. * * Spec: .omc/specs/deep-dive-user-substitute-management.md * Plan: .omc/plans/autopilot-impl.md (T12) * * 지정/수정/해지 버튼 없음 — 관리자가 admin/userMng 에서만 변경 가능 (B4). */ export function MySubstituteView({ isVisible }: { isVisible: boolean }) { const [proxyingForMe, setProxyingForMe] = useState[]>([]); const [myProxies, setMyProxies] = useState[]>([]); const [loading, setLoading] = useState(false); useEffect(() => { if (!isVisible) return; let cancelled = false; (async () => { setLoading(true); const res = await getMySubstitutes(); if (cancelled) return; if (res.success && res.data) { setProxyingForMe(res.data.proxying_for_me ?? []); setMyProxies(res.data.my_proxies ?? []); } setLoading(false); })(); return () => { cancelled = true; }; }, [isVisible]); const statusBadge = (row: Record) => { const status = row.status as string | undefined; const baseClass = "ml-1 inline-block rounded px-1.5 py-0.5 text-[0.65rem] font-medium border"; if (status === "active") return 활성; if (status === "upcoming") return 예정; return null; }; const renderRow = (r: Record, target: "proxy" | "original") => { const personName = target === "proxy" ? r.proxy_user_name || r.proxy_user_id : r.original_user_name || r.original_user_id; const deptName = target === "proxy" ? r.proxy_dept_name : r.original_dept_name; const days = r.days_remaining; return (
{personName} {deptName && ({deptName})} {statusBadge(r)}
{r.start_date ?? "즉시"} ~ {r.end_date} {typeof days === "number" && days >= 0 && ( D-{days} )}
); }; return (
나의 대무 관계
{loading ? (
불러오는 중...
) : ( <>
내 대무자 (내 부재 시 대신 처리할 사람)
{proxyingForMe.length === 0 ? (
없음
) : ( proxyingForMe.map((r) => renderRow(r, "proxy")) )}
내가 대무 중인 사람 (현재 권한을 빌려쓰고 있음)
{myProxies.length === 0 ? (
없음
) : ( myProxies.map((r) => renderRow(r, "original")) )}

대무자 지정/해지는 관리자만 가능합니다.

)}
); }