@aglyn/plugins-commerce 1.20.3 → 1.21.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.
Files changed (33) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/cart.js +106 -9
  3. package/src/lib/components/cart.js.map +1 -1
  4. package/src/lib/components/console/catalog-organization-card.component.js +81 -30
  5. package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
  6. package/src/lib/components/console/discounts-card.component.js +28 -3
  7. package/src/lib/components/console/discounts-card.component.js.map +1 -1
  8. package/src/lib/components/console/local-delivery-settings-card.component.js +23 -7
  9. package/src/lib/components/console/local-delivery-settings-card.component.js.map +1 -1
  10. package/src/lib/components/console/product-editor-dialog.component.js +61 -44
  11. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  12. package/src/lib/components/console/products-hub-card.component.js +32 -4
  13. package/src/lib/components/console/products-hub-card.component.js.map +1 -1
  14. package/src/lib/components/console/quote-settings-card.component.js +20 -6
  15. package/src/lib/components/console/quote-settings-card.component.js.map +1 -1
  16. package/src/lib/components/console/reservations-card.component.js +28 -2
  17. package/src/lib/components/console/reservations-card.component.js.map +1 -1
  18. package/src/lib/components/console/return-settings-card.component.js +28 -15
  19. package/src/lib/components/console/return-settings-card.component.js.map +1 -1
  20. package/src/lib/components/console/shipping-settings-card.component.js +23 -8
  21. package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
  22. package/src/lib/components/console/store-settings-card.component.js +27 -11
  23. package/src/lib/components/console/store-settings-card.component.js.map +1 -1
  24. package/src/lib/components/console/suppliers-card.component.js +38 -13
  25. package/src/lib/components/console/suppliers-card.component.js.map +1 -1
  26. package/src/lib/components/console/tax-settings-card.component.js +25 -10
  27. package/src/lib/components/console/tax-settings-card.component.js.map +1 -1
  28. package/src/lib/server/cart.js +57 -0
  29. package/src/lib/server/cart.js.map +1 -1
  30. package/src/lib/server/pos-terminal.js +2 -2
  31. package/src/lib/server/pos-terminal.js.map +1 -1
  32. package/src/lib/transfer/product-transfer.js +15 -1
  33. package/src/lib/transfer/product-transfer.js.map +1 -1
@@ -30,6 +30,8 @@ import { ceilingedWindow, collectionCeiling, useFirestoreCollection, writeGuarde
30
30
  import { ListPagination } from "@aglyn/shared-ui-jsx/components/list-pagination.component";
31
31
  import { TABLE_PAGE_SIZE_DEFAULT } from "@aglyn/shared-ui-jsx/const/table-pagination";
32
32
  import { pluginDocsHelp } from "@aglyn/aglyn";
33
+ import { isSeedChecking, seedCheckingText } from "@aglyn/tenant-feature-instance/hooks/use-seed-edits";
34
+ import { useSeedDraft } from "@aglyn/tenant-feature-instance/hooks/use-seed-draft";
33
35
  import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
34
36
  import TransferHeaderActions from "../../transfer/transfer-header-actions.component.js";
35
37
  import { COMMERCE_CATEGORIES_TRANSFER } from "../../transfer/transfer-keys.js";
@@ -121,6 +123,35 @@ const sameProduct = (option, value)=>option.$id === value.$id;
121
123
  }))
122
124
  });
123
125
  });
126
+ /** A stored category as its editor holds it. */ function categoryDraftOf(category) {
127
+ var _category_parentId;
128
+ return {
129
+ id: category.$id,
130
+ name: category.name,
131
+ parentId: (_category_parentId = category.parentId) != null ? _category_parentId : ''
132
+ };
133
+ }
134
+ /** A stored catalog collection as its editor holds it. */ function collectionDraftOf(row) {
135
+ var _row_slug, _row_mode, _row_productIds, _row_rules;
136
+ return {
137
+ id: row.$id,
138
+ name: row.name,
139
+ slug: (_row_slug = row.slug) != null ? _row_slug : '',
140
+ mode: (_row_mode = row.mode) != null ? _row_mode : 'manual',
141
+ productIds: (_row_productIds = row.productIds) != null ? _row_productIds : [],
142
+ rules: (_row_rules = row.rules) != null ? _row_rules : [],
143
+ matchAll: row.matchAll !== false
144
+ };
145
+ }
146
+ /** Says why a held control is off, while the server has not answered. */ function CheckingNote(props) {
147
+ return props.text ? /*#__PURE__*/ _jsx(Typography, {
148
+ variant: "body2",
149
+ color: "text.secondary",
150
+ role: "status",
151
+ sx: props.sx,
152
+ children: props.text
153
+ }) : null;
154
+ }
124
155
  /**
125
156
  * A text field that redraws only when what it shows changes (AGL-3423).
126
157
  *
@@ -137,6 +168,9 @@ const sameProduct = (option, value)=>option.$id === value.$id;
137
168
  const FIRST_FIELD = {
138
169
  mt: 1
139
170
  };
171
+ const HELD_NOTE = {
172
+ mr: 'auto'
173
+ };
140
174
  const RULE_FIELD = {
141
175
  width: 130
142
176
  };
@@ -165,13 +199,16 @@ const RULE_OP_MENU = RULE_OPS.map((op)=>/*#__PURE__*/ _jsx(MenuItem, {
165
199
  children: op.label
166
200
  }, op.value));
167
201
  /** The category tree, a page at a time, and the button that adds one. */ const CategoriesSection = /*#__PURE__*/ memo(function CategoriesSection(props) {
168
- const { categories, visible, onEdit, onDelete } = props;
202
+ const { categories, visible, onEdit, onDelete, deleteCheckingText } = props;
169
203
  return /*#__PURE__*/ _jsxs(_Fragment, {
170
204
  children: [
171
205
  /*#__PURE__*/ _jsx(Typography, {
172
206
  variant: "subtitle2",
173
207
  children: 'Categories'
174
208
  }),
209
+ categories.length === 0 ? null : /*#__PURE__*/ _jsx(CheckingNote, {
210
+ text: deleteCheckingText
211
+ }),
175
212
  categories.length === 0 ? /*#__PURE__*/ _jsx(Typography, {
176
213
  variant: "body2",
177
214
  color: "text.secondary",
@@ -202,19 +239,13 @@ const RULE_OP_MENU = RULE_OPS.map((op)=>/*#__PURE__*/ _jsx(MenuItem, {
202
239
  }),
203
240
  /*#__PURE__*/ _jsx(Button, {
204
241
  size: "small",
205
- onClick: ()=>{
206
- var _category_parentId;
207
- return onEdit({
208
- id: category.$id,
209
- name: category.name,
210
- parentId: (_category_parentId = category.parentId) != null ? _category_parentId : ''
211
- });
212
- },
242
+ onClick: ()=>onEdit(categoryDraftOf(category)),
213
243
  children: 'Edit'
214
244
  }),
215
245
  /*#__PURE__*/ _jsx(Button, {
216
246
  size: "small",
217
247
  color: "error",
248
+ disabled: Boolean(deleteCheckingText),
218
249
  onClick: onDelete(category),
219
250
  children: 'Delete'
220
251
  })
@@ -292,18 +323,7 @@ const RULE_OP_MENU = RULE_OPS.map((op)=>/*#__PURE__*/ _jsx(MenuItem, {
292
323
  }),
293
324
  /*#__PURE__*/ _jsx(Button, {
294
325
  size: "small",
295
- onClick: ()=>{
296
- var _row_slug, _row_mode, _row_productIds, _row_rules;
297
- return onEdit({
298
- id: row.$id,
299
- name: row.name,
300
- slug: (_row_slug = row.slug) != null ? _row_slug : '',
301
- mode: (_row_mode = row.mode) != null ? _row_mode : 'manual',
302
- productIds: (_row_productIds = row.productIds) != null ? _row_productIds : [],
303
- rules: (_row_rules = row.rules) != null ? _row_rules : [],
304
- matchAll: row.matchAll !== false
305
- });
306
- },
326
+ onClick: ()=>onEdit(collectionDraftOf(row)),
307
327
  children: 'Edit'
308
328
  }),
309
329
  /*#__PURE__*/ _jsx(Button, {
@@ -351,7 +371,7 @@ const RULE_OP_MENU = RULE_OPS.map((op)=>/*#__PURE__*/ _jsx(MenuItem, {
351
371
  });
352
372
  /** The category editor: a name and a parent. */ const CategoryDialog = /*#__PURE__*/ memo(function CategoryDialog(props) {
353
373
  var _ref, _ref1;
354
- const { draft, categories, setDraft } = props;
374
+ const { draft, categories, setDraft, checkingText } = props;
355
375
  const draftId = draft == null ? void 0 : draft.id;
356
376
  const close = useCallback(()=>setDraft(null), [
357
377
  setDraft
@@ -418,6 +438,10 @@ const RULE_OP_MENU = RULE_OPS.map((op)=>/*#__PURE__*/ _jsx(MenuItem, {
418
438
  }),
419
439
  /*#__PURE__*/ _jsxs(DialogActions, {
420
440
  children: [
441
+ /*#__PURE__*/ _jsx(CheckingNote, {
442
+ text: checkingText,
443
+ sx: HELD_NOTE
444
+ }),
421
445
  /*#__PURE__*/ _jsx(Button, {
422
446
  onClick: close,
423
447
  children: 'Cancel'
@@ -425,7 +449,7 @@ const RULE_OP_MENU = RULE_OPS.map((op)=>/*#__PURE__*/ _jsx(MenuItem, {
425
449
  /*#__PURE__*/ _jsx(Button, {
426
450
  variant: "contained",
427
451
  color: "primary",
428
- disabled: !(draft == null ? void 0 : draft.name.trim()),
452
+ disabled: Boolean(checkingText) || !(draft == null ? void 0 : draft.name.trim()),
429
453
  onClick: props.onSave,
430
454
  children: 'Save'
431
455
  })
@@ -592,7 +616,7 @@ const CollectionRuleRow = /*#__PURE__*/ memo(function CollectionRuleRow(props) {
592
616
  });
593
617
  /** The collection editor: a name, a mode, and the products or rules it holds. */ const CollectionDialog = /*#__PURE__*/ memo(function CollectionDialog(props) {
594
618
  var _ref, _ref1, _ref2;
595
- const { draft, error, setDraft } = props;
619
+ const { draft, error, setDraft, checkingText } = props;
596
620
  const close = useCallback(()=>setDraft(null), [
597
621
  setDraft
598
622
  ]);
@@ -663,6 +687,10 @@ const CollectionRuleRow = /*#__PURE__*/ memo(function CollectionRuleRow(props) {
663
687
  }),
664
688
  /*#__PURE__*/ _jsxs(DialogActions, {
665
689
  children: [
690
+ /*#__PURE__*/ _jsx(CheckingNote, {
691
+ text: checkingText,
692
+ sx: HELD_NOTE
693
+ }),
666
694
  /*#__PURE__*/ _jsx(Button, {
667
695
  onClick: close,
668
696
  children: 'Cancel'
@@ -670,7 +698,7 @@ const CollectionRuleRow = /*#__PURE__*/ memo(function CollectionRuleRow(props) {
670
698
  /*#__PURE__*/ _jsx(Button, {
671
699
  variant: "contained",
672
700
  color: "primary",
673
- disabled: !(draft == null ? void 0 : draft.name.trim()) || Boolean(error),
701
+ disabled: Boolean(checkingText) || !(draft == null ? void 0 : draft.name.trim()) || Boolean(error),
674
702
  onClick: props.onSave,
675
703
  children: 'Save'
676
704
  })
@@ -848,8 +876,28 @@ const CollectionRuleRow = /*#__PURE__*/ memo(function CollectionRuleRow(props) {
848
876
  collectionPage,
849
877
  collectionPageSize
850
878
  ]);
851
- const [categoryDraft, setCategoryDraft] = useState(null);
852
- const [collectionDraft, setCollectionDraft] = useState(null);
879
+ /*
880
+ * Each editor's draft, kept as EDITS over the row as the list has it now
881
+ * (AGL-4047): opened from the cache's row, the server's copy replaces it
882
+ * under every field nobody touched (a category's parent, a collection's
883
+ * membership), and Save is held until it has.
884
+ */ const [categoryDraft, setCategoryDraft] = useSeedDraft((opened)=>{
885
+ const row = opened.id ? categoryDocs == null ? void 0 : categoryDocs.find((category)=>category.$id === opened.id) : undefined;
886
+ return row ? categoryDraftOf(row) : undefined;
887
+ });
888
+ const [collectionDraft, setCollectionDraft] = useSeedDraft((opened)=>{
889
+ const row = opened.id ? collectionDocs == null ? void 0 : collectionDocs.find((collection)=>collection.$id === opened.id) : undefined;
890
+ return row ? collectionDraftOf(row) : undefined;
891
+ });
892
+ const categoriesChecking = isSeedChecking({
893
+ fromCache: categoriesFromCache,
894
+ unreadable: categoriesStatus === 'error'
895
+ }) ? seedCheckingText('categories') : undefined;
896
+ const categoryChecking = (categoryDraft == null ? void 0 : categoryDraft.id) ? categoriesChecking && seedCheckingText('category') : undefined;
897
+ const collectionChecking = (collectionDraft == null ? void 0 : collectionDraft.id) && isSeedChecking({
898
+ fromCache: collectionsFromCache,
899
+ unreadable: collectionsStatus === 'error'
900
+ }) ? seedCheckingText('collection') : undefined;
853
901
  const handleCategorySave = useCallback(async ()=>{
854
902
  var _categoryDraft_id;
855
903
  if (!(categoryDraft == null ? void 0 : categoryDraft.name.trim())) return;
@@ -1302,7 +1350,8 @@ const CollectionRuleRow = /*#__PURE__*/ memo(function CollectionRuleRow(props) {
1302
1350
  onPageChange: setCategoryPage,
1303
1351
  onPageSizeChange: setCategoryPageSize,
1304
1352
  onEdit: setCategoryDraft,
1305
- onDelete: handleCategoryDelete
1353
+ onDelete: handleCategoryDelete,
1354
+ deleteCheckingText: categoriesChecking
1306
1355
  }),
1307
1356
  /*#__PURE__*/ _jsx(Divider, {
1308
1357
  sx: {
@@ -1328,7 +1377,8 @@ const CollectionRuleRow = /*#__PURE__*/ memo(function CollectionRuleRow(props) {
1328
1377
  draft: categoryDraft,
1329
1378
  categories: categories,
1330
1379
  setDraft: setCategoryDraft,
1331
- onSave: handleCategorySave
1380
+ onSave: handleCategorySave,
1381
+ checkingText: categoryChecking
1332
1382
  }),
1333
1383
  /*#__PURE__*/ _jsx(CollectionDialog, {
1334
1384
  draft: collectionDraft,
@@ -1343,7 +1393,8 @@ const CollectionRuleRow = /*#__PURE__*/ memo(function CollectionRuleRow(props) {
1343
1393
  setDraft: setCollectionDraft,
1344
1394
  onProducts: setCollectionProducts,
1345
1395
  onRule: updateRule,
1346
- onSave: handleCollectionSave
1396
+ onSave: handleCollectionSave,
1397
+ checkingText: collectionChecking
1347
1398
  })
1348
1399
  ]
1349
1400
  });