'use client'; import { useState } from 'react'; import { FoxButton } from '@fox/core/components/fox-button'; import { FoxButtonGroup } from '@fox/core/components/fox-button-group'; import { FoxIconButton } from '@fox/core/components/fox-icon-button'; import { useFeedback } from '@/app/_hooks/use-feedback'; import { useBlockingAction } from '@/app/_hooks/use-blocking-action'; import { formatContentExcerpt, type BoardPost } from '@/lib/domain/board-post'; import type { CommonCode } from '@/lib/domain/common-code'; import { deleteBoardPostAction, loadBoardPostAction } from '../../_actions'; import { InquiryAnswerModal } from './inquiry-answer-modal'; interface InquiryRowActionsProps { post: BoardPost; answerStatuses: readonly CommonCode[]; } /** * 1:1문의 행의 "관리" 셀 — 시안 A_BOA_012 ③. * * 공지사항·FAQ의 `BoardRowActions`와 나눈 이유: 여기서 여는 팝업이 수정 폼이 아니라 **상세 및 답변** * 팝업이고(관리자는 질문 글을 수정하지 않는다), 등록 경로도 없다. 삭제만 동작이 같다. */ export function InquiryRowActions({ post, answerStatuses, }: InquiryRowActionsProps) { const { showAlert, hideAlert, showToast } = useFeedback(); // 목록 행이 아니라 단건 조회 결과로 채운다 — 답변 중에 남이 고쳤을 수 있다. const [answerPost, setAnswerPost] = useState(null); const [isLoading, startLoading] = useBlockingAction(); const [isDeleting, startDeleting] = useBlockingAction(); function openAnswer() { startLoading(async () => { const result = await loadBoardPostAction(post.id); if (result.status === 'error') { showToast({ variant: 'danger', message: result.message }); return; } setAnswerPost(result.post); }); } function runDelete() { hideAlert(); startDeleting(async () => { const result = await deleteBoardPostAction('inquiry', post.id); if (result.status === 'error') { showToast({ variant: 'danger', message: result.message ?? '삭제하지 못했습니다.', }); return; } showToast({ variant: 'success', message: '문의를 삭제했습니다.' }); }); } function confirmDelete() { showAlert({ variant: 'danger', title: '문의를 삭제하시겠습니까?', message: `"${formatContentExcerpt(post.content, 30)}" 문의를 삭제합니다. 삭제 후에는 되돌릴 수 없습니다.`, actions: ( ), }); } return ( ); }