2026-06-05 17:05:27 +00:00
|
|
|
import { useLanguage } from "../contexts/LanguageContext";
|
2026-06-05 17:12:44 +00:00
|
|
|
import {
|
|
|
|
|
useListRequests,
|
|
|
|
|
getListRequestsQueryKey,
|
|
|
|
|
useVerifyRequest,
|
|
|
|
|
usePublishRequest,
|
|
|
|
|
useDeliverSupport,
|
|
|
|
|
useConfirmReceipt,
|
|
|
|
|
useCloseRequest,
|
|
|
|
|
useRejectRequest,
|
|
|
|
|
} from "@workspace/api-client-react";
|
2026-06-05 17:05:27 +00:00
|
|
|
import { useQueryClient } from "@tanstack/react-query";
|
2026-06-05 17:12:44 +00:00
|
|
|
import {
|
|
|
|
|
Table, TableBody, TableCell, TableHead,
|
|
|
|
|
TableHeader, TableRow,
|
|
|
|
|
} from "@/components/ui/table";
|
2026-06-05 17:05:27 +00:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
|
import { Link } from "wouter";
|
|
|
|
|
|
|
|
|
|
export default function Admin() {
|
|
|
|
|
const { t } = useLanguage();
|
|
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
const { data: requests, isLoading } = useListRequests();
|
2026-06-05 17:12:44 +00:00
|
|
|
|
2026-06-05 17:05:27 +00:00
|
|
|
const verifyRequest = useVerifyRequest();
|
|
|
|
|
const publishRequest = usePublishRequest();
|
|
|
|
|
const deliverSupport = useDeliverSupport();
|
|
|
|
|
const confirmReceipt = useConfirmReceipt();
|
|
|
|
|
const closeRequest = useCloseRequest();
|
|
|
|
|
const rejectRequest = useRejectRequest();
|
|
|
|
|
|
|
|
|
|
const handleAction = async (action: any, id: string) => {
|
|
|
|
|
try {
|
|
|
|
|
await action.mutateAsync({ id });
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: getListRequestsQueryKey() });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="container mx-auto px-4 py-12">
|
|
|
|
|
<h1 className="text-3xl font-bold text-foreground mb-8">{t.admin.title}</h1>
|
2026-06-05 17:12:44 +00:00
|
|
|
|
2026-06-05 17:05:27 +00:00
|
|
|
<div className="bg-card rounded-xl border overflow-hidden shadow-sm">
|
|
|
|
|
<Table>
|
|
|
|
|
<TableHeader className="bg-muted/50">
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableHead>{t.admin.caseId}</TableHead>
|
|
|
|
|
<TableHead>{t.admin.beneficiary}</TableHead>
|
2026-06-05 17:12:44 +00:00
|
|
|
<TableHead>{t.admin.needType}</TableHead>
|
|
|
|
|
<TableHead>{t.admin.amount}</TableHead>
|
2026-06-05 17:05:27 +00:00
|
|
|
<TableHead>{t.admin.status}</TableHead>
|
|
|
|
|
<TableHead>{t.admin.currentStep}</TableHead>
|
|
|
|
|
<TableHead className="text-right">{t.admin.actions}</TableHead>
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableCell colSpan={7} className="text-center py-8 text-muted-foreground">
|
|
|
|
|
{t.common.loading}
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
) : requests?.map((req) => (
|
|
|
|
|
<TableRow key={req.id}>
|
|
|
|
|
<TableCell className="font-mono text-xs">{req.caseId}</TableCell>
|
|
|
|
|
<TableCell>{req.beneficiaryName}</TableCell>
|
2026-06-05 17:12:44 +00:00
|
|
|
<TableCell>
|
|
|
|
|
{t.needTypes[req.needType as keyof typeof t.needTypes] || req.needType}
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>{req.requestedAmount.toLocaleString()} ﷼</TableCell>
|
2026-06-05 17:05:27 +00:00
|
|
|
<TableCell>
|
|
|
|
|
<Badge variant="secondary" className="font-normal">
|
|
|
|
|
{t.statuses[req.status as keyof typeof t.statuses] || req.status}
|
|
|
|
|
</Badge>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>{req.currentStep}/10</TableCell>
|
|
|
|
|
<TableCell className="text-right">
|
2026-06-05 17:12:44 +00:00
|
|
|
<div className="flex items-center justify-end gap-2 flex-wrap">
|
2026-06-05 17:05:27 +00:00
|
|
|
<Link href={`/track/${req.id}`}>
|
2026-06-05 17:12:44 +00:00
|
|
|
<Button variant="outline" size="sm">{t.admin.track}</Button>
|
2026-06-05 17:05:27 +00:00
|
|
|
</Link>
|
2026-06-05 17:12:44 +00:00
|
|
|
{req.status === "new" && (
|
2026-06-05 17:05:27 +00:00
|
|
|
<>
|
2026-06-05 17:12:44 +00:00
|
|
|
<Button size="sm" onClick={() => handleAction(verifyRequest, req.id)}>
|
|
|
|
|
{t.admin.verify}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button size="sm" variant="destructive" onClick={() => handleAction(rejectRequest, req.id)}>
|
|
|
|
|
{t.admin.reject}
|
|
|
|
|
</Button>
|
2026-06-05 17:05:27 +00:00
|
|
|
</>
|
|
|
|
|
)}
|
2026-06-05 17:12:44 +00:00
|
|
|
{req.status === "pending_review" && (
|
|
|
|
|
<>
|
|
|
|
|
<Button size="sm" onClick={() => handleAction(verifyRequest, req.id)}>
|
|
|
|
|
{t.admin.verify}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button size="sm" variant="destructive" onClick={() => handleAction(rejectRequest, req.id)}>
|
|
|
|
|
{t.admin.reject}
|
|
|
|
|
</Button>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{req.status === "verified" && (
|
|
|
|
|
<Button size="sm" onClick={() => handleAction(publishRequest, req.id)}>
|
|
|
|
|
{t.admin.publish}
|
|
|
|
|
</Button>
|
2026-06-05 17:05:27 +00:00
|
|
|
)}
|
2026-06-05 17:12:44 +00:00
|
|
|
{req.status === "donated" && (
|
|
|
|
|
<Button size="sm" onClick={() => handleAction(deliverSupport, req.id)}>
|
|
|
|
|
{t.admin.deliver}
|
|
|
|
|
</Button>
|
2026-06-05 17:05:27 +00:00
|
|
|
)}
|
2026-06-05 17:12:44 +00:00
|
|
|
{req.status === "delivered" && (
|
|
|
|
|
<Button size="sm" onClick={() => handleAction(confirmReceipt, req.id)}>
|
|
|
|
|
{t.admin.confirmReceipt}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
{req.status === "receipt_confirmed" && (
|
|
|
|
|
<Link href={`/thank-you/${req.id}`}>
|
|
|
|
|
<Button size="sm" variant="outline">
|
|
|
|
|
{t.track.submitThankYou}
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
2026-06-05 17:05:27 +00:00
|
|
|
)}
|
2026-06-05 17:12:44 +00:00
|
|
|
{req.status === "thank_you_submitted" && (
|
|
|
|
|
<Link href="/whatsapp-log">
|
|
|
|
|
<Button size="sm" variant="outline">{t.admin.whatsapp}</Button>
|
2026-06-05 17:05:27 +00:00
|
|
|
</Link>
|
|
|
|
|
)}
|
2026-06-05 17:12:44 +00:00
|
|
|
{req.status === "whatsapp_sent" && (
|
|
|
|
|
<Button size="sm" onClick={() => handleAction(closeRequest, req.id)}>
|
|
|
|
|
{t.admin.close}
|
|
|
|
|
</Button>
|
2026-06-05 17:05:27 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
))}
|
|
|
|
|
{(!requests || requests.length === 0) && !isLoading && (
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableCell colSpan={7} className="text-center py-8 text-muted-foreground">
|
2026-06-05 17:12:44 +00:00
|
|
|
{t.admin.noRequests}
|
2026-06-05 17:05:27 +00:00
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
)}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2026-06-05 17:12:44 +00:00
|
|
|
}
|