Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6a041ac10 |
@@ -1,10 +1,10 @@
|
|||||||
import prisma from "../prisma/client.js";
|
import prisma from "../prisma/client.js";
|
||||||
import {sendEmail} from "../utils/sendEmail.js";
|
import { sendEmail } from "../utils/sendEmail.js";
|
||||||
import {getEmailsByType} from "../utils/getEmailByTypes.js";
|
import { getEmailsByType } from "../utils/getEmailByTypes.js";
|
||||||
|
|
||||||
export const createAppointment = async (req, res) => {
|
export const createAppointment = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const {name, mobileNumber, email, message, date, doctorId, departmentId} =
|
const { name, mobileNumber, email, message, date, doctorId, departmentId } =
|
||||||
req.body;
|
req.body;
|
||||||
|
|
||||||
if (!name || !mobileNumber || !doctorId || !departmentId || !date) {
|
if (!name || !mobileNumber || !doctorId || !departmentId || !date) {
|
||||||
@@ -71,19 +71,98 @@ export const createAppointment = async (req, res) => {
|
|||||||
|
|
||||||
export const getAppointments = async (req, res) => {
|
export const getAppointments = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const appointments = await prisma.appointment.findMany({
|
const page = parseInt(req.query.page);
|
||||||
include: {
|
const limit = parseInt(req.query.limit);
|
||||||
doctor: true,
|
|
||||||
department: true,
|
|
||||||
},
|
|
||||||
orderBy: {
|
|
||||||
createdAt: "desc",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
res.status(200).json({
|
const search = req.query.search || "";
|
||||||
|
const doctor = req.query.doctor || "";
|
||||||
|
const department = req.query.department || "";
|
||||||
|
const date = req.query.date || "";
|
||||||
|
|
||||||
|
if (!page && !limit) {
|
||||||
|
const appointments = await prisma.appointment.findMany({
|
||||||
|
include: {
|
||||||
|
doctor: true,
|
||||||
|
department: true,
|
||||||
|
},
|
||||||
|
orderBy: { createdAt: "desc" },
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
data: appointments,
|
||||||
|
meta: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentPage = page || 1;
|
||||||
|
const currentLimit = limit || 10;
|
||||||
|
const skip = (currentPage - 1) * currentLimit;
|
||||||
|
|
||||||
|
const where = {
|
||||||
|
AND: [
|
||||||
|
search
|
||||||
|
? {
|
||||||
|
OR: [
|
||||||
|
{ name: { contains: search, mode: "insensitive" } },
|
||||||
|
{ mobileNumber: { contains: search } },
|
||||||
|
{ email: { contains: search, mode: "insensitive" } },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
|
||||||
|
doctor
|
||||||
|
? {
|
||||||
|
doctor: {
|
||||||
|
name: { contains: doctor, mode: "insensitive" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
|
||||||
|
department
|
||||||
|
? {
|
||||||
|
department: {
|
||||||
|
name: { contains: department, mode: "insensitive" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
|
||||||
|
date
|
||||||
|
? {
|
||||||
|
date: {
|
||||||
|
gte: new Date(date),
|
||||||
|
lt: new Date(
|
||||||
|
new Date(date).setDate(new Date(date).getDate() + 1),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const [appointments, total] = await Promise.all([
|
||||||
|
prisma.appointment.findMany({
|
||||||
|
where,
|
||||||
|
include: {
|
||||||
|
doctor: true,
|
||||||
|
department: true,
|
||||||
|
},
|
||||||
|
orderBy: { createdAt: "desc" },
|
||||||
|
skip,
|
||||||
|
take: currentLimit,
|
||||||
|
}),
|
||||||
|
prisma.appointment.count({ where }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
data: appointments,
|
data: appointments,
|
||||||
|
meta: {
|
||||||
|
total,
|
||||||
|
page: currentPage,
|
||||||
|
limit: currentLimit,
|
||||||
|
totalPages: Math.ceil(total / currentLimit),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -98,7 +177,7 @@ export const getAppointments = async (req, res) => {
|
|||||||
|
|
||||||
export const getAppointment = async (req, res) => {
|
export const getAppointment = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const {id} = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
const appointment = await prisma.appointment.findUnique({
|
const appointment = await prisma.appointment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
@@ -134,7 +213,7 @@ export const getAppointment = async (req, res) => {
|
|||||||
|
|
||||||
export const getAppointmentsByDoctor = async (req, res) => {
|
export const getAppointmentsByDoctor = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const {doctorId} = req.params;
|
const { doctorId } = req.params;
|
||||||
|
|
||||||
const appointments = await prisma.appointment.findMany({
|
const appointments = await prisma.appointment.findMany({
|
||||||
where: {
|
where: {
|
||||||
@@ -166,7 +245,7 @@ export const getAppointmentsByDoctor = async (req, res) => {
|
|||||||
|
|
||||||
export const getAppointmentsByDepartment = async (req, res) => {
|
export const getAppointmentsByDepartment = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const {departmentId} = req.params;
|
const { departmentId } = req.params;
|
||||||
|
|
||||||
const appointments = await prisma.appointment.findMany({
|
const appointments = await prisma.appointment.findMany({
|
||||||
where: {
|
where: {
|
||||||
@@ -195,7 +274,7 @@ export const getAppointmentsByDepartment = async (req, res) => {
|
|||||||
|
|
||||||
export const updateAppointment = async (req, res) => {
|
export const updateAppointment = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const {id} = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
const appointment = await prisma.appointment.update({
|
const appointment = await prisma.appointment.update({
|
||||||
where: {
|
where: {
|
||||||
@@ -226,7 +305,7 @@ export const updateAppointment = async (req, res) => {
|
|||||||
|
|
||||||
export const deleteAppointment = async (req, res) => {
|
export const deleteAppointment = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const {id} = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
await prisma.appointment.delete({
|
await prisma.appointment.delete({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -1,7 +1,22 @@
|
|||||||
import apiClient from "@/api/client";
|
import apiClient from "@/api/client";
|
||||||
|
|
||||||
export const getAppointmentsApi = async () => {
|
export const getAppointmentsApi = async (
|
||||||
const res = await apiClient.get("/appointments/getall");
|
page?: number,
|
||||||
|
limit?: number,
|
||||||
|
search?: string,
|
||||||
|
doctor?: string,
|
||||||
|
department?: string,
|
||||||
|
date?: string,
|
||||||
|
) => {
|
||||||
|
let url = "/appointments/getAll";
|
||||||
|
|
||||||
|
if (page && limit) {
|
||||||
|
url += `?page=${page}&limit=${limit}&search=${search || ""}&doctor=${
|
||||||
|
doctor || ""
|
||||||
|
}&department=${department || ""}&date=${date || ""}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await apiClient.get(url);
|
||||||
return res.data;
|
return res.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
import * as React from "react"
|
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
|
||||||
import { Slot } from "radix-ui"
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
|
|
||||||
const badgeVariants = cva(
|
|
||||||
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!",
|
|
||||||
{
|
|
||||||
variants: {
|
|
||||||
variant: {
|
|
||||||
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
|
||||||
secondary:
|
|
||||||
"bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
|
|
||||||
destructive:
|
|
||||||
"bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
|
|
||||||
outline:
|
|
||||||
"border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
|
|
||||||
ghost:
|
|
||||||
"hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
|
|
||||||
link: "text-primary underline-offset-4 hover:underline",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
defaultVariants: {
|
|
||||||
variant: "default",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
function Badge({
|
|
||||||
className,
|
|
||||||
variant = "default",
|
|
||||||
asChild = false,
|
|
||||||
...props
|
|
||||||
}: React.ComponentProps<"span"> &
|
|
||||||
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
|
||||||
const Comp = asChild ? Slot.Root : "span"
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Comp
|
|
||||||
data-slot="badge"
|
|
||||||
data-variant={variant}
|
|
||||||
className={cn(badgeVariants({ variant }), className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export { Badge, badgeVariants }
|
|
||||||
@@ -13,26 +13,11 @@ import {
|
|||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogFooter,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
|
|
||||||
import {
|
import { Loader2, Trash, RefreshCw, Download } from "lucide-react";
|
||||||
Loader2,
|
|
||||||
Trash,
|
|
||||||
RefreshCw,
|
|
||||||
Download,
|
|
||||||
ChevronLeft,
|
|
||||||
ChevronRight,
|
|
||||||
Eye,
|
|
||||||
BookOpen,
|
|
||||||
} from "lucide-react";
|
|
||||||
|
|
||||||
export default function AcademicsPage() {
|
export default function AcademicsPage() {
|
||||||
const [records, setRecords] = useState<any[]>([]);
|
const [records, setRecords] = useState<any[]>([]);
|
||||||
@@ -40,12 +25,6 @@ export default function AcademicsPage() {
|
|||||||
|
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
|
|
||||||
const [viewOpen, setViewOpen] = useState(false);
|
|
||||||
const [viewData, setViewData] = useState<any>(null);
|
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
|
||||||
const itemsPerPage = 10;
|
|
||||||
|
|
||||||
const fetchAll = useCallback(async () => {
|
const fetchAll = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
@@ -72,20 +51,6 @@ export default function AcademicsPage() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setCurrentPage(1);
|
|
||||||
}, [searchText]);
|
|
||||||
|
|
||||||
const totalPages = Math.ceil(filteredRecords.length / itemsPerPage);
|
|
||||||
const indexOfLastItem = currentPage * itemsPerPage;
|
|
||||||
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
|
||||||
const currentItems = filteredRecords.slice(indexOfFirstItem, indexOfLastItem);
|
|
||||||
|
|
||||||
function openView(item: any) {
|
|
||||||
setViewData(item);
|
|
||||||
setViewOpen(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleDelete(id: number) {
|
async function handleDelete(id: number) {
|
||||||
if (!confirm("Delete record?")) return;
|
if (!confirm("Delete record?")) return;
|
||||||
await deleteAcademicsApi(id);
|
await deleteAcademicsApi(id);
|
||||||
@@ -109,29 +74,24 @@ export default function AcademicsPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
<div className="flex justify-between items-center gap-3 flex-wrap">
|
||||||
<h1 className="text-3xl font-bold">Academics & Research</h1>
|
<h1 className="text-2xl font-bold">Academics & Research</h1>
|
||||||
|
|
||||||
<div className="flex flex-wrap gap-3">
|
<div className="flex flex-wrap gap-2">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search name / course / email..."
|
placeholder="Search name / phone / email / subject..."
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
className="w-[280px] text-base"
|
className="w-[260px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button variant="outline" onClick={fetchAll} disabled={loading}>
|
||||||
variant="outline"
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
onClick={fetchAll}
|
|
||||||
disabled={loading}
|
|
||||||
className="text-base"
|
|
||||||
>
|
|
||||||
<RefreshCw className="mr-2 h-5 w-5" />
|
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button onClick={handleExport} className="text-base">
|
<Button variant="outline" onClick={handleExport}>
|
||||||
<Download className="mr-2 h-5 w-5" />
|
<Download className="mr-2 h-4 w-4" />
|
||||||
Export
|
Export
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -139,108 +99,65 @@ export default function AcademicsPage() {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">Academic Records</CardTitle>
|
<CardTitle>Academics Records</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="p-0 sm:p-6 space-y-4">
|
<CardContent>
|
||||||
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
<div className="overflow-x-auto">
|
||||||
<Table className="w-full min-w-[1100px] table-fixed border-separate border-spacing-0">
|
<Table className="min-w-[1000px]">
|
||||||
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[60px] bg-background font-bold text-sm">
|
<TableHead>ID</TableHead>
|
||||||
ID
|
<TableHead>Name</TableHead>
|
||||||
</TableHead>
|
<TableHead>Phone</TableHead>
|
||||||
<TableHead className="w-[220px] bg-background font-bold text-sm">
|
<TableHead>Email</TableHead>
|
||||||
Full Name
|
<TableHead>Course</TableHead>
|
||||||
</TableHead>
|
<TableHead>Subject</TableHead>
|
||||||
<TableHead className="w-[180px] bg-background font-bold text-sm">
|
<TableHead>Message</TableHead>
|
||||||
Course
|
<TableHead>Date</TableHead>
|
||||||
</TableHead>
|
<TableHead>Actions</TableHead>
|
||||||
<TableHead className="w-[180px] bg-background font-bold text-sm">
|
|
||||||
Subject
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[140px] bg-background font-bold text-sm">
|
|
||||||
Applied Date
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[220px] bg-background font-bold text-sm">
|
|
||||||
Message
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[120px] bg-background font-bold text-right text-sm">
|
|
||||||
Actions
|
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={7} className="text-center py-10">
|
<TableCell colSpan={9} className="text-center">
|
||||||
<Loader2 className="h-8 w-8 animate-spin mx-auto" />
|
<Loader2 className="h-6 w-6 animate-spin mx-auto" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : currentItems.length === 0 ? (
|
) : filteredRecords.length === 0 ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell colSpan={9} className="text-center">
|
||||||
colSpan={7}
|
|
||||||
className="text-center text-muted-foreground py-10 text-base"
|
|
||||||
>
|
|
||||||
No records found
|
No records found
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
currentItems.map((item) => (
|
filteredRecords.map((item) => (
|
||||||
<TableRow key={item.id} className="hover:bg-muted/50">
|
<TableRow key={item.id}>
|
||||||
<TableCell className="font-mono text-xs">
|
<TableCell>{item.id}</TableCell>
|
||||||
{item.id}
|
<TableCell>{item.fullName}</TableCell>
|
||||||
|
<TableCell>{item.number}</TableCell>
|
||||||
|
<TableCell>{item.emailId}</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.courseName}</TableCell>
|
||||||
|
<TableCell>{item.subject}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="max-w-[250px] whitespace-normal">
|
||||||
|
{item.message}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="font-semibold text-base truncate">
|
|
||||||
{item.fullName}
|
|
||||||
</div>
|
|
||||||
<div className="text-xs text-muted-foreground truncate">
|
|
||||||
{item.emailId}
|
|
||||||
</div>
|
|
||||||
<div className="text-[11px] font-medium">
|
|
||||||
{item.number}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm font-medium line-clamp-2">
|
|
||||||
{item.courseName || "-"}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm line-clamp-2">
|
|
||||||
{item.subject || "-"}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-sm">
|
|
||||||
{new Date(item.createdAt).toLocaleDateString()}
|
{new Date(item.createdAt).toLocaleDateString()}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="text-sm line-clamp-2 text-muted-foreground italic">
|
<Button
|
||||||
{item.message || "-"}
|
size="sm"
|
||||||
</div>
|
variant="destructive"
|
||||||
</TableCell>
|
onClick={() => handleDelete(item.id)}>
|
||||||
<TableCell className="text-right">
|
<Trash className="h-4 w-4" />
|
||||||
<div className="flex justify-end gap-2">
|
</Button>
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9"
|
|
||||||
onClick={() => openView(item)}
|
|
||||||
>
|
|
||||||
<Eye className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
|
||||||
onClick={() => handleDelete(item.id)}
|
|
||||||
>
|
|
||||||
<Trash className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
@@ -248,117 +165,8 @@ export default function AcademicsPage() {
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!loading && filteredRecords.length > 0 && (
|
|
||||||
<div className="flex items-center justify-between px-2 py-6 border-t">
|
|
||||||
<div className="text-base text-muted-foreground">
|
|
||||||
Showing{" "}
|
|
||||||
<span className="font-semibold">{indexOfFirstItem + 1}</span> to{" "}
|
|
||||||
<span className="font-semibold">
|
|
||||||
{Math.min(indexOfLastItem, filteredRecords.length)}
|
|
||||||
</span>{" "}
|
|
||||||
of{" "}
|
|
||||||
<span className="font-semibold">{filteredRecords.length}</span>{" "}
|
|
||||||
records
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-6">
|
|
||||||
<div className="text-base font-semibold">
|
|
||||||
Page {currentPage} of {totalPages}
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
||||||
}
|
|
||||||
disabled={currentPage === 1}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
|
||||||
}
|
|
||||||
disabled={currentPage === totalPages || totalPages === 0}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
|
||||||
<DialogContent className="w-full !max-w-3xl max-h-[85vh] overflow-y-auto">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle className="text-2xl border-b pb-2 flex items-center gap-2">
|
|
||||||
<BookOpen className="h-6 w-6" /> Academic Detail View
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
{viewData && (
|
|
||||||
<div className="space-y-6 py-4">
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Applicant Information
|
|
||||||
</p>
|
|
||||||
<p className="text-lg font-bold text-primary">
|
|
||||||
{viewData.fullName}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm font-medium">{viewData.emailId}</p>
|
|
||||||
<p className="text-sm">{viewData.number}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Course & Subject
|
|
||||||
</p>
|
|
||||||
<p className="text-base font-semibold">
|
|
||||||
{viewData.courseName || "N/A"}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{viewData.subject}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Submission Date
|
|
||||||
</p>
|
|
||||||
<p className="text-sm">
|
|
||||||
{new Date(viewData.createdAt).toLocaleString()}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div className="p-4 bg-muted/30 rounded-lg border">
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground mb-2">
|
|
||||||
Message / Research Inquiry
|
|
||||||
</p>
|
|
||||||
<p className="text-sm leading-relaxed whitespace-pre-wrap italic">
|
|
||||||
{viewData.message || "No message content provided."}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<DialogFooter>
|
|
||||||
<Button
|
|
||||||
onClick={() => setViewOpen(false)}
|
|
||||||
className="w-full md:w-auto"
|
|
||||||
>
|
|
||||||
Close
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+178
-287
@@ -15,13 +15,6 @@ import {
|
|||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogFooter,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Loader2,
|
Loader2,
|
||||||
@@ -30,7 +23,6 @@ import {
|
|||||||
Download,
|
Download,
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
Eye,
|
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
export default function AppointmentPage() {
|
export default function AppointmentPage() {
|
||||||
@@ -39,116 +31,157 @@ export default function AppointmentPage() {
|
|||||||
|
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
const [filterDoctor, setFilterDoctor] = useState("");
|
const [filterDoctor, setFilterDoctor] = useState("");
|
||||||
|
const [filterDepartment, setFilterDepartment] = useState("");
|
||||||
const [filterDate, setFilterDate] = useState("");
|
const [filterDate, setFilterDate] = useState("");
|
||||||
|
|
||||||
const [viewOpen, setViewOpen] = useState(false);
|
|
||||||
const [viewData, setViewData] = useState<any>(null);
|
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const itemsPerPage = 10;
|
const [itemsPerPage, setItemsPerPage] = useState(10);
|
||||||
|
|
||||||
|
const [meta, setMeta] = useState<any>({});
|
||||||
|
|
||||||
const fetchAll = useCallback(async () => {
|
const fetchAll = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const res = await getAppointmentsApi();
|
const res = await getAppointmentsApi(
|
||||||
|
currentPage,
|
||||||
|
itemsPerPage,
|
||||||
|
searchText,
|
||||||
|
filterDoctor,
|
||||||
|
filterDepartment,
|
||||||
|
filterDate,
|
||||||
|
);
|
||||||
|
|
||||||
setAppointments(res?.data || []);
|
setAppointments(res?.data || []);
|
||||||
|
setMeta(res?.meta || {});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [
|
||||||
|
currentPage,
|
||||||
|
itemsPerPage,
|
||||||
|
searchText,
|
||||||
|
filterDoctor,
|
||||||
|
filterDepartment,
|
||||||
|
filterDate,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAll();
|
fetchAll();
|
||||||
}, [fetchAll]);
|
}, [fetchAll]);
|
||||||
|
|
||||||
const filteredAppointments = appointments.filter((item) => {
|
|
||||||
const matchesSearch =
|
|
||||||
item.name?.toLowerCase().includes(searchText.toLowerCase()) ||
|
|
||||||
item.mobileNumber?.includes(searchText) ||
|
|
||||||
item.email?.toLowerCase().includes(searchText.toLowerCase());
|
|
||||||
|
|
||||||
const matchesDoctor = filterDoctor
|
|
||||||
? item.doctor?.name?.toLowerCase().includes(filterDoctor.toLowerCase())
|
|
||||||
: true;
|
|
||||||
|
|
||||||
const matchesDate = filterDate
|
|
||||||
? new Date(item.date).toISOString().split("T")[0] === filterDate
|
|
||||||
: true;
|
|
||||||
|
|
||||||
return matchesSearch && matchesDoctor && matchesDate;
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setCurrentPage(1);
|
|
||||||
}, [searchText, filterDoctor, filterDate]);
|
|
||||||
|
|
||||||
const totalPages = Math.ceil(filteredAppointments.length / itemsPerPage);
|
|
||||||
const indexOfLastItem = currentPage * itemsPerPage;
|
|
||||||
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
|
||||||
const currentItems = filteredAppointments.slice(
|
|
||||||
indexOfFirstItem,
|
|
||||||
indexOfLastItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
function openView(item: any) {
|
|
||||||
setViewData(item);
|
|
||||||
setViewOpen(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleDelete(id: number) {
|
async function handleDelete(id: number) {
|
||||||
if (!confirm("Delete appointment?")) return;
|
if (!confirm("Delete appointment?")) return;
|
||||||
await deleteAppointmentApi(id);
|
await deleteAppointmentApi(id);
|
||||||
fetchAll();
|
fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleExport = () => {
|
const handleExport = async () => {
|
||||||
const exportData = filteredAppointments.map((item) => ({
|
try {
|
||||||
ID: item.id,
|
const res = await getAppointmentsApi();
|
||||||
Name: item.name,
|
|
||||||
Phone: item.mobileNumber,
|
let data = res?.data || [];
|
||||||
Email: item.email,
|
|
||||||
Doctor: item.doctor?.name,
|
data = data.filter((item: any) => {
|
||||||
Department: item.department?.name,
|
const matchesSearch =
|
||||||
Date: new Date(item.date).toLocaleDateString(),
|
item.name?.toLowerCase().includes(searchText.toLowerCase()) ||
|
||||||
Message: item.message,
|
item.mobileNumber?.includes(searchText) ||
|
||||||
}));
|
item.email?.toLowerCase().includes(searchText.toLowerCase());
|
||||||
exportToExcel(exportData, "appointments");
|
|
||||||
|
const matchesDoctor = filterDoctor
|
||||||
|
? item.doctor?.name
|
||||||
|
?.toLowerCase()
|
||||||
|
.includes(filterDoctor.toLowerCase())
|
||||||
|
: true;
|
||||||
|
|
||||||
|
const matchesDepartment = filterDepartment
|
||||||
|
? item.department?.name
|
||||||
|
?.toLowerCase()
|
||||||
|
.includes(filterDepartment.toLowerCase())
|
||||||
|
: true;
|
||||||
|
|
||||||
|
const matchesDate = filterDate
|
||||||
|
? new Date(item.date).toISOString().split("T")[0] === filterDate
|
||||||
|
: true;
|
||||||
|
|
||||||
|
return (
|
||||||
|
matchesSearch && matchesDoctor && matchesDepartment && matchesDate
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const exportData = data.map((item: any) => ({
|
||||||
|
ID: item.id,
|
||||||
|
Name: item.name,
|
||||||
|
Phone: item.mobileNumber,
|
||||||
|
Email: item.email,
|
||||||
|
Doctor: item.doctor?.name,
|
||||||
|
Department: item.department?.name,
|
||||||
|
Date: new Date(item.date).toLocaleDateString(),
|
||||||
|
Message: item.message,
|
||||||
|
}));
|
||||||
|
|
||||||
|
exportToExcel(exportData, "appointments");
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
<div className="flex justify-between items-center flex-wrap gap-3">
|
||||||
<h1 className="text-3xl font-bold">Appointments</h1>
|
<h1 className="text-2xl font-bold">Appointments</h1>
|
||||||
|
|
||||||
<div className="flex flex-wrap gap-3">
|
<div className="flex flex-wrap gap-2 items-center">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search name / phone..."
|
placeholder="Search..."
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={(e) => {
|
||||||
className="w-[220px] text-base"
|
setSearchText(e.target.value);
|
||||||
|
setCurrentPage(1);
|
||||||
|
}}
|
||||||
|
className="w-[200px]"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
placeholder="Doctor"
|
||||||
|
value={filterDoctor}
|
||||||
|
onChange={(e) => setFilterDoctor(e.target.value)}
|
||||||
|
className="w-[160px]"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
placeholder="Department"
|
||||||
|
value={filterDepartment}
|
||||||
|
onChange={(e) => setFilterDepartment(e.target.value)}
|
||||||
|
className="w-[160px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
type="date"
|
type="date"
|
||||||
value={filterDate}
|
value={filterDate}
|
||||||
onChange={(e) => setFilterDate(e.target.value)}
|
onChange={(e) => setFilterDate(e.target.value)}
|
||||||
className="w-[160px] text-base"
|
className="w-[160px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<select
|
||||||
variant="outline"
|
value={itemsPerPage}
|
||||||
onClick={fetchAll}
|
onChange={(e) => {
|
||||||
disabled={loading}
|
setItemsPerPage(Number(e.target.value));
|
||||||
className="text-base"
|
setCurrentPage(1);
|
||||||
>
|
}}
|
||||||
<RefreshCw className="mr-2 h-5 w-5" />
|
className="border px-2 py-1 rounded">
|
||||||
Refresh
|
<option value={5}>5</option>
|
||||||
|
<option value={10}>10</option>
|
||||||
|
<option value={20}>20</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<Button onClick={fetchAll}>
|
||||||
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button onClick={handleExport} className="text-base">
|
<Button onClick={handleExport}>
|
||||||
<Download className="mr-2 h-5 w-5" />
|
<Download className="mr-2 h-4 w-4" />
|
||||||
Export
|
Export
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -156,226 +189,84 @@ export default function AppointmentPage() {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">Appointment List</CardTitle>
|
<CardTitle>Appointment List</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="p-0 sm:p-6 space-y-4">
|
<CardContent>
|
||||||
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
<Table>
|
||||||
<Table className="w-full min-w-[1000px] table-fixed border-separate border-spacing-0">
|
<TableHeader>
|
||||||
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
<TableRow>
|
||||||
|
<TableHead>ID</TableHead>
|
||||||
|
<TableHead>Name</TableHead>
|
||||||
|
<TableHead>Phone</TableHead>
|
||||||
|
<TableHead>Doctor</TableHead>
|
||||||
|
<TableHead>Department</TableHead>
|
||||||
|
<TableHead>Date</TableHead>
|
||||||
|
<TableHead>Actions</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
|
||||||
|
<TableBody>
|
||||||
|
{loading ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[60px] bg-background font-bold text-sm">
|
<TableCell colSpan={7} className="text-center">
|
||||||
ID
|
<Loader2 className="animate-spin mx-auto" />
|
||||||
</TableHead>
|
</TableCell>
|
||||||
<TableHead className="w-[200px] bg-background font-bold text-sm">
|
|
||||||
Patient
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[180px] bg-background font-bold text-sm">
|
|
||||||
Doctor
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[150px] bg-background font-bold text-sm">
|
|
||||||
Date
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[250px] bg-background font-bold text-sm">
|
|
||||||
Message
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[120px] bg-background font-bold text-right text-sm">
|
|
||||||
Actions
|
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
) : appointments.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
<TableBody>
|
<TableCell
|
||||||
{loading ? (
|
colSpan={7}
|
||||||
<TableRow>
|
className="text-center py-6 text-gray-500">
|
||||||
<TableCell colSpan={6} className="text-center py-10">
|
No appointments found
|
||||||
<Loader2 className="h-8 w-8 animate-spin mx-auto" />
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : (
|
||||||
|
appointments.map((item) => (
|
||||||
|
<TableRow key={item.id}>
|
||||||
|
<TableCell>{item.id}</TableCell>
|
||||||
|
<TableCell>{item.name}</TableCell>
|
||||||
|
<TableCell>{item.mobileNumber}</TableCell>
|
||||||
|
<TableCell>{item.doctor?.name}</TableCell>
|
||||||
|
<TableCell>{item.department?.name}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{new Date(item.date).toLocaleDateString()}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="destructive"
|
||||||
|
onClick={() => handleDelete(item.id)}>
|
||||||
|
<Trash className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : currentItems.length === 0 ? (
|
))
|
||||||
<TableRow>
|
)}
|
||||||
<TableCell
|
</TableBody>
|
||||||
colSpan={6}
|
</Table>
|
||||||
className="text-center text-muted-foreground py-10 text-base"
|
|
||||||
>
|
|
||||||
No appointments found
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
) : (
|
|
||||||
currentItems.map((item) => (
|
|
||||||
<TableRow key={item.id} className="hover:bg-muted/50">
|
|
||||||
<TableCell className="font-mono text-xs">
|
|
||||||
{item.id}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="font-semibold text-base truncate">
|
|
||||||
{item.name}
|
|
||||||
</div>
|
|
||||||
<div className="text-xs text-muted-foreground">
|
|
||||||
{item.mobileNumber}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm font-medium">
|
|
||||||
{item.doctor?.name || "-"}
|
|
||||||
</div>
|
|
||||||
<div className="text-[10px] text-muted-foreground truncate">
|
|
||||||
{item.department?.name}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm">
|
|
||||||
{new Date(item.date).toLocaleDateString()}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm line-clamp-2 text-muted-foreground italic">
|
|
||||||
{item.message || "-"}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-right">
|
|
||||||
<div className="flex justify-end gap-2">
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9"
|
|
||||||
onClick={() => openView(item)}
|
|
||||||
>
|
|
||||||
<Eye className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
|
||||||
onClick={() => handleDelete(item.id)}
|
|
||||||
>
|
|
||||||
<Trash className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{!loading && filteredAppointments.length > 0 && (
|
<div className="flex justify-between mt-4">
|
||||||
<div className="flex items-center justify-between px-2 py-6 border-t">
|
<p>
|
||||||
<div className="text-base text-muted-foreground">
|
Page {meta.page || 1} of {meta.totalPages || 1}
|
||||||
Showing{" "}
|
</p>
|
||||||
<span className="font-semibold">{indexOfFirstItem + 1}</span> to{" "}
|
|
||||||
<span className="font-semibold">
|
<div className="flex gap-2">
|
||||||
{Math.min(indexOfLastItem, filteredAppointments.length)}
|
<Button
|
||||||
</span>{" "}
|
disabled={currentPage === 1}
|
||||||
of{" "}
|
onClick={() => setCurrentPage((p) => p - 1)}>
|
||||||
<span className="font-semibold">
|
<ChevronLeft />
|
||||||
{filteredAppointments.length}
|
</Button>
|
||||||
</span>
|
|
||||||
</div>
|
<Button
|
||||||
<div className="flex items-center gap-6">
|
disabled={currentPage === meta.totalPages}
|
||||||
<div className="text-base font-semibold">
|
onClick={() => setCurrentPage((p) => p + 1)}>
|
||||||
Page {currentPage} of {totalPages}
|
<ChevronRight />
|
||||||
</div>
|
</Button>
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
||||||
}
|
|
||||||
disabled={currentPage === 1}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
|
||||||
}
|
|
||||||
disabled={currentPage === totalPages || totalPages === 0}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
|
||||||
<DialogContent className="w-full !max-w-3xl max-h-[85vh] overflow-y-auto">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle className="text-2xl border-b pb-2">
|
|
||||||
Appointment Details
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
{viewData && (
|
|
||||||
<div className="space-y-6 py-4">
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Patient Information
|
|
||||||
</p>
|
|
||||||
<p className="text-lg font-bold text-primary">
|
|
||||||
{viewData.name}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm">{viewData.mobileNumber}</p>
|
|
||||||
<p className="text-sm">
|
|
||||||
{viewData.email || "No email provided"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Appointment Date
|
|
||||||
</p>
|
|
||||||
<p className="text-base font-semibold">
|
|
||||||
{new Date(viewData.date).toLocaleDateString()}
|
|
||||||
</p>
|
|
||||||
<p className="text-[10px] text-muted-foreground">
|
|
||||||
Booked on: {new Date(viewData.createdAt).toLocaleString()}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Doctor / Department
|
|
||||||
</p>
|
|
||||||
<p className="text-base font-bold">
|
|
||||||
{viewData.doctor?.name || "Not Assigned"}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{viewData.department?.name || "General"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="p-4 bg-muted/30 rounded-lg">
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground mb-2">
|
|
||||||
Message from Patient
|
|
||||||
</p>
|
|
||||||
<p className="text-sm italic leading-relaxed whitespace-pre-wrap">
|
|
||||||
{viewData.message || "No message provided."}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<DialogFooter>
|
|
||||||
<Button
|
|
||||||
onClick={() => setViewOpen(false)}
|
|
||||||
className="w-full md:w-auto"
|
|
||||||
>
|
|
||||||
Close
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+110
-238
@@ -1,6 +1,7 @@
|
|||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect, useCallback } from "react";
|
||||||
|
|
||||||
import { getCareersApi, deleteCareerApi } from "@/api/career";
|
import { getCareersApi, deleteCareerApi } from "@/api/career";
|
||||||
|
|
||||||
import apiClient from "@/api/client";
|
import apiClient from "@/api/client";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -14,6 +15,7 @@ import {
|
|||||||
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -23,17 +25,8 @@ import {
|
|||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
|
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
|
|
||||||
import {
|
import { Loader2, Plus, Pencil, Trash, RefreshCw } from "lucide-react";
|
||||||
Loader2,
|
|
||||||
Plus,
|
|
||||||
Pencil,
|
|
||||||
Trash,
|
|
||||||
RefreshCw,
|
|
||||||
ChevronLeft,
|
|
||||||
ChevronRight,
|
|
||||||
} from "lucide-react";
|
|
||||||
|
|
||||||
export default function CareerPage() {
|
export default function CareerPage() {
|
||||||
const [careers, setCareers] = useState<any[]>([]);
|
const [careers, setCareers] = useState<any[]>([]);
|
||||||
@@ -44,9 +37,6 @@ export default function CareerPage() {
|
|||||||
|
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
|
||||||
const itemsPerPage = 10;
|
|
||||||
|
|
||||||
const [form, setForm] = useState({
|
const [form, setForm] = useState({
|
||||||
post: "",
|
post: "",
|
||||||
designation: "",
|
designation: "",
|
||||||
@@ -73,21 +63,10 @@ export default function CareerPage() {
|
|||||||
fetchAll();
|
fetchAll();
|
||||||
}, [fetchAll]);
|
}, [fetchAll]);
|
||||||
|
|
||||||
const filteredCareers = careers.filter(
|
const filteredCareers = careers.filter((item) =>
|
||||||
(item) =>
|
item.post?.toLowerCase().includes(searchText.toLowerCase()),
|
||||||
item.post?.toLowerCase().includes(searchText.toLowerCase()) ||
|
|
||||||
item.designation?.toLowerCase().includes(searchText.toLowerCase()),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setCurrentPage(1);
|
|
||||||
}, [searchText]);
|
|
||||||
|
|
||||||
const totalPages = Math.ceil(filteredCareers.length / itemsPerPage);
|
|
||||||
const indexOfLastItem = currentPage * itemsPerPage;
|
|
||||||
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
|
||||||
const currentItems = filteredCareers.slice(indexOfFirstItem, indexOfLastItem);
|
|
||||||
|
|
||||||
function handleChange(e: any) {
|
function handleChange(e: any) {
|
||||||
setForm({ ...form, [e.target.name]: e.target.value });
|
setForm({ ...form, [e.target.name]: e.target.value });
|
||||||
}
|
}
|
||||||
@@ -108,6 +87,7 @@ export default function CareerPage() {
|
|||||||
|
|
||||||
function openEdit(item: any) {
|
function openEdit(item: any) {
|
||||||
setEditing(item);
|
setEditing(item);
|
||||||
|
|
||||||
setForm({
|
setForm({
|
||||||
post: item.post || "",
|
post: item.post || "",
|
||||||
designation: item.designation || "",
|
designation: item.designation || "",
|
||||||
@@ -117,6 +97,7 @@ export default function CareerPage() {
|
|||||||
number: item.number || "",
|
number: item.number || "",
|
||||||
status: item.status || "new",
|
status: item.status || "new",
|
||||||
});
|
});
|
||||||
|
|
||||||
setOpenModal(true);
|
setOpenModal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +108,7 @@ export default function CareerPage() {
|
|||||||
} else {
|
} else {
|
||||||
await apiClient.post("/careers", form);
|
await apiClient.post("/careers", form);
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenModal(false);
|
setOpenModal(false);
|
||||||
fetchAll();
|
fetchAll();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -142,29 +124,24 @@ export default function CareerPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
<div className="flex justify-between items-center gap-3 flex-wrap">
|
||||||
<h1 className="text-3xl font-bold">Careers</h1>
|
<h1 className="text-2xl font-bold">Careers</h1>
|
||||||
|
|
||||||
<div className="flex flex-wrap gap-3">
|
<div className="flex gap-2 flex-wrap">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search post / designation..."
|
placeholder="Search career..."
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
className="w-[250px] text-base"
|
className="w-[220px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button variant="outline" onClick={fetchAll} disabled={loading}>
|
||||||
variant="outline"
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
onClick={fetchAll}
|
|
||||||
disabled={loading}
|
|
||||||
className="text-base"
|
|
||||||
>
|
|
||||||
<RefreshCw className="mr-2 h-5 w-5" />
|
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button onClick={openAdd} className="text-base">
|
<Button onClick={openAdd}>
|
||||||
<Plus className="mr-2 h-5 w-5" />
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
Add Career
|
Add Career
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -172,113 +149,67 @@ export default function CareerPage() {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">Career Opportunities</CardTitle>
|
<CardTitle>Career List</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="p-0 sm:p-6 space-y-4">
|
<CardContent>
|
||||||
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
<div className="overflow-x-auto">
|
||||||
<Table className="w-full min-w-[1000px] table-fixed border-separate border-spacing-0">
|
<Table className="min-w-[900px]">
|
||||||
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[60px] bg-background font-bold text-sm">
|
<TableHead>ID</TableHead>
|
||||||
ID
|
<TableHead>Post</TableHead>
|
||||||
</TableHead>
|
<TableHead>Designation</TableHead>
|
||||||
<TableHead className="w-[200px] bg-background font-bold text-sm">
|
<TableHead>Qualification</TableHead>
|
||||||
Post & Designation
|
<TableHead>Experience</TableHead>
|
||||||
</TableHead>
|
<TableHead>Email</TableHead>
|
||||||
<TableHead className="w-[200px] bg-background font-bold text-sm">
|
<TableHead>Phone</TableHead>
|
||||||
Qualification
|
<TableHead>Status</TableHead>
|
||||||
</TableHead>
|
<TableHead>Actions</TableHead>
|
||||||
<TableHead className="w-[120px] bg-background font-bold text-sm">
|
|
||||||
Experience
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[200px] bg-background font-bold text-sm">
|
|
||||||
Contact Info
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[100px] bg-background font-bold text-sm">
|
|
||||||
Status
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[120px] bg-background font-bold text-right text-sm">
|
|
||||||
Actions
|
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={7} className="text-center py-10">
|
<TableCell colSpan={9} className="text-center">
|
||||||
<Loader2 className="h-8 w-8 animate-spin mx-auto" />
|
<Loader2 className="h-6 w-6 animate-spin mx-auto" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : currentItems.length === 0 ? (
|
) : filteredCareers.length === 0 ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell colSpan={9} className="text-center">
|
||||||
colSpan={7}
|
|
||||||
className="text-center text-muted-foreground py-10 text-base"
|
|
||||||
>
|
|
||||||
No careers found
|
No careers found
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
currentItems.map((item) => (
|
filteredCareers.map((item) => (
|
||||||
<TableRow key={item.id} className="hover:bg-muted/50">
|
<TableRow key={item.id}>
|
||||||
<TableCell className="font-mono text-xs">
|
<TableCell>{item.id}</TableCell>
|
||||||
{item.id}
|
<TableCell>{item.post}</TableCell>
|
||||||
</TableCell>
|
<TableCell>{item.designation}</TableCell>
|
||||||
<TableCell>
|
<TableCell>{item.qualification}</TableCell>
|
||||||
<div className="font-semibold text-base truncate">
|
<TableCell>{item.experienceNeed}</TableCell>
|
||||||
{item.post}
|
<TableCell>{item.email}</TableCell>
|
||||||
</div>
|
<TableCell>{item.number}</TableCell>
|
||||||
<div className="text-xs text-muted-foreground truncate">
|
<TableCell>{item.status}</TableCell>
|
||||||
{item.designation}
|
|
||||||
</div>
|
<TableCell className="flex gap-2">
|
||||||
</TableCell>
|
<Button
|
||||||
<TableCell>
|
size="sm"
|
||||||
<div className="text-sm line-clamp-2">
|
variant="outline"
|
||||||
{item.qualification}
|
onClick={() => openEdit(item)}
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-sm">
|
|
||||||
{item.experienceNeed}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm font-medium">{item.email}</div>
|
|
||||||
<div className="text-xs text-muted-foreground">
|
|
||||||
{item.number}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<Badge
|
|
||||||
variant={
|
|
||||||
item.status === "active" ? "default" : "secondary"
|
|
||||||
}
|
|
||||||
className="capitalize"
|
|
||||||
>
|
>
|
||||||
{item.status}
|
<Pencil className="h-4 w-4" />
|
||||||
</Badge>
|
</Button>
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell className="text-right">
|
<Button
|
||||||
<div className="flex justify-end gap-2">
|
size="sm"
|
||||||
<Button
|
variant="destructive"
|
||||||
size="icon"
|
onClick={() => handleDelete(item.id)}
|
||||||
variant="ghost"
|
>
|
||||||
className="h-9 w-9"
|
<Trash className="h-4 w-4" />
|
||||||
onClick={() => openEdit(item)}
|
</Button>
|
||||||
>
|
|
||||||
<Pencil className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
|
||||||
onClick={() => handleDelete(item.id)}
|
|
||||||
>
|
|
||||||
<Trash className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
@@ -286,126 +217,67 @@ export default function CareerPage() {
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!loading && filteredCareers.length > 0 && (
|
|
||||||
<div className="flex items-center justify-between px-2 py-6 border-t">
|
|
||||||
<div className="text-base text-muted-foreground">
|
|
||||||
Showing{" "}
|
|
||||||
<span className="font-semibold">{indexOfFirstItem + 1}</span> to{" "}
|
|
||||||
<span className="font-semibold">
|
|
||||||
{Math.min(indexOfLastItem, filteredCareers.length)}
|
|
||||||
</span>{" "}
|
|
||||||
of{" "}
|
|
||||||
<span className="font-semibold">{filteredCareers.length}</span>{" "}
|
|
||||||
careers
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-6">
|
|
||||||
<div className="text-base font-semibold">
|
|
||||||
Page {currentPage} of {totalPages}
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
||||||
}
|
|
||||||
disabled={currentPage === 1}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
|
||||||
}
|
|
||||||
disabled={currentPage === totalPages || totalPages === 0}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{/* MODAL */}
|
||||||
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
||||||
<DialogContent className="w-full max-w-lg">
|
<DialogContent>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl">
|
<DialogTitle>{editing ? "Edit Career" : "Add Career"}</DialogTitle>
|
||||||
{editing ? "Edit Career" : "Add New Career"}
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="space-y-4 py-4">
|
<div className="space-y-3">
|
||||||
<div className="grid grid-cols-1 gap-4">
|
<Input
|
||||||
<Input
|
name="post"
|
||||||
name="post"
|
placeholder="Post"
|
||||||
placeholder="Post (e.g. Staff Nurse)"
|
value={form.post}
|
||||||
value={form.post}
|
onChange={handleChange}
|
||||||
onChange={handleChange}
|
/>
|
||||||
className="text-base"
|
<Input
|
||||||
/>
|
name="designation"
|
||||||
<Input
|
placeholder="Designation"
|
||||||
name="designation"
|
value={form.designation}
|
||||||
placeholder="Designation"
|
onChange={handleChange}
|
||||||
value={form.designation}
|
/>
|
||||||
onChange={handleChange}
|
<Input
|
||||||
className="text-base"
|
name="qualification"
|
||||||
/>
|
placeholder="Qualification"
|
||||||
<Input
|
value={form.qualification}
|
||||||
name="qualification"
|
onChange={handleChange}
|
||||||
placeholder="Qualification"
|
/>
|
||||||
value={form.qualification}
|
<Input
|
||||||
onChange={handleChange}
|
name="experienceNeed"
|
||||||
className="text-base"
|
placeholder="Experience Needed"
|
||||||
/>
|
value={form.experienceNeed}
|
||||||
<Input
|
onChange={handleChange}
|
||||||
name="experienceNeed"
|
/>
|
||||||
placeholder="Experience Needed"
|
<Input
|
||||||
value={form.experienceNeed}
|
name="email"
|
||||||
onChange={handleChange}
|
placeholder="Email"
|
||||||
className="text-base"
|
value={form.email}
|
||||||
/>
|
onChange={handleChange}
|
||||||
<Input
|
/>
|
||||||
name="email"
|
<Input
|
||||||
type="email"
|
name="number"
|
||||||
placeholder="HR Email Address"
|
placeholder="Phone Number"
|
||||||
value={form.email}
|
value={form.number}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
className="text-base"
|
/>
|
||||||
/>
|
<Input
|
||||||
<Input
|
name="status"
|
||||||
name="number"
|
placeholder="Status"
|
||||||
placeholder="Contact Number"
|
value={form.status}
|
||||||
value={form.number}
|
onChange={handleChange}
|
||||||
onChange={handleChange}
|
/>
|
||||||
className="text-base"
|
|
||||||
/>
|
|
||||||
<Input
|
|
||||||
name="status"
|
|
||||||
placeholder="Status (e.g. active / closed)"
|
|
||||||
value={form.status}
|
|
||||||
onChange={handleChange}
|
|
||||||
className="text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter className="pt-4 border-t">
|
<DialogFooter>
|
||||||
<Button
|
<Button variant="outline" onClick={() => setOpenModal(false)}>
|
||||||
variant="ghost"
|
|
||||||
onClick={() => setOpenModal(false)}
|
|
||||||
className="text-base"
|
|
||||||
>
|
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleSubmit} className="px-8 text-base">
|
<Button onClick={handleSubmit}>
|
||||||
{editing ? "Save Changes" : "Create Career"}
|
{editing ? "Update" : "Create"}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
@@ -31,16 +31,7 @@ import {
|
|||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
|
||||||
import {
|
import { Loader2, RefreshCw, Plus, Pencil, Trash, Eye } from "lucide-react";
|
||||||
Loader2,
|
|
||||||
RefreshCw,
|
|
||||||
Plus,
|
|
||||||
Pencil,
|
|
||||||
Trash,
|
|
||||||
Eye,
|
|
||||||
ChevronLeft,
|
|
||||||
ChevronRight,
|
|
||||||
} from "lucide-react";
|
|
||||||
|
|
||||||
interface Department {
|
interface Department {
|
||||||
departmentId: string;
|
departmentId: string;
|
||||||
@@ -65,9 +56,6 @@ export default function DepartmentPage() {
|
|||||||
|
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
|
||||||
const itemsPerPage = 10;
|
|
||||||
|
|
||||||
const [form, setForm] = useState<Department>({
|
const [form, setForm] = useState<Department>({
|
||||||
departmentId: "",
|
departmentId: "",
|
||||||
name: "",
|
name: "",
|
||||||
@@ -100,22 +88,8 @@ export default function DepartmentPage() {
|
|||||||
fetchDepartments();
|
fetchDepartments();
|
||||||
}, [fetchDepartments]);
|
}, [fetchDepartments]);
|
||||||
|
|
||||||
const filteredDepartments = departments.filter(
|
const filteredDepartments = departments.filter((dep) =>
|
||||||
(dep) =>
|
dep.name.toLowerCase().includes(searchText.toLowerCase()),
|
||||||
dep.name.toLowerCase().includes(searchText.toLowerCase()) ||
|
|
||||||
dep.departmentId.toLowerCase().includes(searchText.toLowerCase()),
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setCurrentPage(1);
|
|
||||||
}, [searchText]);
|
|
||||||
|
|
||||||
const totalPages = Math.ceil(filteredDepartments.length / itemsPerPage);
|
|
||||||
const indexOfLastItem = currentPage * itemsPerPage;
|
|
||||||
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
|
||||||
const currentItems = filteredDepartments.slice(
|
|
||||||
indexOfFirstItem,
|
|
||||||
indexOfLastItem,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
function handleChange(e: any) {
|
function handleChange(e: any) {
|
||||||
@@ -181,153 +155,118 @@ export default function DepartmentPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-3">
|
||||||
<h1 className="text-3xl font-bold">Departments</h1>
|
<h1 className="text-2xl font-bold">Departments</h1>
|
||||||
|
|
||||||
<div className="flex flex-wrap gap-3">
|
<div className="flex flex-wrap gap-3">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search department..."
|
placeholder="Search department..."
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
className="w-[250px] text-base"
|
className="w-[220px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={fetchDepartments}
|
onClick={fetchDepartments}
|
||||||
disabled={loading}
|
disabled={loading}>
|
||||||
className="text-base"
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
>
|
|
||||||
<RefreshCw className="mr-2 h-5 w-5" />
|
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button onClick={openAdd} className="text-base">
|
<Button onClick={openAdd}>
|
||||||
<Plus className="mr-2 h-5 w-5" />
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
Add Department
|
Add Department
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div className="p-4 text-red-600 bg-red-50 border rounded-md text-base">
|
<div className="p-4 text-red-600 bg-red-50 border rounded-md">
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">Department List</CardTitle>
|
<CardTitle>Department List</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="p-0 sm:p-6 space-y-4">
|
<CardContent>
|
||||||
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
<div className="border rounded-md max-h-[500px] overflow-y-auto">
|
||||||
<Table className="w-full min-w-[900px] table-fixed border-separate border-spacing-0">
|
<Table className="w-full table-fixed">
|
||||||
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[100px] bg-background text-sm font-bold">
|
<TableHead className="w-[80px]">ID</TableHead>
|
||||||
ID
|
<TableHead className="w-[180px]">Name</TableHead>
|
||||||
</TableHead>
|
<TableHead className="w-[250px]">Para1</TableHead>
|
||||||
<TableHead className="w-[200px] bg-background text-sm font-bold">
|
<TableHead className="w-[220px]">Facilities</TableHead>
|
||||||
Name
|
<TableHead className="w-[220px]">Services</TableHead>
|
||||||
</TableHead>
|
<TableHead className="w-[120px]">Actions</TableHead>
|
||||||
<TableHead className="w-[250px] bg-background text-sm font-bold">
|
|
||||||
Para 1
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[220px] bg-background text-sm font-bold">
|
|
||||||
Facilities
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[220px] bg-background text-sm font-bold">
|
|
||||||
Services
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[140px] bg-background text-right text-sm font-bold">
|
|
||||||
Actions
|
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={6} className="text-center py-10">
|
<TableCell colSpan={6} className="text-center">
|
||||||
<Loader2 className="h-8 w-8 animate-spin mx-auto" />
|
<Loader2 className="h-6 w-6 animate-spin mx-auto" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : currentItems.length === 0 ? (
|
) : filteredDepartments.length === 0 ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell colSpan={6} className="text-center">
|
||||||
colSpan={6}
|
|
||||||
className="text-center text-muted-foreground py-10 text-base"
|
|
||||||
>
|
|
||||||
No departments found
|
No departments found
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
currentItems.map((dep) => (
|
filteredDepartments.map((dep) => (
|
||||||
<TableRow
|
<TableRow key={dep.departmentId}>
|
||||||
key={dep.departmentId}
|
<TableCell>{dep.departmentId}</TableCell>
|
||||||
className="hover:bg-muted/50"
|
|
||||||
>
|
<TableCell>
|
||||||
<TableCell className="font-mono text-xs">
|
<div className="break-words">{dep.name}</div>
|
||||||
{dep.departmentId}
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div
|
<div className="break-words whitespace-normal">
|
||||||
className="font-semibold text-base truncate"
|
|
||||||
title={dep.name}
|
|
||||||
>
|
|
||||||
{dep.name}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm break-words whitespace-normal">
|
|
||||||
{truncate(dep.para1)}
|
{truncate(dep.para1)}
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="text-sm break-words whitespace-normal">
|
<div className="break-words whitespace-normal">
|
||||||
{truncate(dep.facilities)}
|
{truncate(dep.facilities)}
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="text-sm break-words whitespace-normal">
|
<div className="break-words whitespace-normal">
|
||||||
{truncate(dep.services)}
|
{truncate(dep.services)}
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="text-right">
|
<TableCell className="flex gap-2 whitespace-nowrap">
|
||||||
<div className="flex justify-end gap-2">
|
<Button
|
||||||
<Button
|
size="sm"
|
||||||
size="icon"
|
variant="outline"
|
||||||
variant="ghost"
|
onClick={() => openView(dep)}>
|
||||||
className="h-9 w-9"
|
<Eye className="h-4 w-4" />
|
||||||
onClick={() => openView(dep)}
|
</Button>
|
||||||
>
|
|
||||||
<Eye className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
size="icon"
|
size="sm"
|
||||||
variant="ghost"
|
variant="outline"
|
||||||
className="h-9 w-9"
|
onClick={() => openEdit(dep)}>
|
||||||
onClick={() => openEdit(dep)}
|
<Pencil className="h-4 w-4" />
|
||||||
>
|
</Button>
|
||||||
<Pencil className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
size="icon"
|
size="sm"
|
||||||
variant="ghost"
|
variant="destructive"
|
||||||
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
onClick={() => handleDelete(dep.departmentId)}>
|
||||||
onClick={() => handleDelete(dep.departmentId)}
|
<Trash className="h-4 w-4" />
|
||||||
>
|
</Button>
|
||||||
<Trash className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
@@ -335,52 +274,6 @@ export default function DepartmentPage() {
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!loading && filteredDepartments.length > 0 && (
|
|
||||||
<div className="flex items-center justify-between px-2 py-6 border-t">
|
|
||||||
<div className="text-base text-muted-foreground">
|
|
||||||
Showing{" "}
|
|
||||||
<span className="font-semibold">{indexOfFirstItem + 1}</span> to{" "}
|
|
||||||
<span className="font-semibold">
|
|
||||||
{Math.min(indexOfLastItem, filteredDepartments.length)}
|
|
||||||
</span>{" "}
|
|
||||||
of{" "}
|
|
||||||
<span className="font-semibold">
|
|
||||||
{filteredDepartments.length}
|
|
||||||
</span>{" "}
|
|
||||||
departments
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-6">
|
|
||||||
<div className="text-base font-semibold">
|
|
||||||
Page {currentPage} of {totalPages}
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
||||||
}
|
|
||||||
disabled={currentPage === 1}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
|
||||||
}
|
|
||||||
disabled={currentPage === totalPages || totalPages === 0}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
@@ -453,6 +346,7 @@ export default function DepartmentPage() {
|
|||||||
|
|
||||||
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
||||||
<DialogContent className="w-full !max-w-5xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="w-full !max-w-5xl max-h-[90vh] overflow-y-auto">
|
||||||
|
{" "}
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Department Details</DialogTitle>
|
<DialogTitle>Department Details</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
@@ -461,29 +355,35 @@ export default function DepartmentPage() {
|
|||||||
<p>
|
<p>
|
||||||
<b>ID:</b> {viewData.departmentId}
|
<b>ID:</b> {viewData.departmentId}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Name:</b> {viewData.name}
|
<b>Name:</b> {viewData.name}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Para1:</b>
|
<b>Para1:</b>
|
||||||
<br />
|
<br />
|
||||||
{viewData.para1}
|
{viewData.para1}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Para2:</b>
|
<b>Para2:</b>
|
||||||
<br />
|
<br />
|
||||||
{viewData.para2}
|
{viewData.para2}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Para3:</b>
|
<b>Para3:</b>
|
||||||
<br />
|
<br />
|
||||||
{viewData.para3}
|
{viewData.para3}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Facilities:</b>
|
<b>Facilities:</b>
|
||||||
<br />
|
<br />
|
||||||
{viewData.facilities}
|
{viewData.facilities}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Services:</b>
|
<b>Services:</b>
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
+236
-371
@@ -1,5 +1,4 @@
|
|||||||
import { useState, useEffect, useCallback } from "react";
|
import {useState, useEffect, useCallback} from "react";
|
||||||
import { AxiosError } from "axios";
|
|
||||||
import {
|
import {
|
||||||
getDoctorsApi,
|
getDoctorsApi,
|
||||||
createDoctorApi,
|
createDoctorApi,
|
||||||
@@ -7,7 +6,8 @@ import {
|
|||||||
deleteDoctorApi,
|
deleteDoctorApi,
|
||||||
getDoctorTimingApi,
|
getDoctorTimingApi,
|
||||||
} from "@/api/doctor";
|
} from "@/api/doctor";
|
||||||
import { getDepartmentsApi } from "@/api/department";
|
|
||||||
|
import {getDepartmentsApi} from "@/api/department";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
@@ -17,8 +17,10 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
||||||
import { Button } from "@/components/ui/button";
|
import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card";
|
||||||
|
import {Button} from "@/components/ui/button";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -26,49 +28,33 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
import {Popover, PopoverContent, PopoverTrigger} from "@/components/ui/popover";
|
||||||
import {
|
import {
|
||||||
Loader2,
|
Command,
|
||||||
RefreshCw,
|
CommandGroup,
|
||||||
Plus,
|
CommandItem,
|
||||||
Pencil,
|
CommandInput,
|
||||||
Trash,
|
} from "@/components/ui/command";
|
||||||
ChevronLeft,
|
|
||||||
ChevronRight,
|
import {Input} from "@/components/ui/input";
|
||||||
} from "lucide-react";
|
import {Loader2, Plus, Pencil, Trash, RefreshCw} from "lucide-react";
|
||||||
|
|
||||||
interface Department {
|
interface Department {
|
||||||
departmentId: string;
|
departmentId: string;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DAYS = [
|
|
||||||
"monday",
|
|
||||||
"tuesday",
|
|
||||||
"wednesday",
|
|
||||||
"thursday",
|
|
||||||
"friday",
|
|
||||||
"saturday",
|
|
||||||
"sunday",
|
|
||||||
"additional",
|
|
||||||
];
|
|
||||||
|
|
||||||
export default function DoctorPage() {
|
export default function DoctorPage() {
|
||||||
const [doctors, setDoctors] = useState<any[]>([]);
|
const [doctors, setDoctors] = useState<any[]>([]);
|
||||||
const [departments, setDepartments] = useState<Department[]>([]);
|
const [departments, setDepartments] = useState<Department[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState("");
|
|
||||||
|
|
||||||
const [openModal, setOpenModal] = useState(false);
|
const [openModal, setOpenModal] = useState(false);
|
||||||
const [editing, setEditing] = useState<any>(null);
|
const [editing, setEditing] = useState<any>(null);
|
||||||
|
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
const [filterDepartment, setFilterDepartment] = useState("");
|
const [filterDepartment, setFilterDepartment] = useState("");
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
|
||||||
const itemsPerPage = 10;
|
|
||||||
|
|
||||||
const [form, setForm] = useState<any>({
|
const [form, setForm] = useState<any>({
|
||||||
doctorId: "",
|
doctorId: "",
|
||||||
name: "",
|
name: "",
|
||||||
@@ -80,20 +66,16 @@ export default function DoctorPage() {
|
|||||||
|
|
||||||
const fetchAll = useCallback(async () => {
|
const fetchAll = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError("");
|
|
||||||
try {
|
try {
|
||||||
const [docRes, depRes] = await Promise.all([
|
const [docRes, depRes] = await Promise.all([
|
||||||
getDoctorsApi(),
|
getDoctorsApi(),
|
||||||
getDepartmentsApi(),
|
getDepartmentsApi(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setDoctors(docRes?.data || []);
|
setDoctors(docRes?.data || []);
|
||||||
setDepartments(depRes?.data || []);
|
setDepartments(depRes?.data || []);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof AxiosError) {
|
console.error(err);
|
||||||
setError(err.response?.data?.message || "Failed to load data");
|
|
||||||
} else {
|
|
||||||
setError("Something went wrong");
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -115,21 +97,13 @@ export default function DoctorPage() {
|
|||||||
return matchesSearch && matchesDepartment;
|
return matchesSearch && matchesDepartment;
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setCurrentPage(1);
|
|
||||||
}, [searchText, filterDepartment]);
|
|
||||||
|
|
||||||
const totalPages = Math.ceil(filteredDoctors.length / itemsPerPage);
|
|
||||||
const indexOfLastItem = currentPage * itemsPerPage;
|
|
||||||
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
|
||||||
const currentItems = filteredDoctors.slice(indexOfFirstItem, indexOfLastItem);
|
|
||||||
|
|
||||||
function handleChange(e: any) {
|
function handleChange(e: any) {
|
||||||
setForm({ ...form, [e.target.name]: e.target.value });
|
setForm({...form, [e.target.name]: e.target.value});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDepartmentToggle(depId: string) {
|
function handleDepartmentChange(depId: string) {
|
||||||
const exists = form.departments.find((d: any) => d.departmentId === depId);
|
const exists = form.departments.find((d: any) => d.departmentId === depId);
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
setForm({
|
setForm({
|
||||||
...form,
|
...form,
|
||||||
@@ -140,7 +114,7 @@ export default function DoctorPage() {
|
|||||||
} else {
|
} else {
|
||||||
setForm({
|
setForm({
|
||||||
...form,
|
...form,
|
||||||
departments: [...form.departments, { departmentId: depId, timing: {} }],
|
departments: [...form.departments, {departmentId: depId, timing: {}}],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,7 +124,10 @@ export default function DoctorPage() {
|
|||||||
...form,
|
...form,
|
||||||
departments: form.departments.map((d: any) =>
|
departments: form.departments.map((d: any) =>
|
||||||
d.departmentId === depId
|
d.departmentId === depId
|
||||||
? { ...d, timing: { ...d.timing, [day]: value } }
|
? {
|
||||||
|
...d,
|
||||||
|
timing: {...d.timing, [day]: value},
|
||||||
|
}
|
||||||
: d,
|
: d,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
@@ -171,20 +148,25 @@ export default function DoctorPage() {
|
|||||||
|
|
||||||
async function openEdit(doc: any) {
|
async function openEdit(doc: any) {
|
||||||
setEditing(doc);
|
setEditing(doc);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const timingRes = await getDoctorTimingApi(doc.doctorId);
|
const timingRes = await getDoctorTimingApi(doc.doctorId);
|
||||||
const timingData = timingRes?.data?.departments || [];
|
const timingData = timingRes?.data?.departments || [];
|
||||||
|
|
||||||
|
const mappedDepartments = timingData.map((d: any) => ({
|
||||||
|
departmentId: d.departmentId,
|
||||||
|
timing: d.timing || {},
|
||||||
|
}));
|
||||||
|
|
||||||
setForm({
|
setForm({
|
||||||
doctorId: doc.doctorId,
|
doctorId: doc.doctorId,
|
||||||
name: doc.name,
|
name: doc.name,
|
||||||
designation: doc.designation,
|
designation: doc.designation,
|
||||||
workingStatus: doc.workingStatus,
|
workingStatus: doc.workingStatus,
|
||||||
qualification: doc.qualification,
|
qualification: doc.qualification,
|
||||||
departments: timingData.map((d: any) => ({
|
departments: mappedDepartments,
|
||||||
departmentId: d.departmentId,
|
|
||||||
timing: d.timing || {},
|
|
||||||
})),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setOpenModal(true);
|
setOpenModal(true);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@@ -198,40 +180,38 @@ export default function DoctorPage() {
|
|||||||
} else {
|
} else {
|
||||||
await createDoctorApi(form);
|
await createDoctorApi(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenModal(false);
|
setOpenModal(false);
|
||||||
fetchAll();
|
fetchAll();
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
console.error(error);
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleDelete(id: string) {
|
async function handleDelete(id: string) {
|
||||||
if (!confirm("Delete this doctor?")) return;
|
if (!confirm("Delete doctor?")) return;
|
||||||
try {
|
await deleteDoctorApi(id);
|
||||||
await deleteDoctorApi(id);
|
fetchAll();
|
||||||
fetchAll();
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
{/* HEADER */}
|
||||||
<h1 className="text-3xl font-bold">Doctors</h1>
|
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-3">
|
||||||
|
<h1 className="text-2xl font-bold">Doctors</h1>
|
||||||
|
|
||||||
<div className="flex flex-wrap gap-3">
|
<div className="flex flex-wrap gap-2">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search doctor..."
|
placeholder="Search doctor..."
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
className="w-[250px] text-base"
|
className="w-[200px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<select
|
<select
|
||||||
value={filterDepartment}
|
value={filterDepartment}
|
||||||
onChange={(e) => setFilterDepartment(e.target.value)}
|
onChange={(e) => setFilterDepartment(e.target.value)}
|
||||||
className="flex h-10 w-[220px] rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
className="border rounded px-2 py-1"
|
||||||
>
|
>
|
||||||
<option value="">All Departments</option>
|
<option value="">All Departments</option>
|
||||||
{departments.map((dep) => (
|
{departments.map((dep) => (
|
||||||
@@ -241,149 +221,93 @@ export default function DoctorPage() {
|
|||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<Button
|
<Button variant="outline" onClick={fetchAll} disabled={loading}>
|
||||||
variant="outline"
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
onClick={fetchAll}
|
|
||||||
disabled={loading}
|
|
||||||
className="text-base"
|
|
||||||
>
|
|
||||||
<RefreshCw className="mr-2 h-5 w-5" />
|
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button onClick={openAdd} className="text-base">
|
<Button onClick={openAdd}>
|
||||||
<Plus className="mr-2 h-5 w-5" />
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
Add Doctor
|
Add Doctor
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{/* TABLE */}
|
||||||
<div className="p-4 text-red-600 bg-red-50 border rounded-md text-base">
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">Doctor List</CardTitle>
|
<CardTitle>Doctor List</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="p-0 sm:p-6 space-y-4">
|
<CardContent>
|
||||||
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
<div className="overflow-x-auto">
|
||||||
<Table className="w-full min-w-[900px] table-fixed border-separate border-spacing-0">
|
<Table className="min-w-[1000px]">
|
||||||
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[100px] bg-background text-sm font-bold">
|
<TableHead>ID</TableHead>
|
||||||
ID
|
<TableHead>Name</TableHead>
|
||||||
</TableHead>
|
<TableHead>Designation</TableHead>
|
||||||
<TableHead className="w-[200px] bg-background text-sm font-bold">
|
<TableHead>Status</TableHead>
|
||||||
Name
|
<TableHead>Qualification</TableHead>
|
||||||
</TableHead>
|
<TableHead>Departments</TableHead>
|
||||||
<TableHead className="w-[180px] bg-background text-sm font-bold">
|
<TableHead>Timing</TableHead>
|
||||||
Designation
|
<TableHead>Actions</TableHead>
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[180px] bg-background text-sm font-bold">
|
|
||||||
Qualification
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[220px] bg-background text-sm font-bold">
|
|
||||||
Departments
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[120px] bg-background text-right text-sm font-bold">
|
|
||||||
Actions
|
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={6} className="text-center py-10">
|
<TableCell colSpan={8} className="text-center">
|
||||||
<Loader2 className="h-8 w-8 animate-spin mx-auto" />
|
<Loader2 className="h-6 w-6 animate-spin mx-auto" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : currentItems.length === 0 ? (
|
) : filteredDoctors.length === 0 ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell colSpan={8} className="text-center">
|
||||||
colSpan={6}
|
|
||||||
className="text-center text-muted-foreground py-10 text-base"
|
|
||||||
>
|
|
||||||
No doctors found
|
No doctors found
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
currentItems.map((doc) => (
|
filteredDoctors.map((doc) => (
|
||||||
<TableRow key={doc.doctorId} className="hover:bg-muted/50">
|
<TableRow key={doc.doctorId}>
|
||||||
<TableCell className="truncate font-mono text-xs">
|
<TableCell>{doc.doctorId}</TableCell>
|
||||||
{doc.doctorId}
|
<TableCell>{doc.name}</TableCell>
|
||||||
</TableCell>
|
<TableCell>{doc.designation}</TableCell>
|
||||||
|
<TableCell>{doc.workingStatus}</TableCell>
|
||||||
|
<TableCell>{doc.qualification}</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div
|
{doc.departments
|
||||||
className="font-semibold text-base truncate"
|
?.map((d: any) => d.departmentName)
|
||||||
title={doc.name}
|
.join(", ")}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="max-w-[250px] whitespace-normal">
|
||||||
|
{doc.departments?.map((d: any) => (
|
||||||
|
<div key={d.departmentId}>
|
||||||
|
<b>{d.departmentName}:</b>{" "}
|
||||||
|
{JSON.stringify(d.timing)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="flex gap-2">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => openEdit(doc)}
|
||||||
>
|
>
|
||||||
{doc.name}
|
<Pencil className="h-4 w-4" />
|
||||||
</div>
|
</Button>
|
||||||
<div className="text-xs text-muted-foreground truncate italic">
|
|
||||||
{doc.workingStatus}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
<Button
|
||||||
<div
|
size="sm"
|
||||||
className="truncate text-sm"
|
variant="destructive"
|
||||||
title={doc.designation}
|
onClick={() => handleDelete(doc.doctorId)}
|
||||||
>
|
>
|
||||||
{doc.designation || "-"}
|
<Trash className="h-4 w-4" />
|
||||||
</div>
|
</Button>
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
|
||||||
<div
|
|
||||||
className="truncate text-sm"
|
|
||||||
title={doc.qualification}
|
|
||||||
>
|
|
||||||
{doc.qualification || "-"}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
|
||||||
<div className="flex flex-wrap gap-1">
|
|
||||||
{doc.departments?.map((d: any) => (
|
|
||||||
<Badge
|
|
||||||
key={d.departmentId}
|
|
||||||
variant="secondary"
|
|
||||||
className="text-xs px-2 h-5 leading-none"
|
|
||||||
>
|
|
||||||
{d.departmentName}
|
|
||||||
</Badge>
|
|
||||||
))}
|
|
||||||
{doc.departments?.length === 0 && (
|
|
||||||
<span className="text-muted-foreground">-</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell className="text-right">
|
|
||||||
<div className="flex justify-end gap-2">
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9"
|
|
||||||
onClick={() => openEdit(doc)}
|
|
||||||
>
|
|
||||||
<Pencil className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
|
||||||
onClick={() => handleDelete(doc.doctorId)}
|
|
||||||
>
|
|
||||||
<Trash className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
@@ -391,212 +315,153 @@ export default function DoctorPage() {
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!loading && filteredDoctors.length > 0 && (
|
|
||||||
<div className="flex items-center justify-between px-2 py-6 border-t">
|
|
||||||
<div className="text-base text-muted-foreground">
|
|
||||||
Showing{" "}
|
|
||||||
<span className="font-semibold">{indexOfFirstItem + 1}</span> to{" "}
|
|
||||||
<span className="font-semibold">
|
|
||||||
{Math.min(indexOfLastItem, filteredDoctors.length)}
|
|
||||||
</span>{" "}
|
|
||||||
of{" "}
|
|
||||||
<span className="font-semibold">{filteredDoctors.length}</span>{" "}
|
|
||||||
doctors
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-6">
|
|
||||||
<div className="text-base font-semibold">
|
|
||||||
Page {currentPage} of {totalPages}
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
||||||
}
|
|
||||||
disabled={currentPage === 1}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
|
||||||
}
|
|
||||||
disabled={currentPage === totalPages || totalPages === 0}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{/* MODAL */}
|
||||||
|
{/* MODAL */}
|
||||||
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
||||||
<DialogContent className="w-full !max-w-5xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="overflow-y-auto max-h-[80vh] ">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl">
|
<DialogTitle>{editing ? "Edit Doctor" : "Add Doctor"}</DialogTitle>
|
||||||
{editing ? "Edit Doctor" : "Add Doctor"}
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8 mt-6">
|
<div className="space-y-4">
|
||||||
<div className="space-y-6">
|
<Input
|
||||||
<h3 className="font-bold text-base border-b pb-2">
|
name="doctorId"
|
||||||
Basic Information
|
placeholder="Doctor ID"
|
||||||
</h3>
|
value={form.doctorId}
|
||||||
<div className="space-y-4">
|
onChange={handleChange}
|
||||||
<div className="space-y-1">
|
disabled={!!editing}
|
||||||
<label className="text-sm font-semibold">Doctor ID</label>
|
/>
|
||||||
<Input
|
|
||||||
name="doctorId"
|
|
||||||
placeholder="GG-DOC-001"
|
|
||||||
value={form.doctorId}
|
|
||||||
onChange={handleChange}
|
|
||||||
disabled={!!editing}
|
|
||||||
className="text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1">
|
|
||||||
<label className="text-sm font-semibold">Full Name</label>
|
|
||||||
<Input
|
|
||||||
name="name"
|
|
||||||
placeholder="Dr. John Doe"
|
|
||||||
value={form.name}
|
|
||||||
onChange={handleChange}
|
|
||||||
className="text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1">
|
|
||||||
<label className="text-sm font-semibold">Designation</label>
|
|
||||||
<Input
|
|
||||||
name="designation"
|
|
||||||
placeholder="Senior Consultant"
|
|
||||||
value={form.designation}
|
|
||||||
onChange={handleChange}
|
|
||||||
className="text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1">
|
|
||||||
<label className="text-sm font-semibold">
|
|
||||||
Working Status
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
name="workingStatus"
|
|
||||||
placeholder="Active / On Call"
|
|
||||||
value={form.workingStatus}
|
|
||||||
onChange={handleChange}
|
|
||||||
className="text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1">
|
|
||||||
<label className="text-sm font-semibold">Qualification</label>
|
|
||||||
<Input
|
|
||||||
name="qualification"
|
|
||||||
placeholder="MBBS, MD"
|
|
||||||
value={form.qualification}
|
|
||||||
onChange={handleChange}
|
|
||||||
className="text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-5 border rounded-md bg-muted/20">
|
<Input
|
||||||
<p className="text-base font-bold mb-4">Assign Departments</p>
|
name="name"
|
||||||
<div className="grid grid-cols-2 gap-3">
|
placeholder="Name"
|
||||||
{departments.map((dep) => {
|
value={form.name}
|
||||||
const isSelected = form.departments.some(
|
onChange={handleChange}
|
||||||
(d: any) => d.departmentId === dep.departmentId,
|
/>
|
||||||
);
|
<Input
|
||||||
return (
|
name="designation"
|
||||||
<Button
|
placeholder="Designation"
|
||||||
key={dep.departmentId}
|
value={form.designation}
|
||||||
type="button"
|
onChange={handleChange}
|
||||||
variant={isSelected ? "default" : "outline"}
|
/>
|
||||||
size="sm"
|
<Input
|
||||||
className="justify-start text-sm h-9"
|
name="workingStatus"
|
||||||
onClick={() => handleDepartmentToggle(dep.departmentId)}
|
placeholder="Working Status"
|
||||||
>
|
value={form.workingStatus}
|
||||||
{dep.name}
|
onChange={handleChange}
|
||||||
</Button>
|
/>
|
||||||
);
|
<Input
|
||||||
})}
|
name="qualification"
|
||||||
</div>
|
placeholder="Qualification"
|
||||||
</div>
|
value={form.qualification}
|
||||||
</div>
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
|
||||||
<div className="space-y-6">
|
{/* Departments */}
|
||||||
<h3 className="font-bold text-base border-b pb-2">
|
<div>
|
||||||
Working Hours / Timing
|
<p className="font-medium mb-2">Departments</p>
|
||||||
</h3>
|
|
||||||
{form.departments.length === 0 ? (
|
<Popover>
|
||||||
<div className="text-base text-muted-foreground italic py-24 text-center border-2 border-dashed rounded-lg">
|
<PopoverTrigger asChild>
|
||||||
Select a department to configure timing slots
|
<Button className="w-full justify-between h-auto min-h-[40px]">
|
||||||
</div>
|
{form.departments.length > 0 ? (
|
||||||
) : (
|
<div className="flex flex-col items-start gap-1 text-left">
|
||||||
<div className="space-y-8">
|
{form.departments.map((d: any) => {
|
||||||
{form.departments.map((dep: any) => {
|
const name = departments.find(
|
||||||
const depName = departments.find(
|
(dep) => dep.departmentId === d.departmentId,
|
||||||
(d) => d.departmentId === dep.departmentId,
|
)?.name;
|
||||||
)?.name;
|
|
||||||
return (
|
return (
|
||||||
<div
|
<span key={d.departmentId} className="text-sm">
|
||||||
key={dep.departmentId}
|
{name}
|
||||||
className="space-y-4 p-5 border rounded-lg bg-background shadow-sm"
|
</span>
|
||||||
>
|
);
|
||||||
<div className="flex items-center justify-between">
|
})}
|
||||||
<p className="font-bold text-base text-primary">
|
|
||||||
{depName}
|
|
||||||
</p>
|
|
||||||
<Badge variant="outline" className="text-xs">
|
|
||||||
Timing Slot
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-3">
|
|
||||||
{DAYS.map((day) => (
|
|
||||||
<div key={day} className="space-y-1">
|
|
||||||
<label className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
{day}
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
className="h-9 text-sm"
|
|
||||||
placeholder="e.g. 09:00 AM - 01:00 PM"
|
|
||||||
value={dep.timing?.[day] || ""}
|
|
||||||
onChange={(e) =>
|
|
||||||
handleTimingChange(
|
|
||||||
dep.departmentId,
|
|
||||||
day,
|
|
||||||
e.target.value,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
) : (
|
||||||
})}
|
<span>Select Departments</span>
|
||||||
</div>
|
)}
|
||||||
)}
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
|
||||||
|
<PopoverContent className="w-[300px] p-0">
|
||||||
|
<Command>
|
||||||
|
<CommandInput placeholder="Search department..." />
|
||||||
|
|
||||||
|
<CommandGroup className="max-h-[250px] overflow-y-auto">
|
||||||
|
{departments.map((dep) => {
|
||||||
|
const selected = form.departments.some(
|
||||||
|
(d: any) => d.departmentId === dep.departmentId,
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CommandItem
|
||||||
|
key={dep.departmentId}
|
||||||
|
className="flex justify-between"
|
||||||
|
onSelect={() =>
|
||||||
|
handleDepartmentChange(dep.departmentId)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span>{dep.name}</span>
|
||||||
|
{selected && <span>✔</span>}
|
||||||
|
</CommandItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</CommandGroup>
|
||||||
|
</Command>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{form.departments.map((dep: any) => {
|
||||||
|
const depName = departments.find(
|
||||||
|
(d) => d.departmentId === dep.departmentId,
|
||||||
|
)?.name;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={dep.departmentId}
|
||||||
|
className="tw-border tw-p-3 tw-rounded"
|
||||||
|
>
|
||||||
|
<p className="tw-font-semibold">{depName}</p>
|
||||||
|
|
||||||
|
{[
|
||||||
|
"monday",
|
||||||
|
"tuesday",
|
||||||
|
"wednesday",
|
||||||
|
"thursday",
|
||||||
|
"friday",
|
||||||
|
"saturday",
|
||||||
|
"sunday",
|
||||||
|
"additional",
|
||||||
|
].map((day) => (
|
||||||
|
<Input
|
||||||
|
key={day}
|
||||||
|
placeholder={day}
|
||||||
|
value={dep.timing?.[day] || ""}
|
||||||
|
onChange={(e) =>
|
||||||
|
handleTimingChange(
|
||||||
|
dep.departmentId,
|
||||||
|
day,
|
||||||
|
e.target.value,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter className="mt-10 pt-6 border-t">
|
<DialogFooter>
|
||||||
<Button
|
<Button variant="outline" onClick={() => setOpenModal(false)}>
|
||||||
variant="ghost"
|
|
||||||
onClick={() => setOpenModal(false)}
|
|
||||||
className="text-base"
|
|
||||||
>
|
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleSubmit} className="px-10 text-base">
|
<Button onClick={handleSubmit}>
|
||||||
{editing ? "Save Changes" : "Create Doctor Profile"}
|
{editing ? "Update" : "Create"}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
@@ -13,26 +13,11 @@ import {
|
|||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogFooter,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
|
|
||||||
import {
|
import { Loader2, Trash, RefreshCw, Download } from "lucide-react";
|
||||||
Loader2,
|
|
||||||
Trash,
|
|
||||||
RefreshCw,
|
|
||||||
Download,
|
|
||||||
ChevronLeft,
|
|
||||||
ChevronRight,
|
|
||||||
Eye,
|
|
||||||
User,
|
|
||||||
} from "lucide-react";
|
|
||||||
|
|
||||||
export default function CandidatePage() {
|
export default function CandidatePage() {
|
||||||
const [candidates, setCandidates] = useState<any[]>([]);
|
const [candidates, setCandidates] = useState<any[]>([]);
|
||||||
@@ -41,12 +26,6 @@ export default function CandidatePage() {
|
|||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
const [filterCareer, setFilterCareer] = useState("");
|
const [filterCareer, setFilterCareer] = useState("");
|
||||||
|
|
||||||
const [viewOpen, setViewOpen] = useState(false);
|
|
||||||
const [viewData, setViewData] = useState<any>(null);
|
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
|
||||||
const itemsPerPage = 10;
|
|
||||||
|
|
||||||
const fetchAll = useCallback(async () => {
|
const fetchAll = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
@@ -76,23 +55,6 @@ export default function CandidatePage() {
|
|||||||
return matchesSearch && matchesCareer;
|
return matchesSearch && matchesCareer;
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setCurrentPage(1);
|
|
||||||
}, [searchText, filterCareer]);
|
|
||||||
|
|
||||||
const totalPages = Math.ceil(filteredCandidates.length / itemsPerPage);
|
|
||||||
const indexOfLastItem = currentPage * itemsPerPage;
|
|
||||||
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
|
||||||
const currentItems = filteredCandidates.slice(
|
|
||||||
indexOfFirstItem,
|
|
||||||
indexOfLastItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
function openView(item: any) {
|
|
||||||
setViewData(item);
|
|
||||||
setViewOpen(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleDelete(id: number) {
|
async function handleDelete(id: number) {
|
||||||
if (!confirm("Delete candidate?")) return;
|
if (!confirm("Delete candidate?")) return;
|
||||||
await deleteCandidateApi(id);
|
await deleteCandidateApi(id);
|
||||||
@@ -109,7 +71,7 @@ export default function CandidatePage() {
|
|||||||
Designation: item.career?.designation,
|
Designation: item.career?.designation,
|
||||||
Subject: item.subject,
|
Subject: item.subject,
|
||||||
CoverLetter: item.coverLetter,
|
CoverLetter: item.coverLetter,
|
||||||
AppliedDate: new Date(item.createdAt).toLocaleDateString(),
|
Date: new Date(item.createdAt).toLocaleDateString(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
exportToExcel(exportData, "candidates");
|
exportToExcel(exportData, "candidates");
|
||||||
@@ -117,36 +79,31 @@ export default function CandidatePage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
<div className="flex justify-between items-center gap-3 flex-wrap">
|
||||||
<h1 className="text-3xl font-bold">Candidates</h1>
|
<h1 className="text-2xl font-bold">Candidates</h1>
|
||||||
|
|
||||||
<div className="flex flex-wrap gap-3">
|
<div className="flex flex-wrap gap-2">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search candidate..."
|
placeholder="Search name / phone / email..."
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
className="w-[250px] text-base"
|
className="w-[220px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
placeholder="Filter by Career"
|
placeholder="Filter Career"
|
||||||
value={filterCareer}
|
value={filterCareer}
|
||||||
onChange={(e) => setFilterCareer(e.target.value)}
|
onChange={(e) => setFilterCareer(e.target.value)}
|
||||||
className="w-[200px] text-base"
|
className="w-[200px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button variant="outline" onClick={fetchAll} disabled={loading}>
|
||||||
variant="outline"
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
onClick={fetchAll}
|
|
||||||
disabled={loading}
|
|
||||||
className="text-base"
|
|
||||||
>
|
|
||||||
<RefreshCw className="mr-2 h-5 w-5" />
|
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button onClick={handleExport} className="text-base">
|
<Button variant="outline" onClick={handleExport}>
|
||||||
<Download className="mr-2 h-5 w-5" />
|
<Download className="mr-2 h-4 w-4" />
|
||||||
Export
|
Export
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -154,104 +111,68 @@ export default function CandidatePage() {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">Application List</CardTitle>
|
<CardTitle>Candidate List</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="p-0 sm:p-6 space-y-4">
|
<CardContent>
|
||||||
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
<div className="overflow-x-auto">
|
||||||
<Table className="w-full min-w-[1100px] table-fixed border-separate border-spacing-0">
|
<Table className="min-w-[900px]">
|
||||||
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[60px] bg-background font-bold text-sm">
|
<TableHead>ID</TableHead>
|
||||||
ID
|
<TableHead>Name</TableHead>
|
||||||
</TableHead>
|
<TableHead>Phone</TableHead>
|
||||||
<TableHead className="w-[220px] bg-background font-bold text-sm">
|
<TableHead>Email</TableHead>
|
||||||
Full Name
|
<TableHead>Career</TableHead>
|
||||||
</TableHead>
|
<TableHead>Designation</TableHead>
|
||||||
<TableHead className="w-[180px] bg-background font-bold text-sm">
|
<TableHead>Subject</TableHead>
|
||||||
Career & Post
|
<TableHead>Cover Letter</TableHead>
|
||||||
</TableHead>
|
<TableHead>Applied On</TableHead>
|
||||||
<TableHead className="w-[150px] bg-background font-bold text-sm">
|
<TableHead>Actions</TableHead>
|
||||||
Contact
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[140px] bg-background font-bold text-sm">
|
|
||||||
Applied On
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[250px] bg-background font-bold text-sm">
|
|
||||||
Cover Letter
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[120px] bg-background font-bold text-right text-sm">
|
|
||||||
Actions
|
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={7} className="text-center py-10">
|
<TableCell colSpan={10} className="text-center">
|
||||||
<Loader2 className="h-8 w-8 animate-spin mx-auto" />
|
<Loader2 className="h-6 w-6 animate-spin mx-auto" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : currentItems.length === 0 ? (
|
) : filteredCandidates.length === 0 ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell colSpan={10} className="text-center">
|
||||||
colSpan={7}
|
|
||||||
className="text-center text-muted-foreground py-10 text-base"
|
|
||||||
>
|
|
||||||
No candidates found
|
No candidates found
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
currentItems.map((item) => (
|
filteredCandidates.map((item) => (
|
||||||
<TableRow key={item.id} className="hover:bg-muted/50">
|
<TableRow key={item.id}>
|
||||||
<TableCell className="font-mono text-xs">
|
<TableCell>{item.id}</TableCell>
|
||||||
{item.id}
|
<TableCell>{item.fullName}</TableCell>
|
||||||
|
<TableCell>{item.mobile}</TableCell>
|
||||||
|
<TableCell>{item.email}</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.career?.post}</TableCell>
|
||||||
|
<TableCell>{item.career?.designation}</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.subject}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="max-w-[250px] whitespace-normal">
|
||||||
|
{item.coverLetter}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="font-semibold text-base truncate">
|
|
||||||
{item.fullName}
|
|
||||||
</div>
|
|
||||||
<div className="text-xs text-muted-foreground truncate">
|
|
||||||
{item.email}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm font-medium">
|
|
||||||
{item.career?.post || "-"}
|
|
||||||
</div>
|
|
||||||
<div className="text-[10px] text-muted-foreground truncate">
|
|
||||||
{item.career?.designation}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-sm">{item.mobile}</TableCell>
|
|
||||||
<TableCell className="text-sm">
|
|
||||||
{new Date(item.createdAt).toLocaleDateString()}
|
{new Date(item.createdAt).toLocaleDateString()}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="text-sm line-clamp-2 text-muted-foreground italic">
|
<Button
|
||||||
{item.coverLetter || "No cover letter provided."}
|
size="sm"
|
||||||
</div>
|
variant="destructive"
|
||||||
</TableCell>
|
onClick={() => handleDelete(item.id)}>
|
||||||
<TableCell className="text-right">
|
<Trash className="h-4 w-4" />
|
||||||
<div className="flex justify-end gap-2">
|
</Button>
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9"
|
|
||||||
onClick={() => openView(item)}
|
|
||||||
>
|
|
||||||
<Eye className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
|
||||||
onClick={() => handleDelete(item.id)}
|
|
||||||
>
|
|
||||||
<Trash className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
@@ -259,126 +180,8 @@ export default function CandidatePage() {
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!loading && filteredCandidates.length > 0 && (
|
|
||||||
<div className="flex items-center justify-between px-2 py-6 border-t">
|
|
||||||
<div className="text-base text-muted-foreground">
|
|
||||||
Showing{" "}
|
|
||||||
<span className="font-semibold">{indexOfFirstItem + 1}</span> to{" "}
|
|
||||||
<span className="font-semibold">
|
|
||||||
{Math.min(indexOfLastItem, filteredCandidates.length)}
|
|
||||||
</span>{" "}
|
|
||||||
of{" "}
|
|
||||||
<span className="font-semibold">
|
|
||||||
{filteredCandidates.length}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-6">
|
|
||||||
<div className="text-base font-semibold">
|
|
||||||
Page {currentPage} of {totalPages}
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
||||||
}
|
|
||||||
disabled={currentPage === 1}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
|
||||||
}
|
|
||||||
disabled={currentPage === totalPages || totalPages === 0}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
|
||||||
<DialogContent className="w-full !max-w-3xl max-h-[85vh] overflow-y-auto">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle className="text-2xl border-b pb-2 flex items-center gap-2">
|
|
||||||
<User className="h-6 w-6" /> Candidate Details
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
{viewData && (
|
|
||||||
<div className="space-y-6 py-4">
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Personal Information
|
|
||||||
</p>
|
|
||||||
<p className="text-lg font-bold text-primary">
|
|
||||||
{viewData.fullName}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm font-medium">{viewData.email}</p>
|
|
||||||
<p className="text-sm">{viewData.mobile}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Applied For
|
|
||||||
</p>
|
|
||||||
<p className="text-base font-semibold">
|
|
||||||
{viewData.career?.post || "General Application"}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{viewData.career?.designation}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Application Date
|
|
||||||
</p>
|
|
||||||
<p className="text-sm">
|
|
||||||
{new Date(viewData.createdAt).toLocaleString()}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Subject
|
|
||||||
</p>
|
|
||||||
<p className="text-sm font-semibold">
|
|
||||||
{viewData.subject || "N/A"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="p-4 bg-muted/30 rounded-lg">
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground mb-2">
|
|
||||||
Cover Letter / Message
|
|
||||||
</p>
|
|
||||||
<p className="text-sm leading-relaxed whitespace-pre-wrap italic">
|
|
||||||
{viewData.coverLetter || "No cover letter provided."}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<DialogFooter>
|
|
||||||
<Button
|
|
||||||
onClick={() => setViewOpen(false)}
|
|
||||||
className="w-full md:w-auto"
|
|
||||||
>
|
|
||||||
Close
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-234
@@ -13,26 +13,11 @@ import {
|
|||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogFooter,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
|
|
||||||
import {
|
import { Loader2, Trash, RefreshCw, Download } from "lucide-react";
|
||||||
Loader2,
|
|
||||||
Trash,
|
|
||||||
RefreshCw,
|
|
||||||
Download,
|
|
||||||
ChevronLeft,
|
|
||||||
ChevronRight,
|
|
||||||
Eye,
|
|
||||||
Mail,
|
|
||||||
} from "lucide-react";
|
|
||||||
|
|
||||||
export default function InquiryPage() {
|
export default function InquiryPage() {
|
||||||
const [inquiries, setInquiries] = useState<any[]>([]);
|
const [inquiries, setInquiries] = useState<any[]>([]);
|
||||||
@@ -40,12 +25,6 @@ export default function InquiryPage() {
|
|||||||
|
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
|
|
||||||
const [viewOpen, setViewOpen] = useState(false);
|
|
||||||
const [viewData, setViewData] = useState<any>(null);
|
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
|
||||||
const itemsPerPage = 10;
|
|
||||||
|
|
||||||
const fetchAll = useCallback(async () => {
|
const fetchAll = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
@@ -71,23 +50,6 @@ export default function InquiryPage() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setCurrentPage(1);
|
|
||||||
}, [searchText]);
|
|
||||||
|
|
||||||
const totalPages = Math.ceil(filteredInquiries.length / itemsPerPage);
|
|
||||||
const indexOfLastItem = currentPage * itemsPerPage;
|
|
||||||
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
|
|
||||||
const currentItems = filteredInquiries.slice(
|
|
||||||
indexOfFirstItem,
|
|
||||||
indexOfLastItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
function openView(item: any) {
|
|
||||||
setViewData(item);
|
|
||||||
setViewOpen(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleDelete(id: number) {
|
async function handleDelete(id: number) {
|
||||||
if (!confirm("Delete inquiry?")) return;
|
if (!confirm("Delete inquiry?")) return;
|
||||||
await deleteInquiryApi(id);
|
await deleteInquiryApi(id);
|
||||||
@@ -110,29 +72,24 @@ export default function InquiryPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
<div className="flex justify-between items-center gap-3 flex-wrap">
|
||||||
<h1 className="text-3xl font-bold">Inquiries</h1>
|
<h1 className="text-2xl font-bold">Inquiries</h1>
|
||||||
|
|
||||||
<div className="flex flex-wrap gap-3">
|
<div className="flex flex-wrap gap-2">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search name / phone / subject..."
|
placeholder="Search name / phone / email / subject..."
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
className="w-[280px] text-base"
|
className="w-[260px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button variant="outline" onClick={fetchAll} disabled={loading}>
|
||||||
variant="outline"
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
onClick={fetchAll}
|
|
||||||
disabled={loading}
|
|
||||||
className="text-base"
|
|
||||||
>
|
|
||||||
<RefreshCw className="mr-2 h-5 w-5" />
|
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button onClick={handleExport} className="text-base">
|
<Button variant="outline" onClick={handleExport}>
|
||||||
<Download className="mr-2 h-5 w-5" />
|
<Download className="mr-2 h-4 w-4" />
|
||||||
Export
|
Export
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -140,100 +97,62 @@ export default function InquiryPage() {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">Customer Inquiries</CardTitle>
|
<CardTitle>Inquiry List</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="p-0 sm:p-6 space-y-4">
|
<CardContent>
|
||||||
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
<div className="overflow-x-auto">
|
||||||
<Table className="w-full min-w-[1000px] table-fixed border-separate border-spacing-0">
|
<Table className="min-w-[900px]">
|
||||||
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[60px] bg-background font-bold text-sm">
|
<TableHead>ID</TableHead>
|
||||||
ID
|
<TableHead>Name</TableHead>
|
||||||
</TableHead>
|
<TableHead>Phone</TableHead>
|
||||||
<TableHead className="w-[220px] bg-background font-bold text-sm">
|
<TableHead>Email</TableHead>
|
||||||
Customer Details
|
<TableHead>Subject</TableHead>
|
||||||
</TableHead>
|
<TableHead>Message</TableHead>
|
||||||
<TableHead className="w-[200px] bg-background font-bold text-sm">
|
<TableHead>Date</TableHead>
|
||||||
Subject
|
<TableHead>Actions</TableHead>
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[150px] bg-background font-bold text-sm">
|
|
||||||
Date
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[280px] bg-background font-bold text-sm">
|
|
||||||
Message Snippet
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[120px] bg-background font-bold text-right text-sm">
|
|
||||||
Actions
|
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={6} className="text-center py-10">
|
<TableCell colSpan={8} className="text-center">
|
||||||
<Loader2 className="h-8 w-8 animate-spin mx-auto" />
|
<Loader2 className="h-6 w-6 animate-spin mx-auto" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : currentItems.length === 0 ? (
|
) : filteredInquiries.length === 0 ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell colSpan={8} className="text-center">
|
||||||
colSpan={6}
|
|
||||||
className="text-center text-muted-foreground py-10 text-base"
|
|
||||||
>
|
|
||||||
No inquiries found
|
No inquiries found
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
currentItems.map((item) => (
|
filteredInquiries.map((item) => (
|
||||||
<TableRow key={item.id} className="hover:bg-muted/50">
|
<TableRow key={item.id}>
|
||||||
<TableCell className="font-mono text-xs">
|
<TableCell>{item.id}</TableCell>
|
||||||
{item.id}
|
<TableCell>{item.fullName}</TableCell>
|
||||||
|
<TableCell>{item.number}</TableCell>
|
||||||
|
<TableCell>{item.emailId}</TableCell>
|
||||||
|
<TableCell>{item.subject}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="max-w-[250px] whitespace-normal">
|
||||||
|
{item.message}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="font-semibold text-base truncate">
|
|
||||||
{item.fullName}
|
|
||||||
</div>
|
|
||||||
<div className="text-xs text-muted-foreground truncate">
|
|
||||||
{item.emailId}
|
|
||||||
</div>
|
|
||||||
<div className="text-[11px] font-medium">
|
|
||||||
{item.number}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm font-medium line-clamp-2">
|
|
||||||
{item.subject || "-"}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-sm">
|
|
||||||
{new Date(item.createdAt).toLocaleDateString()}
|
{new Date(item.createdAt).toLocaleDateString()}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="text-sm line-clamp-2 text-muted-foreground italic">
|
<Button
|
||||||
{item.message || "-"}
|
size="sm"
|
||||||
</div>
|
variant="destructive"
|
||||||
</TableCell>
|
onClick={() => handleDelete(item.id)}>
|
||||||
<TableCell className="text-right">
|
<Trash className="h-4 w-4" />
|
||||||
<div className="flex justify-end gap-2">
|
</Button>
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9"
|
|
||||||
onClick={() => openView(item)}
|
|
||||||
>
|
|
||||||
<Eye className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
|
||||||
onClick={() => handleDelete(item.id)}
|
|
||||||
>
|
|
||||||
<Trash className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
@@ -241,115 +160,8 @@ export default function InquiryPage() {
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!loading && filteredInquiries.length > 0 && (
|
|
||||||
<div className="flex items-center justify-between px-2 py-6 border-t">
|
|
||||||
<div className="text-base text-muted-foreground">
|
|
||||||
Showing{" "}
|
|
||||||
<span className="font-semibold">{indexOfFirstItem + 1}</span> to{" "}
|
|
||||||
<span className="font-semibold">
|
|
||||||
{Math.min(indexOfLastItem, filteredInquiries.length)}
|
|
||||||
</span>{" "}
|
|
||||||
of{" "}
|
|
||||||
<span className="font-semibold">
|
|
||||||
{filteredInquiries.length}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-6">
|
|
||||||
<div className="text-base font-semibold">
|
|
||||||
Page {currentPage} of {totalPages}
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
||||||
}
|
|
||||||
disabled={currentPage === 1}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
|
||||||
}
|
|
||||||
disabled={currentPage === totalPages || totalPages === 0}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
|
||||||
<DialogContent className="w-full !max-w-3xl max-h-[85vh] overflow-y-auto">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle className="text-2xl border-b pb-2 flex items-center gap-2">
|
|
||||||
<Mail className="h-6 w-6" /> Inquiry Details
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
{viewData && (
|
|
||||||
<div className="space-y-6 py-4">
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Customer Information
|
|
||||||
</p>
|
|
||||||
<p className="text-lg font-bold text-primary">
|
|
||||||
{viewData.fullName}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm font-medium">{viewData.emailId}</p>
|
|
||||||
<p className="text-sm">{viewData.number}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Received Date
|
|
||||||
</p>
|
|
||||||
<p className="text-sm">
|
|
||||||
{new Date(viewData.createdAt).toLocaleString()}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground">
|
|
||||||
Subject
|
|
||||||
</p>
|
|
||||||
<p className="text-base font-semibold">
|
|
||||||
{viewData.subject || "No Subject"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="p-4 bg-muted/30 rounded-lg border">
|
|
||||||
<p className="text-xs uppercase font-bold text-muted-foreground mb-2">
|
|
||||||
Message
|
|
||||||
</p>
|
|
||||||
<p className="text-sm leading-relaxed whitespace-pre-wrap">
|
|
||||||
{viewData.message || "No message content."}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<DialogFooter>
|
|
||||||
<Button
|
|
||||||
onClick={() => setViewOpen(false)}
|
|
||||||
className="w-full md:w-auto"
|
|
||||||
>
|
|
||||||
Close
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+172
-272
@@ -19,7 +19,6 @@ import {
|
|||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -38,13 +37,11 @@ import {
|
|||||||
Eye,
|
Eye,
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
Newspaper,
|
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
export default function NewsPage() {
|
export default function NewsPage() {
|
||||||
const [news, setNews] = useState<any[]>([]);
|
const [news, setNews] = useState<any[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [totalItems, setTotalItems] = useState(0);
|
|
||||||
|
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
|
|
||||||
@@ -69,28 +66,29 @@ export default function NewsPage() {
|
|||||||
const fetchAll = useCallback(async () => {
|
const fetchAll = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const res = await getNewsApi(currentPage, itemsPerPage);
|
const res = await getNewsApi();
|
||||||
|
|
||||||
setNews(res?.data || []);
|
setNews(res?.data || []);
|
||||||
setTotalItems(res?.meta?.total || 0);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [currentPage, itemsPerPage]);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAll();
|
fetchAll();
|
||||||
}, [fetchAll]);
|
}, [fetchAll]);
|
||||||
|
|
||||||
const filteredNews = news.filter(
|
const filteredNews = news.filter((item) =>
|
||||||
(item) =>
|
item.Headline?.toLowerCase().includes(searchText.toLowerCase()),
|
||||||
item.Headline?.toLowerCase().includes(searchText.toLowerCase()) ||
|
|
||||||
item.Author?.toLowerCase().includes(searchText.toLowerCase()),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const totalPages = Math.ceil(totalItems / itemsPerPage);
|
const totalPages = Math.ceil(filteredNews.length / itemsPerPage);
|
||||||
|
const startIndex = (currentPage - 1) * itemsPerPage;
|
||||||
|
const paginatedData = filteredNews.slice(
|
||||||
|
startIndex,
|
||||||
|
startIndex + itemsPerPage,
|
||||||
|
);
|
||||||
|
|
||||||
function handleChange(e: any) {
|
function handleChange(e: any) {
|
||||||
setForm({ ...form, [e.target.name]: e.target.value });
|
setForm({ ...form, [e.target.name]: e.target.value });
|
||||||
@@ -111,6 +109,7 @@ export default function NewsPage() {
|
|||||||
|
|
||||||
function openEdit(item: any) {
|
function openEdit(item: any) {
|
||||||
setEditing(item);
|
setEditing(item);
|
||||||
|
|
||||||
setForm({
|
setForm({
|
||||||
headline: item.Headline || "",
|
headline: item.Headline || "",
|
||||||
content: item.Content || "",
|
content: item.Content || "",
|
||||||
@@ -119,6 +118,7 @@ export default function NewsPage() {
|
|||||||
date: item.Date ? item.Date.split("T")[0] : "",
|
date: item.Date ? item.Date.split("T")[0] : "",
|
||||||
author: item.Author || "",
|
author: item.Author || "",
|
||||||
});
|
});
|
||||||
|
|
||||||
setOpenModal(true);
|
setOpenModal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,17 +149,18 @@ export default function NewsPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-4">
|
<div className="flex justify-between items-center flex-wrap gap-3">
|
||||||
<h1 className="text-3xl font-bold font-sans tracking-tight">
|
<h1 className="text-2xl font-bold">News Media</h1>
|
||||||
News Media
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<div className="flex flex-wrap gap-3 items-center">
|
<div className="flex gap-2 flex-wrap items-center">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Filter headline..."
|
placeholder="Search headline..."
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={(e) => {
|
||||||
className="w-[250px] text-base"
|
setSearchText(e.target.value);
|
||||||
|
setCurrentPage(1);
|
||||||
|
}}
|
||||||
|
className="w-[250px]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<select
|
<select
|
||||||
@@ -168,131 +169,98 @@ export default function NewsPage() {
|
|||||||
setItemsPerPage(Number(e.target.value));
|
setItemsPerPage(Number(e.target.value));
|
||||||
setCurrentPage(1);
|
setCurrentPage(1);
|
||||||
}}
|
}}
|
||||||
className="flex h-10 rounded-md border border-input bg-background px-3 py-2 text-sm focus:ring-2 focus:ring-primary"
|
className="border px-2 py-1 rounded">
|
||||||
>
|
|
||||||
<option value={5}>5 / page</option>
|
<option value={5}>5 / page</option>
|
||||||
<option value={10}>10 / page</option>
|
<option value={10}>10 / page</option>
|
||||||
<option value={20}>20 / page</option>
|
<option value={20}>20 / page</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<Button
|
<Button variant="outline" onClick={fetchAll} disabled={loading}>
|
||||||
variant="outline"
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
onClick={fetchAll}
|
|
||||||
disabled={loading}
|
|
||||||
className="text-base"
|
|
||||||
>
|
|
||||||
<RefreshCw className="mr-2 h-5 w-5" />
|
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button onClick={openAdd} className="text-base">
|
<Button onClick={openAdd}>
|
||||||
<Plus className="mr-2 h-5 w-5" />
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
Add News
|
Add News
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Card className="shadow-sm">
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">News Archives</CardTitle>
|
<CardTitle>News List</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="p-0 sm:p-6 space-y-4">
|
<CardContent>
|
||||||
<div className="rounded-md border overflow-x-auto overflow-y-auto max-h-[650px] relative">
|
<div className="overflow-x-auto">
|
||||||
<Table className="w-full min-w-[1000px] table-fixed border-separate border-spacing-0">
|
<Table className="min-w-[900px] table-fixed">
|
||||||
<TableHeader className="sticky top-0 z-20 bg-background shadow-sm">
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[80px] bg-background font-bold">
|
<TableHead className="w-[60px]">ID</TableHead>
|
||||||
ID
|
<TableHead className="w-[220px]">Headline</TableHead>
|
||||||
</TableHead>
|
<TableHead className="w-[120px]">Author</TableHead>
|
||||||
<TableHead className="w-[280px] bg-background font-bold">
|
<TableHead className="w-[120px]">Date</TableHead>
|
||||||
Headline
|
<TableHead className="w-[260px]">Content</TableHead>
|
||||||
</TableHead>
|
<TableHead className="w-[150px]">Actions</TableHead>
|
||||||
<TableHead className="w-[150px] bg-background font-bold">
|
|
||||||
Author
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[140px] bg-background font-bold">
|
|
||||||
Date
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[250px] bg-background font-bold">
|
|
||||||
Content Preview
|
|
||||||
</TableHead>
|
|
||||||
<TableHead className="w-[150px] bg-background font-bold text-right">
|
|
||||||
Actions
|
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={6} className="text-center py-10">
|
<TableCell colSpan={6} className="text-center">
|
||||||
<Loader2 className="h-8 w-8 animate-spin mx-auto text-primary" />
|
<Loader2 className="animate-spin mx-auto" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : filteredNews.length === 0 ? (
|
) : paginatedData.length === 0 ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell colSpan={6} className="text-center">
|
||||||
colSpan={6}
|
No news found
|
||||||
className="text-center text-muted-foreground py-10 text-base"
|
|
||||||
>
|
|
||||||
No news articles found
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
filteredNews.map((item) => (
|
paginatedData.map((item) => (
|
||||||
<TableRow key={item.Id} className="hover:bg-muted/50">
|
<TableRow key={item.Id}>
|
||||||
<TableCell className="font-mono text-xs">
|
<TableCell>{item.Id}</TableCell>
|
||||||
{item.Id}
|
|
||||||
|
<TableCell className="break-words whitespace-normal">
|
||||||
|
{item.Headline}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.Author}</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div
|
|
||||||
className="font-semibold text-base line-clamp-2"
|
|
||||||
title={item.Headline}
|
|
||||||
>
|
|
||||||
{item.Headline}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-sm font-medium">
|
|
||||||
{item.Author || "-"}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-sm">
|
|
||||||
{item.Date
|
{item.Date
|
||||||
? new Date(item.Date).toLocaleDateString()
|
? new Date(item.Date).toLocaleDateString()
|
||||||
: "-"}
|
: "-"}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
|
||||||
<div className="text-sm line-clamp-2 text-muted-foreground">
|
<TableCell className="break-words whitespace-normal">
|
||||||
{item.Content}
|
{item.Content}
|
||||||
</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="text-right">
|
|
||||||
<div className="flex justify-end gap-2">
|
<TableCell className="flex gap-2">
|
||||||
<Button
|
<Button
|
||||||
size="icon"
|
size="sm"
|
||||||
variant="ghost"
|
variant="outline"
|
||||||
className="h-9 w-9"
|
onClick={() => openView(item)}>
|
||||||
onClick={() => openView(item)}
|
<Eye className="h-4 w-4" />
|
||||||
>
|
</Button>
|
||||||
<Eye className="h-4 w-4" />
|
|
||||||
</Button>
|
<Button
|
||||||
<Button
|
size="sm"
|
||||||
size="icon"
|
variant="outline"
|
||||||
variant="ghost"
|
onClick={() => openEdit(item)}>
|
||||||
className="h-9 w-9"
|
<Pencil className="h-4 w-4" />
|
||||||
onClick={() => openEdit(item)}
|
</Button>
|
||||||
>
|
|
||||||
<Pencil className="h-4 w-4" />
|
<Button
|
||||||
</Button>
|
size="sm"
|
||||||
<Button
|
variant="destructive"
|
||||||
size="icon"
|
onClick={() => handleDelete(Number(item.Id))}>
|
||||||
variant="ghost"
|
<Trash className="h-4 w-4" />
|
||||||
className="h-9 w-9 text-destructive hover:bg-destructive/10"
|
</Button>
|
||||||
onClick={() => handleDelete(Number(item.Id))}
|
|
||||||
>
|
|
||||||
<Trash className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
@@ -301,197 +269,129 @@ export default function NewsPage() {
|
|||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!loading && totalItems > 0 && (
|
{/* PAGINATION */}
|
||||||
<div className="flex items-center justify-between px-2 py-4 border-t">
|
<div className="flex justify-between items-center mt-4">
|
||||||
<div className="text-sm text-muted-foreground">
|
<p className="text-sm">
|
||||||
Total <span className="font-bold">{totalItems}</span> articles
|
Page {currentPage} of {totalPages}
|
||||||
(Page <span className="font-bold">{currentPage}</span> of{" "}
|
</p>
|
||||||
{totalPages})
|
|
||||||
</div>
|
<div className="flex gap-2">
|
||||||
<div className="flex items-center gap-6">
|
<Button
|
||||||
<div className="text-base font-semibold">
|
variant="outline"
|
||||||
Page {currentPage} of {totalPages}
|
size="sm"
|
||||||
</div>
|
disabled={currentPage === 1}
|
||||||
<div className="flex gap-2">
|
onClick={() => setCurrentPage((p) => p - 1)}>
|
||||||
<Button
|
<ChevronLeft className="h-4 w-4" />
|
||||||
variant="outline"
|
</Button>
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
<Button
|
||||||
onClick={() =>
|
variant="outline"
|
||||||
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
size="sm"
|
||||||
}
|
disabled={currentPage === totalPages}
|
||||||
disabled={currentPage === 1}
|
onClick={() => setCurrentPage((p) => p + 1)}>
|
||||||
>
|
<ChevronRight className="h-4 w-4" />
|
||||||
<ChevronLeft className="h-5 w-5" />
|
</Button>
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="h-10 w-10"
|
|
||||||
onClick={() =>
|
|
||||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
|
||||||
}
|
|
||||||
disabled={currentPage === totalPages || totalPages === 0}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{/* CREATE / EDIT MODAL */}
|
||||||
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
||||||
<DialogContent className="w-full !max-w-5xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="w-[95vw] max-w-none max-h-[90vh] overflow-y-auto">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl font-bold">
|
<DialogTitle>{editing ? "Edit News" : "Add News"}</DialogTitle>
|
||||||
{editing ? "Edit News Article" : "Add New News Article"}
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8 mt-6">
|
<div className="space-y-3">
|
||||||
<div className="space-y-6">
|
<Input
|
||||||
<h3 className="font-bold text-base border-b pb-2 text-primary">
|
name="headline"
|
||||||
Article Information
|
placeholder="Headline"
|
||||||
</h3>
|
value={form.headline}
|
||||||
<div className="space-y-4">
|
onChange={handleChange}
|
||||||
<div className="space-y-1">
|
/>
|
||||||
<label className="text-sm font-semibold">Headline</label>
|
<Input
|
||||||
<Input
|
name="author"
|
||||||
name="headline"
|
placeholder="Author"
|
||||||
value={form.headline}
|
value={form.author}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
className="text-base"
|
/>
|
||||||
/>
|
<Input
|
||||||
</div>
|
type="date"
|
||||||
<div className="space-y-1">
|
name="date"
|
||||||
<label className="text-sm font-semibold">Author</label>
|
value={form.date}
|
||||||
<Input
|
onChange={handleChange}
|
||||||
name="author"
|
/>
|
||||||
value={form.author}
|
|
||||||
onChange={handleChange}
|
|
||||||
className="text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1">
|
|
||||||
<label className="text-sm font-semibold">Publish Date</label>
|
|
||||||
<Input
|
|
||||||
type="date"
|
|
||||||
name="date"
|
|
||||||
value={form.date}
|
|
||||||
onChange={handleChange}
|
|
||||||
className="text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1 pt-2">
|
|
||||||
<label className="text-sm font-semibold">Intro Paragraph</label>
|
|
||||||
<Textarea
|
|
||||||
name="firstPara"
|
|
||||||
value={form.firstPara}
|
|
||||||
onChange={handleChange}
|
|
||||||
className="min-h-[140px] text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-6">
|
<textarea
|
||||||
<h3 className="font-bold text-base border-b pb-2 text-primary">
|
name="firstPara"
|
||||||
Story Details
|
placeholder="First Paragraph"
|
||||||
</h3>
|
value={form.firstPara}
|
||||||
<div className="space-y-4">
|
onChange={handleChange}
|
||||||
<div className="space-y-1">
|
className="border rounded p-2 w-full min-h-[100px]"
|
||||||
<label className="text-sm font-semibold">
|
/>
|
||||||
Second Paragraph
|
<textarea
|
||||||
</label>
|
name="secondPara"
|
||||||
<Textarea
|
placeholder="Second Paragraph"
|
||||||
name="secondPara"
|
value={form.secondPara}
|
||||||
value={form.secondPara}
|
onChange={handleChange}
|
||||||
onChange={handleChange}
|
className="border rounded p-2 w-full min-h-[100px]"
|
||||||
className="min-h-[140px] text-base"
|
/>
|
||||||
/>
|
<textarea
|
||||||
</div>
|
name="content"
|
||||||
<div className="space-y-1">
|
placeholder="Content"
|
||||||
<label className="text-sm font-semibold">Content</label>
|
value={form.content}
|
||||||
<Textarea
|
onChange={handleChange}
|
||||||
name="content"
|
className="border rounded p-2 w-full min-h-[150px]"
|
||||||
value={form.content}
|
/>
|
||||||
onChange={handleChange}
|
|
||||||
className="min-h-[200px] text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter className="mt-10 pt-6 border-t">
|
<DialogFooter>
|
||||||
<Button
|
<Button variant="outline" onClick={() => setOpenModal(false)}>
|
||||||
variant="ghost"
|
|
||||||
onClick={() => setOpenModal(false)}
|
|
||||||
className="text-base"
|
|
||||||
>
|
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button onClick={handleSubmit}>
|
||||||
onClick={handleSubmit}
|
{editing ? "Update" : "Create"}
|
||||||
className="px-10 text-base bg-primary text-white"
|
|
||||||
>
|
|
||||||
{editing ? "Save Changes" : "Publish Now"}
|
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
|
{/* VIEW MODAL */}
|
||||||
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
||||||
<DialogContent className="w-full !max-w-4xl max-h-[85vh] overflow-y-auto p-6">
|
<DialogContent className="w-[95vw] max-w-none max-h-[90vh] overflow-y-auto p-6">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl border-b pb-2 flex items-center gap-2">
|
<DialogTitle>News Details</DialogTitle>
|
||||||
<Newspaper className="h-6 w-6 text-primary" /> News Preview
|
|
||||||
</DialogTitle>
|
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
{viewData && (
|
{viewData && (
|
||||||
<div className="space-y-6 py-4">
|
<div className="space-y-4 text-sm">
|
||||||
<div className="space-y-2">
|
<b>Headline:</b>
|
||||||
<h2 className="text-2xl font-bold leading-tight">
|
<p>{viewData.Headline}</p>
|
||||||
{viewData.Headline}
|
|
||||||
</h2>
|
|
||||||
<div className="flex gap-4 text-sm text-muted-foreground font-medium italic">
|
|
||||||
<span>By: {viewData.Author || "Anonymous"}</span>
|
|
||||||
<span>•</span>
|
|
||||||
<span>
|
|
||||||
{viewData.Date
|
|
||||||
? new Date(viewData.Date).toLocaleDateString("en-IN", {
|
|
||||||
dateStyle: "long",
|
|
||||||
})
|
|
||||||
: "No Date"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-5 leading-relaxed text-base">
|
<b>Author:</b>
|
||||||
<div className="bg-muted/30 p-4 rounded-lg border-l-4 border-primary">
|
<p>{viewData.Author}</p>
|
||||||
<p className="whitespace-pre-line">{viewData.FirstPara}</p>
|
|
||||||
</div>
|
<b>Date:</b>
|
||||||
<div className="space-y-4 px-1">
|
<p>
|
||||||
<p className="whitespace-pre-line">{viewData.SecondPara}</p>
|
{viewData.Date
|
||||||
<hr />
|
? new Date(viewData.Date).toLocaleDateString()
|
||||||
<p className="whitespace-pre-line text-muted-foreground">
|
: "-"}
|
||||||
{viewData.Content}
|
</p>
|
||||||
</p>
|
|
||||||
</div>
|
<b>First Para:</b>
|
||||||
</div>
|
<p className="whitespace-pre-line">{viewData.FirstPara}</p>
|
||||||
|
|
||||||
|
<b>Second Para:</b>
|
||||||
|
<p className="whitespace-pre-line">{viewData.SecondPara}</p>
|
||||||
|
|
||||||
|
<b>Content:</b>
|
||||||
|
<p className="whitespace-pre-line">{viewData.Content}</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button
|
<Button onClick={() => setViewOpen(false)}>Close</Button>
|
||||||
onClick={() => setViewOpen(false)}
|
|
||||||
className="w-full md:w-auto"
|
|
||||||
>
|
|
||||||
Close Preview
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
Reference in New Issue
Block a user