@burdenoff/microfe-healthybowl 2026.714.3 → 2026.714.5
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/dist/healthybowl/HealthyBowlRoot.js +114 -106
- package/dist/healthybowl/HealthyBowlRoot.js.map +1 -1
- package/dist/healthybowl/HealthyBowlRoutes.js +141 -113
- package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlContacts.js +149 -0
- package/dist/healthybowl/hooks/useHealthyBowlContacts.js.map +1 -0
- package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js +200 -0
- package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js.map +1 -0
- package/dist/healthybowl/hooks/useHealthyBowlStorage.js +162 -0
- package/dist/healthybowl/hooks/useHealthyBowlStorage.js.map +1 -0
- package/dist/healthybowl/hooks/usePlantScans.js +131 -0
- package/dist/healthybowl/hooks/usePlantScans.js.map +1 -0
- package/dist/healthybowl/pages/contacts/ContactDetailPage.js +224 -0
- package/dist/healthybowl/pages/contacts/ContactDetailPage.js.map +1 -0
- package/dist/healthybowl/pages/contacts/ContactFormModal.js +147 -0
- package/dist/healthybowl/pages/contacts/ContactFormModal.js.map +1 -0
- package/dist/healthybowl/pages/contacts/ContactsPage.js +241 -0
- package/dist/healthybowl/pages/contacts/ContactsPage.js.map +1 -0
- package/dist/healthybowl/pages/contacts/CsvImportModal.js +155 -0
- package/dist/healthybowl/pages/contacts/CsvImportModal.js.map +1 -0
- package/dist/healthybowl/pages/contacts/RecordOrderModal.js +131 -0
- package/dist/healthybowl/pages/contacts/RecordOrderModal.js.map +1 -0
- package/dist/healthybowl/pages/contacts/labels.js +46 -0
- package/dist/healthybowl/pages/contacts/labels.js.map +1 -0
- package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js +152 -0
- package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js.map +1 -0
- package/dist/healthybowl/pages/livestock/AnimalDepthPage.js +245 -0
- package/dist/healthybowl/pages/livestock/AnimalDepthPage.js.map +1 -0
- package/dist/healthybowl/pages/livestock/AnimalGroupModal.js +210 -0
- package/dist/healthybowl/pages/livestock/AnimalGroupModal.js.map +1 -0
- package/dist/healthybowl/pages/livestock/HerdDepthPage.js +189 -0
- package/dist/healthybowl/pages/livestock/HerdDepthPage.js.map +1 -0
- package/dist/healthybowl/pages/livestock/RecordWeightModal.js +100 -0
- package/dist/healthybowl/pages/livestock/RecordWeightModal.js.map +1 -0
- package/dist/healthybowl/pages/livestock/depthLabels.js +31 -0
- package/dist/healthybowl/pages/livestock/depthLabels.js.map +1 -0
- package/dist/healthybowl/pages/pest-management/AiPestDetectionPage.js +726 -0
- package/dist/healthybowl/pages/pest-management/AiPestDetectionPage.js.map +1 -0
- package/dist/healthybowl/pages/pest-management/PestOverviewPage.js +98 -88
- package/dist/healthybowl/pages/pest-management/PestOverviewPage.js.map +1 -1
- package/dist/healthybowl/pages/storage/PlaceLotModal.js +150 -0
- package/dist/healthybowl/pages/storage/PlaceLotModal.js.map +1 -0
- package/dist/healthybowl/pages/storage/RecordMovementModal.js +140 -0
- package/dist/healthybowl/pages/storage/RecordMovementModal.js.map +1 -0
- package/dist/healthybowl/pages/storage/StorageLocationFormModal.js +139 -0
- package/dist/healthybowl/pages/storage/StorageLocationFormModal.js.map +1 -0
- package/dist/healthybowl/pages/storage/StorageLotDetailPage.js +150 -0
- package/dist/healthybowl/pages/storage/StorageLotDetailPage.js.map +1 -0
- package/dist/healthybowl/pages/storage/StoragePage.js +251 -0
- package/dist/healthybowl/pages/storage/StoragePage.js.map +1 -0
- package/dist/healthybowl/pages/storage/labels.js +67 -0
- package/dist/healthybowl/pages/storage/labels.js.map +1 -0
- package/dist/healthybowl/utils/imageDownscale.js +76 -0
- package/dist/healthybowl/utils/imageDownscale.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { cn as e } from "../../utils/helpers.js";
|
|
2
|
+
import { useBasePath as t } from "../../hooks/useBasePath.js";
|
|
3
|
+
import { PageLayout as n } from "../../components/PageLayout.js";
|
|
4
|
+
import { StatCard as r } from "../../components/StatCard.js";
|
|
5
|
+
import { DataTable as i } from "../../components/DataTable.js";
|
|
6
|
+
import { StatusBadge as a } from "../../components/StatusBadge.js";
|
|
7
|
+
import { EmptyState as o } from "../../components/EmptyState.js";
|
|
8
|
+
import { ErrorState as ee } from "../../components/ErrorState.js";
|
|
9
|
+
import { useConfirm as s } from "../../components/ConfirmDialog.js";
|
|
10
|
+
import { PageLoader as c } from "../../components/PageLoader.js";
|
|
11
|
+
import { useToast as l } from "../../hooks/useToast.js";
|
|
12
|
+
import "../../components/index.js";
|
|
13
|
+
import { useHealthyBowlContacts as u } from "../../hooks/useHealthyBowlContacts.js";
|
|
14
|
+
import { ContactFormModal as d } from "./ContactFormModal.js";
|
|
15
|
+
import { CONTACT_TYPE_TABS as f, contactStatusVariant as p, contactTypeLabel as m, contactTypeVariant as h } from "./labels.js";
|
|
16
|
+
import { CsvImportModal as g } from "./CsvImportModal.js";
|
|
17
|
+
import { useMemo as _, useState as v } from "react";
|
|
18
|
+
import { useI18n as y } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
19
|
+
import { Contact as b, Pencil as x, Plus as S, Search as te, Trash2 as C, Upload as w, Users as T } from "lucide-react";
|
|
20
|
+
import { useNavigate as E } from "react-router-dom";
|
|
21
|
+
import { Fragment as D, jsx as O, jsxs as k } from "react/jsx-runtime";
|
|
22
|
+
import { Button as A, Input as j } from "@burdenoff/fe-libs/ui";
|
|
23
|
+
//#region src/healthybowl/pages/contacts/ContactsPage.tsx
|
|
24
|
+
var M = () => {
|
|
25
|
+
let { t: M } = y(), N = E(), { buildPath: P } = t(), { toast: F } = l(), I = s(), [L, R] = v(null), [z, B] = v(""), [V, H] = v(!1), [ne, U] = v(!1), [W, G] = v(null), [K, q] = v(null), { contacts: J, loading: Y, errors: X, refetchContacts: Z, createContact: re, updateContact: ie, deleteContact: ae, importContacts: oe } = u({
|
|
26
|
+
list: !0,
|
|
27
|
+
type: L,
|
|
28
|
+
search: z.trim() || null
|
|
29
|
+
}), Q = () => {
|
|
30
|
+
G(null), H(!0);
|
|
31
|
+
}, $ = (e) => {
|
|
32
|
+
G(e), H(!0);
|
|
33
|
+
}, se = async (e) => {
|
|
34
|
+
W ? (await ie(e), F({
|
|
35
|
+
title: M("healthybowl.contacts.toast.updated", "Contact updated"),
|
|
36
|
+
description: String(e.name ?? W.name),
|
|
37
|
+
variant: "success"
|
|
38
|
+
})) : (await re(e), F({
|
|
39
|
+
title: M("healthybowl.contacts.toast.created", "Contact added"),
|
|
40
|
+
description: String(e.name ?? ""),
|
|
41
|
+
variant: "success"
|
|
42
|
+
}));
|
|
43
|
+
}, ce = async (e) => {
|
|
44
|
+
let t = await oe(e);
|
|
45
|
+
return t && F({
|
|
46
|
+
title: M("healthybowl.contacts.toast.imported", "Import complete"),
|
|
47
|
+
description: M("healthybowl.contacts.toast.importedDesc", "{{imported}} added, {{updated}} updated, {{skipped}} skipped", {
|
|
48
|
+
imported: t.imported,
|
|
49
|
+
updated: t.updated,
|
|
50
|
+
skipped: t.skipped
|
|
51
|
+
}),
|
|
52
|
+
variant: "success"
|
|
53
|
+
}), t;
|
|
54
|
+
}, le = async (e) => {
|
|
55
|
+
if (await I({
|
|
56
|
+
title: M("healthybowl.contacts.confirm.deleteTitle", "Delete contact?"),
|
|
57
|
+
message: M("healthybowl.contacts.confirm.delete", "Delete \"{{name}}\"? This cannot be undone.", { name: e.name })
|
|
58
|
+
})) {
|
|
59
|
+
q(e.id);
|
|
60
|
+
try {
|
|
61
|
+
await ae(e.id), F({
|
|
62
|
+
title: M("healthybowl.contacts.toast.deleted", "Contact deleted"),
|
|
63
|
+
description: e.name,
|
|
64
|
+
variant: "success"
|
|
65
|
+
});
|
|
66
|
+
} catch (e) {
|
|
67
|
+
F({
|
|
68
|
+
title: M("healthybowl.contacts.toast.deleteFailed", "Could not delete contact"),
|
|
69
|
+
description: e instanceof Error ? e.message : String(e),
|
|
70
|
+
variant: "error"
|
|
71
|
+
});
|
|
72
|
+
} finally {
|
|
73
|
+
q(null);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, ue = _(() => J.filter((e) => e.type === "BUYER").length, [J]), de = _(() => J.filter((e) => e.type === "SUPPLIER").length, [J]), fe = [
|
|
77
|
+
{
|
|
78
|
+
key: "name",
|
|
79
|
+
header: M("healthybowl.contacts.table.name", "Name"),
|
|
80
|
+
render: (e) => /* @__PURE__ */ k("div", { children: [/* @__PURE__ */ O("div", {
|
|
81
|
+
className: "font-medium text-text-primary",
|
|
82
|
+
children: e.name
|
|
83
|
+
}), /* @__PURE__ */ O("div", {
|
|
84
|
+
className: "text-xs text-text-secondary",
|
|
85
|
+
children: m(e.type)
|
|
86
|
+
})] })
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
key: "type",
|
|
90
|
+
header: M("healthybowl.contacts.table.type", "Type"),
|
|
91
|
+
render: (e) => /* @__PURE__ */ O(a, {
|
|
92
|
+
variant: h(e.type),
|
|
93
|
+
label: m(e.type)
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
key: "lastOrder",
|
|
98
|
+
header: M("healthybowl.contacts.table.lastOrder", "Last Order"),
|
|
99
|
+
render: (e) => /* @__PURE__ */ O("span", {
|
|
100
|
+
className: "tabular-nums text-text-secondary",
|
|
101
|
+
children: e.lastOrderDate ?? "—"
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
key: "phone",
|
|
106
|
+
header: M("healthybowl.contacts.table.phone", "Phone"),
|
|
107
|
+
render: (e) => /* @__PURE__ */ O("span", {
|
|
108
|
+
className: "text-text-secondary",
|
|
109
|
+
children: e.phone ?? "—"
|
|
110
|
+
})
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
key: "status",
|
|
114
|
+
header: M("healthybowl.contacts.table.status", "Status"),
|
|
115
|
+
render: (e) => /* @__PURE__ */ O(a, {
|
|
116
|
+
variant: p(e.status),
|
|
117
|
+
label: e.status.toLowerCase(),
|
|
118
|
+
dot: !0
|
|
119
|
+
})
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
key: "actions",
|
|
123
|
+
header: "",
|
|
124
|
+
render: (e) => /* @__PURE__ */ k("div", {
|
|
125
|
+
className: "flex items-center justify-end gap-1",
|
|
126
|
+
children: [/* @__PURE__ */ O(A, {
|
|
127
|
+
variant: "ghost",
|
|
128
|
+
size: "icon-sm",
|
|
129
|
+
disabled: K === e.id,
|
|
130
|
+
onClick: (t) => {
|
|
131
|
+
t.stopPropagation(), $(e);
|
|
132
|
+
},
|
|
133
|
+
"aria-label": M("healthybowl.contacts.actions.edit", "Edit contact"),
|
|
134
|
+
children: /* @__PURE__ */ O(x, { className: "h-4 w-4" })
|
|
135
|
+
}), /* @__PURE__ */ O(A, {
|
|
136
|
+
variant: "ghost",
|
|
137
|
+
size: "icon-sm",
|
|
138
|
+
disabled: K === e.id,
|
|
139
|
+
onClick: (t) => {
|
|
140
|
+
t.stopPropagation(), le(e);
|
|
141
|
+
},
|
|
142
|
+
"aria-label": M("healthybowl.contacts.actions.delete", "Delete contact"),
|
|
143
|
+
className: "text-text-secondary hover:text-status-error-text",
|
|
144
|
+
children: /* @__PURE__ */ O(C, { className: "h-4 w-4" })
|
|
145
|
+
})]
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
];
|
|
149
|
+
return Y.list && J.length === 0 ? /* @__PURE__ */ O(c, {}) : /* @__PURE__ */ k(n, {
|
|
150
|
+
title: M("healthybowl.contacts.title", "Contacts"),
|
|
151
|
+
titleAccent: M("healthybowl.contacts.titleAccent", "Contacts"),
|
|
152
|
+
description: M("healthybowl.contacts.description", "Your buyers and suppliers — contact details, notes, and order history."),
|
|
153
|
+
actions: /* @__PURE__ */ k("div", {
|
|
154
|
+
className: "flex items-center gap-2",
|
|
155
|
+
children: [/* @__PURE__ */ k(A, {
|
|
156
|
+
variant: "outline",
|
|
157
|
+
onClick: () => U(!0),
|
|
158
|
+
children: [/* @__PURE__ */ O(w, { className: "h-4 w-4" }), M("healthybowl.contacts.actions.import", "Import CSV")]
|
|
159
|
+
}), /* @__PURE__ */ k(A, {
|
|
160
|
+
onClick: Q,
|
|
161
|
+
children: [/* @__PURE__ */ O(S, { className: "h-4 w-4" }), M("healthybowl.contacts.actions.new", "Add Contact")]
|
|
162
|
+
})]
|
|
163
|
+
}),
|
|
164
|
+
children: [
|
|
165
|
+
X.list && J.length === 0 ? /* @__PURE__ */ O(ee, {
|
|
166
|
+
description: X.list.message,
|
|
167
|
+
onRetry: () => void Z()
|
|
168
|
+
}) : /* @__PURE__ */ k(D, { children: [
|
|
169
|
+
/* @__PURE__ */ k("div", {
|
|
170
|
+
className: "mt-4 grid grid-cols-1 gap-3 sm:grid-cols-3",
|
|
171
|
+
children: [
|
|
172
|
+
/* @__PURE__ */ O(r, {
|
|
173
|
+
label: M("healthybowl.contacts.stats.total", "Contacts"),
|
|
174
|
+
value: J.length,
|
|
175
|
+
icon: /* @__PURE__ */ O(T, { className: "h-5 w-5" }),
|
|
176
|
+
hero: !0
|
|
177
|
+
}),
|
|
178
|
+
/* @__PURE__ */ O(r, {
|
|
179
|
+
label: M("healthybowl.contacts.stats.buyers", "Buyers"),
|
|
180
|
+
value: ue
|
|
181
|
+
}),
|
|
182
|
+
/* @__PURE__ */ O(r, {
|
|
183
|
+
label: M("healthybowl.contacts.stats.suppliers", "Suppliers"),
|
|
184
|
+
value: de
|
|
185
|
+
})
|
|
186
|
+
]
|
|
187
|
+
}),
|
|
188
|
+
/* @__PURE__ */ k("div", {
|
|
189
|
+
className: "mt-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",
|
|
190
|
+
children: [/* @__PURE__ */ O("div", {
|
|
191
|
+
className: "flex flex-wrap gap-1",
|
|
192
|
+
children: f.map((t) => /* @__PURE__ */ O("button", {
|
|
193
|
+
type: "button",
|
|
194
|
+
onClick: () => R(t.value),
|
|
195
|
+
className: e("rounded-full px-3 py-1.5 text-sm font-medium transition-colors", L === t.value ? "bg-accent-teal text-white" : "bg-bg-sunken text-text-secondary hover:text-text-primary"),
|
|
196
|
+
children: M(`healthybowl.contacts.tabs.${t.key.toLowerCase()}`, t.label)
|
|
197
|
+
}, t.key))
|
|
198
|
+
}), /* @__PURE__ */ k("div", {
|
|
199
|
+
className: "relative sm:w-64",
|
|
200
|
+
children: [/* @__PURE__ */ O(te, { className: "pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-text-tertiary" }), /* @__PURE__ */ O(j, {
|
|
201
|
+
value: z,
|
|
202
|
+
onChange: (e) => B(e.target.value),
|
|
203
|
+
placeholder: M("healthybowl.contacts.search", "Search name, phone, email"),
|
|
204
|
+
className: "pl-8"
|
|
205
|
+
})]
|
|
206
|
+
})]
|
|
207
|
+
}),
|
|
208
|
+
J.length === 0 ? /* @__PURE__ */ O(o, {
|
|
209
|
+
icon: /* @__PURE__ */ O(b, { className: "h-8 w-8 text-text-secondary" }),
|
|
210
|
+
title: M("healthybowl.contacts.empty.title", "No contacts yet"),
|
|
211
|
+
description: M("healthybowl.contacts.empty.description", "Add a buyer or supplier, or import your existing contacts from a CSV."),
|
|
212
|
+
action: /* @__PURE__ */ k(A, {
|
|
213
|
+
onClick: Q,
|
|
214
|
+
children: [/* @__PURE__ */ O(S, { className: "h-4 w-4" }), M("healthybowl.contacts.actions.new", "Add Contact")]
|
|
215
|
+
})
|
|
216
|
+
}) : /* @__PURE__ */ O(i, {
|
|
217
|
+
columns: fe,
|
|
218
|
+
data: J,
|
|
219
|
+
keyField: "id",
|
|
220
|
+
pageSize: 12,
|
|
221
|
+
onRowClick: (e) => N(P(`contacts/${e.id}`))
|
|
222
|
+
})
|
|
223
|
+
] }),
|
|
224
|
+
/* @__PURE__ */ O(d, {
|
|
225
|
+
open: V,
|
|
226
|
+
onClose: () => H(!1),
|
|
227
|
+
contact: W,
|
|
228
|
+
onSubmit: se
|
|
229
|
+
}),
|
|
230
|
+
/* @__PURE__ */ O(g, {
|
|
231
|
+
open: ne,
|
|
232
|
+
onClose: () => U(!1),
|
|
233
|
+
onImport: ce
|
|
234
|
+
})
|
|
235
|
+
]
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
//#endregion
|
|
239
|
+
export { M as ContactsPage };
|
|
240
|
+
|
|
241
|
+
//# sourceMappingURL=ContactsPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContactsPage.js","names":[],"sources":["../../../../src/healthybowl/pages/contacts/ContactsPage.tsx"],"sourcesContent":["/**\n * Buyer/Supplier CRM — contacts list (BOFF-2890 · J-1).\n * A searchable table of real Contact rows with per-contact order aggregates (last order, order\n * count) derived on the backend from the orders table. Add / edit / delete / CSV import. No\n * fabricated data.\n */\nimport { useMemo, useState } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { Contact as ContactIcon, Pencil, Plus, Search, Trash2, Upload, Users } from 'lucide-react';\nimport { Button, Input } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport {\n PageLayout,\n StatCard,\n DataTable,\n StatusBadge,\n EmptyState,\n ErrorState,\n PageLoader,\n useConfirm,\n} from '../../components';\nimport type { Column } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { cn } from '../../utils/helpers';\nimport { useHealthyBowlContacts, type Contact } from '../../hooks/useHealthyBowlContacts';\nimport { ContactFormModal } from './ContactFormModal';\nimport { CsvImportModal } from './CsvImportModal';\nimport { CONTACT_TYPE_TABS, contactStatusVariant, contactTypeLabel, contactTypeVariant } from './labels';\n\nexport const ContactsPage = () => {\n const { t } = useI18n();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toast } = useToast();\n const confirm = useConfirm();\n\n const [typeFilter, setTypeFilter] = useState<string | null>(null);\n const [search, setSearch] = useState('');\n const [formOpen, setFormOpen] = useState(false);\n const [importOpen, setImportOpen] = useState(false);\n const [editing, setEditing] = useState<Contact | null>(null);\n const [busyId, setBusyId] = useState<string | null>(null);\n\n const { contacts, loading, errors, refetchContacts, createContact, updateContact, deleteContact, importContacts } =\n useHealthyBowlContacts({ list: true, type: typeFilter, search: search.trim() || null });\n\n const openCreate = () => {\n setEditing(null);\n setFormOpen(true);\n };\n const openEdit = (c: Contact) => {\n setEditing(c);\n setFormOpen(true);\n };\n\n const handleSubmit = async (input: Record<string, unknown>) => {\n if (editing) {\n await updateContact(input);\n toast({\n title: t('healthybowl.contacts.toast.updated', 'Contact updated'),\n description: String(input.name ?? editing.name),\n variant: 'success',\n });\n } else {\n await createContact(input);\n toast({\n title: t('healthybowl.contacts.toast.created', 'Contact added'),\n description: String(input.name ?? ''),\n variant: 'success',\n });\n }\n };\n\n const handleImport = async (csv: string) => {\n const res = await importContacts(csv);\n if (res) {\n toast({\n title: t('healthybowl.contacts.toast.imported', 'Import complete'),\n description: t(\n 'healthybowl.contacts.toast.importedDesc',\n '{{imported}} added, {{updated}} updated, {{skipped}} skipped',\n {\n imported: res.imported,\n updated: res.updated,\n skipped: res.skipped,\n }\n ),\n variant: 'success',\n });\n }\n return res;\n };\n\n const handleDelete = async (c: Contact) => {\n if (\n !(await confirm({\n title: t('healthybowl.contacts.confirm.deleteTitle', 'Delete contact?'),\n message: t('healthybowl.contacts.confirm.delete', 'Delete \"{{name}}\"? This cannot be undone.', {\n name: c.name,\n }),\n }))\n )\n return;\n setBusyId(c.id);\n try {\n await deleteContact(c.id);\n toast({\n title: t('healthybowl.contacts.toast.deleted', 'Contact deleted'),\n description: c.name,\n variant: 'success',\n });\n } catch (err) {\n toast({\n title: t('healthybowl.contacts.toast.deleteFailed', 'Could not delete contact'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n } finally {\n setBusyId(null);\n }\n };\n\n const buyers = useMemo(() => contacts.filter((c) => c.type === 'BUYER').length, [contacts]);\n const suppliers = useMemo(() => contacts.filter((c) => c.type === 'SUPPLIER').length, [contacts]);\n\n const columns: Column<Contact>[] = [\n {\n key: 'name',\n header: t('healthybowl.contacts.table.name', 'Name'),\n render: (c) => (\n <div>\n <div className=\"font-medium text-text-primary\">{c.name}</div>\n <div className=\"text-xs text-text-secondary\">{contactTypeLabel(c.type)}</div>\n </div>\n ),\n },\n {\n key: 'type',\n header: t('healthybowl.contacts.table.type', 'Type'),\n render: (c) => <StatusBadge variant={contactTypeVariant(c.type)} label={contactTypeLabel(c.type)} />,\n },\n {\n key: 'lastOrder',\n header: t('healthybowl.contacts.table.lastOrder', 'Last Order'),\n render: (c) => <span className=\"tabular-nums text-text-secondary\">{c.lastOrderDate ?? '—'}</span>,\n },\n {\n key: 'phone',\n header: t('healthybowl.contacts.table.phone', 'Phone'),\n render: (c) => <span className=\"text-text-secondary\">{c.phone ?? '—'}</span>,\n },\n {\n key: 'status',\n header: t('healthybowl.contacts.table.status', 'Status'),\n render: (c) => <StatusBadge variant={contactStatusVariant(c.status)} label={c.status.toLowerCase()} dot />,\n },\n {\n key: 'actions',\n header: '',\n render: (c) => (\n <div className=\"flex items-center justify-end gap-1\">\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n disabled={busyId === c.id}\n onClick={(e) => {\n e.stopPropagation();\n openEdit(c);\n }}\n aria-label={t('healthybowl.contacts.actions.edit', 'Edit contact')}\n >\n <Pencil className=\"h-4 w-4\" />\n </Button>\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n disabled={busyId === c.id}\n onClick={(e) => {\n e.stopPropagation();\n void handleDelete(c);\n }}\n aria-label={t('healthybowl.contacts.actions.delete', 'Delete contact')}\n className=\"text-text-secondary hover:text-status-error-text\"\n >\n <Trash2 className=\"h-4 w-4\" />\n </Button>\n </div>\n ),\n },\n ];\n\n if (loading.list && contacts.length === 0) {\n return <PageLoader />;\n }\n\n return (\n <PageLayout\n title={t('healthybowl.contacts.title', 'Contacts')}\n titleAccent={t('healthybowl.contacts.titleAccent', 'Contacts')}\n description={t(\n 'healthybowl.contacts.description',\n 'Your buyers and suppliers — contact details, notes, and order history.'\n )}\n actions={\n <div className=\"flex items-center gap-2\">\n <Button variant=\"outline\" onClick={() => setImportOpen(true)}>\n <Upload className=\"h-4 w-4\" />\n {t('healthybowl.contacts.actions.import', 'Import CSV')}\n </Button>\n <Button onClick={openCreate}>\n <Plus className=\"h-4 w-4\" />\n {t('healthybowl.contacts.actions.new', 'Add Contact')}\n </Button>\n </div>\n }\n >\n {errors.list && contacts.length === 0 ? (\n <ErrorState description={errors.list.message} onRetry={() => void refetchContacts()} />\n ) : (\n <>\n <div className=\"mt-4 grid grid-cols-1 gap-3 sm:grid-cols-3\">\n <StatCard\n label={t('healthybowl.contacts.stats.total', 'Contacts')}\n value={contacts.length}\n icon={<Users className=\"h-5 w-5\" />}\n hero\n />\n <StatCard label={t('healthybowl.contacts.stats.buyers', 'Buyers')} value={buyers} />\n <StatCard label={t('healthybowl.contacts.stats.suppliers', 'Suppliers')} value={suppliers} />\n </div>\n\n <div className=\"mt-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between\">\n <div className=\"flex flex-wrap gap-1\">\n {CONTACT_TYPE_TABS.map((tab) => (\n <button\n key={tab.key}\n type=\"button\"\n onClick={() => setTypeFilter(tab.value)}\n className={cn(\n 'rounded-full px-3 py-1.5 text-sm font-medium transition-colors',\n typeFilter === tab.value\n ? 'bg-accent-teal text-white'\n : 'bg-bg-sunken text-text-secondary hover:text-text-primary'\n )}\n >\n {t(`healthybowl.contacts.tabs.${tab.key.toLowerCase()}`, tab.label)}\n </button>\n ))}\n </div>\n <div className=\"relative sm:w-64\">\n <Search className=\"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-text-tertiary\" />\n <Input\n value={search}\n onChange={(e) => setSearch(e.target.value)}\n placeholder={t('healthybowl.contacts.search', 'Search name, phone, email')}\n className=\"pl-8\"\n />\n </div>\n </div>\n\n {contacts.length === 0 ? (\n <EmptyState\n icon={<ContactIcon className=\"h-8 w-8 text-text-secondary\" />}\n title={t('healthybowl.contacts.empty.title', 'No contacts yet')}\n description={t(\n 'healthybowl.contacts.empty.description',\n 'Add a buyer or supplier, or import your existing contacts from a CSV.'\n )}\n action={\n <Button onClick={openCreate}>\n <Plus className=\"h-4 w-4\" />\n {t('healthybowl.contacts.actions.new', 'Add Contact')}\n </Button>\n }\n />\n ) : (\n <DataTable\n columns={columns}\n data={contacts}\n keyField=\"id\"\n pageSize={12}\n onRowClick={(c) => navigate(buildPath(`contacts/${c.id}`))}\n />\n )}\n </>\n )}\n\n <ContactFormModal open={formOpen} onClose={() => setFormOpen(false)} contact={editing} onSubmit={handleSubmit} />\n <CsvImportModal open={importOpen} onClose={() => setImportOpen(false)} onImport={handleImport} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,UAAqB;CAChC,IAAM,EAAE,SAAM,GAAS,EACjB,IAAW,GAAa,EACxB,EAAE,iBAAc,GAAa,EAC7B,EAAE,aAAU,GAAU,EACtB,IAAU,GAAY,EAEtB,CAAC,GAAY,KAAiB,EAAwB,KAAK,EAC3D,CAAC,GAAQ,KAAa,EAAS,GAAG,EAClC,CAAC,GAAU,KAAe,EAAS,GAAM,EACzC,CAAC,IAAY,KAAiB,EAAS,GAAM,EAC7C,CAAC,GAAS,KAAc,EAAyB,KAAK,EACtD,CAAC,GAAQ,KAAa,EAAwB,KAAK,EAEnD,EAAE,aAAU,YAAS,WAAQ,oBAAiB,mBAAe,mBAAe,mBAAe,uBAC/F,EAAuB;EAAE,MAAM;EAAM,MAAM;EAAY,QAAQ,EAAO,MAAM,IAAI;EAAM,CAAC,EAEnF,UAAmB;AAEvB,EADA,EAAW,KAAK,EAChB,EAAY,GAAK;IAEb,KAAY,MAAe;AAE/B,EADA,EAAW,EAAE,EACb,EAAY,GAAK;IAGb,KAAe,O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W,EACT,kEACA,MAAe,EAAI,QACf,8BACA,2DACL;iBAEA,EAAE,6BAA6B,EAAI,IAAI,aAAa,IAAI,EAAI,MAAM;OAC5D,EAXF,EAAI,IAWF,CACT;MACE,CAAA,EACN,kBAAC,OAAD;MAAK,WAAU;gBAAf,CACE,kBAAC,IAAD,EAAQ,WAAU,6FAA8F,CAAA,EAChH,kBAAC,GAAD;OACE,OAAO;OACP,WAAW,MAAM,EAAU,EAAE,OAAO,MAAM;OAC1C,aAAa,EAAE,+BAA+B,4BAA4B;OAC1E,WAAU;OACV,CAAA,CACE;QACF;;IAEL,EAAS,WAAW,IACnB,kBAAC,GAAD;KACE,MAAM,kBAAC,GAAD,EAAa,WAAU,+BAAgC,CAAA;KAC7D,OAAO,EAAE,oCAAoC,kBAAkB;KAC/D,aAAa,EACX,0CACA,wEACD;KACD,QACE,kBAAC,GAAD;MAAQ,SAAS;gBAAjB,CACE,kBAAC,GAAD,EAAM,WAAU,WAAY,CAAA,EAC3B,EAAE,oCAAoC,cAAc,CAC9C;;KAEX,CAAA,GAEF,kBAAC,GAAD;KACW;KACT,MAAM;KACN,UAAS;KACT,UAAU;KACV,aAAa,MAAM,EAAS,EAAU,YAAY,EAAE,KAAK,CAAC;KAC1D,CAAA;IAEH,EAAA,CAAA;GAGL,kBAAC,GAAD;IAAkB,MAAM;IAAU,eAAe,EAAY,GAAM;IAAE,SAAS;IAAS,UAAU;IAAgB,CAAA;GACjH,kBAAC,GAAD;IAAgB,MAAM;IAAY,eAAe,EAAc,GAAM;IAAE,UAAU;IAAgB,CAAA;GACtF"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Modal as e } from "../../components/Modal.js";
|
|
2
|
+
import "../../components/index.js";
|
|
3
|
+
import { useEffect as t, useRef as n, useState as r } from "react";
|
|
4
|
+
import { useI18n as i } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
5
|
+
import { Download as a, FileText as o, Upload as s } from "lucide-react";
|
|
6
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
7
|
+
import { Button as u, Textarea as d } from "@burdenoff/fe-libs/ui";
|
|
8
|
+
//#region src/healthybowl/pages/contacts/CsvImportModal.tsx
|
|
9
|
+
var f = "name,type,phone,email,address,gstin,notes,status\nBigBasket Organic,Buyer,+91 98450 12345,orders@bigbasket-organic.in,\"Whitefield, Bengaluru\",29AABCB1234C1Z5,Repeat organic buyer,Active\nGreen Agri Inputs,Supplier,+91 98111 22222,hello@greenagri.in,Erode,,Seeds & fertilizer supplier,Active\n", p = ({ open: p, onClose: m, onImport: h }) => {
|
|
10
|
+
let { t: g } = i(), [_, v] = r(""), [y, b] = r(null), [x, S] = r(!1), [C, w] = r(null), [T, E] = r(null), D = n(null);
|
|
11
|
+
t(() => {
|
|
12
|
+
p || (v(""), b(null), w(null), E(null), S(!1));
|
|
13
|
+
}, [p]);
|
|
14
|
+
let O = async (e) => {
|
|
15
|
+
e && (b(e.name), v(await e.text()));
|
|
16
|
+
}, k = () => {
|
|
17
|
+
let e = new Blob([f], { type: "text/csv;charset=utf-8;" }), t = URL.createObjectURL(e), n = document.createElement("a");
|
|
18
|
+
n.href = t, n.download = "healthybowl-contacts-template.csv", document.body.appendChild(n), n.click(), n.remove(), URL.revokeObjectURL(t);
|
|
19
|
+
}, A = async () => {
|
|
20
|
+
if (!(!_.trim() || x)) {
|
|
21
|
+
S(!0), E(null), w(null);
|
|
22
|
+
try {
|
|
23
|
+
w(await h(_));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
E(e instanceof Error ? e.message : String(e));
|
|
26
|
+
} finally {
|
|
27
|
+
S(!1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return /* @__PURE__ */ c(e, {
|
|
32
|
+
open: p,
|
|
33
|
+
onClose: m,
|
|
34
|
+
title: g("healthybowl.contacts.import.title", "Import Contacts"),
|
|
35
|
+
description: g("healthybowl.contacts.import.subtitle", "Import your existing buyers & suppliers from a CSV file."),
|
|
36
|
+
size: "lg",
|
|
37
|
+
footer: /* @__PURE__ */ l("div", {
|
|
38
|
+
className: "flex items-center justify-between gap-2",
|
|
39
|
+
children: [/* @__PURE__ */ l("button", {
|
|
40
|
+
type: "button",
|
|
41
|
+
onClick: k,
|
|
42
|
+
className: "inline-flex items-center gap-1.5 text-sm font-medium text-accent-teal hover:underline",
|
|
43
|
+
children: [/* @__PURE__ */ c(a, { className: "h-4 w-4" }), g("healthybowl.contacts.import.template", "Download template")]
|
|
44
|
+
}), /* @__PURE__ */ l("div", {
|
|
45
|
+
className: "flex items-center gap-2",
|
|
46
|
+
children: [/* @__PURE__ */ c(u, {
|
|
47
|
+
variant: "ghost",
|
|
48
|
+
onClick: m,
|
|
49
|
+
disabled: x,
|
|
50
|
+
children: C ? g("common.close", "Close") : g("common.cancel", "Cancel")
|
|
51
|
+
}), /* @__PURE__ */ l(u, {
|
|
52
|
+
onClick: () => void A(),
|
|
53
|
+
disabled: !_.trim() || x,
|
|
54
|
+
children: [/* @__PURE__ */ c(s, { className: "h-4 w-4" }), g("healthybowl.contacts.import.run", "Import")]
|
|
55
|
+
})]
|
|
56
|
+
})]
|
|
57
|
+
}),
|
|
58
|
+
children: /* @__PURE__ */ l("div", {
|
|
59
|
+
className: "space-y-4",
|
|
60
|
+
children: [
|
|
61
|
+
/* @__PURE__ */ l("div", {
|
|
62
|
+
className: "flex flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed border-border-subtle bg-bg-sunken px-4 py-6 text-center",
|
|
63
|
+
onDragOver: (e) => e.preventDefault(),
|
|
64
|
+
onDrop: (e) => {
|
|
65
|
+
e.preventDefault(), O(e.dataTransfer.files?.[0]);
|
|
66
|
+
},
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ c(o, { className: "h-8 w-8 text-text-secondary" }),
|
|
69
|
+
/* @__PURE__ */ l("div", {
|
|
70
|
+
className: "text-sm text-text-secondary",
|
|
71
|
+
children: [
|
|
72
|
+
g("healthybowl.contacts.import.drop", "Drop a .CSV file here or"),
|
|
73
|
+
" ",
|
|
74
|
+
/* @__PURE__ */ c("button", {
|
|
75
|
+
type: "button",
|
|
76
|
+
onClick: () => D.current?.click(),
|
|
77
|
+
className: "font-medium text-accent-teal hover:underline",
|
|
78
|
+
children: g("healthybowl.contacts.import.browse", "browse")
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
}),
|
|
82
|
+
y ? /* @__PURE__ */ c("div", {
|
|
83
|
+
className: "text-xs text-text-tertiary",
|
|
84
|
+
children: y
|
|
85
|
+
}) : null,
|
|
86
|
+
/* @__PURE__ */ c("input", {
|
|
87
|
+
ref: D,
|
|
88
|
+
type: "file",
|
|
89
|
+
accept: ".csv,text/csv",
|
|
90
|
+
className: "hidden",
|
|
91
|
+
onChange: (e) => void O(e.target.files?.[0] ?? void 0)
|
|
92
|
+
})
|
|
93
|
+
]
|
|
94
|
+
}),
|
|
95
|
+
/* @__PURE__ */ l("div", { children: [/* @__PURE__ */ c("label", {
|
|
96
|
+
className: "mb-1 block text-sm font-medium text-text-primary",
|
|
97
|
+
children: g("healthybowl.contacts.import.paste", "Or paste CSV")
|
|
98
|
+
}), /* @__PURE__ */ c(d, {
|
|
99
|
+
value: _,
|
|
100
|
+
onChange: (e) => v(e.target.value),
|
|
101
|
+
rows: 6,
|
|
102
|
+
placeholder: "name,type,phone,email,address,gstin,notes,status",
|
|
103
|
+
className: "font-mono text-xs"
|
|
104
|
+
})] }),
|
|
105
|
+
T ? /* @__PURE__ */ c("div", {
|
|
106
|
+
className: "rounded-md border border-status-error-border bg-status-error-bg px-3 py-2 text-sm text-status-error-text",
|
|
107
|
+
children: T
|
|
108
|
+
}) : null,
|
|
109
|
+
C ? /* @__PURE__ */ l("div", {
|
|
110
|
+
className: "rounded-md border border-border-subtle bg-bg-surface p-3 text-sm",
|
|
111
|
+
children: [/* @__PURE__ */ l("div", {
|
|
112
|
+
className: "flex flex-wrap gap-x-6 gap-y-1 text-text-primary",
|
|
113
|
+
children: [
|
|
114
|
+
/* @__PURE__ */ l("span", { children: [
|
|
115
|
+
/* @__PURE__ */ c("span", {
|
|
116
|
+
className: "font-semibold text-status-success-text",
|
|
117
|
+
children: C.imported
|
|
118
|
+
}),
|
|
119
|
+
" ",
|
|
120
|
+
g("healthybowl.contacts.import.imported", "imported")
|
|
121
|
+
] }),
|
|
122
|
+
/* @__PURE__ */ l("span", { children: [
|
|
123
|
+
/* @__PURE__ */ c("span", {
|
|
124
|
+
className: "font-semibold text-status-info-text",
|
|
125
|
+
children: C.updated
|
|
126
|
+
}),
|
|
127
|
+
" ",
|
|
128
|
+
g("healthybowl.contacts.import.updated", "updated")
|
|
129
|
+
] }),
|
|
130
|
+
/* @__PURE__ */ l("span", { children: [
|
|
131
|
+
/* @__PURE__ */ c("span", {
|
|
132
|
+
className: "font-semibold text-text-secondary",
|
|
133
|
+
children: C.skipped
|
|
134
|
+
}),
|
|
135
|
+
" ",
|
|
136
|
+
g("healthybowl.contacts.import.skipped", "skipped")
|
|
137
|
+
] })
|
|
138
|
+
]
|
|
139
|
+
}), C.errors.length > 0 ? /* @__PURE__ */ l("ul", {
|
|
140
|
+
className: "mt-2 list-disc space-y-0.5 pl-5 text-xs text-status-warning-text",
|
|
141
|
+
children: [C.errors.slice(0, 8).map((e, t) => /* @__PURE__ */ c("li", { children: e }, t)), C.errors.length > 8 ? /* @__PURE__ */ l("li", { children: [
|
|
142
|
+
"+",
|
|
143
|
+
C.errors.length - 8,
|
|
144
|
+
" more…"
|
|
145
|
+
] }) : null]
|
|
146
|
+
}) : null]
|
|
147
|
+
}) : null
|
|
148
|
+
]
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
//#endregion
|
|
153
|
+
export { p as CsvImportModal };
|
|
154
|
+
|
|
155
|
+
//# sourceMappingURL=CsvImportModal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CsvImportModal.js","names":[],"sources":["../../../../src/healthybowl/pages/contacts/CsvImportModal.tsx"],"sourcesContent":["/**\n * CSV import for buyers & suppliers (BOFF-2890 · J-1).\n * Paste CSV text or pick a .csv file; rows are upserted by (name, type) via the real backend\n * import mutation. The result counts + per-row errors are surfaced — no fabricated data.\n */\nimport { useEffect, useRef, useState } from 'react';\nimport { Download, FileText, Upload } from 'lucide-react';\nimport { Button, Textarea } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { Modal } from '../../components';\nimport type { ContactImportResult } from '../../hooks/useHealthyBowlContacts';\n\ninterface CsvImportModalProps {\n open: boolean;\n onClose: () => void;\n onImport: (csv: string) => Promise<ContactImportResult | null>;\n}\n\nconst TEMPLATE =\n 'name,type,phone,email,address,gstin,notes,status\\nBigBasket Organic,Buyer,+91 98450 12345,orders@bigbasket-organic.in,\"Whitefield, Bengaluru\",29AABCB1234C1Z5,Repeat organic buyer,Active\\nGreen Agri Inputs,Supplier,+91 98111 22222,hello@greenagri.in,Erode,,Seeds & fertilizer supplier,Active\\n';\n\nexport const CsvImportModal = ({ open, onClose, onImport }: CsvImportModalProps) => {\n const { t } = useI18n();\n const [csv, setCsv] = useState('');\n const [fileName, setFileName] = useState<string | null>(null);\n const [submitting, setSubmitting] = useState(false);\n const [result, setResult] = useState<ContactImportResult | null>(null);\n const [error, setError] = useState<string | null>(null);\n const fileInputRef = useRef<HTMLInputElement | null>(null);\n\n useEffect(() => {\n if (!open) {\n setCsv('');\n setFileName(null);\n setResult(null);\n setError(null);\n setSubmitting(false);\n }\n }, [open]);\n\n const handleFile = async (file: File | undefined) => {\n if (!file) return;\n setFileName(file.name);\n setCsv(await file.text());\n };\n\n const downloadTemplate = () => {\n const blob = new Blob([TEMPLATE], { type: 'text/csv;charset=utf-8;' });\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = 'healthybowl-contacts-template.csv';\n document.body.appendChild(a);\n a.click();\n a.remove();\n URL.revokeObjectURL(url);\n };\n\n const handleSubmit = async () => {\n if (!csv.trim() || submitting) return;\n setSubmitting(true);\n setError(null);\n setResult(null);\n try {\n const res = await onImport(csv);\n setResult(res);\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err));\n } finally {\n setSubmitting(false);\n }\n };\n\n return (\n <Modal\n open={open}\n onClose={onClose}\n title={t('healthybowl.contacts.import.title', 'Import Contacts')}\n description={t(\n 'healthybowl.contacts.import.subtitle',\n 'Import your existing buyers & suppliers from a CSV file.'\n )}\n size=\"lg\"\n footer={\n <div className=\"flex items-center justify-between gap-2\">\n <button\n type=\"button\"\n onClick={downloadTemplate}\n className=\"inline-flex items-center gap-1.5 text-sm font-medium text-accent-teal hover:underline\"\n >\n <Download className=\"h-4 w-4\" />\n {t('healthybowl.contacts.import.template', 'Download template')}\n </button>\n <div className=\"flex items-center gap-2\">\n <Button variant=\"ghost\" onClick={onClose} disabled={submitting}>\n {result ? t('common.close', 'Close') : t('common.cancel', 'Cancel')}\n </Button>\n <Button onClick={() => void handleSubmit()} disabled={!csv.trim() || submitting}>\n <Upload className=\"h-4 w-4\" />\n {t('healthybowl.contacts.import.run', 'Import')}\n </Button>\n </div>\n </div>\n }\n >\n <div className=\"space-y-4\">\n <div\n className=\"flex flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed border-border-subtle bg-bg-sunken px-4 py-6 text-center\"\n onDragOver={(e) => e.preventDefault()}\n onDrop={(e) => {\n e.preventDefault();\n void handleFile(e.dataTransfer.files?.[0]);\n }}\n >\n <FileText className=\"h-8 w-8 text-text-secondary\" />\n <div className=\"text-sm text-text-secondary\">\n {t('healthybowl.contacts.import.drop', 'Drop a .CSV file here or')}{' '}\n <button\n type=\"button\"\n onClick={() => fileInputRef.current?.click()}\n className=\"font-medium text-accent-teal hover:underline\"\n >\n {t('healthybowl.contacts.import.browse', 'browse')}\n </button>\n </div>\n {fileName ? <div className=\"text-xs text-text-tertiary\">{fileName}</div> : null}\n <input\n ref={fileInputRef}\n type=\"file\"\n accept=\".csv,text/csv\"\n className=\"hidden\"\n onChange={(e) => void handleFile(e.target.files?.[0] ?? undefined)}\n />\n </div>\n\n <div>\n <label className=\"mb-1 block text-sm font-medium text-text-primary\">\n {t('healthybowl.contacts.import.paste', 'Or paste CSV')}\n </label>\n <Textarea\n value={csv}\n onChange={(e) => setCsv(e.target.value)}\n rows={6}\n placeholder=\"name,type,phone,email,address,gstin,notes,status\"\n className=\"font-mono text-xs\"\n />\n </div>\n\n {error ? (\n <div className=\"rounded-md border border-status-error-border bg-status-error-bg px-3 py-2 text-sm text-status-error-text\">\n {error}\n </div>\n ) : null}\n\n {result ? (\n <div className=\"rounded-md border border-border-subtle bg-bg-surface p-3 text-sm\">\n <div className=\"flex flex-wrap gap-x-6 gap-y-1 text-text-primary\">\n <span>\n <span className=\"font-semibold text-status-success-text\">{result.imported}</span>{' '}\n {t('healthybowl.contacts.import.imported', 'imported')}\n </span>\n <span>\n <span className=\"font-semibold text-status-info-text\">{result.updated}</span>{' '}\n {t('healthybowl.contacts.import.updated', 'updated')}\n </span>\n <span>\n <span className=\"font-semibold text-text-secondary\">{result.skipped}</span>{' '}\n {t('healthybowl.contacts.import.skipped', 'skipped')}\n </span>\n </div>\n {result.errors.length > 0 ? (\n <ul className=\"mt-2 list-disc space-y-0.5 pl-5 text-xs text-status-warning-text\">\n {result.errors.slice(0, 8).map((e, i) => (\n <li key={i}>{e}</li>\n ))}\n {result.errors.length > 8 ? <li>+{result.errors.length - 8} more…</li> : null}\n </ul>\n ) : null}\n </div>\n ) : null}\n </div>\n </Modal>\n );\n};\n"],"mappings":";;;;;;;;AAkBA,IAAM,IACJ,0SAEW,KAAkB,EAAE,SAAM,YAAS,kBAAoC;CAClF,IAAM,EAAE,SAAM,GAAS,EACjB,CAAC,GAAK,KAAU,EAAS,GAAG,EAC5B,CAAC,GAAU,KAAe,EAAwB,KAAK,EACvD,CAAC,GAAY,KAAiB,EAAS,GAAM,EAC7C,CAAC,GAAQ,KAAa,EAAqC,KAAK,E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BAAC,QAAD,EAAA,UAAA;QACE,kBAAC,QAAD;SAAM,WAAU;mBAA0C,EAAO;SAAgB,CAAA;QAAC;QACjF,EAAE,wCAAwC,WAAW;QACjD,EAAA,CAAA;OACP,kBAAC,QAAD,EAAA,UAAA;QACE,kBAAC,QAAD;SAAM,WAAU;mBAAuC,EAAO;SAAe,CAAA;QAAC;QAC7E,EAAE,uCAAuC,UAAU;QAC/C,EAAA,CAAA;OACP,kBAAC,QAAD,EAAA,UAAA;QACE,kBAAC,QAAD;SAAM,WAAU;mBAAqC,EAAO;SAAe,CAAA;QAAC;QAC3E,EAAE,uCAAuC,UAAU;QAC/C,EAAA,CAAA;OACH;SACL,EAAO,OAAO,SAAS,IACtB,kBAAC,MAAD;MAAI,WAAU;gBAAd,CACG,EAAO,OAAO,MAAM,GAAG,EAAE,CAAC,KAAK,GAAG,MACjC,kBAAC,MAAD,EAAA,UAAa,GAAO,EAAX,EAAW,CACpB,EACD,EAAO,OAAO,SAAS,IAAI,kBAAC,MAAD,EAAA,UAAA;OAAI;OAAE,EAAO,OAAO,SAAS;OAAE;OAAW,EAAA,CAAA,GAAG,KACtE;UACH,KACA;SACJ;IACA;;EACA,CAAA"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Modal as e } from "../../components/Modal.js";
|
|
2
|
+
import "../../components/index.js";
|
|
3
|
+
import { useEffect as t, useState as n } from "react";
|
|
4
|
+
import { useI18n as r } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
5
|
+
import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
6
|
+
import { Button as s, Input as c, Select as l, SelectContent as u, SelectItem as d, SelectTrigger as f, SelectValue as p } from "@burdenoff/fe-libs/ui";
|
|
7
|
+
//#region src/healthybowl/pages/contacts/RecordOrderModal.tsx
|
|
8
|
+
var m = [
|
|
9
|
+
"DELIVERED",
|
|
10
|
+
"SHIPPED",
|
|
11
|
+
"CONFIRMED",
|
|
12
|
+
"PENDING",
|
|
13
|
+
"CANCELLED"
|
|
14
|
+
], h = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10), g = "mb-1 block text-sm font-medium text-text-primary", _ = "w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]", v = ({ open: v, onClose: y, contactName: b, onSubmit: x }) => {
|
|
15
|
+
let { t: S } = r(), [C, w] = n(""), [T, E] = n(""), [D, O] = n("kg"), [k, A] = n(""), [j, M] = n(h()), [N, P] = n("DELIVERED"), [F, I] = n(!1), [L, R] = n(null);
|
|
16
|
+
t(() => {
|
|
17
|
+
v && (w(""), E(""), O("kg"), A(""), M(h()), P("DELIVERED"), R(null));
|
|
18
|
+
}, [v]);
|
|
19
|
+
let z = C.trim().length > 0 && Number(k) > 0 && !F, B = async () => {
|
|
20
|
+
if (z) {
|
|
21
|
+
I(!0), R(null);
|
|
22
|
+
try {
|
|
23
|
+
await x({
|
|
24
|
+
items: [{
|
|
25
|
+
productName: C.trim(),
|
|
26
|
+
quantity: Number(T) || 0,
|
|
27
|
+
unit: D.trim() || "kg"
|
|
28
|
+
}],
|
|
29
|
+
amount: Number(k),
|
|
30
|
+
date: j,
|
|
31
|
+
status: N
|
|
32
|
+
}), y();
|
|
33
|
+
} catch (e) {
|
|
34
|
+
R(e instanceof Error ? e.message : String(e));
|
|
35
|
+
} finally {
|
|
36
|
+
I(!1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return /* @__PURE__ */ a(e, {
|
|
41
|
+
open: v,
|
|
42
|
+
onClose: y,
|
|
43
|
+
title: S("healthybowl.contacts.order.title", "Record an order"),
|
|
44
|
+
description: b,
|
|
45
|
+
footer: /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ a(s, {
|
|
46
|
+
variant: "outline",
|
|
47
|
+
onClick: y,
|
|
48
|
+
disabled: F,
|
|
49
|
+
children: S("common.cancel", "Cancel")
|
|
50
|
+
}), /* @__PURE__ */ a(s, {
|
|
51
|
+
onClick: () => void B(),
|
|
52
|
+
disabled: !z,
|
|
53
|
+
children: S("healthybowl.contacts.order.save", "Record order")
|
|
54
|
+
})] }),
|
|
55
|
+
children: /* @__PURE__ */ o("div", {
|
|
56
|
+
className: "space-y-3",
|
|
57
|
+
children: [
|
|
58
|
+
L ? /* @__PURE__ */ a("div", {
|
|
59
|
+
className: "rounded-md border border-status-error-border bg-status-error-bg px-3 py-2 text-sm text-status-error-text",
|
|
60
|
+
children: L
|
|
61
|
+
}) : null,
|
|
62
|
+
/* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("label", {
|
|
63
|
+
className: g,
|
|
64
|
+
children: S("healthybowl.contacts.order.item", "Item")
|
|
65
|
+
}), /* @__PURE__ */ a(c, {
|
|
66
|
+
value: C,
|
|
67
|
+
onChange: (e) => w(e.target.value),
|
|
68
|
+
placeholder: "Tomatoes"
|
|
69
|
+
})] }),
|
|
70
|
+
/* @__PURE__ */ o("div", {
|
|
71
|
+
className: "grid grid-cols-3 gap-3",
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("label", {
|
|
74
|
+
className: g,
|
|
75
|
+
children: S("healthybowl.contacts.order.quantity", "Quantity")
|
|
76
|
+
}), /* @__PURE__ */ a(c, {
|
|
77
|
+
type: "number",
|
|
78
|
+
min: "0",
|
|
79
|
+
step: "0.1",
|
|
80
|
+
value: T,
|
|
81
|
+
onChange: (e) => E(e.target.value)
|
|
82
|
+
})] }),
|
|
83
|
+
/* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("label", {
|
|
84
|
+
className: g,
|
|
85
|
+
children: S("healthybowl.contacts.order.unit", "Unit")
|
|
86
|
+
}), /* @__PURE__ */ a(c, {
|
|
87
|
+
value: D,
|
|
88
|
+
onChange: (e) => O(e.target.value)
|
|
89
|
+
})] }),
|
|
90
|
+
/* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("label", {
|
|
91
|
+
className: g,
|
|
92
|
+
children: S("healthybowl.contacts.order.amount", "Amount (₹)")
|
|
93
|
+
}), /* @__PURE__ */ a(c, {
|
|
94
|
+
type: "number",
|
|
95
|
+
min: "0",
|
|
96
|
+
step: "1",
|
|
97
|
+
value: k,
|
|
98
|
+
onChange: (e) => A(e.target.value)
|
|
99
|
+
})] })
|
|
100
|
+
]
|
|
101
|
+
}),
|
|
102
|
+
/* @__PURE__ */ o("div", {
|
|
103
|
+
className: "grid grid-cols-2 gap-3",
|
|
104
|
+
children: [/* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("label", {
|
|
105
|
+
className: g,
|
|
106
|
+
children: S("healthybowl.contacts.order.date", "Date")
|
|
107
|
+
}), /* @__PURE__ */ a("input", {
|
|
108
|
+
type: "date",
|
|
109
|
+
className: _,
|
|
110
|
+
value: j,
|
|
111
|
+
onChange: (e) => M(e.target.value)
|
|
112
|
+
})] }), /* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("label", {
|
|
113
|
+
className: g,
|
|
114
|
+
children: S("healthybowl.contacts.order.status", "Status")
|
|
115
|
+
}), /* @__PURE__ */ o(l, {
|
|
116
|
+
value: N,
|
|
117
|
+
onValueChange: P,
|
|
118
|
+
children: [/* @__PURE__ */ a(f, { children: /* @__PURE__ */ a(p, {}) }), /* @__PURE__ */ a(u, { children: m.map((e) => /* @__PURE__ */ a(d, {
|
|
119
|
+
value: e,
|
|
120
|
+
children: e
|
|
121
|
+
}, e)) })]
|
|
122
|
+
})] })]
|
|
123
|
+
})
|
|
124
|
+
]
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
129
|
+
export { v as RecordOrderModal };
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=RecordOrderModal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RecordOrderModal.js","names":[],"sources":["../../../../src/healthybowl/pages/contacts/RecordOrderModal.tsx"],"sourcesContent":["/**\n * Record a sale/order against a buyer contact (BOFF-2890 · J-1).\n * Creates a real Order linked to the contact (Order.buyerId = contactId) so it appears in the\n * contact's order history. No fabricated data — every field is user-entered and persisted.\n */\nimport { useEffect, useState } from 'react';\nimport {\n Button,\n Input,\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { Modal } from '../../components';\n\ninterface RecordOrderModalProps {\n open: boolean;\n onClose: () => void;\n contactName: string;\n onSubmit: (input: Record<string, unknown>) => Promise<void>;\n}\n\nconst ORDER_STATUSES = ['DELIVERED', 'SHIPPED', 'CONFIRMED', 'PENDING', 'CANCELLED'] as const;\nconst todayIso = (): string => new Date().toISOString().slice(0, 10);\nconst fieldLabel = 'mb-1 block text-sm font-medium text-text-primary';\nconst dateInput =\n 'w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]';\n\nexport const RecordOrderModal = ({ open, onClose, contactName, onSubmit }: RecordOrderModalProps) => {\n const { t } = useI18n();\n const [productName, setProductName] = useState('');\n const [quantity, setQuantity] = useState('');\n const [unit, setUnit] = useState('kg');\n const [amount, setAmount] = useState('');\n const [date, setDate] = useState(todayIso());\n const [status, setStatus] = useState('DELIVERED');\n const [submitting, setSubmitting] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n if (!open) return;\n setProductName('');\n setQuantity('');\n setUnit('kg');\n setAmount('');\n setDate(todayIso());\n setStatus('DELIVERED');\n setError(null);\n }, [open]);\n\n const canSubmit = productName.trim().length > 0 && Number(amount) > 0 && !submitting;\n\n const handleSubmit = async () => {\n if (!canSubmit) return;\n setSubmitting(true);\n setError(null);\n try {\n await onSubmit({\n items: [{ productName: productName.trim(), quantity: Number(quantity) || 0, unit: unit.trim() || 'kg' }],\n amount: Number(amount),\n date,\n status,\n });\n onClose();\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err));\n } finally {\n setSubmitting(false);\n }\n };\n\n return (\n <Modal\n open={open}\n onClose={onClose}\n title={t('healthybowl.contacts.order.title', 'Record an order')}\n description={contactName}\n footer={\n <>\n <Button variant=\"outline\" onClick={onClose} disabled={submitting}>\n {t('common.cancel', 'Cancel')}\n </Button>\n <Button onClick={() => void handleSubmit()} disabled={!canSubmit}>\n {t('healthybowl.contacts.order.save', 'Record order')}\n </Button>\n </>\n }\n >\n <div className=\"space-y-3\">\n {error ? (\n <div className=\"rounded-md border border-status-error-border bg-status-error-bg px-3 py-2 text-sm text-status-error-text\">\n {error}\n </div>\n ) : null}\n <div>\n <label className={fieldLabel}>{t('healthybowl.contacts.order.item', 'Item')}</label>\n <Input value={productName} onChange={(e) => setProductName(e.target.value)} placeholder=\"Tomatoes\" />\n </div>\n <div className=\"grid grid-cols-3 gap-3\">\n <div>\n <label className={fieldLabel}>{t('healthybowl.contacts.order.quantity', 'Quantity')}</label>\n <Input type=\"number\" min=\"0\" step=\"0.1\" value={quantity} onChange={(e) => setQuantity(e.target.value)} />\n </div>\n <div>\n <label className={fieldLabel}>{t('healthybowl.contacts.order.unit', 'Unit')}</label>\n <Input value={unit} onChange={(e) => setUnit(e.target.value)} />\n </div>\n <div>\n <label className={fieldLabel}>{t('healthybowl.contacts.order.amount', 'Amount (₹)')}</label>\n <Input type=\"number\" min=\"0\" step=\"1\" value={amount} onChange={(e) => setAmount(e.target.value)} />\n </div>\n </div>\n <div className=\"grid grid-cols-2 gap-3\">\n <div>\n <label className={fieldLabel}>{t('healthybowl.contacts.order.date', 'Date')}</label>\n <input type=\"date\" className={dateInput} value={date} onChange={(e) => setDate(e.target.value)} />\n </div>\n <div>\n <label className={fieldLabel}>{t('healthybowl.contacts.order.status', 'Status')}</label>\n <Select value={status} onValueChange={setStatus}>\n <SelectTrigger>\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {ORDER_STATUSES.map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AqC,aAAa;OAAS,CAAA,EAC5F,kBAAC,GAAD;OAAO,MAAK;OAAS,KAAI;OAAI,MAAK;OAAI,OAAO;OAAQ,WAAW,MAAM,EAAU,EAAE,OAAO,MAAM;OAAI,CAAA,CAC/F,EAAA,CAAA;MACF;;IACN,kBAAC,OAAD;KAAK,WAAU;eAAf,CACE,kBAAC,OAAD,EAAA,UAAA,CACE,kBAAC,SAAD;MAAO,WAAW;gBAAa,EAAE,mCAAmC,OAAO;MAAS,CAAA,EACpF,kBAAC,SAAD;MAAO,MAAK;MAAO,WAAW;MAAW,OAAO;MAAM,WAAW,MAAM,EAAQ,EAAE,OAAO,MAAM;MAAI,CAAA,CAC9F,EAAA,CAAA,EACN,kBAAC,OAAD,EAAA,UAAA,CACE,kBAAC,SAAD;MAAO,WAAW;gBAAa,EAAE,qCAAqC,SAAS;MAAS,CAAA,EACxF,kBAAC,GAAD;MAAQ,OAAO;MAAQ,eAAe;gBAAtC,CACE,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD,EAAe,CAAA,EACD,CAAA,EAChB,kBAAC,GAAD,EAAA,UACG,EAAe,KAAK,MACnB,kBAAC,GAAD;OAAoB,OAAO;iBACxB;OACU,EAFI,EAEJ,CACb,EACY,CAAA,CACT;QACL,EAAA,CAAA,CACF;;IACF;;EACA,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region src/healthybowl/pages/contacts/labels.ts
|
|
2
|
+
var e = [
|
|
3
|
+
{
|
|
4
|
+
key: "ALL",
|
|
5
|
+
label: "All",
|
|
6
|
+
value: null
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
key: "BUYER",
|
|
10
|
+
label: "Buyers",
|
|
11
|
+
value: "BUYER"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
key: "SUPPLIER",
|
|
15
|
+
label: "Suppliers",
|
|
16
|
+
value: "SUPPLIER"
|
|
17
|
+
}
|
|
18
|
+
], t = (e) => {
|
|
19
|
+
switch (e) {
|
|
20
|
+
case "BUYER": return "Buyer";
|
|
21
|
+
case "SUPPLIER": return "Supplier";
|
|
22
|
+
default: return e;
|
|
23
|
+
}
|
|
24
|
+
}, n = (e) => {
|
|
25
|
+
switch (e) {
|
|
26
|
+
case "BUYER": return "success";
|
|
27
|
+
case "SUPPLIER": return "info";
|
|
28
|
+
default: return "muted";
|
|
29
|
+
}
|
|
30
|
+
}, r = (e) => {
|
|
31
|
+
switch (e) {
|
|
32
|
+
case "ACTIVE": return "success";
|
|
33
|
+
case "INACTIVE": return "muted";
|
|
34
|
+
default: return "muted";
|
|
35
|
+
}
|
|
36
|
+
}, i = (e) => {
|
|
37
|
+
let t = e.toUpperCase();
|
|
38
|
+
return t === "DELIVERED" || t === "PAID" || t === "COMPLETED" ? "success" : t === "SHIPPED" || t === "IN_TRANSIT" || t === "IN TRANSIT" ? "info" : t === "PENDING" || t === "CONFIRMED" || t === "PROCESSING" ? "warning" : t === "CANCELLED" || t === "CANCELED" || t === "FAILED" ? "error" : "muted";
|
|
39
|
+
}, a = (e) => {
|
|
40
|
+
let t = e.trim().split(/\s+/).filter(Boolean);
|
|
41
|
+
return t.length === 0 ? "?" : t.length === 1 ? t[0].slice(0, 2).toUpperCase() : (t[0][0] + t[t.length - 1][0]).toUpperCase();
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { e as CONTACT_TYPE_TABS, a as contactInitials, r as contactStatusVariant, t as contactTypeLabel, n as contactTypeVariant, i as orderStatusVariant };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=labels.js.map
|