"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(); 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 ? (

No Client Found

Try to change the filter or create one to get started.

) : null} {clients.length > 0 && layout === 'list' ? : null} {clients.length > 0 && layout === 'grid' ? : null} {action === 'EDIT' && ( { router.refresh(); handleClose(); }} /> )} {action === 'DELETE' && selectedData ? { 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} ); }