@apptimate/ui 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/src/base-components/DateLabel.tsx +68 -0
- package/src/base-components/DateRangePicker.tsx +392 -0
- package/src/base-components/ImageDropzone.tsx +80 -0
- package/src/base-components/Modal.tsx +19 -7
- package/src/base-components/PopConfirm.tsx +15 -4
- package/src/common-components/DashboardLayout.tsx +16 -5
- package/src/common-components/charts/RBarChart.tsx +145 -0
- package/src/common-components/charts/RLineChart.tsx +116 -0
- package/src/common-components/charts/index.ts +3 -0
- package/src/common-components/charts/palette.ts +10 -0
- package/src/components/shared/CustomerSelectorComponent.tsx +163 -0
- package/src/components/shared/ImageUploadComponent.tsx +228 -0
- package/src/components/shared/PaymentModeComponent.tsx +421 -0
- package/src/components/shared/ProcurementManagerSelector.tsx +5 -0
- package/src/components/shared/ProductSelectorComponent.tsx +166 -0
- package/src/components/shared/SupplierSelectorComponent.tsx +5 -0
- package/src/index.tsx +6 -1
- /package/src/common-components/{Charts.tsx → charts/ApexCharts.tsx} +0 -0
|
@@ -69,7 +69,11 @@ export function DashboardLayout({
|
|
|
69
69
|
const fullPath = basePath + (pathname === "/" && basePath ? "" : pathname);
|
|
70
70
|
|
|
71
71
|
const currentMainMenu = menus.find(menu =>
|
|
72
|
-
menu.groups.some(group => group.items.some(item =>
|
|
72
|
+
menu.groups.some(group => group.items.some(item =>
|
|
73
|
+
fullPath === item.path ||
|
|
74
|
+
fullPath.startsWith(item.path + "/") ||
|
|
75
|
+
item.path.startsWith(fullPath + "/")
|
|
76
|
+
))
|
|
73
77
|
) || menus[0];
|
|
74
78
|
|
|
75
79
|
const [activeMenuId, setActiveMenuId] = useState(currentMainMenu?.id || "");
|
|
@@ -162,7 +166,11 @@ export function DashboardLayout({
|
|
|
162
166
|
<h3 className="px-2 text-xs font-bold text-gray-400 uppercase tracking-wider mb-2">{group.label}</h3>
|
|
163
167
|
<nav className="flex flex-col gap-1">
|
|
164
168
|
{group.items.map((item) => {
|
|
165
|
-
|
|
169
|
+
// Find the longest matching path in this group to avoid parent paths being active
|
|
170
|
+
const allGroupItems = activeMenu.groups.flatMap(g => g.items);
|
|
171
|
+
const matchingItems = allGroupItems.filter(i => fullPath === i.path || fullPath.startsWith(`${i.path}/`));
|
|
172
|
+
const longestMatch = matchingItems.sort((a, b) => b.path.length - a.path.length)[0];
|
|
173
|
+
const isItemActive = longestMatch?.path === item.path;
|
|
166
174
|
const isInternal = basePath
|
|
167
175
|
? item.path.startsWith(basePath)
|
|
168
176
|
: !externalPaths.some(ext => item.path.startsWith(ext));
|
|
@@ -244,8 +252,8 @@ export function DashboardLayout({
|
|
|
244
252
|
</header>
|
|
245
253
|
|
|
246
254
|
{/* Main Content Scrollable Area */}
|
|
247
|
-
<main className="flex-1 p-4 md:p-6 lg:p-8 overflow-
|
|
248
|
-
<div className="bg-white rounded-2xl
|
|
255
|
+
<main className="flex-1 p-4 md:p-6 lg:p-8 overflow-hidden min-h-0">
|
|
256
|
+
<div className="bg-white rounded-2xl h-full p-4 md:p-8 flex flex-col overflow-y-auto">
|
|
249
257
|
{children}
|
|
250
258
|
</div>
|
|
251
259
|
</main>
|
|
@@ -296,7 +304,10 @@ export function DashboardLayout({
|
|
|
296
304
|
{group.label}
|
|
297
305
|
</span>
|
|
298
306
|
{group.items.map(item => {
|
|
299
|
-
const
|
|
307
|
+
const allMenuItems = menu.groups.flatMap(g => g.items);
|
|
308
|
+
const matchingItems = allMenuItems.filter(i => fullPath === i.path || fullPath.startsWith(`${i.path}/`));
|
|
309
|
+
const longestMatch = matchingItems.sort((a, b) => b.path.length - a.path.length)[0];
|
|
310
|
+
const isItemActive = longestMatch?.path === item.path;
|
|
300
311
|
const isInternal = basePath
|
|
301
312
|
? item.path.startsWith(basePath)
|
|
302
313
|
: !externalPaths.some(ext => item.path.startsWith(ext));
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import {
|
|
5
|
+
BarChart,
|
|
6
|
+
Bar,
|
|
7
|
+
XAxis,
|
|
8
|
+
YAxis,
|
|
9
|
+
CartesianGrid,
|
|
10
|
+
Tooltip,
|
|
11
|
+
Legend,
|
|
12
|
+
ResponsiveContainer,
|
|
13
|
+
} from "recharts";
|
|
14
|
+
import { CHART_COLORS } from "./palette";
|
|
15
|
+
|
|
16
|
+
export interface RBarChartSeries {
|
|
17
|
+
dataKey: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
color?: string;
|
|
20
|
+
stackId?: string;
|
|
21
|
+
radius?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RBarChartProps {
|
|
25
|
+
data: Record<string, any>[];
|
|
26
|
+
series: RBarChartSeries[];
|
|
27
|
+
xAxisKey: string;
|
|
28
|
+
height?: number;
|
|
29
|
+
colors?: string[];
|
|
30
|
+
layout?: "horizontal" | "vertical";
|
|
31
|
+
barSize?: number;
|
|
32
|
+
showGrid?: boolean;
|
|
33
|
+
showTooltip?: boolean;
|
|
34
|
+
showLegend?: boolean;
|
|
35
|
+
legendPosition?: "top" | "bottom";
|
|
36
|
+
xAxisFormatter?: (value: any) => string;
|
|
37
|
+
yAxisFormatter?: (value: any) => string;
|
|
38
|
+
tooltipFormatter?: (value: any, name: string) => [string, string];
|
|
39
|
+
className?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function RBarChart({
|
|
43
|
+
data,
|
|
44
|
+
series,
|
|
45
|
+
xAxisKey,
|
|
46
|
+
height = 350,
|
|
47
|
+
colors = [...CHART_COLORS],
|
|
48
|
+
layout = "horizontal",
|
|
49
|
+
barSize,
|
|
50
|
+
showGrid = true,
|
|
51
|
+
showTooltip = true,
|
|
52
|
+
showLegend = true,
|
|
53
|
+
legendPosition = "bottom",
|
|
54
|
+
xAxisFormatter,
|
|
55
|
+
yAxisFormatter,
|
|
56
|
+
tooltipFormatter,
|
|
57
|
+
className = "",
|
|
58
|
+
}: RBarChartProps) {
|
|
59
|
+
return (
|
|
60
|
+
<div className={`w-full ${className}`} style={{ height }}>
|
|
61
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
62
|
+
<BarChart data={data} layout={layout} margin={{ top: 10, right: 10, left: 0, bottom: 10 }}>
|
|
63
|
+
{showGrid && (
|
|
64
|
+
<CartesianGrid stroke="#f1f5f9" strokeDasharray="0" />
|
|
65
|
+
)}
|
|
66
|
+
{layout === "horizontal" ? (
|
|
67
|
+
<>
|
|
68
|
+
<XAxis
|
|
69
|
+
dataKey={xAxisKey}
|
|
70
|
+
tickFormatter={xAxisFormatter}
|
|
71
|
+
tick={{ fontSize: 11, fontWeight: 600, fill: "#94a3b8" }}
|
|
72
|
+
tickLine={false}
|
|
73
|
+
axisLine={false}
|
|
74
|
+
/>
|
|
75
|
+
<YAxis
|
|
76
|
+
tickFormatter={yAxisFormatter}
|
|
77
|
+
tick={{ fontSize: 11, fontWeight: 600, fill: "#94a3b8" }}
|
|
78
|
+
tickLine={false}
|
|
79
|
+
axisLine={false}
|
|
80
|
+
/>
|
|
81
|
+
</>
|
|
82
|
+
) : (
|
|
83
|
+
<>
|
|
84
|
+
<XAxis
|
|
85
|
+
type="number"
|
|
86
|
+
tickFormatter={xAxisFormatter}
|
|
87
|
+
tick={{ fontSize: 11, fontWeight: 600, fill: "#94a3b8" }}
|
|
88
|
+
tickLine={false}
|
|
89
|
+
axisLine={false}
|
|
90
|
+
/>
|
|
91
|
+
<YAxis
|
|
92
|
+
type="category"
|
|
93
|
+
dataKey={xAxisKey}
|
|
94
|
+
tickFormatter={yAxisFormatter}
|
|
95
|
+
tick={{ fontSize: 11, fontWeight: 600, fill: "#94a3b8" }}
|
|
96
|
+
tickLine={false}
|
|
97
|
+
axisLine={false}
|
|
98
|
+
/>
|
|
99
|
+
</>
|
|
100
|
+
)}
|
|
101
|
+
{showTooltip && (
|
|
102
|
+
<Tooltip
|
|
103
|
+
formatter={tooltipFormatter}
|
|
104
|
+
contentStyle={{
|
|
105
|
+
backgroundColor: "#1e293b",
|
|
106
|
+
color: "#fff",
|
|
107
|
+
borderRadius: "8px",
|
|
108
|
+
border: "none",
|
|
109
|
+
}}
|
|
110
|
+
itemStyle={{ color: "#fff" }}
|
|
111
|
+
cursor={{ fill: "transparent" }}
|
|
112
|
+
animationDuration={1000}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
{showLegend && (
|
|
116
|
+
<Legend
|
|
117
|
+
verticalAlign={legendPosition}
|
|
118
|
+
wrapperStyle={{ fontSize: "12px", fontWeight: 700 }}
|
|
119
|
+
iconType="circle"
|
|
120
|
+
/>
|
|
121
|
+
)}
|
|
122
|
+
{series.map((s, idx) => {
|
|
123
|
+
const radius = s.radius !== undefined ? s.radius : 4;
|
|
124
|
+
const radiusArray =
|
|
125
|
+
layout === "vertical" ? [0, radius, radius, 0] : [radius, radius, 0, 0];
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<Bar
|
|
129
|
+
key={s.dataKey}
|
|
130
|
+
dataKey={s.dataKey}
|
|
131
|
+
name={s.name || s.dataKey}
|
|
132
|
+
fill={s.color || colors[idx % colors.length]}
|
|
133
|
+
stackId={s.stackId}
|
|
134
|
+
barSize={barSize}
|
|
135
|
+
radius={radiusArray as any}
|
|
136
|
+
isAnimationActive={true}
|
|
137
|
+
animationDuration={1000}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
})}
|
|
141
|
+
</BarChart>
|
|
142
|
+
</ResponsiveContainer>
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import {
|
|
5
|
+
LineChart,
|
|
6
|
+
Line,
|
|
7
|
+
XAxis,
|
|
8
|
+
YAxis,
|
|
9
|
+
CartesianGrid,
|
|
10
|
+
Tooltip,
|
|
11
|
+
Legend,
|
|
12
|
+
ResponsiveContainer,
|
|
13
|
+
} from "recharts";
|
|
14
|
+
import { CHART_COLORS } from "./palette";
|
|
15
|
+
|
|
16
|
+
export interface RLineChartSeries {
|
|
17
|
+
dataKey: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
color?: string;
|
|
20
|
+
strokeWidth?: number;
|
|
21
|
+
type?: "monotone" | "linear" | "step" | "basis";
|
|
22
|
+
dashed?: boolean;
|
|
23
|
+
showDot?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface RLineChartProps {
|
|
27
|
+
data: Record<string, any>[];
|
|
28
|
+
series: RLineChartSeries[];
|
|
29
|
+
xAxisKey: string;
|
|
30
|
+
height?: number;
|
|
31
|
+
colors?: string[];
|
|
32
|
+
showGrid?: boolean;
|
|
33
|
+
showTooltip?: boolean;
|
|
34
|
+
showLegend?: boolean;
|
|
35
|
+
legendPosition?: "top" | "bottom";
|
|
36
|
+
xAxisFormatter?: (value: any) => string;
|
|
37
|
+
yAxisFormatter?: (value: any) => string;
|
|
38
|
+
tooltipFormatter?: (value: any, name: string) => [string, string];
|
|
39
|
+
className?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function RLineChart({
|
|
43
|
+
data,
|
|
44
|
+
series,
|
|
45
|
+
xAxisKey,
|
|
46
|
+
height = 350,
|
|
47
|
+
colors = [...CHART_COLORS],
|
|
48
|
+
showGrid = true,
|
|
49
|
+
showTooltip = true,
|
|
50
|
+
showLegend = true,
|
|
51
|
+
legendPosition = "bottom",
|
|
52
|
+
xAxisFormatter,
|
|
53
|
+
yAxisFormatter,
|
|
54
|
+
tooltipFormatter,
|
|
55
|
+
className = "",
|
|
56
|
+
}: RLineChartProps) {
|
|
57
|
+
return (
|
|
58
|
+
<div className={`w-full ${className}`} style={{ height }}>
|
|
59
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
60
|
+
<LineChart data={data} margin={{ top: 10, right: 10, left: 0, bottom: 10 }}>
|
|
61
|
+
{showGrid && (
|
|
62
|
+
<CartesianGrid stroke="#f1f5f9" strokeDasharray="0" />
|
|
63
|
+
)}
|
|
64
|
+
<XAxis
|
|
65
|
+
dataKey={xAxisKey}
|
|
66
|
+
tickFormatter={xAxisFormatter}
|
|
67
|
+
tick={{ fontSize: 11, fontWeight: 600, fill: "#94a3b8" }}
|
|
68
|
+
tickLine={false}
|
|
69
|
+
axisLine={false}
|
|
70
|
+
/>
|
|
71
|
+
<YAxis
|
|
72
|
+
tickFormatter={yAxisFormatter}
|
|
73
|
+
tick={{ fontSize: 11, fontWeight: 600, fill: "#94a3b8" }}
|
|
74
|
+
tickLine={false}
|
|
75
|
+
axisLine={false}
|
|
76
|
+
/>
|
|
77
|
+
{showTooltip && (
|
|
78
|
+
<Tooltip
|
|
79
|
+
formatter={tooltipFormatter}
|
|
80
|
+
contentStyle={{
|
|
81
|
+
backgroundColor: "#1e293b",
|
|
82
|
+
color: "#fff",
|
|
83
|
+
borderRadius: "8px",
|
|
84
|
+
border: "none",
|
|
85
|
+
}}
|
|
86
|
+
itemStyle={{ color: "#fff" }}
|
|
87
|
+
animationDuration={1000}
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
{showLegend && (
|
|
91
|
+
<Legend
|
|
92
|
+
verticalAlign={legendPosition}
|
|
93
|
+
wrapperStyle={{ fontSize: "12px", fontWeight: 700 }}
|
|
94
|
+
iconType="circle"
|
|
95
|
+
/>
|
|
96
|
+
)}
|
|
97
|
+
{series.map((s, idx) => (
|
|
98
|
+
<Line
|
|
99
|
+
key={s.dataKey}
|
|
100
|
+
type={s.type || "monotone"}
|
|
101
|
+
dataKey={s.dataKey}
|
|
102
|
+
name={s.name || s.dataKey}
|
|
103
|
+
stroke={s.color || colors[idx % colors.length]}
|
|
104
|
+
strokeWidth={s.strokeWidth || 2}
|
|
105
|
+
strokeDasharray={s.dashed ? "5 5" : undefined}
|
|
106
|
+
dot={s.showDot ? { r: 4 } : false}
|
|
107
|
+
activeDot={{ r: 6 }}
|
|
108
|
+
isAnimationActive={true}
|
|
109
|
+
animationDuration={1000}
|
|
110
|
+
/>
|
|
111
|
+
))}
|
|
112
|
+
</LineChart>
|
|
113
|
+
</ResponsiveContainer>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useState, useEffect, useCallback, useRef } from "react";
|
|
3
|
+
import { Modal, Button, Input, Pagination, EmptyState, ModalFooter } from "@apptimate/ui";
|
|
4
|
+
import { Search, User, Phone, Mail, MapPin, X } from "lucide-react";
|
|
5
|
+
import toast from "react-hot-toast";
|
|
6
|
+
import { sendRequest, IApiResponse } from "@apptimate/core-lib";
|
|
7
|
+
|
|
8
|
+
export interface SelectedCustomer {
|
|
9
|
+
id: number;
|
|
10
|
+
customer_name: string;
|
|
11
|
+
customer_code?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
address?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CustomerSelectorProps {
|
|
18
|
+
/** Currently selected customer ID */
|
|
19
|
+
value?: number | null;
|
|
20
|
+
/** Callback with full customer object on select */
|
|
21
|
+
onChange: (customer: SelectedCustomer | null) => void;
|
|
22
|
+
/** API base URL */
|
|
23
|
+
apiBase?: string;
|
|
24
|
+
/** API endpoint for listing customers. Default: /api/sales/customers */
|
|
25
|
+
apiPath?: string;
|
|
26
|
+
/** Whether the selector is disabled */
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/** Label text */
|
|
29
|
+
label?: string;
|
|
30
|
+
/** Placeholder text */
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
/** Required */
|
|
33
|
+
required?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default function CustomerSelectorComponent({
|
|
37
|
+
value,
|
|
38
|
+
onChange,
|
|
39
|
+
apiBase = process.env.NEXT_PUBLIC_API_URL || "",
|
|
40
|
+
apiPath = "/api/sales/customers",
|
|
41
|
+
disabled = false,
|
|
42
|
+
label = "Customer",
|
|
43
|
+
placeholder = "Search customers...",
|
|
44
|
+
required = false,
|
|
45
|
+
}: CustomerSelectorProps) {
|
|
46
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
47
|
+
const [search, setSearch] = useState("");
|
|
48
|
+
const [dSearch, setDSearch] = useState("");
|
|
49
|
+
const [customers, setCustomers] = useState<any[]>([]);
|
|
50
|
+
const [loading, setLoading] = useState(false);
|
|
51
|
+
const [page, setPage] = useState(1);
|
|
52
|
+
const [total, setTotal] = useState(0);
|
|
53
|
+
const [selected, setSelected] = useState<SelectedCustomer | null>(null);
|
|
54
|
+
const searchRef = useRef<HTMLInputElement>(null);
|
|
55
|
+
|
|
56
|
+
useEffect(() => { const t = setTimeout(() => { setDSearch(search); setPage(1); }, 350); return () => clearTimeout(t); }, [search]);
|
|
57
|
+
|
|
58
|
+
const fetchCustomers = useCallback(async () => {
|
|
59
|
+
setLoading(true);
|
|
60
|
+
try {
|
|
61
|
+
const qs = new URLSearchParams({ page: String(page), per_page: "15", ...(dSearch ? { search: dSearch } : {}) }).toString();
|
|
62
|
+
const r = await sendRequest({ url: `${apiBase}${apiPath}?${qs}`, method: "GET" });
|
|
63
|
+
const data = r.responseData as IApiResponse;
|
|
64
|
+
if (data.is_success) { setCustomers(data.result?.data || []); setTotal(data.result?.total ?? 0); }
|
|
65
|
+
} catch (e: any) { toast.error(e.message); } finally { setLoading(false); }
|
|
66
|
+
}, [page, dSearch, apiBase, apiPath]);
|
|
67
|
+
|
|
68
|
+
useEffect(() => { if (isOpen) fetchCustomers(); }, [isOpen, fetchCustomers]);
|
|
69
|
+
useEffect(() => { if (isOpen) setTimeout(() => searchRef.current?.focus(), 100); }, [isOpen]);
|
|
70
|
+
|
|
71
|
+
const handleSelect = (c: any) => {
|
|
72
|
+
const sel: SelectedCustomer = {
|
|
73
|
+
id: c.id,
|
|
74
|
+
customer_name: c.customer_name || c.name,
|
|
75
|
+
customer_code: c.customer_code || c.code,
|
|
76
|
+
phone: c.phone,
|
|
77
|
+
email: c.email,
|
|
78
|
+
address: c.address,
|
|
79
|
+
};
|
|
80
|
+
setSelected(sel);
|
|
81
|
+
onChange(sel);
|
|
82
|
+
setIsOpen(false);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const handleClear = () => {
|
|
86
|
+
setSelected(null);
|
|
87
|
+
onChange(null);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div>
|
|
92
|
+
<label className="text-xs font-bold text-gray-500 uppercase mb-1 block">{label}{required && <span className="text-red-500 ml-0.5">*</span>}</label>
|
|
93
|
+
|
|
94
|
+
{/* Display */}
|
|
95
|
+
{selected ? (
|
|
96
|
+
<div className="flex items-center gap-2 border border-gray-200 rounded-lg px-3 py-2 bg-white">
|
|
97
|
+
<div className="flex-1 min-w-0">
|
|
98
|
+
<p className="text-sm font-bold text-gray-800 truncate">{selected.customer_name}</p>
|
|
99
|
+
<p className="text-xs text-gray-500">{[selected.customer_code, selected.phone].filter(Boolean).join(" • ")}</p>
|
|
100
|
+
</div>
|
|
101
|
+
{!disabled && <button onClick={handleClear} className="p-1 rounded hover:bg-gray-100"><X size={14} className="text-gray-400" /></button>}
|
|
102
|
+
</div>
|
|
103
|
+
) : (
|
|
104
|
+
<button
|
|
105
|
+
onClick={() => !disabled && setIsOpen(true)}
|
|
106
|
+
className={`w-full text-left border border-gray-200 rounded-lg px-3 py-2 text-sm text-gray-400 hover:border-blue-300 transition-colors ${disabled ? "bg-gray-50 cursor-not-allowed" : "bg-white cursor-pointer"}`}
|
|
107
|
+
>
|
|
108
|
+
<span className="flex items-center gap-2"><Search size={14} />{placeholder}</span>
|
|
109
|
+
</button>
|
|
110
|
+
)}
|
|
111
|
+
|
|
112
|
+
{/* Selector Modal */}
|
|
113
|
+
<Modal isOpen={isOpen} onClose={() => setIsOpen(false)} title={`Select ${label}`} size="lg">
|
|
114
|
+
<div className="p-1">
|
|
115
|
+
<div className="relative mb-4">
|
|
116
|
+
<Search size={16} className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400" />
|
|
117
|
+
<input
|
|
118
|
+
ref={searchRef}
|
|
119
|
+
type="text"
|
|
120
|
+
value={search}
|
|
121
|
+
onChange={e => setSearch(e.target.value)}
|
|
122
|
+
placeholder="Search by name, code, phone, or email..."
|
|
123
|
+
className="w-full pl-9 pr-4 py-2.5 border border-gray-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-blue-300"
|
|
124
|
+
/>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
{loading ? (
|
|
128
|
+
<div className="flex items-center justify-center py-16"><div className="w-6 h-6 border-2 border-blue-400 border-t-transparent rounded-full animate-spin" /></div>
|
|
129
|
+
) : customers.length === 0 ? (
|
|
130
|
+
<div className="py-12 text-center"><EmptyState message="No customers found." /></div>
|
|
131
|
+
) : (
|
|
132
|
+
<div className="space-y-1.5 max-h-[50vh] overflow-y-auto">
|
|
133
|
+
{customers.map((c: any) => (
|
|
134
|
+
<button
|
|
135
|
+
key={c.id}
|
|
136
|
+
onClick={() => handleSelect(c)}
|
|
137
|
+
className="w-full text-left p-3 rounded-xl hover:bg-blue-50 border border-transparent hover:border-blue-200 transition-all flex items-start gap-3"
|
|
138
|
+
>
|
|
139
|
+
<div className="p-2 rounded-xl bg-gray-100 text-gray-500"><User size={16} /></div>
|
|
140
|
+
<div className="flex-1 min-w-0">
|
|
141
|
+
<p className="text-sm font-bold text-gray-800">{c.customer_name || c.name}</p>
|
|
142
|
+
<div className="flex items-center gap-3 mt-1 text-xs text-gray-500">
|
|
143
|
+
{c.customer_code && <span className="bg-gray-100 px-1.5 py-0.5 rounded font-mono">{c.customer_code}</span>}
|
|
144
|
+
{c.phone && <span className="flex items-center gap-1"><Phone size={10} />{c.phone}</span>}
|
|
145
|
+
{c.email && <span className="flex items-center gap-1"><Mail size={10} />{c.email}</span>}
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
</button>
|
|
149
|
+
))}
|
|
150
|
+
</div>
|
|
151
|
+
)}
|
|
152
|
+
|
|
153
|
+
{!loading && customers.length > 0 && total > 15 && (
|
|
154
|
+
<div className="mt-3 pt-3 border-t border-gray-100">
|
|
155
|
+
<Pagination currentPage={page} totalItems={total} itemsPerPage={15} onPageChange={setPage} />
|
|
156
|
+
</div>
|
|
157
|
+
)}
|
|
158
|
+
</div>
|
|
159
|
+
<ModalFooter><Button variant="soft" color="default" onClick={() => setIsOpen(false)}>Cancel</Button></ModalFooter>
|
|
160
|
+
</Modal>
|
|
161
|
+
</div>
|
|
162
|
+
);
|
|
163
|
+
}
|