mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 20:36:29 +00:00
93d2c272f2
Dynamically import client and assignment lists, grids, forms, filters, and activity timelines to reduce initial bundle work, with loading placeholders for list and grid views. Also refine client logo corners and assignment activity accents.
126 lines
4.4 KiB
TypeScript
126 lines
4.4 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from 'react';
|
|
import { useRouter, useSearchParams } from 'next/navigation';
|
|
import { Users } from 'lucide-react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { IClient } from '../../types';
|
|
import dynamic from 'next/dynamic';
|
|
|
|
const ClientGrid = dynamic(() => import('./ClientGrid'), {
|
|
ssr: false,
|
|
loading: () => (
|
|
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
{[1, 2, 3, 4, 5, 6].map((i) => (
|
|
<div key={i} className="h-80 w-full animate-pulse rounded-2xl border border-border/80 bg-card p-6" />
|
|
))}
|
|
</div>
|
|
),
|
|
});
|
|
|
|
const ClientList = dynamic(() => import('./ClientList'), {
|
|
ssr: false,
|
|
loading: () => (
|
|
<div className="flex flex-col gap-6">
|
|
{[1, 2, 3, 4].map((i) => (
|
|
<div key={i} className="h-64 w-full animate-pulse rounded-2xl border border-border/80 bg-card p-6" />
|
|
))}
|
|
</div>
|
|
),
|
|
});
|
|
|
|
const FormClient = dynamic(() => import('./FormClient'), { ssr: false });
|
|
|
|
const ConfirmDeleteWithInput = dynamic(
|
|
() => import('@/components/modal/ConfirmDeleteWithInput').then((mod) => mod.ConfirmDeleteWithInput),
|
|
{ ssr: false }
|
|
);
|
|
|
|
interface ClientProps {
|
|
clients: IClient[];
|
|
initialLayout?: 'grid' | 'list';
|
|
}
|
|
|
|
export default function Client({ clients, initialLayout = 'grid' }: ClientProps) {
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
const layout = searchParams?.get('layout') === 'list' ? 'list' : initialLayout;
|
|
|
|
const [action, setAction] = useState<'EDIT' | 'DELETE' | undefined>(undefined);
|
|
const [selectedData, setSelectedData] = useState<IClient>();
|
|
|
|
const handleClose = () => {
|
|
setAction(undefined);
|
|
setSelectedData(undefined);
|
|
};
|
|
|
|
const handleEdit = (client: IClient) => {
|
|
setSelectedData(client);
|
|
setAction('EDIT');
|
|
};
|
|
|
|
const handleDelete = (client: IClient) => {
|
|
setSelectedData(client);
|
|
setAction('DELETE');
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{clients.length === 0 ? (
|
|
<div className="py-12 text-center border-2 border-dashed rounded-xl">
|
|
<Users className="w-12 h-12 mx-auto text-muted-foreground mb-4 opacity-20" />
|
|
<div className="text-center">
|
|
<h3 className="text-xl font-semibold">No Client Found</h3>
|
|
<p className="text-muted-foreground max-w-sm mx-auto mt-2">
|
|
Try to change the filter or create one to get started.
|
|
</p>
|
|
<Button
|
|
variant="outline"
|
|
className="mt-4"
|
|
onClick={() => {
|
|
setAction('EDIT');
|
|
setSelectedData(undefined);
|
|
}}
|
|
>
|
|
Create New Client
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
|
|
{clients.length > 0 && layout === 'list' ?
|
|
<ClientList clients={clients} onEdit={handleEdit} onDelete={handleDelete} />
|
|
: null}
|
|
|
|
{clients.length > 0 && layout === 'grid' ?
|
|
<ClientGrid clients={clients} onEdit={handleEdit} onDelete={handleDelete} />
|
|
: null}
|
|
|
|
{action === 'EDIT' && (
|
|
<FormClient
|
|
data={selectedData}
|
|
onCancel={handleClose}
|
|
onSuccess={() => {
|
|
router.refresh();
|
|
handleClose();
|
|
}}
|
|
/>
|
|
)}
|
|
|
|
{action === 'DELETE' && selectedData ?
|
|
<ConfirmDeleteWithInput
|
|
endpoint={`/client/${selectedData.id}`}
|
|
onCancel={handleClose}
|
|
onSuccess={() => {
|
|
router.refresh();
|
|
handleClose();
|
|
}}
|
|
title={selectedData.name}
|
|
description={`This action cannot be undone. This will permanently delete and remove client ${selectedData.name} from our servers.`}
|
|
titleButton="I understand the consequences, delete this client"
|
|
/>
|
|
: null}
|
|
</>
|
|
);
|
|
}
|