@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,150 @@
|
|
|
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 { StatusBadge as i } from "../../components/StatusBadge.js";
|
|
6
|
+
import { ErrorState as a } from "../../components/ErrorState.js";
|
|
7
|
+
import { PageLoader as o } from "../../components/PageLoader.js";
|
|
8
|
+
import { useToast as s } from "../../hooks/useToast.js";
|
|
9
|
+
import "../../components/index.js";
|
|
10
|
+
import { useHealthyBowlStorage as c } from "../../hooks/useHealthyBowlStorage.js";
|
|
11
|
+
import { lotStatusVariant as l, reasonLabel as u } from "./labels.js";
|
|
12
|
+
import { RecordMovementModal as d } from "./RecordMovementModal.js";
|
|
13
|
+
import { useState as f } from "react";
|
|
14
|
+
import { useI18n as p } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
15
|
+
import { ArrowDown as m, ArrowLeft as h, ArrowUp as g, Plus as _ } from "lucide-react";
|
|
16
|
+
import { useNavigate as v, useParams as y } from "react-router-dom";
|
|
17
|
+
import { jsx as b, jsxs as x } from "react/jsx-runtime";
|
|
18
|
+
import { Button as S } from "@burdenoff/fe-libs/ui";
|
|
19
|
+
//#region src/healthybowl/pages/storage/StorageLotDetailPage.tsx
|
|
20
|
+
var C = () => {
|
|
21
|
+
let { t: C } = p(), w = v(), { buildPath: T } = t(), { toast: E } = s(), { lotId: D } = y(), { lotDetail: O, loading: k, errors: A, refetchLot: j, recordMovement: M } = c({ lotId: D ?? null }), [N, P] = f(!1), F = async (e) => {
|
|
22
|
+
await M(e), E({
|
|
23
|
+
title: C("healthybowl.storage.toast.movementRecorded", "Movement recorded"),
|
|
24
|
+
variant: "success"
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
if (k.lot && !O) return /* @__PURE__ */ b(o, {});
|
|
28
|
+
if (A.lot && !O || !O) return /* @__PURE__ */ b("div", {
|
|
29
|
+
className: "p-4",
|
|
30
|
+
children: /* @__PURE__ */ b(a, {
|
|
31
|
+
description: A.lot?.message ?? C("healthybowl.storage.lot.notFound", "Lot not found."),
|
|
32
|
+
onRetry: () => void j()
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
let { lot: I, movements: L } = O;
|
|
36
|
+
return /* @__PURE__ */ x(n, {
|
|
37
|
+
title: `${I.produce} · ${I.lotCode}`,
|
|
38
|
+
description: `${I.warehouseName} · ${I.locationName}`,
|
|
39
|
+
hideHelp: !0,
|
|
40
|
+
children: [
|
|
41
|
+
/* @__PURE__ */ x("button", {
|
|
42
|
+
type: "button",
|
|
43
|
+
onClick: () => w(T("storage")),
|
|
44
|
+
className: "mb-3 inline-flex items-center gap-1 text-sm text-text-secondary hover:text-text-primary",
|
|
45
|
+
children: [/* @__PURE__ */ b(h, { className: "h-4 w-4" }), C("healthybowl.storage.lot.backToStorage", "Storage")]
|
|
46
|
+
}),
|
|
47
|
+
/* @__PURE__ */ x("div", {
|
|
48
|
+
className: "flex flex-wrap items-center justify-between gap-3",
|
|
49
|
+
children: [/* @__PURE__ */ x("div", {
|
|
50
|
+
className: "flex items-center gap-2",
|
|
51
|
+
children: [/* @__PURE__ */ b(i, {
|
|
52
|
+
variant: l(I.status),
|
|
53
|
+
label: I.status.toLowerCase(),
|
|
54
|
+
dot: !0
|
|
55
|
+
}), I.expiryDate ? /* @__PURE__ */ b("span", {
|
|
56
|
+
className: "text-xs text-text-tertiary",
|
|
57
|
+
children: C("healthybowl.storage.lot.expires", "Expires {{date}}", { date: I.expiryDate.slice(0, 10) })
|
|
58
|
+
}) : null]
|
|
59
|
+
}), /* @__PURE__ */ x(S, {
|
|
60
|
+
onClick: () => P(!0),
|
|
61
|
+
children: [/* @__PURE__ */ b(_, { className: "h-4 w-4" }), C("healthybowl.storage.movement.record", "Record Movement")]
|
|
62
|
+
})]
|
|
63
|
+
}),
|
|
64
|
+
/* @__PURE__ */ x("div", {
|
|
65
|
+
className: "mt-4 grid grid-cols-1 gap-3 sm:grid-cols-3",
|
|
66
|
+
children: [
|
|
67
|
+
/* @__PURE__ */ b(r, {
|
|
68
|
+
label: C("healthybowl.storage.lot.onHand", "On hand"),
|
|
69
|
+
value: `${I.quantity} ${I.unit}`,
|
|
70
|
+
hero: !0
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ b(r, {
|
|
73
|
+
label: C("healthybowl.storage.lot.location", "Location"),
|
|
74
|
+
value: I.locationName
|
|
75
|
+
}),
|
|
76
|
+
/* @__PURE__ */ b(r, {
|
|
77
|
+
label: C("healthybowl.storage.lot.received", "Received"),
|
|
78
|
+
value: I.receivedAt ? I.receivedAt.slice(0, 10) : "—"
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
}),
|
|
82
|
+
/* @__PURE__ */ x("div", {
|
|
83
|
+
className: "mt-4 rounded-xl border border-border-subtle bg-bg-surface p-4",
|
|
84
|
+
children: [/* @__PURE__ */ b("h3", {
|
|
85
|
+
className: "mb-3 text-sm font-semibold text-text-primary",
|
|
86
|
+
children: C("healthybowl.storage.movementHistory", "Movement History")
|
|
87
|
+
}), L.length === 0 ? /* @__PURE__ */ b("div", {
|
|
88
|
+
className: "py-6 text-center text-sm text-text-secondary",
|
|
89
|
+
children: C("healthybowl.storage.noMovements", "No stock movements yet.")
|
|
90
|
+
}) : /* @__PURE__ */ b("ol", {
|
|
91
|
+
className: "space-y-3",
|
|
92
|
+
children: L.map((t) => {
|
|
93
|
+
let n = t.direction === "IN";
|
|
94
|
+
return /* @__PURE__ */ x("li", {
|
|
95
|
+
className: "flex items-start gap-3",
|
|
96
|
+
children: [/* @__PURE__ */ b("span", {
|
|
97
|
+
className: e("mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full", n ? "bg-status-success-bg text-status-success-text" : "bg-status-error-bg text-status-error-text"),
|
|
98
|
+
children: b(n ? g : m, { className: "h-3.5 w-3.5" })
|
|
99
|
+
}), /* @__PURE__ */ x("div", {
|
|
100
|
+
className: "min-w-0 flex-1",
|
|
101
|
+
children: [
|
|
102
|
+
/* @__PURE__ */ x("div", {
|
|
103
|
+
className: "text-sm",
|
|
104
|
+
children: [
|
|
105
|
+
/* @__PURE__ */ x("span", {
|
|
106
|
+
className: e("font-semibold", n ? "text-status-success-text" : "text-status-error-text"),
|
|
107
|
+
children: [
|
|
108
|
+
n ? "IN +" : "OUT −",
|
|
109
|
+
t.quantity,
|
|
110
|
+
" ",
|
|
111
|
+
t.unit
|
|
112
|
+
]
|
|
113
|
+
}),
|
|
114
|
+
t.reason ? /* @__PURE__ */ b("span", {
|
|
115
|
+
className: "ml-2 text-xs text-text-tertiary",
|
|
116
|
+
children: u(t.reason)
|
|
117
|
+
}) : null,
|
|
118
|
+
t.reference ? /* @__PURE__ */ b("span", {
|
|
119
|
+
className: "ml-2 text-xs text-text-secondary",
|
|
120
|
+
children: t.reference
|
|
121
|
+
}) : null
|
|
122
|
+
]
|
|
123
|
+
}),
|
|
124
|
+
/* @__PURE__ */ b("div", {
|
|
125
|
+
className: "text-xs tabular-nums text-text-tertiary",
|
|
126
|
+
children: t.occurredAt.slice(0, 10)
|
|
127
|
+
}),
|
|
128
|
+
t.notes ? /* @__PURE__ */ b("div", {
|
|
129
|
+
className: "mt-0.5 text-xs text-text-secondary",
|
|
130
|
+
children: t.notes
|
|
131
|
+
}) : null
|
|
132
|
+
]
|
|
133
|
+
})]
|
|
134
|
+
}, t.id);
|
|
135
|
+
})
|
|
136
|
+
})]
|
|
137
|
+
}),
|
|
138
|
+
/* @__PURE__ */ b(d, {
|
|
139
|
+
open: N,
|
|
140
|
+
onClose: () => P(!1),
|
|
141
|
+
lot: I,
|
|
142
|
+
onSubmit: F
|
|
143
|
+
})
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
//#endregion
|
|
148
|
+
export { C as StorageLotDetailPage };
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=StorageLotDetailPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageLotDetailPage.js","names":[],"sources":["../../../../src/healthybowl/pages/storage/StorageLotDetailPage.tsx"],"sourcesContent":["/**\n * Storage lot detail (BOFF-2890 · K-1).\n * A lot's on-hand quantity + location + its full IN/OUT movement history, with a \"Record\n * Movement\" action. All from the backend ledger — no fabricated data.\n */\nimport { useState } from 'react';\nimport { useNavigate, useParams } from 'react-router-dom';\nimport { ArrowDown, ArrowLeft, ArrowUp, Plus } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { PageLayout, StatCard, StatusBadge, ErrorState, PageLoader } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { cn } from '../../utils/helpers';\nimport { useHealthyBowlStorage } from '../../hooks/useHealthyBowlStorage';\nimport { RecordMovementModal } from './RecordMovementModal';\nimport { lotStatusVariant, reasonLabel } from './labels';\n\nexport const StorageLotDetailPage = () => {\n const { t } = useI18n();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toast } = useToast();\n const { lotId } = useParams<{ lotId: string }>();\n\n const { lotDetail, loading, errors, refetchLot, recordMovement } = useHealthyBowlStorage({ lotId: lotId ?? null });\n const [moveOpen, setMoveOpen] = useState(false);\n\n const handleRecord = async (input: Record<string, unknown>) => {\n await recordMovement(input);\n toast({ title: t('healthybowl.storage.toast.movementRecorded', 'Movement recorded'), variant: 'success' });\n };\n\n if (loading.lot && !lotDetail) {\n return <PageLoader />;\n }\n if ((errors.lot && !lotDetail) || !lotDetail) {\n return (\n <div className=\"p-4\">\n <ErrorState\n description={errors.lot?.message ?? t('healthybowl.storage.lot.notFound', 'Lot not found.')}\n onRetry={() => void refetchLot()}\n />\n </div>\n );\n }\n\n const { lot, movements } = lotDetail;\n\n return (\n <PageLayout\n title={`${lot.produce} · ${lot.lotCode}`}\n description={`${lot.warehouseName} · ${lot.locationName}`}\n hideHelp\n >\n <button\n type=\"button\"\n onClick={() => navigate(buildPath('storage'))}\n className=\"mb-3 inline-flex items-center gap-1 text-sm text-text-secondary hover:text-text-primary\"\n >\n <ArrowLeft className=\"h-4 w-4\" />\n {t('healthybowl.storage.lot.backToStorage', 'Storage')}\n </button>\n\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <div className=\"flex items-center gap-2\">\n <StatusBadge variant={lotStatusVariant(lot.status)} label={lot.status.toLowerCase()} dot />\n {lot.expiryDate ? (\n <span className=\"text-xs text-text-tertiary\">\n {t('healthybowl.storage.lot.expires', 'Expires {{date}}', { date: lot.expiryDate.slice(0, 10) })}\n </span>\n ) : null}\n </div>\n <Button onClick={() => setMoveOpen(true)}>\n <Plus className=\"h-4 w-4\" />\n {t('healthybowl.storage.movement.record', 'Record Movement')}\n </Button>\n </div>\n\n <div className=\"mt-4 grid grid-cols-1 gap-3 sm:grid-cols-3\">\n <StatCard label={t('healthybowl.storage.lot.onHand', 'On hand')} value={`${lot.quantity} ${lot.unit}`} hero />\n <StatCard label={t('healthybowl.storage.lot.location', 'Location')} value={lot.locationName} />\n <StatCard\n label={t('healthybowl.storage.lot.received', 'Received')}\n value={lot.receivedAt ? lot.receivedAt.slice(0, 10) : '—'}\n />\n </div>\n\n <div className=\"mt-4 rounded-xl border border-border-subtle bg-bg-surface p-4\">\n <h3 className=\"mb-3 text-sm font-semibold text-text-primary\">\n {t('healthybowl.storage.movementHistory', 'Movement History')}\n </h3>\n {movements.length === 0 ? (\n <div className=\"py-6 text-center text-sm text-text-secondary\">\n {t('healthybowl.storage.noMovements', 'No stock movements yet.')}\n </div>\n ) : (\n <ol className=\"space-y-3\">\n {movements.map((m) => {\n const isIn = m.direction === 'IN';\n return (\n <li key={m.id} className=\"flex items-start gap-3\">\n <span\n className={cn(\n 'mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full',\n isIn\n ? 'bg-status-success-bg text-status-success-text'\n : 'bg-status-error-bg text-status-error-text'\n )}\n >\n {isIn ? <ArrowUp className=\"h-3.5 w-3.5\" /> : <ArrowDown className=\"h-3.5 w-3.5\" />}\n </span>\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-sm\">\n <span\n className={cn('font-semibold', isIn ? 'text-status-success-text' : 'text-status-error-text')}\n >\n {isIn ? 'IN +' : 'OUT −'}\n {m.quantity} {m.unit}\n </span>\n {m.reason ? (\n <span className=\"ml-2 text-xs text-text-tertiary\">{reasonLabel(m.reason)}</span>\n ) : null}\n {m.reference ? <span className=\"ml-2 text-xs text-text-secondary\">{m.reference}</span> : null}\n </div>\n <div className=\"text-xs tabular-nums text-text-tertiary\">{m.occurredAt.slice(0, 10)}</div>\n {m.notes ? <div className=\"mt-0.5 text-xs text-text-secondary\">{m.notes}</div> : null}\n </div>\n </li>\n );\n })}\n </ol>\n )}\n </div>\n\n <RecordMovementModal open={moveOpen} onClose={() => setMoveOpen(false)} lot={lot} onSubmit={handleRecord} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,UAA6B;CACxC,IAAM,EAAE,SAAM,GAAS,EACjB,IAAW,GAAa,EACxB,EAAE,iBAAc,GAAa,EAC7B,EAAE,aAAU,GAAU,EACtB,EAAE,aAAU,GAA8B,EAE1C,EAAE,cAAW,YAAS,WAAQ,eAAY,sBAAmB,EAAsB,EAAE,OAAO,KAAS,MAAM,CAAC,EAC5G,CAAC,GAAU,KAAe,EAAS,GAAM,EAEzC,IAAe,OAAO,MAAmC;AAE7D,EADA,MAAM,EAAe,EAAM,EAC3B,EAAM;GAAE,OAAO,EAAE,8CAA8C,oBAAoB;GAAE,SAAS;GAAW,CAAC;;AAG5G,KAAI,EAAQ,OAAO,CAAC,EAClB,QAAO,kBAAC,GAAD,EAAc,CAAA;AAEvB,KAAK,EAAO,OAAO,CAAC,KAAc,CAAC,EACjC,QACE,kBAAC,OAAD;EAAK,WAAU;YACb,kBAAC,GAAD;GACE,aAAa,EAAO,KAAK,WAAW,EAAE,o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ePath.js";
|
|
3
|
+
import { PageLayout as n } from "../../components/PageLayout.js";
|
|
4
|
+
import { EmptyState as r } from "../../components/EmptyState.js";
|
|
5
|
+
import { ErrorState as i } from "../../components/ErrorState.js";
|
|
6
|
+
import { PageLoader as a } from "../../components/PageLoader.js";
|
|
7
|
+
import { useToast as o } from "../../hooks/useToast.js";
|
|
8
|
+
import "../../components/index.js";
|
|
9
|
+
import { useHealthyBowlStorage as s } from "../../hooks/useHealthyBowlStorage.js";
|
|
10
|
+
import { capacityBarClass as c, capacityLabel as l, reasonLabel as u, storageTypeLabel as d } from "./labels.js";
|
|
11
|
+
import { StorageLocationFormModal as f } from "./StorageLocationFormModal.js";
|
|
12
|
+
import { PlaceLotModal as p } from "./PlaceLotModal.js";
|
|
13
|
+
import { useMemo as m, useState as h } from "react";
|
|
14
|
+
import { useI18n as g } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
15
|
+
import { ArrowDown as _, ArrowUp as v, Boxes as y, ChevronRight as b, Package as x, Plus as S, Warehouse as C } from "lucide-react";
|
|
16
|
+
import { useNavigate as w } from "react-router-dom";
|
|
17
|
+
import { jsx as T, jsxs as E } from "react/jsx-runtime";
|
|
18
|
+
import { Button as D } from "@burdenoff/fe-libs/ui";
|
|
19
|
+
//#region src/healthybowl/pages/storage/StoragePage.tsx
|
|
20
|
+
var O = () => {
|
|
21
|
+
let { t: O } = g(), k = w(), { buildPath: A } = t(), { toast: j } = o(), { overview: M, loading: N, errors: P, refetchOverview: F, createLocation: I, placeLot: L } = s({ overview: !0 }), [R, z] = h(!1), [B, V] = h("WAREHOUSE"), [H, U] = h(!1), W = M?.warehouses ?? [], G = m(() => W.map((e) => e.warehouse), [W]), K = m(() => W.flatMap((e) => e.bins.map((e) => e.location)), [W]), q = () => {
|
|
22
|
+
V("WAREHOUSE"), z(!0);
|
|
23
|
+
}, J = () => {
|
|
24
|
+
V("BIN"), z(!0);
|
|
25
|
+
}, Y = async (e) => {
|
|
26
|
+
await I(e), j({
|
|
27
|
+
title: O("healthybowl.storage.toast.locationSaved", "Location saved"),
|
|
28
|
+
description: String(e.name ?? ""),
|
|
29
|
+
variant: "success"
|
|
30
|
+
});
|
|
31
|
+
}, X = async (e) => {
|
|
32
|
+
await L(e), j({
|
|
33
|
+
title: O("healthybowl.storage.toast.lotPlaced", "Lot placed"),
|
|
34
|
+
description: String(e.lotCode ?? ""),
|
|
35
|
+
variant: "success"
|
|
36
|
+
});
|
|
37
|
+
}, Z = (e) => k(A(`storage/lots/${e.id}`));
|
|
38
|
+
return N.overview && !M ? /* @__PURE__ */ T(a, {}) : /* @__PURE__ */ E(n, {
|
|
39
|
+
title: O("healthybowl.storage.title", "Storage"),
|
|
40
|
+
titleAccent: O("healthybowl.storage.titleAccent", "Storage"),
|
|
41
|
+
description: O("healthybowl.storage.description", "Warehouses, cold-stores and bins — where each batch of produce and milk is stored, and its in/out history."),
|
|
42
|
+
actions: /* @__PURE__ */ E("div", {
|
|
43
|
+
className: "flex items-center gap-2",
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ E(D, {
|
|
46
|
+
variant: "outline",
|
|
47
|
+
onClick: q,
|
|
48
|
+
children: [/* @__PURE__ */ T(C, { className: "h-4 w-4" }), O("healthybowl.storage.actions.addWarehouse", "Add Warehouse")]
|
|
49
|
+
}),
|
|
50
|
+
/* @__PURE__ */ E(D, {
|
|
51
|
+
variant: "outline",
|
|
52
|
+
onClick: J,
|
|
53
|
+
disabled: G.length === 0,
|
|
54
|
+
children: [/* @__PURE__ */ T(y, { className: "h-4 w-4" }), O("healthybowl.storage.actions.addBin", "Add Bin")]
|
|
55
|
+
}),
|
|
56
|
+
/* @__PURE__ */ E(D, {
|
|
57
|
+
onClick: () => U(!0),
|
|
58
|
+
disabled: K.length === 0,
|
|
59
|
+
children: [/* @__PURE__ */ T(S, { className: "h-4 w-4" }), O("healthybowl.storage.actions.placeLot", "Place Lot")]
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
}),
|
|
63
|
+
children: [
|
|
64
|
+
P.overview && !M ? /* @__PURE__ */ T(i, {
|
|
65
|
+
description: P.overview.message,
|
|
66
|
+
onRetry: () => void F()
|
|
67
|
+
}) : W.length === 0 ? /* @__PURE__ */ T(r, {
|
|
68
|
+
icon: /* @__PURE__ */ T(C, { className: "h-8 w-8 text-text-secondary" }),
|
|
69
|
+
title: O("healthybowl.storage.empty.title", "No warehouses yet"),
|
|
70
|
+
description: O("healthybowl.storage.empty.description", "Add a warehouse or cold-store, create bins inside it, then place lots of produce or milk."),
|
|
71
|
+
action: /* @__PURE__ */ E(D, {
|
|
72
|
+
onClick: q,
|
|
73
|
+
children: [/* @__PURE__ */ T(C, { className: "h-4 w-4" }), O("healthybowl.storage.actions.addWarehouse", "Add Warehouse")]
|
|
74
|
+
})
|
|
75
|
+
}) : /* @__PURE__ */ E("div", {
|
|
76
|
+
className: "space-y-6",
|
|
77
|
+
children: [/* @__PURE__ */ E("section", { children: [/* @__PURE__ */ T("h3", {
|
|
78
|
+
className: "mb-2 text-sm font-semibold text-text-primary",
|
|
79
|
+
children: O("healthybowl.storage.capacity", "Warehouse capacity")
|
|
80
|
+
}), /* @__PURE__ */ T("div", {
|
|
81
|
+
className: "grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-4",
|
|
82
|
+
children: W.map((t) => /* @__PURE__ */ E("div", {
|
|
83
|
+
className: "rounded-xl border border-border-subtle bg-bg-surface p-4",
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ E("div", {
|
|
86
|
+
className: "flex items-start justify-between gap-2",
|
|
87
|
+
children: [/* @__PURE__ */ E("div", { children: [/* @__PURE__ */ T("div", {
|
|
88
|
+
className: "font-medium text-text-primary",
|
|
89
|
+
children: t.warehouse.name
|
|
90
|
+
}), t.warehouse.storageType ? /* @__PURE__ */ T("div", {
|
|
91
|
+
className: "text-xs text-text-tertiary",
|
|
92
|
+
children: d(t.warehouse.storageType)
|
|
93
|
+
}) : null] }), /* @__PURE__ */ T("div", {
|
|
94
|
+
className: "text-right text-sm font-semibold text-text-primary",
|
|
95
|
+
children: l(t.capacityPct)
|
|
96
|
+
})]
|
|
97
|
+
}),
|
|
98
|
+
/* @__PURE__ */ E("div", {
|
|
99
|
+
className: "mt-1 text-xs tabular-nums text-text-secondary",
|
|
100
|
+
children: [
|
|
101
|
+
t.usedCapacity,
|
|
102
|
+
t.capacity === null ? "" : ` / ${t.capacity}`,
|
|
103
|
+
" ",
|
|
104
|
+
t.capacityUnit
|
|
105
|
+
]
|
|
106
|
+
}),
|
|
107
|
+
/* @__PURE__ */ T("div", {
|
|
108
|
+
className: "mt-2 h-2 w-full overflow-hidden rounded-full bg-bg-sunken",
|
|
109
|
+
children: /* @__PURE__ */ T("div", {
|
|
110
|
+
className: e("h-full rounded-full transition-all", c(t.capacityPct)),
|
|
111
|
+
style: { width: `${Math.min(100, t.capacityPct ?? 0)}%` }
|
|
112
|
+
})
|
|
113
|
+
}),
|
|
114
|
+
/* @__PURE__ */ T("div", {
|
|
115
|
+
className: "mt-2 text-xs text-text-tertiary",
|
|
116
|
+
children: O("healthybowl.storage.binCount", "{{bins}} bins · {{lots}} lots", {
|
|
117
|
+
bins: t.binCount,
|
|
118
|
+
lots: t.lotCount
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
}, t.warehouse.id))
|
|
123
|
+
})] }), /* @__PURE__ */ E("div", {
|
|
124
|
+
className: "grid grid-cols-1 gap-6 lg:grid-cols-2",
|
|
125
|
+
children: [/* @__PURE__ */ E("section", {
|
|
126
|
+
className: "rounded-xl border border-border-subtle bg-bg-surface p-4",
|
|
127
|
+
children: [/* @__PURE__ */ T("h3", {
|
|
128
|
+
className: "mb-3 text-sm font-semibold text-text-primary",
|
|
129
|
+
children: O("healthybowl.storage.binsLots", "Bins & Lots")
|
|
130
|
+
}), /* @__PURE__ */ T("div", {
|
|
131
|
+
className: "space-y-4",
|
|
132
|
+
children: W.map((e) => /* @__PURE__ */ E("div", { children: [/* @__PURE__ */ T("div", {
|
|
133
|
+
className: "text-sm font-medium text-text-primary",
|
|
134
|
+
children: e.warehouse.name
|
|
135
|
+
}), /* @__PURE__ */ T("div", {
|
|
136
|
+
className: "mt-1 space-y-2 border-l border-border-subtle pl-3",
|
|
137
|
+
children: e.bins.length === 0 ? /* @__PURE__ */ T("div", {
|
|
138
|
+
className: "text-xs text-text-tertiary",
|
|
139
|
+
children: O("healthybowl.storage.noBins", "No bins yet")
|
|
140
|
+
}) : e.bins.map((e) => /* @__PURE__ */ E("div", { children: [/* @__PURE__ */ E("div", {
|
|
141
|
+
className: "flex items-center gap-1 text-xs font-medium text-text-secondary",
|
|
142
|
+
children: [/* @__PURE__ */ T(b, { className: "h-3 w-3" }), e.location.name]
|
|
143
|
+
}), /* @__PURE__ */ T("div", {
|
|
144
|
+
className: "ml-4 mt-1 space-y-1",
|
|
145
|
+
children: e.lots.length === 0 ? /* @__PURE__ */ T("div", {
|
|
146
|
+
className: "text-xs text-text-tertiary",
|
|
147
|
+
children: O("healthybowl.storage.empty2", "empty")
|
|
148
|
+
}) : e.lots.map((e) => /* @__PURE__ */ E("button", {
|
|
149
|
+
type: "button",
|
|
150
|
+
onClick: () => Z(e),
|
|
151
|
+
className: "flex w-full items-center justify-between gap-2 rounded-md bg-bg-sunken px-2.5 py-1.5 text-left text-sm hover:bg-accent-teal/5",
|
|
152
|
+
children: [/* @__PURE__ */ E("span", {
|
|
153
|
+
className: "inline-flex items-center gap-1.5 text-text-primary",
|
|
154
|
+
children: [
|
|
155
|
+
/* @__PURE__ */ T(x, { className: "h-3.5 w-3.5 text-text-tertiary" }),
|
|
156
|
+
/* @__PURE__ */ T("span", {
|
|
157
|
+
className: "font-medium",
|
|
158
|
+
children: e.produce
|
|
159
|
+
}),
|
|
160
|
+
/* @__PURE__ */ E("span", {
|
|
161
|
+
className: "text-text-tertiary",
|
|
162
|
+
children: ["· ", e.lotCode]
|
|
163
|
+
})
|
|
164
|
+
]
|
|
165
|
+
}), /* @__PURE__ */ E("span", {
|
|
166
|
+
className: "tabular-nums text-text-secondary",
|
|
167
|
+
children: [
|
|
168
|
+
e.quantity,
|
|
169
|
+
" ",
|
|
170
|
+
e.unit
|
|
171
|
+
]
|
|
172
|
+
})]
|
|
173
|
+
}, e.id))
|
|
174
|
+
})] }, e.location.id))
|
|
175
|
+
})] }, e.warehouse.id))
|
|
176
|
+
})]
|
|
177
|
+
}), /* @__PURE__ */ E("section", {
|
|
178
|
+
className: "rounded-xl border border-border-subtle bg-bg-surface p-4",
|
|
179
|
+
children: [/* @__PURE__ */ T("h3", {
|
|
180
|
+
className: "mb-3 text-sm font-semibold text-text-primary",
|
|
181
|
+
children: O("healthybowl.storage.movementHistory", "Movement History")
|
|
182
|
+
}), (M?.recentMovements.length ?? 0) === 0 ? /* @__PURE__ */ T("div", {
|
|
183
|
+
className: "py-6 text-center text-sm text-text-secondary",
|
|
184
|
+
children: O("healthybowl.storage.noMovements", "No stock movements yet.")
|
|
185
|
+
}) : /* @__PURE__ */ T("ol", {
|
|
186
|
+
className: "space-y-3",
|
|
187
|
+
children: M.recentMovements.map((t) => {
|
|
188
|
+
let n = t.direction === "IN";
|
|
189
|
+
return /* @__PURE__ */ E("li", {
|
|
190
|
+
className: "flex items-start gap-3",
|
|
191
|
+
children: [/* @__PURE__ */ T("span", {
|
|
192
|
+
className: e("mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full", n ? "bg-status-success-bg text-status-success-text" : "bg-status-error-bg text-status-error-text"),
|
|
193
|
+
children: T(n ? v : _, { className: "h-3.5 w-3.5" })
|
|
194
|
+
}), /* @__PURE__ */ E("div", {
|
|
195
|
+
className: "min-w-0 flex-1",
|
|
196
|
+
children: [/* @__PURE__ */ E("div", {
|
|
197
|
+
className: "text-sm",
|
|
198
|
+
children: [/* @__PURE__ */ E("span", {
|
|
199
|
+
className: e("font-semibold", n ? "text-status-success-text" : "text-status-error-text"),
|
|
200
|
+
children: [
|
|
201
|
+
n ? "IN" : "OUT",
|
|
202
|
+
" ",
|
|
203
|
+
n ? "+" : "−",
|
|
204
|
+
t.quantity,
|
|
205
|
+
" ",
|
|
206
|
+
t.unit
|
|
207
|
+
]
|
|
208
|
+
}), t.reason ? /* @__PURE__ */ T("span", {
|
|
209
|
+
className: "ml-2 text-xs text-text-tertiary",
|
|
210
|
+
children: u(t.reason)
|
|
211
|
+
}) : null]
|
|
212
|
+
}), /* @__PURE__ */ E("div", {
|
|
213
|
+
className: "truncate text-sm text-text-primary",
|
|
214
|
+
children: [
|
|
215
|
+
t.produce ?? O("healthybowl.storage.lot.produce", "Produce"),
|
|
216
|
+
" → ",
|
|
217
|
+
t.reference ?? t.locationName ?? "—",
|
|
218
|
+
/* @__PURE__ */ T("span", {
|
|
219
|
+
className: "ml-2 text-xs tabular-nums text-text-tertiary",
|
|
220
|
+
children: t.occurredAt.slice(0, 10)
|
|
221
|
+
})
|
|
222
|
+
]
|
|
223
|
+
})]
|
|
224
|
+
})]
|
|
225
|
+
}, t.id);
|
|
226
|
+
})
|
|
227
|
+
})]
|
|
228
|
+
})]
|
|
229
|
+
})]
|
|
230
|
+
}),
|
|
231
|
+
/* @__PURE__ */ T(f, {
|
|
232
|
+
open: R,
|
|
233
|
+
onClose: () => z(!1),
|
|
234
|
+
location: null,
|
|
235
|
+
warehouses: G,
|
|
236
|
+
defaultKind: B,
|
|
237
|
+
onSubmit: Y
|
|
238
|
+
}),
|
|
239
|
+
/* @__PURE__ */ T(p, {
|
|
240
|
+
open: H,
|
|
241
|
+
onClose: () => U(!1),
|
|
242
|
+
bins: K,
|
|
243
|
+
onSubmit: X
|
|
244
|
+
})
|
|
245
|
+
]
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
//#endregion
|
|
249
|
+
export { O as StoragePage };
|
|
250
|
+
|
|
251
|
+
//# sourceMappingURL=StoragePage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoragePage.js","names":[],"sources":["../../../../src/healthybowl/pages/storage/StoragePage.tsx"],"sourcesContent":["/**\n * Warehouse storage overview (BOFF-2890 · K-1).\n * Per-warehouse capacity bars, a warehouse → bin → lot tree, and a stock-movement timeline.\n * Every number comes from the backend (lots summed into capacity, real IN/OUT ledger). No\n * fabricated data.\n */\nimport { useMemo, useState } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { ArrowDown, ArrowUp, Boxes, ChevronRight, Package, Plus, Warehouse } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { PageLayout, EmptyState, ErrorState, PageLoader } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { cn } from '../../utils/helpers';\nimport { useHealthyBowlStorage, type StorageLocation, type StorageLot } from '../../hooks/useHealthyBowlStorage';\nimport { StorageLocationFormModal } from './StorageLocationFormModal';\nimport { PlaceLotModal } from './PlaceLotModal';\nimport { capacityBarClass, capacityLabel, reasonLabel, storageTypeLabel } from './labels';\n\nexport const StoragePage = () => {\n const { t } = useI18n();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toast } = useToast();\n\n const { overview, loading, errors, refetchOverview, createLocation, placeLot } = useHealthyBowlStorage({\n overview: true,\n });\n\n const [locOpen, setLocOpen] = useState(false);\n const [locKind, setLocKind] = useState<'WAREHOUSE' | 'BIN'>('WAREHOUSE');\n const [placeOpen, setPlaceOpen] = useState(false);\n\n const warehouses = overview?.warehouses ?? [];\n const allWarehouseLocations = useMemo<StorageLocation[]>(() => warehouses.map((w) => w.warehouse), [warehouses]);\n const allBins = useMemo<StorageLocation[]>(\n () => warehouses.flatMap((w) => w.bins.map((b) => b.location)),\n [warehouses]\n );\n\n const openAddWarehouse = () => {\n setLocKind('WAREHOUSE');\n setLocOpen(true);\n };\n const openAddBin = () => {\n setLocKind('BIN');\n setLocOpen(true);\n };\n\n const handleCreateLocation = async (input: Record<string, unknown>) => {\n await createLocation(input);\n toast({\n title: t('healthybowl.storage.toast.locationSaved', 'Location saved'),\n description: String(input.name ?? ''),\n variant: 'success',\n });\n };\n\n const handlePlaceLot = async (input: Record<string, unknown>) => {\n await placeLot(input);\n toast({\n title: t('healthybowl.storage.toast.lotPlaced', 'Lot placed'),\n description: String(input.lotCode ?? ''),\n variant: 'success',\n });\n };\n\n const goToLot = (lot: StorageLot) => navigate(buildPath(`storage/lots/${lot.id}`));\n\n if (loading.overview && !overview) {\n return <PageLoader />;\n }\n\n return (\n <PageLayout\n title={t('healthybowl.storage.title', 'Storage')}\n titleAccent={t('healthybowl.storage.titleAccent', 'Storage')}\n description={t(\n 'healthybowl.storage.description',\n 'Warehouses, cold-stores and bins — where each batch of produce and milk is stored, and its in/out history.'\n )}\n actions={\n <div className=\"flex items-center gap-2\">\n <Button variant=\"outline\" onClick={openAddWarehouse}>\n <Warehouse className=\"h-4 w-4\" />\n {t('healthybowl.storage.actions.addWarehouse', 'Add Warehouse')}\n </Button>\n <Button variant=\"outline\" onClick={openAddBin} disabled={allWarehouseLocations.length === 0}>\n <Boxes className=\"h-4 w-4\" />\n {t('healthybowl.storage.actions.addBin', 'Add Bin')}\n </Button>\n <Button onClick={() => setPlaceOpen(true)} disabled={allBins.length === 0}>\n <Plus className=\"h-4 w-4\" />\n {t('healthybowl.storage.actions.placeLot', 'Place Lot')}\n </Button>\n </div>\n }\n >\n {errors.overview && !overview ? (\n <ErrorState description={errors.overview.message} onRetry={() => void refetchOverview()} />\n ) : warehouses.length === 0 ? (\n <EmptyState\n icon={<Warehouse className=\"h-8 w-8 text-text-secondary\" />}\n title={t('healthybowl.storage.empty.title', 'No warehouses yet')}\n description={t(\n 'healthybowl.storage.empty.description',\n 'Add a warehouse or cold-store, create bins inside it, then place lots of produce or milk.'\n )}\n action={\n <Button onClick={openAddWarehouse}>\n <Warehouse className=\"h-4 w-4\" />\n {t('healthybowl.storage.actions.addWarehouse', 'Add Warehouse')}\n </Button>\n }\n />\n ) : (\n <div className=\"space-y-6\">\n {/* Warehouse capacity cards */}\n <section>\n <h3 className=\"mb-2 text-sm font-semibold text-text-primary\">\n {t('healthybowl.storage.capacity', 'Warehouse capacity')}\n </h3>\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-4\">\n {warehouses.map((w) => (\n <div key={w.warehouse.id} className=\"rounded-xl border border-border-subtle bg-bg-surface p-4\">\n <div className=\"flex items-start justify-between gap-2\">\n <div>\n <div className=\"font-medium text-text-primary\">{w.warehouse.name}</div>\n {w.warehouse.storageType ? (\n <div className=\"text-xs text-text-tertiary\">{storageTypeLabel(w.warehouse.storageType)}</div>\n ) : null}\n </div>\n <div className=\"text-right text-sm font-semibold text-text-primary\">\n {capacityLabel(w.capacityPct)}\n </div>\n </div>\n <div className=\"mt-1 text-xs tabular-nums text-text-secondary\">\n {w.usedCapacity}\n {w.capacity !== null ? ` / ${w.capacity}` : ''} {w.capacityUnit}\n </div>\n <div className=\"mt-2 h-2 w-full overflow-hidden rounded-full bg-bg-sunken\">\n <div\n className={cn('h-full rounded-full transition-all', capacityBarClass(w.capacityPct))}\n style={{ width: `${Math.min(100, w.capacityPct ?? 0)}%` }}\n />\n </div>\n <div className=\"mt-2 text-xs text-text-tertiary\">\n {t('healthybowl.storage.binCount', '{{bins}} bins · {{lots}} lots', {\n bins: w.binCount,\n lots: w.lotCount,\n })}\n </div>\n </div>\n ))}\n </div>\n </section>\n\n <div className=\"grid grid-cols-1 gap-6 lg:grid-cols-2\">\n {/* Bins & Lots tree */}\n <section className=\"rounded-xl border border-border-subtle bg-bg-surface p-4\">\n <h3 className=\"mb-3 text-sm font-semibold text-text-primary\">\n {t('healthybowl.storage.binsLots', 'Bins & Lots')}\n </h3>\n <div className=\"space-y-4\">\n {warehouses.map((w) => (\n <div key={w.warehouse.id}>\n <div className=\"text-sm font-medium text-text-primary\">{w.warehouse.name}</div>\n <div className=\"mt-1 space-y-2 border-l border-border-subtle pl-3\">\n {w.bins.length === 0 ? (\n <div className=\"text-xs text-text-tertiary\">\n {t('healthybowl.storage.noBins', 'No bins yet')}\n </div>\n ) : (\n w.bins.map((bin) => (\n <div key={bin.location.id}>\n <div className=\"flex items-center gap-1 text-xs font-medium text-text-secondary\">\n <ChevronRight className=\"h-3 w-3\" />\n {bin.location.name}\n </div>\n <div className=\"ml-4 mt-1 space-y-1\">\n {bin.lots.length === 0 ? (\n <div className=\"text-xs text-text-tertiary\">\n {t('healthybowl.storage.empty2', 'empty')}\n </div>\n ) : (\n bin.lots.map((lot) => (\n <button\n key={lot.id}\n type=\"button\"\n onClick={() => goToLot(lot)}\n className=\"flex w-full items-center justify-between gap-2 rounded-md bg-bg-sunken px-2.5 py-1.5 text-left text-sm hover:bg-accent-teal/5\"\n >\n <span className=\"inline-flex items-center gap-1.5 text-text-primary\">\n <Package className=\"h-3.5 w-3.5 text-text-tertiary\" />\n <span className=\"font-medium\">{lot.produce}</span>\n <span className=\"text-text-tertiary\">· {lot.lotCode}</span>\n </span>\n <span className=\"tabular-nums text-text-secondary\">\n {lot.quantity} {lot.unit}\n </span>\n </button>\n ))\n )}\n </div>\n </div>\n ))\n )}\n </div>\n </div>\n ))}\n </div>\n </section>\n\n {/* Movement history timeline */}\n <section className=\"rounded-xl border border-border-subtle bg-bg-surface p-4\">\n <h3 className=\"mb-3 text-sm font-semibold text-text-primary\">\n {t('healthybowl.storage.movementHistory', 'Movement History')}\n </h3>\n {(overview?.recentMovements.length ?? 0) === 0 ? (\n <div className=\"py-6 text-center text-sm text-text-secondary\">\n {t('healthybowl.storage.noMovements', 'No stock movements yet.')}\n </div>\n ) : (\n <ol className=\"space-y-3\">\n {overview!.recentMovements.map((m) => {\n const isIn = m.direction === 'IN';\n return (\n <li key={m.id} className=\"flex items-start gap-3\">\n <span\n className={cn(\n 'mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full',\n isIn\n ? 'bg-status-success-bg text-status-success-text'\n : 'bg-status-error-bg text-status-error-text'\n )}\n >\n {isIn ? <ArrowUp className=\"h-3.5 w-3.5\" /> : <ArrowDown className=\"h-3.5 w-3.5\" />}\n </span>\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-sm\">\n <span\n className={cn(\n 'font-semibold',\n isIn ? 'text-status-success-text' : 'text-status-error-text'\n )}\n >\n {isIn ? 'IN' : 'OUT'} {isIn ? '+' : '−'}\n {m.quantity} {m.unit}\n </span>\n {m.reason ? (\n <span className=\"ml-2 text-xs text-text-tertiary\">{reasonLabel(m.reason)}</span>\n ) : null}\n </div>\n <div className=\"truncate text-sm text-text-primary\">\n {m.produce ?? t('healthybowl.storage.lot.produce', 'Produce')}\n {' → '}\n {m.reference ?? m.locationName ?? '—'}\n <span className=\"ml-2 text-xs tabular-nums text-text-tertiary\">\n {m.occurredAt.slice(0, 10)}\n </span>\n </div>\n </div>\n </li>\n );\n })}\n </ol>\n )}\n </section>\n </div>\n </div>\n )}\n\n <StorageLocationFormModal\n open={locOpen}\n onClose={() => setLocOpen(false)}\n location={null}\n warehouses={allWarehouseLocations}\n defaultKind={locKind}\n onSubmit={handleCreateLocation}\n />\n <PlaceLotModal open={placeOpen} onClose={() => setPlaceOpen(false)} bins={allBins} onSubmit={handlePlaceLot} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,IAAa,UAAoB;CAC/B,IAAM,EAAE,SAAM,GAAS,EACjB,IAAW,GAAa,EACxB,EAAE,iBAAc,GAAa,EAC7B,EAAE,aAAU,GAAU,EAEtB,EAAE,aAAU,YAAS,WAAQ,oBAAiB,mBAAgB,gBAAa,EAAsB,EACrG,UAAU,IACX,CAAC,EAEI,CAAC,GAAS,KAAc,EAAS,GAAM,EACvC,CAAC,GAAS,KAAc,EAA8B,YAAY,EAClE,CAAC,GAAW,KAAgB,EAAS,GAAM,EAE3C,IAAa,GAAU,cAAc,EAAE,EACvC,IAAwB,QAAiC,EAAW,KAAK,MAAM,EAAE,UAAU,EAAE,CAAC,EAAW,CAAC,E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;aACrB,CAAA;YACH;aACF;YACH;WAnCI,EAAE,GAmCN;SAEP;OACC,CAAA,CAEC;QACN;OACF;;GAGR,kBAAC,GAAD;IACE,MAAM;IACN,eAAe,EAAW,GAAM;IAChC,UAAU;IACV,YAAY;IACZ,aAAa;IACb,UAAU;IACV,CAAA;GACF,kBAAC,GAAD;IAAe,MAAM;IAAW,eAAe,EAAa,GAAM;IAAE,MAAM;IAAS,UAAU;IAAkB,CAAA;GACpG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/healthybowl/pages/storage/labels.ts
|
|
2
|
+
var e = [
|
|
3
|
+
{
|
|
4
|
+
value: "COLD_STORE",
|
|
5
|
+
label: "Cold Store"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
value: "DRY",
|
|
9
|
+
label: "Dry Store"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
value: "AMBIENT",
|
|
13
|
+
label: "Ambient"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
value: "FREEZER",
|
|
17
|
+
label: "Freezer"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
value: "MILK_TANK",
|
|
21
|
+
label: "Milk Tank"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: "OTHER",
|
|
25
|
+
label: "Other"
|
|
26
|
+
}
|
|
27
|
+
], t = [
|
|
28
|
+
{
|
|
29
|
+
value: "HARVEST",
|
|
30
|
+
label: "Harvest"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
value: "RECEIPT",
|
|
34
|
+
label: "Receipt"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
value: "SALE",
|
|
38
|
+
label: "Sale"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
value: "TRANSFER",
|
|
42
|
+
label: "Transfer"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
value: "ADJUSTMENT",
|
|
46
|
+
label: "Adjustment"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
value: "SPOILAGE",
|
|
50
|
+
label: "Spoilage"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
value: "OTHER",
|
|
54
|
+
label: "Other"
|
|
55
|
+
}
|
|
56
|
+
], n = (t) => t ? e.find((e) => e.value === t)?.label ?? t : "", r = (e) => e ? t.find((t) => t.value === e)?.label ?? e : "", i = (e) => {
|
|
57
|
+
switch (e) {
|
|
58
|
+
case "STORED": return "success";
|
|
59
|
+
case "EXPIRED": return "error";
|
|
60
|
+
case "DEPLETED": return "muted";
|
|
61
|
+
default: return "muted";
|
|
62
|
+
}
|
|
63
|
+
}, a = (e) => e === null ? "bg-border-default" : e > 90 ? "bg-status-error-text" : e >= 75 ? "bg-status-warning-text" : "bg-accent-teal", o = (e) => e === null ? "—" : `${Math.round(e)}% full`;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { t as MOVEMENT_REASONS, e as STORAGE_TYPES, a as capacityBarClass, o as capacityLabel, i as lotStatusVariant, r as reasonLabel, n as storageTypeLabel };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.js","names":[],"sources":["../../../../src/healthybowl/pages/storage/labels.ts"],"sourcesContent":["/**\n * Shared label + variant helpers for the Warehouse Storage views (BOFF-2890 · K-1).\n */\n\ntype BadgeVariant = 'success' | 'warning' | 'error' | 'info' | 'default' | 'muted';\n\nexport const STORAGE_TYPES: Array<{ value: string; label: string }> = [\n { value: 'COLD_STORE', label: 'Cold Store' },\n { value: 'DRY', label: 'Dry Store' },\n { value: 'AMBIENT', label: 'Ambient' },\n { value: 'FREEZER', label: 'Freezer' },\n { value: 'MILK_TANK', label: 'Milk Tank' },\n { value: 'OTHER', label: 'Other' },\n];\n\nexport const MOVEMENT_REASONS: Array<{ value: string; label: string }> = [\n { value: 'HARVEST', label: 'Harvest' },\n { value: 'RECEIPT', label: 'Receipt' },\n { value: 'SALE', label: 'Sale' },\n { value: 'TRANSFER', label: 'Transfer' },\n { value: 'ADJUSTMENT', label: 'Adjustment' },\n { value: 'SPOILAGE', label: 'Spoilage' },\n { value: 'OTHER', label: 'Other' },\n];\n\nexport const storageTypeLabel = (value: string | null): string => {\n if (!value) return '';\n return STORAGE_TYPES.find((s) => s.value === value)?.label ?? value;\n};\n\nexport const reasonLabel = (value: string | null): string => {\n if (!value) return '';\n return MOVEMENT_REASONS.find((r) => r.value === value)?.label ?? value;\n};\n\nexport const lotStatusVariant = (status: string): BadgeVariant => {\n switch (status) {\n case 'STORED':\n return 'success';\n case 'EXPIRED':\n return 'error';\n case 'DEPLETED':\n return 'muted';\n default:\n return 'muted';\n }\n};\n\n/** Capacity-bar fill color by fullness: <75% brand green, 75–90% amber, >90% red. */\nexport const capacityBarClass = (pct: number | null): string => {\n if (pct === null) return 'bg-border-default';\n if (pct > 90) return 'bg-status-error-text';\n if (pct >= 75) return 'bg-status-warning-text';\n return 'bg-accent-teal';\n};\n\nexport const capacityLabel = (pct: number | null): string => (pct === null ? '—' : `${Math.round(pct)}% full`);\n"],"mappings":";AAMA,IAAa,IAAyD;CACpE;EAAE,OAAO;EAAc,OAAO;EAAc;CAC5C;EAAE,OAAO;EAAO,OAAO;EAAa;CACpC;EAAE,OAAO;EAAW,OAAO;EAAW;CACtC;EAAE,OAAO;EAAW,OAAO;EAAW;CACtC;EAAE,OAAO;EAAa,OAAO;EAAa;CAC1C;EAAE,OAAO;EAAS,OAAO;EAAS;CACnC,EAEY,IAA4D;CACvE;EAAE,OAAO;EAAW,OAAO;EAAW;CACtC;EAAE,OAAO;EAAW,OAAO;EAAW;CACtC;EAAE,OAAO;EAAQ,OAAO;EAAQ;CAChC;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAc,OAAO;EAAc;CAC5C;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAS,OAAO;EAAS;CACnC,EAEY,KAAoB,MAC1B,IACE,EAAc,MAAM,MAAM,EAAE,UAAU,EAAM,EAAE,SAAS,IAD3C,IAIR,KAAe,MACrB,IACE,EAAiB,MAAM,MAAM,EAAE,UAAU,EAAM,EAAE,SAAS,IAD9C,IAIR,KAAoB,MAAiC;AAChE,SAAQ,GAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,UACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,QACE,QAAO;;GAKA,KAAoB,MAC3B,MAAQ,OAAa,sBACrB,IAAM,KAAW,yBACjB,KAAO,KAAW,2BACf,kBAGI,KAAiB,MAAgC,MAAQ,OAAO,MAAM,GAAG,KAAK,MAAM,EAAI,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//#region src/healthybowl/utils/imageDownscale.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return new Promise((t, n) => {
|
|
4
|
+
let r = new FileReader();
|
|
5
|
+
r.onload = () => {
|
|
6
|
+
let e = String(r.result ?? ""), n = e.indexOf(",");
|
|
7
|
+
t({
|
|
8
|
+
base64: n >= 0 ? e.slice(n + 1) : e,
|
|
9
|
+
dataUrl: e
|
|
10
|
+
});
|
|
11
|
+
}, r.onerror = () => n(r.error ?? /* @__PURE__ */ Error("Could not read image")), r.readAsDataURL(e);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
async function t(e) {
|
|
15
|
+
if (typeof createImageBitmap == "function") try {
|
|
16
|
+
let t = await createImageBitmap(e);
|
|
17
|
+
return {
|
|
18
|
+
width: t.width,
|
|
19
|
+
height: t.height,
|
|
20
|
+
draw: (e, n, r) => {
|
|
21
|
+
e.drawImage(t, 0, 0, n, r), t.close();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
} catch {}
|
|
25
|
+
return new Promise((t) => {
|
|
26
|
+
let n = URL.createObjectURL(e), r = new Image();
|
|
27
|
+
r.onload = () => {
|
|
28
|
+
t({
|
|
29
|
+
width: r.naturalWidth,
|
|
30
|
+
height: r.naturalHeight,
|
|
31
|
+
draw: (e, t, i) => {
|
|
32
|
+
e.drawImage(r, 0, 0, t, i), URL.revokeObjectURL(n);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}, r.onerror = () => {
|
|
36
|
+
URL.revokeObjectURL(n), t(null);
|
|
37
|
+
}, r.src = n;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async function n(n, r = 1280, i = .72) {
|
|
41
|
+
let a = n.name.replace(/\.[^.]+$/, "") + ".jpg";
|
|
42
|
+
try {
|
|
43
|
+
let o = await t(n);
|
|
44
|
+
if (o && o.width > 0 && o.height > 0) {
|
|
45
|
+
let t = Math.min(1, r / Math.max(o.width, o.height)), n = Math.max(1, Math.round(o.width * t)), s = Math.max(1, Math.round(o.height * t)), c = document.createElement("canvas");
|
|
46
|
+
c.width = n, c.height = s;
|
|
47
|
+
let l = c.getContext("2d");
|
|
48
|
+
if (l) {
|
|
49
|
+
o.draw(l, n, s);
|
|
50
|
+
let t = await new Promise((e) => c.toBlob((t) => e(t), "image/jpeg", i));
|
|
51
|
+
if (t && t.size > 0) {
|
|
52
|
+
let { base64: n, dataUrl: r } = await e(t);
|
|
53
|
+
return {
|
|
54
|
+
blob: t,
|
|
55
|
+
base64: n,
|
|
56
|
+
dataUrl: r,
|
|
57
|
+
mimeType: "image/jpeg",
|
|
58
|
+
filename: a
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} catch {}
|
|
64
|
+
let { base64: o, dataUrl: s } = await e(n);
|
|
65
|
+
return {
|
|
66
|
+
blob: n,
|
|
67
|
+
base64: o,
|
|
68
|
+
dataUrl: s,
|
|
69
|
+
mimeType: n.type || "image/jpeg",
|
|
70
|
+
filename: n.name || a
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { n as downscaleImage };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=imageDownscale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageDownscale.js","names":[],"sources":["../../../src/healthybowl/utils/imageDownscale.ts"],"sourcesContent":["/**\n * Client-side image downscaling for the AI Pest & Disease scan flow (BOFF-2887).\n *\n * A phone photo can be several megabytes; we downscale it to a sane max dimension\n * and re-encode as JPEG before (a) sending the base64 to the diagnosis model and\n * (b) uploading it to wspace-files-svc. This keeps the GraphQL payload small, the\n * upload fast, and the model call cheap — without changing what the farmer sees.\n *\n * Falls back to the original file bytes if the browser can't rasterise the image\n * (e.g. an exotic format), so a scan is never blocked by the optimisation.\n */\nexport interface DownscaledImage {\n /** Re-encoded image blob, for upload to files-svc. */\n blob: Blob;\n /** Bare base64 (no `data:` prefix), for the diagnosis mutation. */\n base64: string;\n /** `data:<mime>;base64,...` URL, for an <img> preview. */\n dataUrl: string;\n mimeType: string;\n filename: string;\n}\n\nfunction blobToBase64(blob: Blob): Promise<{ base64: string; dataUrl: string }> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => {\n const dataUrl = String(reader.result ?? '');\n const comma = dataUrl.indexOf(',');\n resolve({ base64: comma >= 0 ? dataUrl.slice(comma + 1) : dataUrl, dataUrl });\n };\n reader.onerror = () => reject(reader.error ?? new Error('Could not read image'));\n reader.readAsDataURL(blob);\n });\n}\n\nasync function loadBitmap(\n file: File\n): Promise<{\n width: number;\n height: number;\n draw: (ctx: CanvasRenderingContext2D, w: number, h: number) => void;\n} | null> {\n // Prefer createImageBitmap (fast, no DOM); fall back to an <img> element.\n if (typeof createImageBitmap === 'function') {\n try {\n const bmp = await createImageBitmap(file);\n return {\n width: bmp.width,\n height: bmp.height,\n draw: (ctx, w, h) => {\n ctx.drawImage(bmp, 0, 0, w, h);\n bmp.close();\n },\n };\n } catch {\n /* fall through */\n }\n }\n return new Promise((resolve) => {\n const url = URL.createObjectURL(file);\n const img = new Image();\n img.onload = () => {\n resolve({\n width: img.naturalWidth,\n height: img.naturalHeight,\n draw: (ctx, w, h) => {\n ctx.drawImage(img, 0, 0, w, h);\n URL.revokeObjectURL(url);\n },\n });\n };\n img.onerror = () => {\n URL.revokeObjectURL(url);\n resolve(null);\n };\n img.src = url;\n });\n}\n\nexport async function downscaleImage(file: File, maxDim = 1280, quality = 0.72): Promise<DownscaledImage> {\n const outName = file.name.replace(/\\.[^.]+$/, '') + '.jpg';\n try {\n const bitmap = await loadBitmap(file);\n if (bitmap && bitmap.width > 0 && bitmap.height > 0) {\n const scale = Math.min(1, maxDim / Math.max(bitmap.width, bitmap.height));\n const w = Math.max(1, Math.round(bitmap.width * scale));\n const h = Math.max(1, Math.round(bitmap.height * scale));\n const canvas = document.createElement('canvas');\n canvas.width = w;\n canvas.height = h;\n const ctx = canvas.getContext('2d');\n if (ctx) {\n bitmap.draw(ctx, w, h);\n const blob = await new Promise<Blob | null>((res) => canvas.toBlob((b) => res(b), 'image/jpeg', quality));\n if (blob && blob.size > 0) {\n const { base64, dataUrl } = await blobToBase64(blob);\n return { blob, base64, dataUrl, mimeType: 'image/jpeg', filename: outName };\n }\n }\n }\n } catch {\n /* fall back to the original bytes below */\n }\n\n // Fallback: use the original file unchanged.\n const { base64, dataUrl } = await blobToBase64(file);\n return {\n blob: file,\n base64,\n dataUrl,\n mimeType: file.type || 'image/jpeg',\n filename: file.name || outName,\n };\n}\n"],"mappings":";AAsBA,SAAS,EAAa,GAA0D;AAC9E,QAAO,IAAI,SAAS,GAAS,MAAW;EACtC,IAAM,IAAS,IAAI,YAAY;AAO/B,EANA,EAAO,eAAe;GACpB,IAAM,IAAU,OAAO,EAAO,UAAU,GAAG,EACrC,IAAQ,EAAQ,QAAQ,IAAI;AAClC,KAAQ;IAAE,QAAQ,KAAS,IAAI,EAAQ,MAAM,IAAQ,EAAE,GAAG;IAAS;IAAS,CAAC;KAE/E,EAAO,gBAAgB,EAAO,EAAO,SAAS,gBAAI,MAAM,uBAAuB,CAAC,EAChF,EAAO,cAAc,EAAK;GAC1B;;AAGJ,eAAe,EACb,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