@apptimate/ui 1.1.0 → 1.3.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/RAreaChart.tsx +139 -0
- package/src/common-components/charts/RBarChart.tsx +171 -0
- package/src/common-components/charts/RLineChart.tsx +156 -0
- package/src/common-components/charts/RPieChart.tsx +215 -0
- package/src/common-components/charts/RStatCard.tsx +138 -0
- package/src/common-components/charts/index.ts +7 -0
- package/src/common-components/charts/palette.ts +84 -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
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useState, useEffect, useCallback, useRef } from "react";
|
|
3
|
+
import { Modal, Button, Pagination, EmptyState, ModalFooter, Badge } from "@apptimate/ui";
|
|
4
|
+
import { Search, Package, X, Tag, Barcode } from "lucide-react";
|
|
5
|
+
import toast from "react-hot-toast";
|
|
6
|
+
import { sendRequest, IApiResponse } from "@apptimate/core-lib";
|
|
7
|
+
|
|
8
|
+
export interface SelectedProduct {
|
|
9
|
+
id: number;
|
|
10
|
+
item_name: string;
|
|
11
|
+
sku?: string;
|
|
12
|
+
barcode?: string;
|
|
13
|
+
category_name?: string;
|
|
14
|
+
unit_price?: number;
|
|
15
|
+
available_qty?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ProductSelectorProps {
|
|
19
|
+
value?: number | null;
|
|
20
|
+
onChange: (product: SelectedProduct | null) => void;
|
|
21
|
+
apiBase?: string;
|
|
22
|
+
apiPath?: string;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
label?: string;
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
/** Show price and stock info */
|
|
28
|
+
showDetails?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default function ProductSelectorComponent({
|
|
32
|
+
value,
|
|
33
|
+
onChange,
|
|
34
|
+
apiBase = process.env.NEXT_PUBLIC_API_URL || "",
|
|
35
|
+
apiPath = "/api/inventory/items",
|
|
36
|
+
disabled = false,
|
|
37
|
+
label = "Product",
|
|
38
|
+
placeholder = "Search products...",
|
|
39
|
+
required = false,
|
|
40
|
+
showDetails = true,
|
|
41
|
+
}: ProductSelectorProps) {
|
|
42
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
43
|
+
const [search, setSearch] = useState("");
|
|
44
|
+
const [dSearch, setDSearch] = useState("");
|
|
45
|
+
const [products, setProducts] = useState<any[]>([]);
|
|
46
|
+
const [loading, setLoading] = useState(false);
|
|
47
|
+
const [page, setPage] = useState(1);
|
|
48
|
+
const [total, setTotal] = useState(0);
|
|
49
|
+
const [selected, setSelected] = useState<SelectedProduct | null>(null);
|
|
50
|
+
const searchRef = useRef<HTMLInputElement>(null);
|
|
51
|
+
|
|
52
|
+
useEffect(() => { const t = setTimeout(() => { setDSearch(search); setPage(1); }, 350); return () => clearTimeout(t); }, [search]);
|
|
53
|
+
|
|
54
|
+
const fetchProducts = useCallback(async () => {
|
|
55
|
+
setLoading(true);
|
|
56
|
+
try {
|
|
57
|
+
const qs = new URLSearchParams({ page: String(page), per_page: "15", ...(dSearch ? { search: dSearch } : {}) }).toString();
|
|
58
|
+
const r = await sendRequest({ url: `${apiBase}${apiPath}?${qs}`, method: "GET" });
|
|
59
|
+
const data = r.responseData as IApiResponse;
|
|
60
|
+
if (data.is_success) { setProducts(data.result?.data || []); setTotal(data.result?.total ?? 0); }
|
|
61
|
+
} catch (e: any) { toast.error(e.message); } finally { setLoading(false); }
|
|
62
|
+
}, [page, dSearch, apiBase, apiPath]);
|
|
63
|
+
|
|
64
|
+
useEffect(() => { if (isOpen) fetchProducts(); }, [isOpen, fetchProducts]);
|
|
65
|
+
useEffect(() => { if (isOpen) setTimeout(() => searchRef.current?.focus(), 100); }, [isOpen]);
|
|
66
|
+
|
|
67
|
+
const handleSelect = (p: any) => {
|
|
68
|
+
const sel: SelectedProduct = {
|
|
69
|
+
id: p.id,
|
|
70
|
+
item_name: p.item_name || p.name,
|
|
71
|
+
sku: p.sku,
|
|
72
|
+
barcode: p.barcode,
|
|
73
|
+
category_name: p.category?.name || p.category_name,
|
|
74
|
+
unit_price: p.selling_price || p.unit_price,
|
|
75
|
+
available_qty: p.available_qty ?? p.current_stock,
|
|
76
|
+
};
|
|
77
|
+
setSelected(sel);
|
|
78
|
+
onChange(sel);
|
|
79
|
+
setIsOpen(false);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const handleClear = () => { setSelected(null); onChange(null); };
|
|
83
|
+
const fmt = (n: number) => Number(n).toLocaleString("en", { minimumFractionDigits: 2 });
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<div>
|
|
87
|
+
<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>
|
|
88
|
+
|
|
89
|
+
{selected ? (
|
|
90
|
+
<div className="flex items-center gap-2 border border-gray-200 rounded-lg px-3 py-2 bg-white">
|
|
91
|
+
<div className="flex-1 min-w-0">
|
|
92
|
+
<p className="text-sm font-bold text-gray-800 truncate">{selected.item_name}</p>
|
|
93
|
+
<p className="text-xs text-gray-500">{[selected.sku, selected.category_name].filter(Boolean).join(" • ")}</p>
|
|
94
|
+
</div>
|
|
95
|
+
{!disabled && <button onClick={handleClear} className="p-1 rounded hover:bg-gray-100"><X size={14} className="text-gray-400" /></button>}
|
|
96
|
+
</div>
|
|
97
|
+
) : (
|
|
98
|
+
<button
|
|
99
|
+
onClick={() => !disabled && setIsOpen(true)}
|
|
100
|
+
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"}`}
|
|
101
|
+
>
|
|
102
|
+
<span className="flex items-center gap-2"><Search size={14} />{placeholder}</span>
|
|
103
|
+
</button>
|
|
104
|
+
)}
|
|
105
|
+
|
|
106
|
+
<Modal isOpen={isOpen} onClose={() => setIsOpen(false)} title={`Select ${label}`} size="lg">
|
|
107
|
+
<div className="p-1">
|
|
108
|
+
<div className="relative mb-4">
|
|
109
|
+
<Search size={16} className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400" />
|
|
110
|
+
<input
|
|
111
|
+
ref={searchRef}
|
|
112
|
+
type="text"
|
|
113
|
+
value={search}
|
|
114
|
+
onChange={e => setSearch(e.target.value)}
|
|
115
|
+
placeholder="Search by name, SKU, barcode..."
|
|
116
|
+
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"
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
{loading ? (
|
|
121
|
+
<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>
|
|
122
|
+
) : products.length === 0 ? (
|
|
123
|
+
<div className="py-12 text-center"><EmptyState message="No products found." /></div>
|
|
124
|
+
) : (
|
|
125
|
+
<div className="space-y-1.5 max-h-[50vh] overflow-y-auto">
|
|
126
|
+
{products.map((p: any) => (
|
|
127
|
+
<button
|
|
128
|
+
key={p.id}
|
|
129
|
+
onClick={() => handleSelect(p)}
|
|
130
|
+
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"
|
|
131
|
+
>
|
|
132
|
+
<div className="p-2 rounded-xl bg-gray-100 text-gray-500"><Package size={16} /></div>
|
|
133
|
+
<div className="flex-1 min-w-0">
|
|
134
|
+
<p className="text-sm font-bold text-gray-800">{p.item_name || p.name}</p>
|
|
135
|
+
<div className="flex items-center gap-3 mt-1 text-xs text-gray-500">
|
|
136
|
+
{p.sku && <span className="flex items-center gap-1 bg-gray-100 px-1.5 py-0.5 rounded font-mono"><Tag size={10} />{p.sku}</span>}
|
|
137
|
+
{p.barcode && <span className="flex items-center gap-1"><Barcode size={10} />{p.barcode}</span>}
|
|
138
|
+
{p.category?.name && <span>{p.category.name}</span>}
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
{showDetails && (
|
|
142
|
+
<div className="text-right flex-shrink-0">
|
|
143
|
+
{p.selling_price != null && <p className="text-sm font-bold text-gray-800">{fmt(p.selling_price)}</p>}
|
|
144
|
+
{p.available_qty != null && (
|
|
145
|
+
<Badge variant="flat" color={p.available_qty > 0 ? "success" : "danger"} className="text-[10px] font-bold px-1.5 py-0 rounded">
|
|
146
|
+
{p.available_qty > 0 ? `${p.available_qty} in stock` : "Out of stock"}
|
|
147
|
+
</Badge>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
)}
|
|
151
|
+
</button>
|
|
152
|
+
))}
|
|
153
|
+
</div>
|
|
154
|
+
)}
|
|
155
|
+
|
|
156
|
+
{!loading && products.length > 0 && total > 15 && (
|
|
157
|
+
<div className="mt-3 pt-3 border-t border-gray-100">
|
|
158
|
+
<Pagination currentPage={page} totalItems={total} itemsPerPage={15} onPageChange={setPage} />
|
|
159
|
+
</div>
|
|
160
|
+
)}
|
|
161
|
+
</div>
|
|
162
|
+
<ModalFooter><Button variant="soft" color="default" onClick={() => setIsOpen(false)}>Cancel</Button></ModalFooter>
|
|
163
|
+
</Modal>
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -12,6 +12,8 @@ export * from './base-components/Dropdown';
|
|
|
12
12
|
export * from './base-components/EmptyState';
|
|
13
13
|
export * from './base-components/HintIcon';
|
|
14
14
|
export * from './base-components/RecordCount';
|
|
15
|
+
export * from './base-components/DateLabel';
|
|
16
|
+
export * from './base-components/DateRangePicker';
|
|
15
17
|
export * from './base-components/TableMobileOptions';
|
|
16
18
|
export * from './base-components/DesktopSearchPopover';
|
|
17
19
|
export * from './base-components/DesktopFilterPopover';
|
|
@@ -23,5 +25,8 @@ export * from './base-components/PopConfirm';
|
|
|
23
25
|
export * from './base-components/SearchableSelect';
|
|
24
26
|
export * from './base-components/Select';
|
|
25
27
|
export * from './base-components/Table';
|
|
28
|
+
export * from './base-components/ImageDropzone';
|
|
29
|
+
export { default as ImageUploadComponent } from './components/shared/ImageUploadComponent';
|
|
30
|
+
export type { ImageUploadComponentProps, ItemImage } from './components/shared/ImageUploadComponent';
|
|
26
31
|
export * from './common-components/DashboardLayout';
|
|
27
|
-
export * from './common-components/
|
|
32
|
+
export * from './common-components/charts';
|
|
File without changes
|