mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 17:16:28 +00:00
ffcf3c6e58
This commit reorganizes client and project-assignment screens into dedicated grid/list components, adds a shared layout toggle via the URL query string, and updates task pages to render the selected view consistently. It also moves shared client form logic into a client folder, improves status badge formatting, extends LazyImage with custom image classes, and updates the illustration assets and Lucide dependency used in the task UI.
100 lines
3.6 KiB
TypeScript
100 lines
3.6 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 FormClient from './FormClient';
|
|
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
|
|
import ClientGrid from './ClientGrid';
|
|
import ClientList from './ClientList';
|
|
|
|
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}
|
|
</>
|
|
);
|
|
}
|