@aglyn/plugins-commerce 1.29.2 → 1.29.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-commerce",
3
- "version": "1.29.2",
3
+ "version": "1.29.3",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,18 +25,18 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.29.2",
29
- "@aglyn/shared-data-mdi": "1.29.2",
30
- "@aglyn/shared-ui-jsx": "1.29.2",
31
- "@aglyn/shared-ui-next": "1.29.2",
32
- "@aglyn/shared-ui-snackstack": "1.29.2",
33
- "@aglyn/shared-util-email": "1.29.2",
34
- "@aglyn/shared-util-http": "1.29.2",
35
- "@aglyn/shared-util-timestamp": "1.29.2",
36
- "@aglyn/shared-util-tools": "1.29.2",
37
- "@aglyn/tenant-data-admin": "1.29.2",
38
- "@aglyn/tenant-feature-instance": "1.29.2",
39
- "@aglyn/tenant-runtime": "1.29.2",
28
+ "@aglyn/aglyn": "1.29.3",
29
+ "@aglyn/shared-data-mdi": "1.29.3",
30
+ "@aglyn/shared-ui-jsx": "1.29.3",
31
+ "@aglyn/shared-ui-next": "1.29.3",
32
+ "@aglyn/shared-ui-snackstack": "1.29.3",
33
+ "@aglyn/shared-util-email": "1.29.3",
34
+ "@aglyn/shared-util-http": "1.29.3",
35
+ "@aglyn/shared-util-timestamp": "1.29.3",
36
+ "@aglyn/shared-util-tools": "1.29.3",
37
+ "@aglyn/tenant-data-admin": "1.29.3",
38
+ "@aglyn/tenant-feature-instance": "1.29.3",
39
+ "@aglyn/tenant-runtime": "1.29.3",
40
40
  "@stripe/react-stripe-js": "^7.0.1",
41
41
  "@stripe/stripe-js": "^10.2.1",
42
42
  "@swc/helpers": "0.5.24",
@@ -34,9 +34,10 @@ import { useListGridFilter } from "@aglyn/shared-ui-jsx/hooks/use-list-grid-filt
34
34
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
35
35
  import { Timestamp } from "@aglyn/shared-util-timestamp";
36
36
  import { Alert, Box, Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, TextField, Tooltip, Typography } from "@mui/material";
37
- import { addDoc, collection, doc, documentId, limit, orderBy, query, updateDoc, where } from "firebase/firestore";
37
+ import { addDoc, collection, doc, documentId, getDocFromServer, limit, orderBy, query, updateDoc, where } from "firebase/firestore";
38
38
  import { getLiveCountFromServer } from "@aglyn/aglyn/app-utils/live-document-count.client";
39
- import { useCallback, useEffect, useMemo, useState } from "react";
39
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
40
+ import { useSearchParams } from "next/navigation";
40
41
  import { useFirestore, useUser } from "@aglyn/tenant-feature-instance";
41
42
  import { writeSiteWideChange } from "@aglyn/tenant-feature-instance/hooks/helpers/site-wide-change";
42
43
  import { useFirestoreCollection, writeGuardedBySeed } from "@aglyn/tenant-feature-instance";
@@ -48,6 +49,7 @@ import ProductEditorDialog from "./product-editor-dialog.component.js";
48
49
  import { productSlugLedger } from "./product-slugs.js";
49
50
  import { productCollectionFields } from "./smart-collections.js";
50
51
  import ProductsHubZone from "./products-hub-zone.component.js";
52
+ import { PRODUCTS_PRODUCT_PARAM } from "../../model/commerce-record-routes.js";
51
53
  import { pluginDocsHelp } from "@aglyn/aglyn";
52
54
  import { heldSaveLabel, isSeedChecking, seedCheckingText, useHeldSave } from "@aglyn/tenant-feature-instance/hooks/use-seed-edits";
53
55
  import { useSeedDraft } from "@aglyn/tenant-feature-instance/hooks/use-seed-draft";
@@ -93,7 +95,7 @@ const STATUS_COLOR = {
93
95
  * gated here on create/duplicate/import (AGL-471); server-side
94
96
  * enforcement of the client-write path rides AGL-473.
95
97
  */ export function ProductsHubCard(props) {
96
- var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref10, _products_find, _ref11;
98
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref10, _ref11, _products_find, _ref12;
97
99
  const { hostId } = props;
98
100
  /** The shell's zone renderer, for the `productsCreate` zone (AGL-3596). */ const CreateZone = useConsoleWidgetSlot();
99
101
  const firestore = useFirestore();
@@ -217,6 +219,41 @@ const STATUS_COLOR = {
217
219
  productDocs
218
220
  ]);
219
221
  /*
222
+ * A product named in the URL opens in its editor on arrival, as an order
223
+ * does over the Orders list (AGL-2622). The admin edit bar on a product's
224
+ * page links here with `?product={id}`, and so does every other surface that
225
+ * asks the record routes for a product. The list shows one page and the
226
+ * product may not be on it, so it is read once by id from the SERVER — the
227
+ * editor replaces the whole document, so a cached seed would revert what
228
+ * the server holds (AGL-1358). Once per id, so closing the editor does not
229
+ * reopen it on the next render.
230
+ */ const searchParams = useSearchParams();
231
+ const linkedProductId = (_ref1 = searchParams == null ? void 0 : searchParams.get(PRODUCTS_PRODUCT_PARAM)) != null ? _ref1 : null;
232
+ const linkedOpened = useRef(null);
233
+ useEffect(()=>{
234
+ if (!linkedProductId || linkedOpened.current === linkedProductId) return;
235
+ if (productsStatus === 'loading') return;
236
+ linkedOpened.current = linkedProductId;
237
+ const loaded = products.find((row)=>row.$id === linkedProductId);
238
+ if (loaded) {
239
+ setEditing(loaded);
240
+ return;
241
+ }
242
+ void getDocFromServer(doc(firestore, 'hosts', hostId, 'products', linkedProductId)).then((snapshot)=>{
243
+ if (linkedOpened.current !== snapshot.id || !snapshot.exists()) return;
244
+ if (snapshot.get('deletedAt')) return;
245
+ setEditing(_extends({}, CommerceModel.liftLegacyProduct(snapshot.data()), {
246
+ $id: snapshot.id
247
+ }));
248
+ }).catch(()=>undefined);
249
+ }, [
250
+ linkedProductId,
251
+ products,
252
+ productsStatus,
253
+ firestore,
254
+ hostId
255
+ ]);
256
+ /*
220
257
  * The stock dialog, kept as EDITS over the product as the list has it now
221
258
  * (AGL-4047). An adjustment recomputes the whole `variants` array from the
222
259
  * product it holds, so the dialog follows the server's row once it answers
@@ -321,7 +358,7 @@ const STATUS_COLOR = {
321
358
  // read, probe row included. Each is a product the site has, so it can only
322
359
  // UNDERSTATE, never overstate, and nothing it gates fires on a count larger
323
360
  // than the truth (AGL-471).
324
- const loadedProductCount = (_ref1 = productWindow == null ? void 0 : productWindow.length) != null ? _ref1 : 0;
361
+ const loadedProductCount = (_ref2 = productWindow == null ? void 0 : productWindow.length) != null ? _ref2 : 0;
325
362
  const productCount = serverProductCount != null ? serverProductCount : loadedProductCount;
326
363
  // Gate only once the org doc has loaded: an unresolved org reads as the
327
364
  // free tier's 0-product cap, which swallowed every Add/Duplicate click.
@@ -857,7 +894,7 @@ const STATUS_COLOR = {
857
894
  /*#__PURE__*/ _jsx(QuotaReadoutComponent, {
858
895
  ready: productQuota !== null,
859
896
  used: productCount,
860
- limit: (_ref2 = productQuota == null ? void 0 : productQuota.limit) != null ? _ref2 : 0,
897
+ limit: (_ref3 = productQuota == null ? void 0 : productQuota.limit) != null ? _ref3 : 0,
861
898
  noun: "product"
862
899
  }),
863
900
  /*#__PURE__*/ _jsx(ProductsHubZone, {
@@ -943,7 +980,7 @@ const STATUS_COLOR = {
943
980
  fullWidth: true,
944
981
  children: [
945
982
  /*#__PURE__*/ _jsx(DialogTitle, {
946
- children: `License keys — ${(_ref3 = keysFor == null ? void 0 : keysFor.name) != null ? _ref3 : ''}`
983
+ children: `License keys — ${(_ref4 = keysFor == null ? void 0 : keysFor.name) != null ? _ref4 : ''}`
947
984
  }),
948
985
  /*#__PURE__*/ _jsx(DialogContent, {
949
986
  sx: {
@@ -1052,7 +1089,7 @@ const STATUS_COLOR = {
1052
1089
  fullWidth: true,
1053
1090
  children: [
1054
1091
  /*#__PURE__*/ _jsx(DialogTitle, {
1055
- children: `Adjust stock — ${(_ref4 = adjusting == null ? void 0 : adjusting.product.name) != null ? _ref4 : ''}`
1092
+ children: `Adjust stock — ${(_ref5 = adjusting == null ? void 0 : adjusting.product.name) != null ? _ref5 : ''}`
1056
1093
  }),
1057
1094
  /*#__PURE__*/ _jsxs(DialogContent, {
1058
1095
  sx: {
@@ -1063,7 +1100,7 @@ const STATUS_COLOR = {
1063
1100
  children: [
1064
1101
  /*#__PURE__*/ _jsx(TextField, {
1065
1102
  label: "Variant",
1066
- value: (_ref5 = adjusting == null ? void 0 : adjusting.variantId) != null ? _ref5 : '',
1103
+ value: (_ref6 = adjusting == null ? void 0 : adjusting.variantId) != null ? _ref6 : '',
1067
1104
  onChange: (event)=>setAdjusting((prev)=>prev ? _extends({}, prev, {
1068
1105
  variantId: event.target.value
1069
1106
  }) : prev),
@@ -1072,7 +1109,7 @@ const STATUS_COLOR = {
1072
1109
  sx: {
1073
1110
  mt: 1
1074
1111
  },
1075
- children: ((_ref6 = adjusting == null ? void 0 : adjusting.product.variants) != null ? _ref6 : []).filter((variant)=>variant.inventory != null).map((variant)=>{
1112
+ children: ((_ref7 = adjusting == null ? void 0 : adjusting.product.variants) != null ? _ref7 : []).filter((variant)=>variant.inventory != null).map((variant)=>{
1076
1113
  var _variant_options;
1077
1114
  return /*#__PURE__*/ _jsx(MenuItem, {
1078
1115
  value: variant.id,
@@ -1080,9 +1117,9 @@ const STATUS_COLOR = {
1080
1117
  }, variant.id);
1081
1118
  })
1082
1119
  }),
1083
- ((_ref7 = locationDocs == null ? void 0 : locationDocs.length) != null ? _ref7 : 0) > 1 ? /*#__PURE__*/ _jsx(TextField, {
1120
+ ((_ref8 = locationDocs == null ? void 0 : locationDocs.length) != null ? _ref8 : 0) > 1 ? /*#__PURE__*/ _jsx(TextField, {
1084
1121
  label: "Location",
1085
- value: (_ref8 = adjusting == null ? void 0 : adjusting.locationId) != null ? _ref8 : '',
1122
+ value: (_ref9 = adjusting == null ? void 0 : adjusting.locationId) != null ? _ref9 : '',
1086
1123
  onChange: (event)=>setAdjusting((prev)=>prev ? _extends({}, prev, {
1087
1124
  locationId: event.target.value
1088
1125
  }) : prev),
@@ -1096,7 +1133,7 @@ const STATUS_COLOR = {
1096
1133
  /*#__PURE__*/ _jsx(TextField, {
1097
1134
  label: "Change",
1098
1135
  placeholder: "+10 or -3",
1099
- value: (_ref9 = adjusting == null ? void 0 : adjusting.delta) != null ? _ref9 : '',
1136
+ value: (_ref10 = adjusting == null ? void 0 : adjusting.delta) != null ? _ref10 : '',
1100
1137
  onChange: (event)=>setAdjusting((prev)=>prev ? _extends({}, prev, {
1101
1138
  delta: event.target.value.replace(/[^0-9+-]/g, '')
1102
1139
  }) : prev),
@@ -1104,7 +1141,7 @@ const STATUS_COLOR = {
1104
1141
  }),
1105
1142
  /*#__PURE__*/ _jsxs(TextField, {
1106
1143
  label: "Reason",
1107
- value: (_ref10 = adjusting == null ? void 0 : adjusting.reason) != null ? _ref10 : 'restock',
1144
+ value: (_ref11 = adjusting == null ? void 0 : adjusting.reason) != null ? _ref11 : 'restock',
1108
1145
  onChange: (event)=>setAdjusting((prev)=>prev ? _extends({}, prev, {
1109
1146
  reason: event.target.value
1110
1147
  }) : prev),
@@ -1177,7 +1214,7 @@ const STATUS_COLOR = {
1177
1214
  // keeps the cap off the dialog's shoulders (AGL-1716).
1178
1215
  setProductCountEpoch((epoch)=>epoch + 1);
1179
1216
  }
1180
- }, (_ref11 = editing == null ? void 0 : editing.$id) != null ? _ref11 : creating ? 'new' : 'closed')
1217
+ }, (_ref12 = editing == null ? void 0 : editing.$id) != null ? _ref12 : creating ? 'new' : 'closed')
1181
1218
  ]
1182
1219
  });
1183
1220
  }