-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcustomer-detail-dialog.tsx
More file actions
151 lines (138 loc) · 5.02 KB
/
customer-detail-dialog.tsx
File metadata and controls
151 lines (138 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Customer Detail Dialog Component
*
* Displays customer details and order history.
*
* @module components/customers/customer-detail-dialog
*/
'use client';
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { Badge } from '@/components/ui/badge';
import { Mail, Phone, Calendar, ShoppingCart, DollarSign } from 'lucide-react';
import { getCustomerDisplayName } from '@/lib/utils/customer';
interface Customer {
id: string;
firstName: string;
lastName: string;
email: string;
phone?: string;
totalOrders: number;
totalSpent: number;
createdAt: string;
lastOrderAt?: string;
status: 'active' | 'inactive';
}
interface CustomerDetailDialogProps {
customer: Customer;
open: boolean;
onOpenChange: (open: boolean) => void;
}
export function CustomerDetailDialog({
customer,
open,
onOpenChange,
}: CustomerDetailDialogProps) {
const formatCurrency = (value: number) => {
return 'BDT ' + new Intl.NumberFormat('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(value);
};
const formatDate = (dateString: string) => {
return new Date(dateString).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
});
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[600px]">
<DialogHeader>
<div className="flex items-center justify-between">
<div>
<DialogTitle className="text-2xl">
{getCustomerDisplayName(customer)}
</DialogTitle>
<DialogDescription>Customer details and activity</DialogDescription>
</div>
<Badge variant={customer.status === 'active' ? 'default' : 'secondary'}>
{customer.status}
</Badge>
</div>
</DialogHeader>
<div className="space-y-6">
{/* Contact Information */}
<div>
<h3 className="text-sm font-semibold mb-3">Contact Information</h3>
<div className="space-y-2">
<div className="flex items-center gap-3 text-sm">
<Mail className="h-4 w-4 text-muted-foreground" />
<span>{customer.email}</span>
</div>
{customer.phone && (
<div className="flex items-center gap-3 text-sm">
<Phone className="h-4 w-4 text-muted-foreground" />
<span>{customer.phone}</span>
</div>
)}
</div>
</div>
{/* Activity Summary */}
<div>
<h3 className="text-sm font-semibold mb-3">Activity Summary</h3>
<div className="grid grid-cols-2 gap-4">
<div className="p-4 border rounded-lg">
<div className="flex items-center gap-2 mb-2">
<ShoppingCart className="h-4 w-4 text-muted-foreground" />
<span className="text-sm text-muted-foreground">Total Orders</span>
</div>
<p className="text-2xl font-bold">{customer.totalOrders}</p>
</div>
<div className="p-4 border rounded-lg">
<div className="flex items-center gap-2 mb-2">
<DollarSign className="h-4 w-4 text-muted-foreground" />
<span className="text-sm text-muted-foreground">Total Spent</span>
</div>
<p className="text-2xl font-bold">{formatCurrency(customer.totalSpent)}</p>
</div>
<div className="p-4 border rounded-lg">
<div className="flex items-center gap-2 mb-2">
<Calendar className="h-4 w-4 text-muted-foreground" />
<span className="text-sm text-muted-foreground">Joined</span>
</div>
<p className="text-sm">{customer.createdAt ? formatDate(customer.createdAt) : '-'}</p>
</div>
{customer.lastOrderAt && (
<div className="p-4 border rounded-lg">
<div className="flex items-center gap-2 mb-2">
<Calendar className="h-4 w-4 text-muted-foreground" />
<span className="text-sm text-muted-foreground">Last Order</span>
</div>
<p className="text-sm">{formatDate(customer.lastOrderAt)}</p>
</div>
)}
</div>
</div>
{/* Stats */}
<div className="p-4 bg-muted rounded-lg">
<div className="flex items-center justify-between">
<span className="text-sm text-muted-foreground">Average Order Value</span>
<span className="text-lg font-semibold">
{customer.totalOrders > 0
? formatCurrency(customer.totalSpent / customer.totalOrders)
: formatCurrency(0)}
</span>
</div>
</div>
</div>
</DialogContent>
</Dialog>
);
}