'use client'; import React, { useState, useEffect } from 'react'; import { Customer } from '@/types'; import { Users, Plus, Phone, Mail, Building, MapPin, X, RefreshCw } from 'lucide-react'; export const CustomerManager: React.FC = () => { const [customers, setCustomers] = useState([]); const [loading, setLoading] = useState(true); const [isModalOpen, setIsModalOpen] = useState(false); const [newCustomer, setNewCustomer] = useState({ name: '', phone: '', email: '', company: '', address: '', notes: '', }); const fetchCustomers = async () => { try { setLoading(true); const res = await fetch('/api/customers'); const data = await res.json(); if (Array.isArray(data)) setCustomers(data); } catch (err) { console.error(err); } finally { setLoading(false); } }; useEffect(() => { fetchCustomers(); }, []); const handleSave = async (e: React.FormEvent) => { e.preventDefault(); try { const res = await fetch('/api/customers', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(newCustomer), }); if (res.ok) { setIsModalOpen(false); setNewCustomer({ name: '', phone: '', email: '', company: '', address: '', notes: '' }); fetchCustomers(); } } catch (err) { console.error(err); } }; return (

Danh Sách Khách Hàng (CRM mini)

Lưu trữ thông tin liên hệ, công ty và lịch sử đặt in của khách hàng

{loading ? (
Đang tải danh sách khách hàng...
) : customers.length === 0 ? (
Chưa có khách hàng nào trong hệ thống
) : ( customers.map((c) => (
{c.name} #{c.id}
{c.company && (
{c.company}
)}
{c.phone}
{c.email && (
{c.email}
)} {c.address && (
{c.address}
)} {c.notes && (

“{c.notes}”

)}
)) )}
{isModalOpen && (

Thêm Mới Khách Hàng

setNewCustomer({ ...newCustomer, name: e.target.value })} placeholder="Ví dụ: Anh Hoàng / Chị Mai" className="w-full border border-slate-300 rounded-lg p-2 focus:ring-1 focus:ring-blue-500" />
setNewCustomer({ ...newCustomer, phone: e.target.value })} placeholder="0901234567" className="w-full border border-slate-300 rounded-lg p-2 focus:ring-1 focus:ring-blue-500" />
setNewCustomer({ ...newCustomer, email: e.target.value })} placeholder="email@example.com" className="w-full border border-slate-300 rounded-lg p-2 focus:ring-1 focus:ring-blue-500" />
setNewCustomer({ ...newCustomer, company: e.target.value })} placeholder="Công ty TNHH..." className="w-full border border-slate-300 rounded-lg p-2 focus:ring-1 focus:ring-blue-500" />
setNewCustomer({ ...newCustomer, address: e.target.value })} placeholder="Số nhà, tên đường, quận/huyện..." className="w-full border border-slate-300 rounded-lg p-2 focus:ring-1 focus:ring-blue-500" />