'use client'; import { useState } from 'react'; import { useDispatch } from 'react-redux'; import { AppDispatch } from '@/store/store'; import { createClient } from '@/store/slices/adminSlice'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; import { toast } from 'sonner'; interface CreateClientDialogProps { open: boolean; onOpenChange: (open: boolean) => void; } export default function CreateClientDialog({ open, onOpenChange }: CreateClientDialogProps) { const dispatch = useDispatch(); const [name, setName] = useState(''); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!name.trim()) return; setLoading(true); try { await dispatch(createClient({ name: name.trim() })).unwrap(); toast.success('Client created successfully'); setName(''); onOpenChange(false); } catch (err) { toast.error(typeof err === 'string' ? err : 'Failed to create client'); } finally { setLoading(false); } }; return ( Create New Client
setName(e.target.value)} placeholder="e.g. Nike, Adidas" required />
); }