"use client"; import { Correspondence, Attachment } from "@/types/correspondence"; import { StatusBadge } from "@/components/common/status-badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { format } from "date-fns"; import { ArrowLeft, Download, FileText, Loader2, Send, CheckCircle, XCircle } from "lucide-react"; import Link from "next/link"; import { useSubmitCorrespondence, useProcessWorkflow } from "@/hooks/use-correspondence"; import { useState } from "react"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; interface CorrespondenceDetailProps { data: Correspondence; } export function CorrespondenceDetail({ data }: CorrespondenceDetailProps) { const submitMutation = useSubmitCorrespondence(); const processMutation = useProcessWorkflow(); const [actionState, setActionState] = useState<"approve" | "reject" | null>(null); const [comments, setComments] = useState(""); const handleSubmit = () => { if (confirm("Are you sure you want to submit this correspondence?")) { // TODO: Implement Template Selection. Hardcoded to 1 for now. submitMutation.mutate({ id: data.correspondenceId, data: {} }); } }; const handleProcess = () => { if (!actionState) return; const action = actionState === "approve" ? "APPROVE" : "REJECT"; processMutation.mutate({ id: data.correspondenceId, data: { action, comments } }, { onSuccess: () => { setActionState(null); setComments(""); } }); }; return (
Created on {format(new Date(data.createdAt), "dd MMM yyyy HH:mm")}
{data.description || "No description provided."}
No attachments.
)}Importance
From Organization
{data.fromOrganization?.orgName}
{data.fromOrganization?.orgCode}
To Organization
{data.toOrganization?.orgName}
{data.toOrganization?.orgCode}