unzip frontend
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
"use client"
|
||||
|
||||
import type React from "react"
|
||||
|
||||
import { useState } from "react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog"
|
||||
import type { Client } from "@/types/business"
|
||||
|
||||
interface ClientFormProps {
|
||||
client?: Client
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
onSubmit: (client: Omit<Client, "id">) => void
|
||||
}
|
||||
|
||||
const paymentTerms = ["Net 15", "Net 30", "Net 45", "Net 60", "COD", "Prepaid", "Custom"]
|
||||
|
||||
export function ClientForm({ client, open, onOpenChange, onSubmit }: ClientFormProps) {
|
||||
const [formData, setFormData] = useState({
|
||||
name: client?.name || "",
|
||||
email: client?.email || "",
|
||||
phone: client?.phone || "",
|
||||
address: client?.address || "",
|
||||
creditLimit: client?.creditLimit || 0,
|
||||
paymentTerms: client?.paymentTerms || "Net 30",
|
||||
notes: client?.notes || "",
|
||||
contactPerson: client?.contactPerson || "",
|
||||
businessType: client?.businessType || "",
|
||||
})
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
onSubmit({
|
||||
...formData,
|
||||
outstandingAmount: client?.outstandingAmount || 0,
|
||||
})
|
||||
onOpenChange(false)
|
||||
// Reset form if it's a new client
|
||||
if (!client) {
|
||||
setFormData({
|
||||
name: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
address: "",
|
||||
creditLimit: 0,
|
||||
paymentTerms: "Net 30",
|
||||
notes: "",
|
||||
contactPerson: "",
|
||||
businessType: "",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[600px] max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{client ? "Edit Client" : "Add New Client"}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{client ? "Update client information" : "Enter the details for the new client"}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="name">Business Name *</Label>
|
||||
<Input
|
||||
id="name"
|
||||
value={formData.name}
|
||||
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
||||
placeholder="Enter business name"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="contactPerson">Contact Person</Label>
|
||||
<Input
|
||||
id="contactPerson"
|
||||
value={formData.contactPerson}
|
||||
onChange={(e) => setFormData({ ...formData, contactPerson: e.target.value })}
|
||||
placeholder="Primary contact name"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
value={formData.email}
|
||||
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
||||
placeholder="client@example.com"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="phone">Phone</Label>
|
||||
<Input
|
||||
id="phone"
|
||||
value={formData.phone}
|
||||
onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
|
||||
placeholder="(555) 123-4567"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="address">Address</Label>
|
||||
<Textarea
|
||||
id="address"
|
||||
value={formData.address}
|
||||
onChange={(e) => setFormData({ ...formData, address: e.target.value })}
|
||||
placeholder="Business address"
|
||||
rows={2}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="businessType">Business Type</Label>
|
||||
<Input
|
||||
id="businessType"
|
||||
value={formData.businessType}
|
||||
onChange={(e) => setFormData({ ...formData, businessType: e.target.value })}
|
||||
placeholder="e.g., Retail, Electronics Store"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="paymentTerms">Payment Terms</Label>
|
||||
<Select
|
||||
value={formData.paymentTerms}
|
||||
onValueChange={(value) => setFormData({ ...formData, paymentTerms: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select payment terms" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{paymentTerms.map((term) => (
|
||||
<SelectItem key={term} value={term}>
|
||||
{term}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="creditLimit">Credit Limit ($)</Label>
|
||||
<Input
|
||||
id="creditLimit"
|
||||
type="number"
|
||||
min="0"
|
||||
step="100"
|
||||
value={formData.creditLimit}
|
||||
onChange={(e) => setFormData({ ...formData, creditLimit: Number.parseFloat(e.target.value) || 0 })}
|
||||
placeholder="0"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">Maximum amount this client can owe at any time</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="notes">Notes</Label>
|
||||
<Textarea
|
||||
id="notes"
|
||||
value={formData.notes}
|
||||
onChange={(e) => setFormData({ ...formData, notes: e.target.value })}
|
||||
placeholder="Additional notes about this client"
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit">{client ? "Update Client" : "Add Client"}</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog"
|
||||
import { Search, MoreHorizontal, Edit, Trash2, Mail, Phone, CreditCard } from "lucide-react"
|
||||
import type { Client } from "@/types/business"
|
||||
|
||||
interface ClientsTableProps {
|
||||
clients: Client[]
|
||||
onEdit: (client: Client) => void
|
||||
onDelete: (clientId: string) => void
|
||||
onAddPayment: (clientId: string) => void
|
||||
}
|
||||
|
||||
export function ClientsTable({ clients, onEdit, onDelete, onAddPayment }: ClientsTableProps) {
|
||||
const [searchTerm, setSearchTerm] = useState("")
|
||||
const [deleteClient, setDeleteClient] = useState<Client | null>(null)
|
||||
|
||||
const filteredClients = clients.filter(
|
||||
(client) =>
|
||||
client.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
client.email.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
client.contactPerson.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
client.businessType.toLowerCase().includes(searchTerm.toLowerCase()),
|
||||
)
|
||||
|
||||
const getCreditStatus = (outstandingAmount: number, creditLimit: number) => {
|
||||
if (outstandingAmount === 0) return { label: "Good Standing", variant: "default" as const, color: "text-green-600" }
|
||||
if (outstandingAmount >= creditLimit * 0.9)
|
||||
return { label: "Near Limit", variant: "secondary" as const, color: "text-yellow-600" }
|
||||
if (outstandingAmount > creditLimit)
|
||||
return { label: "Over Limit", variant: "destructive" as const, color: "text-red-600" }
|
||||
return { label: "Active Credit", variant: "secondary" as const, color: "text-blue-600" }
|
||||
}
|
||||
|
||||
const handleDelete = (client: Client) => {
|
||||
onDelete(client.id)
|
||||
setDeleteClient(null)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Search */}
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4" />
|
||||
<Input
|
||||
placeholder="Search clients by name, email, contact person, or business type..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Clients Table */}
|
||||
<div className="border rounded-lg overflow-hidden">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Client</TableHead>
|
||||
<TableHead>Contact</TableHead>
|
||||
<TableHead>Business Type</TableHead>
|
||||
<TableHead>Payment Terms</TableHead>
|
||||
<TableHead>Credit Status</TableHead>
|
||||
<TableHead>Outstanding</TableHead>
|
||||
<TableHead className="w-[50px]"></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{filteredClients.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="text-center py-8 text-muted-foreground">
|
||||
{searchTerm ? "No clients found matching your search." : "No clients added yet."}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
filteredClients.map((client) => {
|
||||
const creditStatus = getCreditStatus(client.outstandingAmount, client.creditLimit)
|
||||
const creditUtilization =
|
||||
client.creditLimit > 0 ? ((client.outstandingAmount / client.creditLimit) * 100).toFixed(1) : "0"
|
||||
|
||||
return (
|
||||
<TableRow key={client.id}>
|
||||
<TableCell>
|
||||
<div>
|
||||
<p className="font-medium">{client.name}</p>
|
||||
{client.contactPerson && (
|
||||
<p className="text-sm text-muted-foreground">{client.contactPerson}</p>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="space-y-1">
|
||||
{client.email && (
|
||||
<div className="flex items-center gap-1 text-sm">
|
||||
<Mail className="h-3 w-3" />
|
||||
<span className="truncate max-w-[150px]">{client.email}</span>
|
||||
</div>
|
||||
)}
|
||||
{client.phone && (
|
||||
<div className="flex items-center gap-1 text-sm">
|
||||
<Phone className="h-3 w-3" />
|
||||
<span>{client.phone}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="text-sm">{client.businessType || "N/A"}</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{client.paymentTerms}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div>
|
||||
<Badge variant={creditStatus.variant} className="text-xs mb-1">
|
||||
{creditStatus.label}
|
||||
</Badge>
|
||||
{client.creditLimit > 0 && (
|
||||
<p className="text-xs text-muted-foreground">{creditUtilization}% utilized</p>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="text-right">
|
||||
<p className={`font-medium text-sm ${client.outstandingAmount > 0 ? creditStatus.color : ""}`}>
|
||||
${client.outstandingAmount.toFixed(2)}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">/ ${client.creditLimit.toFixed(2)} limit</p>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="sm">
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => onEdit(client)}>
|
||||
<Edit className="h-4 w-4 mr-2" />
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => onAddPayment(client.id)}>
|
||||
<CreditCard className="h-4 w-4 mr-2" />
|
||||
Add Payment
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setDeleteClient(client)} className="text-red-600">
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
{/* Delete Confirmation Dialog */}
|
||||
<AlertDialog open={!!deleteClient} onOpenChange={() => setDeleteClient(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete Client</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Are you sure you want to delete "{deleteClient?.name}"? This action cannot be undone and will remove all
|
||||
associated transaction history.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => deleteClient && handleDelete(deleteClient)}
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
"use client"
|
||||
|
||||
import type React from "react"
|
||||
|
||||
import { useState } from "react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog"
|
||||
|
||||
interface PaymentFormProps {
|
||||
clientName: string
|
||||
outstandingAmount: number
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
onSubmit: (payment: { amount: number; notes: string; date: string }) => void
|
||||
}
|
||||
|
||||
export function PaymentForm({ clientName, outstandingAmount, open, onOpenChange, onSubmit }: PaymentFormProps) {
|
||||
const [formData, setFormData] = useState({
|
||||
amount: 0,
|
||||
notes: "",
|
||||
date: new Date().toISOString().split("T")[0],
|
||||
})
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
onSubmit(formData)
|
||||
onOpenChange(false)
|
||||
setFormData({
|
||||
amount: 0,
|
||||
notes: "",
|
||||
date: new Date().toISOString().split("T")[0],
|
||||
})
|
||||
}
|
||||
|
||||
const maxPayment = outstandingAmount
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[500px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Record Payment</DialogTitle>
|
||||
<DialogDescription>Record a payment from {clientName}</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="p-4 bg-muted rounded-lg">
|
||||
<p className="text-sm text-muted-foreground mb-1">Outstanding Amount</p>
|
||||
<p className="text-2xl font-bold">${outstandingAmount.toFixed(2)}</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="amount">Payment Amount ($) *</Label>
|
||||
<Input
|
||||
id="amount"
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0.01"
|
||||
max={maxPayment}
|
||||
value={formData.amount}
|
||||
onChange={(e) => setFormData({ ...formData, amount: Number.parseFloat(e.target.value) || 0 })}
|
||||
placeholder="0.00"
|
||||
required
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setFormData({ ...formData, amount: maxPayment / 4 })}
|
||||
>
|
||||
25%
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setFormData({ ...formData, amount: maxPayment / 2 })}
|
||||
>
|
||||
50%
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setFormData({ ...formData, amount: maxPayment })}
|
||||
>
|
||||
Full Amount
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="date">Payment Date *</Label>
|
||||
<Input
|
||||
id="date"
|
||||
type="date"
|
||||
value={formData.date}
|
||||
onChange={(e) => setFormData({ ...formData, date: e.target.value })}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="notes">Notes</Label>
|
||||
<Textarea
|
||||
id="notes"
|
||||
value={formData.notes}
|
||||
onChange={(e) => setFormData({ ...formData, notes: e.target.value })}
|
||||
placeholder="Payment method, reference number, etc."
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{formData.amount > 0 && (
|
||||
<div className="p-3 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg">
|
||||
<p className="text-sm text-green-800 dark:text-green-200">
|
||||
New outstanding amount: <strong>${(outstandingAmount - formData.amount).toFixed(2)}</strong>
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={formData.amount <= 0 || formData.amount > maxPayment}>
|
||||
Record Payment
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user