[1.0.0] #19

Merged
ashir merged 80 commits from dev into main 2026-04-30 18:37:18 +00:00
Showing only changes of commit 8004a7a21c - Show all commits
+121 -77
View File
@@ -31,7 +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 {Loader2, RefreshCw, Plus, Pencil, Trash} from "lucide-react"; import { Loader2, RefreshCw, Plus, Pencil, Trash, Eye } from "lucide-react";
interface Department { interface Department {
departmentId: string; departmentId: string;
@@ -51,6 +51,9 @@ export default function DepartmentPage() {
const [openModal, setOpenModal] = useState(false); const [openModal, setOpenModal] = useState(false);
const [editing, setEditing] = useState<Department | null>(null); const [editing, setEditing] = useState<Department | null>(null);
const [viewOpen, setViewOpen] = useState(false);
const [viewData, setViewData] = useState<Department | null>(null);
const [searchText, setSearchText] = useState(""); const [searchText, setSearchText] = useState("");
const [form, setForm] = useState<Department>({ const [form, setForm] = useState<Department>({
@@ -85,32 +88,21 @@ export default function DepartmentPage() {
fetchDepartments(); fetchDepartments();
}, [fetchDepartments]); }, [fetchDepartments]);
const filteredDepartments = departments.filter((dep) => { const filteredDepartments = departments.filter((dep) =>
const text = searchText.toLowerCase(); dep.name.toLowerCase().includes(searchText.toLowerCase()),
return (
dep.name.toLowerCase().includes(text) ||
dep.departmentId.toLowerCase().includes(text) ||
dep.para1.toLowerCase().includes(text) ||
dep.para2.toLowerCase().includes(text) ||
dep.para3.toLowerCase().includes(text) ||
dep.facilities.toLowerCase().includes(text) ||
dep.services.toLowerCase().includes(text)
); );
});
function handleChange( function handleChange(e: any) {
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, setForm({ ...form, [e.target.name]: e.target.value });
) { }
setForm({
...form, function truncate(text: string, limit = 60) {
[e.target.name]: e.target.value, if (!text) return "-";
}); return text.length > limit ? text.substring(0, limit) + "..." : text;
} }
function openAdd() { function openAdd() {
setEditing(null); setEditing(null);
setForm({ setForm({
departmentId: "", departmentId: "",
name: "", name: "",
@@ -120,7 +112,6 @@ export default function DepartmentPage() {
facilities: "", facilities: "",
services: "", services: "",
}); });
setOpenModal(true); setOpenModal(true);
} }
@@ -130,6 +121,11 @@ export default function DepartmentPage() {
setOpenModal(true); setOpenModal(true);
} }
function openView(dep: Department) {
setViewData(dep);
setViewOpen(true);
}
async function handleSubmit() { async function handleSubmit() {
try { try {
if (editing) { if (editing) {
@@ -146,12 +142,11 @@ export default function DepartmentPage() {
} }
} }
async function handleDelete(departmentId: string) { async function handleDelete(id: string) {
const confirmDelete = confirm("Delete this department?"); if (!confirm("Delete this department?")) return;
if (!confirmDelete) return;
try { try {
await deleteDepartmentApi(departmentId); await deleteDepartmentApi(id);
fetchDepartments(); fetchDepartments();
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@@ -172,11 +167,7 @@ export default function DepartmentPage() {
className="w-[220px]" className="w-[220px]"
/> />
<Button <Button onClick={fetchDepartments} disabled={loading}>
variant="outline"
onClick={fetchDepartments}
disabled={loading}
>
<RefreshCw className="mr-2 h-4 w-4" /> <RefreshCw className="mr-2 h-4 w-4" />
Refresh Refresh
</Button> </Button>
@@ -194,37 +185,36 @@ export default function DepartmentPage() {
</div> </div>
)} )}
{/* TABLE */}
<Card> <Card>
<CardHeader> <CardHeader>
<CardTitle>Department List</CardTitle> <CardTitle>Department List</CardTitle>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
<div className="border rounded-md overflow-x-auto max-w-full"> <div className="border rounded-md max-h-[500px] overflow-y-auto">
<Table> <Table className="w-full table-fixed">
<TableHeader> <TableHeader>
<TableRow> <TableRow>
<TableHead>ID</TableHead> <TableHead className="w-[80px]">ID</TableHead>
<TableHead>Name</TableHead> <TableHead className="w-[180px]">Name</TableHead>
<TableHead>Para1</TableHead> <TableHead className="w-[250px]">Para1</TableHead>
<TableHead>Para2</TableHead> <TableHead className="w-[220px]">Facilities</TableHead>
<TableHead>Para3</TableHead> <TableHead className="w-[220px]">Services</TableHead>
<TableHead>Facilities</TableHead> <TableHead className="w-[120px]">Actions</TableHead>
<TableHead>Services</TableHead>
<TableHead>Actions</TableHead>
</TableRow> </TableRow>
</TableHeader> </TableHeader>
<TableBody> <TableBody>
{loading ? ( {loading ? (
<TableRow> <TableRow>
<TableCell colSpan={8} className="text-center"> <TableCell colSpan={6} className="text-center">
<Loader2 className="h-6 w-6 animate-spin mx-auto" /> <Loader2 className="h-6 w-6 animate-spin mx-auto" />
</TableCell> </TableCell>
</TableRow> </TableRow>
) : filteredDepartments.length === 0 ? ( ) : filteredDepartments.length === 0 ? (
<TableRow> <TableRow>
<TableCell colSpan={8} className="text-center"> <TableCell colSpan={6} className="text-center">
No departments found No departments found
</TableCell> </TableCell>
</TableRow> </TableRow>
@@ -233,42 +223,47 @@ export default function DepartmentPage() {
<TableRow key={dep.departmentId}> <TableRow key={dep.departmentId}>
<TableCell>{dep.departmentId}</TableCell> <TableCell>{dep.departmentId}</TableCell>
<TableCell>{dep.name}</TableCell> <TableCell>
<div className="break-words">{dep.name}</div>
<TableCell className="max-w-[300px] whitespace-normal break-words">
{dep.para1}
</TableCell> </TableCell>
<TableCell className="max-w-[300px] whitespace-normal break-words"> <TableCell>
{dep.para2} <div className="break-words whitespace-normal">
{truncate(dep.para1)}
</div>
</TableCell> </TableCell>
<TableCell className="max-w-[300px] whitespace-normal break-words"> <TableCell>
{dep.para3} <div className="break-words whitespace-normal">
{truncate(dep.facilities)}
</div>
</TableCell> </TableCell>
<TableCell className="max-w-[300px] whitespace-normal break-words"> <TableCell>
{dep.facilities} <div className="break-words whitespace-normal">
{truncate(dep.services)}
</div>
</TableCell> </TableCell>
<TableCell className="max-w-[300px] whitespace-normal break-words"> <TableCell className="flex gap-2 whitespace-nowrap">
{dep.services}
</TableCell>
<TableCell className="flex gap-2">
<Button <Button
size="sm" size="sm"
variant="outline" variant="outline"
onClick={() => openEdit(dep)} onClick={() => openView(dep)}>
> <Eye className="h-4 w-4" />
</Button>
<Button
size="sm"
variant="outline"
onClick={() => openEdit(dep)}>
<Pencil className="h-4 w-4" /> <Pencil className="h-4 w-4" />
</Button> </Button>
<Button <Button
size="sm" size="sm"
variant="destructive" variant="destructive"
onClick={() => handleDelete(dep.departmentId)} onClick={() => handleDelete(dep.departmentId)}>
>
<Trash className="h-4 w-4" /> <Trash className="h-4 w-4" />
</Button> </Button>
</TableCell> </TableCell>
@@ -281,64 +276,60 @@ export default function DepartmentPage() {
</CardContent> </CardContent>
</Card> </Card>
{/* MODAL */} {/* ADD / EDIT MODAL */}
<Dialog open={openModal} onOpenChange={setOpenModal}> <Dialog open={openModal} onOpenChange={setOpenModal}>
<DialogContent className="max-w-4xl"> <DialogContent className="w-full !max-w-5xl max-h-[90vh] overflow-y-auto">
<DialogHeader> <DialogHeader>
<DialogTitle> <DialogTitle>
{editing ? "Edit Department" : "Add Department"} {editing ? "Edit Department" : "Add Department"}
</DialogTitle> </DialogTitle>
</DialogHeader> </DialogHeader>
<div className="space-y-4 max-h-[70vh] overflow-y-auto pr-2"> <div className="space-y-4">
<Input <Input
name="departmentId" name="departmentId"
placeholder="Department ID"
value={form.departmentId} value={form.departmentId}
onChange={handleChange} onChange={handleChange}
disabled={!!editing} disabled={!!editing}
placeholder="Department ID"
/> />
<Input <Input
name="name" name="name"
placeholder="Department Name"
value={form.name} value={form.name}
onChange={handleChange} onChange={handleChange}
placeholder="Department Name"
/> />
<Textarea <Textarea
name="para1" name="para1"
placeholder="Paragraph 1"
value={form.para1} value={form.para1}
onChange={handleChange} onChange={handleChange}
placeholder="Para1"
/> />
<Textarea <Textarea
name="para2" name="para2"
placeholder="Paragraph 2"
value={form.para2} value={form.para2}
onChange={handleChange} onChange={handleChange}
placeholder="Para2"
/> />
<Textarea <Textarea
name="para3" name="para3"
placeholder="Paragraph 3"
value={form.para3} value={form.para3}
onChange={handleChange} onChange={handleChange}
placeholder="Para3"
/> />
<Textarea <Textarea
name="facilities" name="facilities"
placeholder="Facilities"
value={form.facilities} value={form.facilities}
onChange={handleChange} onChange={handleChange}
placeholder="Facilities"
/> />
<Textarea <Textarea
name="services" name="services"
placeholder="Services"
value={form.services} value={form.services}
onChange={handleChange} onChange={handleChange}
placeholder="Services"
/> />
</div> </div>
@@ -346,13 +337,66 @@ export default function DepartmentPage() {
<Button variant="outline" onClick={() => setOpenModal(false)}> <Button variant="outline" onClick={() => setOpenModal(false)}>
Cancel Cancel
</Button> </Button>
<Button onClick={handleSubmit}> <Button onClick={handleSubmit}>
{editing ? "Update" : "Create"} {editing ? "Update" : "Create"}
</Button> </Button>
</DialogFooter> </DialogFooter>
</DialogContent> </DialogContent>
</Dialog> </Dialog>
{/* VIEW MODAL */}
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
<DialogContent className="w-full !max-w-5xl max-h-[90vh] overflow-y-auto">
{" "}
<DialogHeader>
<DialogTitle>Department Details</DialogTitle>
</DialogHeader>
{viewData && (
<div className="space-y-4 text-sm">
<p>
<b>ID:</b> {viewData.departmentId}
</p>
<p>
<b>Name:</b> {viewData.name}
</p>
<p>
<b>Para1:</b>
<br />
{viewData.para1}
</p>
<p>
<b>Para2:</b>
<br />
{viewData.para2}
</p>
<p>
<b>Para3:</b>
<br />
{viewData.para3}
</p>
<p>
<b>Facilities:</b>
<br />
{viewData.facilities}
</p>
<p>
<b>Services:</b>
<br />
{viewData.services}
</p>
</div>
)}
<DialogFooter>
<Button onClick={() => setViewOpen(false)}>Close</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div> </div>
); );
} }