@apptimate/ui 5.8.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,8 +13,7 @@ import {
13
13
  PickerItem,
14
14
  PickerTrigger,
15
15
  } from "./EntityPickerModal";
16
- import { getUomGroups, createUom } from "@apptimate/core-lib";
17
- import { UomGroupPicker } from "./UomGroupPicker";
16
+ import { getUomGroups, createUom, createUomGroup } from "@apptimate/core-lib";
18
17
  import toast from "react-hot-toast";
19
18
 
20
19
  interface UomPickerProps {
@@ -53,11 +52,7 @@ export function UomPicker({
53
52
  const [quickAddData, setQuickAddData] = useState({
54
53
  name: "",
55
54
  abbreviation: "",
56
- conversion_factor: "1",
57
- uom_group_id: null as number | null,
58
- uom_group_name: "",
59
- base_uom_id: null as number | null,
60
- base_uom_name: "",
55
+ new_group_name: "",
61
56
  status: "active"
62
57
  });
63
58
  const [isCreating, setIsCreating] = useState(false);
@@ -89,25 +84,39 @@ export function UomPicker({
89
84
  };
90
85
 
91
86
  const handleQuickAdd = async () => {
92
- if (!quickAddData.name.trim() || !quickAddData.abbreviation.trim() || !quickAddData.uom_group_id) {
87
+ if (!quickAddData.name.trim() || !quickAddData.abbreviation.trim() || !quickAddData.new_group_name.trim()) {
93
88
  toast.error("Please fill all required fields");
94
89
  return;
95
90
  }
96
91
  setIsCreating(true);
97
92
  try {
93
+ // 1. Create Group
94
+ const groupRes = await createUomGroup({
95
+ name: quickAddData.new_group_name.trim()
96
+ });
97
+
98
+ if (!groupRes.is_success || !groupRes.result) {
99
+ toast.error(groupRes.message || "Failed to create UOM Group");
100
+ setIsCreating(false);
101
+ return;
102
+ }
103
+
104
+ const newGroupId = groupRes.result.id;
105
+
106
+ // 2. Create UOM (as base unit for the new group)
98
107
  const res = await createUom({
99
108
  name: quickAddData.name.trim(),
100
109
  abbreviation: quickAddData.abbreviation.trim(),
101
- conversion_factor: parseFloat(quickAddData.conversion_factor) || 1,
102
- uom_group_id: quickAddData.uom_group_id,
103
- base_uom_id: quickAddData.base_uom_id || null,
110
+ conversion_factor: 1,
111
+ uom_group_id: newGroupId,
112
+ base_uom_id: null,
104
113
  status: quickAddData.status,
105
114
  });
106
115
  if (res.is_success && res.result) {
107
116
  toast.success("UOM created");
108
117
  onChange({ id: res.result.id, name: res.result.name, abbreviation: res.result.abbreviation, uom_group_id: res.result.uom_group_id });
109
118
  setIsQuickAddOpen(false);
110
- setQuickAddData({ name: "", abbreviation: "", conversion_factor: "1", uom_group_id: null, uom_group_name: "", base_uom_id: null, base_uom_name: "", status: "active" });
119
+ setQuickAddData({ name: "", abbreviation: "", new_group_name: "", status: "active" });
111
120
  setIsOpen(false);
112
121
  } else {
113
122
  toast.error(res.message || "Failed to create");
@@ -158,7 +167,7 @@ export function UomPicker({
158
167
  headerActions={
159
168
  <button
160
169
  type="button"
161
- onClick={() => { setIsQuickAddOpen(true); setQuickAddData({ name: "", abbreviation: "", conversion_factor: "1", uom_group_id: null, uom_group_name: "", base_uom_id: null, base_uom_name: "", status: "active" }); }}
170
+ onClick={() => { setIsQuickAddOpen(true); setQuickAddData({ name: "", abbreviation: "", new_group_name: "", status: "active" }); }}
162
171
  className="p-1.5 rounded-lg bg-primary-50 text-primary-600 hover:bg-primary-100 transition-colors flex-shrink-0"
163
172
  title="Quick Add UOM"
164
173
  >
@@ -207,22 +216,12 @@ export function UomPicker({
207
216
  zIndex={(pickerZIndex || 200) + 100}
208
217
  >
209
218
  <div className="space-y-4">
210
- <UomGroupPicker
211
- label="UOM Group"
219
+ <Input
220
+ label="UOM Group Name"
212
221
  isRequired
213
- value={quickAddData.uom_group_id}
214
- displayValue={quickAddData.uom_group_name || null}
215
- pickerZIndex={400}
216
- onChange={(g) => {
217
- setQuickAddData({
218
- ...quickAddData,
219
- uom_group_id: g?.id ?? null,
220
- uom_group_name: g?.name ?? "",
221
- base_uom_id: null,
222
- base_uom_name: "",
223
- conversion_factor: "1"
224
- });
225
- }}
222
+ placeholder="e.g. Weight, Volume..."
223
+ value={quickAddData.new_group_name}
224
+ onChange={(e) => setQuickAddData({ ...quickAddData, new_group_name: e.target.value })}
226
225
  />
227
226
  <div className="grid grid-cols-2 gap-4">
228
227
  <Input
@@ -240,45 +239,7 @@ export function UomPicker({
240
239
  onChange={(e) => setQuickAddData({ ...quickAddData, abbreviation: e.target.value })}
241
240
  />
242
241
  </div>
243
- {!baseUnitsOnly && (
244
- <UomPicker
245
- label="Base UOM"
246
- placeholder="Select base unit…"
247
- value={quickAddData.base_uom_id}
248
- displayValue={quickAddData.base_uom_name || null}
249
- pickerZIndex={400}
250
- onChange={(uom) => {
251
- let newGroupId = quickAddData.uom_group_id;
252
- let newGroupName = quickAddData.uom_group_name;
253
-
254
- if (uom?.uom_group_id && uom.uom_group_id !== quickAddData.uom_group_id) {
255
- newGroupId = uom.uom_group_id;
256
- const foundGroup = groups.find(g => g.id === uom.uom_group_id);
257
- if (foundGroup) newGroupName = foundGroup.name;
258
- }
259
-
260
- setQuickAddData({
261
- ...quickAddData,
262
- base_uom_id: uom?.id ?? null,
263
- base_uom_name: uom?.name ?? "",
264
- uom_group_id: newGroupId,
265
- uom_group_name: newGroupName,
266
- });
267
- }}
268
- uomGroupId={quickAddData.uom_group_id}
269
- />
270
- )}
271
242
  <div className="grid grid-cols-2 gap-4">
272
- {!baseUnitsOnly && (
273
- <Input
274
- label="Conversion Factor"
275
- isRequired
276
- type="number"
277
- placeholder="1"
278
- value={quickAddData.conversion_factor}
279
- onChange={(e) => setQuickAddData({ ...quickAddData, conversion_factor: e.target.value })}
280
- />
281
- )}
282
243
  <Select
283
244
  label="Status"
284
245
  value={quickAddData.status}
@@ -299,7 +260,7 @@ export function UomPicker({
299
260
  </Button>
300
261
  <Button
301
262
  onClick={handleQuickAdd}
302
- isDisabled={isCreating || !quickAddData.name.trim() || !quickAddData.abbreviation.trim() || !quickAddData.uom_group_id}
263
+ isDisabled={isCreating || !quickAddData.name.trim() || !quickAddData.abbreviation.trim() || !quickAddData.new_group_name.trim()}
303
264
  >
304
265
  {isCreating ? "Creating…" : "Create & Select"}
305
266
  </Button>