'use client'; import { use } from 'react'; import { useRouter } from 'next/navigation'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { getApvreqDetail, requestApvreq, deleteApvreq, APRVL_STUS, APRVL_STUS_LABEL, APRVL_KIND_LABEL, } from '@/lib/api/tam'; import { useAuthStore } from '@/lib/store/authStore'; import ApvreqForm from '@/components/tam/ApvreqForm'; import ApproverSection from '@/components/tam/ApproverSection'; import ApvdocInfo from '@/components/tam/ApvdocInfo'; export default function Tam0020DetailPage({ params }: { params: Promise<{ docId: string }> }) { const { docId } = use(params); const router = useRouter(); const qc = useQueryClient(); const usrId = useAuthStore((s) => s.user?.usrId); const { data, isLoading } = useQuery({ queryKey: ['apvreq', docId], queryFn: () => getApvreqDetail(docId), }); const requestMut = useMutation({ mutationFn: (apprList: Array<{ apprId: string }>) => requestApvreq(docId, apprList), onSuccess: () => { qc.invalidateQueries({ queryKey: ['apvreq'] }); qc.invalidateQueries({ queryKey: ['apvreq', docId] }); alert('결재 상신이 완료되었습니다.'); }, onError: (e: any) => alert(e?.response?.data?.message ?? '상신 오류'), }); const delMut = useMutation({ mutationFn: () => deleteApvreq(docId), onSuccess: () => router.push('/tam/0020/list'), onError: (e: any) => alert(e?.response?.data?.message ?? '삭제 오류'), }); if (isLoading) return
불러오는 중...
; if (!data) return
문서를 찾을 수 없습니다.
; const isOwner = data.aplntId === usrId; const isWriting = data.aprvlStusCd === APRVL_STUS.WRITING; const handleRequest = (apprList: Array<{ apprId: string }>) => { if (apprList.length < 2) { alert('결재자를 2명 이상 지정해주세요.'); return; } if (!confirm(`결재자 ${apprList.length}명으로 상신하시겠습니까?`)) return; requestMut.mutate(apprList); }; const handleDelete = () => { if (!confirm('신청서를 삭제하시겠습니까?')) return; delMut.mutate(); }; return (

결재 신청 상세

{/* 문서 정보 (읽기전용 or 편집) */} {isOwner && isWriting ? ( qc.invalidateQueries({ queryKey: ['apvreq', docId] })} onCancel={() => router.back()} /> ) : ( )} {/* 결재선 */} {/* 버튼 영역 */} {isOwner && isWriting && (
)}
); }