2026-05-26 15:48:01 +05:30
|
|
|
import { useState, useEffect, useCallback } from 'react';
|
|
|
|
|
import { getAllInquiriesApi, HealthInquiry } from '@/api/healthCheck';
|
2026-05-15 17:58:25 +05:30
|
|
|
|
2026-05-26 15:48:01 +05:30
|
|
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
|
|
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
|
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
import { Input } from '@/components/ui/input';
|
|
|
|
|
import { Badge } from '@/components/ui/badge';
|
|
|
|
|
import { Loader2, RefreshCw, ChevronLeft, ChevronRight } from 'lucide-react';
|
2026-05-15 17:58:25 +05:30
|
|
|
|
|
|
|
|
export default function PackageInquiriesTab() {
|
|
|
|
|
const [inquiries, setInquiries] = useState<HealthInquiry[]>([]);
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
2026-05-26 15:48:01 +05:30
|
|
|
const [filterDate, setFilterDate] = useState('');
|
|
|
|
|
const [startDate, setStartDate] = useState('');
|
|
|
|
|
const [endDate, setEndDate] = useState('');
|
2026-05-15 17:58:25 +05:30
|
|
|
|
|
|
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
|
|
|
const [itemsPerPage, setItemsPerPage] = useState(10);
|
|
|
|
|
const [totalItems, setTotalItems] = useState(0);
|
|
|
|
|
const [totalPages, setTotalPages] = useState(1);
|
|
|
|
|
|
|
|
|
|
const fetchInquiries = useCallback(async () => {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
try {
|
2026-05-26 15:48:01 +05:30
|
|
|
const res = await getAllInquiriesApi(currentPage, itemsPerPage, filterDate, startDate, endDate);
|
2026-05-15 17:58:25 +05:30
|
|
|
setInquiries(res.data || []);
|
|
|
|
|
setTotalItems(res.pagination?.total || 0);
|
|
|
|
|
setTotalPages(res.pagination?.totalPages || 1);
|
|
|
|
|
} catch (err) {
|
2026-05-26 15:48:01 +05:30
|
|
|
console.error('Failed to fetch inquiries', err);
|
2026-05-15 17:58:25 +05:30
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
}, [currentPage, itemsPerPage, filterDate, startDate, endDate]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchInquiries();
|
|
|
|
|
}, [fetchInquiries]);
|
|
|
|
|
|
2026-05-26 15:48:01 +05:30
|
|
|
const handleFilterChange = (setter: React.Dispatch<React.SetStateAction<string>>, value: string) => {
|
2026-05-15 17:58:25 +05:30
|
|
|
setter(value);
|
|
|
|
|
setCurrentPage(1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const indexOfFirstItem = (currentPage - 1) * itemsPerPage;
|
|
|
|
|
const indexOfLastItem = Math.min(currentPage * itemsPerPage, totalItems);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader className="flex flex-col md:flex-row items-start md:items-center justify-between gap-4">
|
|
|
|
|
<CardTitle className="text-xl">Package Inquiries</CardTitle>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-wrap items-end gap-3">
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-05-26 15:48:01 +05:30
|
|
|
<label className="text-xs font-medium text-muted-foreground">Specific Date</label>
|
2026-05-15 17:58:25 +05:30
|
|
|
<Input
|
|
|
|
|
type="date"
|
|
|
|
|
value={filterDate}
|
2026-05-26 15:48:01 +05:30
|
|
|
onChange={(e) => handleFilterChange(setFilterDate, e.target.value)}
|
2026-05-15 17:58:25 +05:30
|
|
|
className="w-[140px] text-sm"
|
|
|
|
|
disabled={!!startDate || !!endDate}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-05-26 15:48:01 +05:30
|
|
|
<label className="text-xs font-medium text-muted-foreground">From</label>
|
2026-05-15 17:58:25 +05:30
|
|
|
<Input
|
|
|
|
|
type="date"
|
|
|
|
|
value={startDate}
|
|
|
|
|
onChange={(e) => handleFilterChange(setStartDate, e.target.value)}
|
|
|
|
|
className="w-[140px] text-sm"
|
|
|
|
|
disabled={!!filterDate}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-05-26 15:48:01 +05:30
|
|
|
<label className="text-xs font-medium text-muted-foreground">To</label>
|
2026-05-15 17:58:25 +05:30
|
|
|
<Input
|
|
|
|
|
type="date"
|
|
|
|
|
value={endDate}
|
|
|
|
|
onChange={(e) => handleFilterChange(setEndDate, e.target.value)}
|
|
|
|
|
className="w-[140px] text-sm"
|
|
|
|
|
disabled={!!filterDate}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-05-26 15:48:01 +05:30
|
|
|
<label className="text-xs font-medium text-muted-foreground">Rows</label>
|
2026-05-15 17:58:25 +05:30
|
|
|
<select
|
|
|
|
|
value={itemsPerPage}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setItemsPerPage(Number(e.target.value));
|
|
|
|
|
setCurrentPage(1);
|
|
|
|
|
}}
|
2026-05-26 15:48:01 +05:30
|
|
|
className="flex h-10 rounded-md border border-input bg-background px-3 py-2 text-sm focus:ring-2 focus:ring-primary"
|
|
|
|
|
>
|
2026-05-15 17:58:25 +05:30
|
|
|
<option value={5}>5 / page</option>
|
|
|
|
|
<option value={10}>10 / page</option>
|
|
|
|
|
<option value={20}>20 / page</option>
|
|
|
|
|
<option value={50}>50 / page</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Button variant="outline" onClick={fetchInquiries} disabled={loading}>
|
2026-05-26 15:48:01 +05:30
|
|
|
<RefreshCw className={`mr-2 h-4 w-4 ${loading ? 'animate-spin' : ''}`} />
|
2026-05-15 17:58:25 +05:30
|
|
|
Refresh
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent className="p-0 sm:p-6 sm:pt-0">
|
|
|
|
|
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
|
|
|
|
<Table className="w-full min-w-[1000px] table-fixed border-separate border-spacing-0">
|
|
|
|
|
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
|
|
|
|
<TableRow>
|
2026-05-26 15:48:01 +05:30
|
|
|
<TableHead className="w-[150px] font-bold bg-background">Requested Date</TableHead>
|
|
|
|
|
<TableHead className="w-[220px] font-bold bg-background">Patient Details</TableHead>
|
|
|
|
|
<TableHead className="w-[250px] font-bold bg-background">Requested Package</TableHead>
|
|
|
|
|
<TableHead className="w-[120px] font-bold bg-background">Age/Gender</TableHead>
|
|
|
|
|
<TableHead className="w-[250px] font-bold bg-background">Message</TableHead>
|
2026-05-15 17:58:25 +05:30
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{loading ? (
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableCell colSpan={5} className="text-center py-10">
|
|
|
|
|
<Loader2 className="h-8 w-8 animate-spin mx-auto" />
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
) : inquiries.length === 0 ? (
|
|
|
|
|
<TableRow>
|
2026-05-26 15:48:01 +05:30
|
|
|
<TableCell colSpan={5} className="text-center text-muted-foreground py-10">
|
2026-05-15 17:58:25 +05:30
|
|
|
No inquiries found for the selected criteria
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
) : (
|
|
|
|
|
inquiries.map((inq) => (
|
|
|
|
|
<TableRow key={inq.id} className="hover:bg-muted/50">
|
|
|
|
|
<TableCell>
|
|
|
|
|
<div className="font-semibold text-primary">
|
|
|
|
|
{new Date(inq.preferredDate).toLocaleDateString()}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-[11px] text-muted-foreground mt-1">
|
2026-05-26 15:48:01 +05:30
|
|
|
Submitted: {new Date(inq.createdAt).toLocaleDateString()}
|
2026-05-15 17:58:25 +05:30
|
|
|
</div>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
2026-05-26 15:48:01 +05:30
|
|
|
<div className="font-semibold text-base">{inq.fullName}</div>
|
2026-05-15 17:58:25 +05:30
|
|
|
<div className="text-sm">{inq.mobileNumber}</div>
|
2026-05-26 15:48:01 +05:30
|
|
|
<div className="text-xs text-muted-foreground">{inq.email || '-'}</div>
|
2026-05-15 17:58:25 +05:30
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
2026-05-26 15:48:01 +05:30
|
|
|
<div className="font-semibold text-sm truncate">{inq.healthPackage?.name || 'N/A'}</div>
|
2026-05-15 17:58:25 +05:30
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<div className="font-medium">
|
|
|
|
|
{inq.age} yrs / {inq.gender}
|
|
|
|
|
</div>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TooltipProvider>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<div className="text-sm italic line-clamp-3 text-muted-foreground whitespace-pre-wrap cursor-pointer">
|
2026-05-26 15:48:01 +05:30
|
|
|
{inq.message || 'No message provided.'}
|
2026-05-15 17:58:25 +05:30
|
|
|
</div>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
|
|
|
|
|
<TooltipContent className="max-w-md whitespace-pre-wrap">
|
2026-05-26 15:48:01 +05:30
|
|
|
{inq.message || 'No message provided.'}
|
2026-05-15 17:58:25 +05:30
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
</TableRow>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{!loading && totalItems > 0 && (
|
|
|
|
|
<div className="flex flex-col sm:flex-row items-center justify-between px-2 py-4 border-t gap-4 mt-2">
|
|
|
|
|
<div className="text-sm text-muted-foreground">
|
2026-05-26 15:48:01 +05:30
|
|
|
Showing <span className="font-semibold">{indexOfFirstItem + 1}</span> to{' '}
|
|
|
|
|
<span className="font-semibold">{indexOfLastItem}</span> of{' '}
|
2026-05-15 17:58:25 +05:30
|
|
|
<span className="font-semibold">{totalItems}</span> inquiries
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-6">
|
|
|
|
|
<div className="text-sm font-semibold">
|
|
|
|
|
Page {currentPage} of {totalPages || 1}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-9 w-9"
|
2026-05-26 15:48:01 +05:30
|
|
|
onClick={() => setCurrentPage((prev) => Math.max(prev - 1, 1))}
|
|
|
|
|
disabled={currentPage === 1}
|
|
|
|
|
>
|
2026-05-15 17:58:25 +05:30
|
|
|
<ChevronLeft className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-9 w-9"
|
2026-05-26 15:48:01 +05:30
|
|
|
onClick={() => setCurrentPage((prev) => Math.min(prev + 1, totalPages))}
|
|
|
|
|
disabled={currentPage === totalPages || totalPages === 0}
|
|
|
|
|
>
|
2026-05-15 17:58:25 +05:30
|
|
|
<ChevronRight className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|