@aglyn/plugins-commerce 1.26.6 → 1.28.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.
- package/package.json +13 -13
- package/src/lib/components/console/pos-hardware-card.component.js +70 -67
- package/src/lib/components/console/pos-hardware-card.component.js.map +1 -1
- package/src/lib/components/console/pos-hardware-waiting-card.component.js +19 -17
- package/src/lib/components/console/pos-hardware-waiting-card.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +4 -43
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/contracts.d.ts +7 -0
- package/src/lib/contracts.js.map +1 -1
- package/src/lib/model/pos-hardware-shop.d.ts +152 -0
- package/src/lib/model/pos-hardware-shop.js +152 -0
- package/src/lib/model/pos-hardware-shop.js.map +1 -0
- package/src/lib/model/product-write.d.ts +29 -8
- package/src/lib/model/product-write.js +64 -2
- package/src/lib/model/product-write.js.map +1 -1
- package/src/lib/native-nav.js +13 -1
- package/src/lib/native-nav.js.map +1 -1
- package/src/lib/server/api-v1/openapi.d.ts +6 -6
- package/src/lib/server/api-v1/openapi.js +203 -16
- package/src/lib/server/api-v1/openapi.js.map +1 -1
- package/src/lib/server/api-v1/order-view.d.ts +8 -0
- package/src/lib/server/api-v1/order-view.js +21 -4
- package/src/lib/server/api-v1/order-view.js.map +1 -1
- package/src/lib/server/api-v1/orders-and-products.js +46 -59
- package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
- package/src/lib/server/api-v1/product-view.d.ts +76 -0
- package/src/lib/server/api-v1/product-view.js +86 -0
- package/src/lib/server/api-v1/product-view.js.map +1 -0
- package/src/lib/server/api-v1/product-writes.d.ts +149 -0
- package/src/lib/server/api-v1/product-writes.js +673 -0
- package/src/lib/server/api-v1/product-writes.js.map +1 -0
- package/src/lib/server/products-write.d.ts +94 -2
- package/src/lib/server/products-write.js +171 -112
- package/src/lib/server/products-write.js.map +1 -1
|
@@ -23,9 +23,10 @@ import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
|
23
23
|
import { useUser } from "@aglyn/tenant-feature-instance";
|
|
24
24
|
import { Button, Divider, MenuItem, Stack, TextField, Typography } from "@mui/material";
|
|
25
25
|
import { useCallback, useEffect, useState } from "react";
|
|
26
|
+
import { POS_HARDWARE_WAITING_TEXT as TEXT, posHardwareWaitingItems, posHardwareWaitingNote } from "../../model/pos-hardware-shop.js";
|
|
26
27
|
import { EntitlementUpsell, useCommerceEntitlement } from "./entitlement-gate.component.js";
|
|
27
28
|
import { PosHardwareRequestError, posHardwareChooseStore, posHardwareMarkSetUp, posHardwareWaiting } from "./pos/pos-hardware-api.js";
|
|
28
|
-
const items = (order)=>order.lines
|
|
29
|
+
const items = (order)=>posHardwareWaitingItems(order.lines);
|
|
29
30
|
/**
|
|
30
31
|
* Card readers this workspace bought in person, waiting to be set up
|
|
31
32
|
* (AGL-4038). Each says the one thing it still needs, in order:
|
|
@@ -75,7 +76,7 @@ const items = (order)=>order.lines.map((line)=>`${line.quantity} × ${line.name}
|
|
|
75
76
|
});
|
|
76
77
|
await load();
|
|
77
78
|
} catch (error) {
|
|
78
|
-
enqueueSnackbar(error instanceof PosHardwareRequestError ? error.message :
|
|
79
|
+
enqueueSnackbar(error instanceof PosHardwareRequestError ? error.message : TEXT.failed, {
|
|
79
80
|
variant: 'warning',
|
|
80
81
|
persist: false
|
|
81
82
|
});
|
|
@@ -85,10 +86,10 @@ const items = (order)=>order.lines.map((line)=>`${line.quantity} × ${line.name}
|
|
|
85
86
|
};
|
|
86
87
|
if (!user || !(waiting == null ? void 0 : waiting.orders.length)) return null;
|
|
87
88
|
const devicesReason = devicesBlockedReason || undefined;
|
|
88
|
-
const planReason = waiting.posPlan ? undefined :
|
|
89
|
+
const planReason = waiting.posPlan ? undefined : TEXT.planReason;
|
|
89
90
|
return /*#__PURE__*/ _jsx(CardDisplay, {
|
|
90
|
-
header:
|
|
91
|
-
subheader:
|
|
91
|
+
header: TEXT.header,
|
|
92
|
+
subheader: TEXT.subheader,
|
|
92
93
|
help: pluginDocsHelp('posHardware', {
|
|
93
94
|
anchor: '#card-readers-to-set-up'
|
|
94
95
|
}),
|
|
@@ -103,7 +104,7 @@ const items = (order)=>order.lines.map((line)=>`${line.quantity} × ${line.name}
|
|
|
103
104
|
waiting.posPlan ? null : /*#__PURE__*/ _jsx(EntitlementUpsell, {
|
|
104
105
|
planLabel: plan.planLabel,
|
|
105
106
|
upgradeHref: plan.upgradeHref,
|
|
106
|
-
children:
|
|
107
|
+
children: TEXT.planPrompt
|
|
107
108
|
}),
|
|
108
109
|
waiting.orders.map((order)=>{
|
|
109
110
|
var _ref, _chosen_order_id, _ref1, _ref2;
|
|
@@ -124,12 +125,13 @@ const items = (order)=>order.lines.map((line)=>`${line.quantity} × ${line.name}
|
|
|
124
125
|
}),
|
|
125
126
|
store ? /*#__PURE__*/ _jsxs(_Fragment, {
|
|
126
127
|
children: [
|
|
127
|
-
/*#__PURE__*/
|
|
128
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
128
129
|
variant: "body2",
|
|
129
|
-
children:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
children: posHardwareWaitingNote({
|
|
131
|
+
storeName: store.name,
|
|
132
|
+
serialsTaken: order.serialsTaken,
|
|
133
|
+
hasLocation: store.hasLocation
|
|
134
|
+
})
|
|
133
135
|
}),
|
|
134
136
|
/*#__PURE__*/ _jsxs(Stack, {
|
|
135
137
|
direction: "row",
|
|
@@ -142,7 +144,7 @@ const items = (order)=>order.lines.map((line)=>`${line.quantity} × ${line.name}
|
|
|
142
144
|
variant: "contained",
|
|
143
145
|
size: "small",
|
|
144
146
|
href: store.setupUrl,
|
|
145
|
-
children:
|
|
147
|
+
children: TEXT.openDevices
|
|
146
148
|
})
|
|
147
149
|
}),
|
|
148
150
|
/*#__PURE__*/ _jsx(BlockedControl, {
|
|
@@ -151,8 +153,8 @@ const items = (order)=>order.lines.map((line)=>`${line.quantity} × ${line.name}
|
|
|
151
153
|
children: /*#__PURE__*/ _jsx(Button, {
|
|
152
154
|
size: "small",
|
|
153
155
|
disabled: busy === order.id,
|
|
154
|
-
onClick: ()=>void act(order.id, ()=>posHardwareMarkSetUp(user, order.hostId, order.id),
|
|
155
|
-
children:
|
|
156
|
+
onClick: ()=>void act(order.id, ()=>posHardwareMarkSetUp(user, order.hostId, order.id), TEXT.marked),
|
|
157
|
+
children: TEXT.markSetUp
|
|
156
158
|
})
|
|
157
159
|
})
|
|
158
160
|
]
|
|
@@ -168,7 +170,7 @@ const items = (order)=>order.lines.map((line)=>`${line.quantity} × ${line.name}
|
|
|
168
170
|
/*#__PURE__*/ _jsx(TextField, {
|
|
169
171
|
select: true,
|
|
170
172
|
size: "small",
|
|
171
|
-
label:
|
|
173
|
+
label: TEXT.whichStore,
|
|
172
174
|
value: pick,
|
|
173
175
|
onChange: (event)=>setChosen(_extends({}, chosen, {
|
|
174
176
|
[order.id]: event.target.value
|
|
@@ -187,8 +189,8 @@ const items = (order)=>order.lines.map((line)=>`${line.quantity} × ${line.name}
|
|
|
187
189
|
children: /*#__PURE__*/ _jsx(Button, {
|
|
188
190
|
size: "small",
|
|
189
191
|
disabled: !pick || busy === order.id,
|
|
190
|
-
onClick: ()=>void act(order.id, ()=>posHardwareChooseStore(user, pick, order.id),
|
|
191
|
-
children:
|
|
192
|
+
onClick: ()=>void act(order.id, ()=>posHardwareChooseStore(user, pick, order.id), TEXT.chosen),
|
|
193
|
+
children: TEXT.choose
|
|
192
194
|
})
|
|
193
195
|
})
|
|
194
196
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/pos-hardware-waiting-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { BlockedControl } from '@aglyn/shared-ui-jsx/components/blocked-control.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport { Button, Divider, MenuItem, Stack, TextField, Typography } from '@mui/material'\nimport { useCallback, useEffect, useState } from 'react'\nimport { EntitlementUpsell, useCommerceEntitlement } from './entitlement-gate.component'\nimport {\n PosHardwareRequestError,\n posHardwareChooseStore,\n posHardwareMarkSetUp,\n posHardwareWaiting,\n type WaitingReaderOrder,\n type WaitingReaders,\n} from './pos/pos-hardware-api'\n\nexport interface PosHardwareWaitingCardProps {\n hostId: string\n /**\n * Why the member may not set up devices on this store (`posDevices`), or\n * nothing when they may. Passed in, not resolved here: this card is its own\n * chunk, and reaching into the permissions model from it would pull that\n * eagerly loaded module apart.\n */\n devicesBlockedReason?: string\n}\n\nconst items = (order: WaitingReaderOrder) => order.lines.map((line) => `${line.quantity} × ${line.name}`).join(', ')\n\n/**\n * Card readers this workspace bought in person, waiting to be set up\n * (AGL-4038). Each says the one thing it still needs, in order:\n *\n * 1. a plan with the point of sale, which registering a reader needs;\n * 2. the store it is for, when nobody chose one at the sale;\n * 3. adding it on that store's POS devices card by the code it shows —\n * by itself it then moves to Set up when its serial was taken at the\n * sale, and otherwise \"Mark set up\" says it is done.\n *\n * Drawn only while there is such a reader. Loaded on its own.\n */\nfunction PosHardwareWaitingCard(props: PosHardwareWaitingCardProps) {\n const { hostId, devicesBlockedReason } = props\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const plan = useCommerceEntitlement(hostId, 'pos')\n const [waiting, setWaiting] = useState<WaitingReaders | null>(null)\n const [chosen, setChosen] = useState<Record<string, string>>({})\n const [busy, setBusy] = useState('')\n const uid = user?.uid ?? ''\n\n const load = useCallback(async () => {\n if (!user) return\n try {\n setWaiting(await posHardwareWaiting(user, hostId))\n } catch {\n setWaiting(null)\n }\n // Keyed on the person, not the session object.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [uid, hostId])\n\n useEffect(() => {\n void load()\n }, [load])\n\n const act = async (orderId: string, run: () => Promise<unknown>, done: string) => {\n setBusy(orderId)\n try {\n await run()\n enqueueSnackbar(done, { variant: 'success', persist: false })\n await load()\n } catch (error) {\n enqueueSnackbar(error instanceof PosHardwareRequestError ? error.message : 'That did not work. Try again.', {\n variant: 'warning',\n persist: false,\n })\n } finally {\n setBusy('')\n }\n }\n\n if (!user || !waiting?.orders.length) return null\n const devicesReason = devicesBlockedReason || undefined\n const planReason = waiting.posPlan ? undefined : 'Add a plan with the point of sale first.'\n\n return (\n <CardDisplay\n header={'Card readers to set up'}\n subheader={'Bought in person, ready for your store'}\n help={pluginDocsHelp('posHardware', { anchor: '#card-readers-to-set-up' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2} divider={<Divider flexItem />}>\n {waiting.posPlan ? null : (\n <EntitlementUpsell planLabel={plan.planLabel} upgradeHref={plan.upgradeHref}>\n {'A card reader takes payments at the register, which comes with the point of sale. Add it, then set the reader up here.'}\n </EntitlementUpsell>\n )}\n {waiting.orders.map((order) => {\n const store = waiting.stores.find((candidate) => candidate.hostId === order.hostId)\n const pick = chosen[order.id] ?? waiting.stores[0]?.hostId ?? ''\n return (\n <Stack key={order.id} spacing={1}>\n <Typography variant=\"subtitle2\">{items(order)}</Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`Order ${order.number} · bought ${new Date(order.createdAtMs).toLocaleDateString()}`}\n </Typography>\n {store ? (\n <>\n <Typography variant=\"body2\">\n {order.serialsTaken\n ? `For ${store.name}. Add it on the POS devices card with the code it shows, and it is set up: we know its serial number.`\n : `For ${store.name}. Add it on the POS devices card with the code it shows, then mark it set up.`}\n {store.hasLocation ? '' : ' The first reader asks for the store’s address.'}\n </Typography>\n <Stack direction=\"row\" spacing={1}>\n <BlockedControl blocked={Boolean(planReason ?? devicesReason)} reason={planReason ?? devicesReason ?? ''}>\n <Button variant=\"contained\" size=\"small\" href={store.setupUrl}>\n {'Open POS devices'}\n </Button>\n </BlockedControl>\n <BlockedControl blocked={Boolean(planReason ?? devicesReason)} reason={planReason ?? devicesReason ?? ''}>\n <Button\n size=\"small\"\n disabled={busy === order.id}\n onClick={() =>\n void act(order.id, () => posHardwareMarkSetUp(user, order.hostId, order.id), 'Marked set up')\n }\n >\n {'Mark set up'}\n </Button>\n </BlockedControl>\n </Stack>\n </>\n ) : (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <TextField\n select\n size=\"small\"\n label=\"Which store is it for?\"\n value={pick}\n onChange={(event) => setChosen({ ...chosen, [order.id]: event.target.value })}\n sx={{ minWidth: (theme) => theme.spacing(30) }}\n >\n {waiting.stores.map((candidate) => (\n <MenuItem key={candidate.hostId} value={candidate.hostId}>\n {candidate.name}\n </MenuItem>\n ))}\n </TextField>\n <BlockedControl blocked={Boolean(planReason)} reason={planReason ?? ''}>\n <Button\n size=\"small\"\n disabled={!pick || busy === order.id}\n onClick={() =>\n void act(order.id, () => posHardwareChooseStore(user, pick, order.id), 'Store chosen')\n }\n >\n {'Choose'}\n </Button>\n </BlockedControl>\n </Stack>\n )}\n </Stack>\n )\n })}\n </Stack>\n </CardDisplay>\n )\n}\n\nexport default PosHardwareWaitingCard\n"],"names":["pluginDocsHelp","CardDisplay","BlockedControl","useSnackbar","useUser","Button","Divider","MenuItem","Stack","TextField","Typography","useCallback","useEffect","useState","EntitlementUpsell","useCommerceEntitlement","PosHardwareRequestError","posHardwareChooseStore","posHardwareMarkSetUp","posHardwareWaiting","items","order","lines","map","line","quantity","name","join","PosHardwareWaitingCard","props","hostId","devicesBlockedReason","data","user","enqueueSnackbar","plan","waiting","setWaiting","chosen","setChosen","busy","setBusy","uid","load","act","orderId","run","done","variant","persist","error","message","orders","length","devicesReason","undefined","planReason","posPlan","header","subheader","help","anchor","contentGutterX","contentGutterY","spacing","divider","flexItem","planLabel","upgradeHref","store","stores","find","candidate","pick","id","color","number","Date","createdAtMs","toLocaleDateString","serialsTaken","hasLocation","direction","blocked","Boolean","reason","size","href","setupUrl","disabled","onClick","sx","alignItems","select","label","value","onChange","event","target","minWidth","theme"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,cAAc,QAAQ,eAAc;AAC7C,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SAASC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAe;AACvF,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AACxD,SAASC,iBAAiB,EAAEC,sBAAsB,QAAQ,kCAA8B;AACxF,SACEC,uBAAuB,EACvBC,sBAAsB,EACtBC,oBAAoB,EACpBC,kBAAkB,QAGb,4BAAwB;AAa/B,MAAMC,QAAQ,CAACC,QAA8BA,MAAMC,KAAK,CAACC,GAAG,CAAC,CAACC,OAAS,GAAGA,KAAKC,QAAQ,CAAC,GAAG,EAAED,KAAKE,IAAI,EAAE,EAAEC,IAAI,CAAC;AAE/G;;;;;;;;;;;CAWC,GACD,SAASC,uBAAuBC,KAAkC;;IAChE,MAAM,EAAEC,MAAM,EAAEC,oBAAoB,EAAE,GAAGF;IACzC,MAAM,EAAEG,MAAMC,IAAI,EAAE,GAAG7B;IACvB,MAAM,EAAE8B,eAAe,EAAE,GAAG/B;IAC5B,MAAMgC,OAAOpB,uBAAuBe,QAAQ;IAC5C,MAAM,CAACM,SA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B;0DACpG,cAAA,KAACnD;oDACCiF,MAAK;oDACLG,UAAUjD,SAASnB,MAAMqD,EAAE;oDAC3BgB,SAAS,IACP,KAAK9C,IAAIvB,MAAMqD,EAAE,EAAE,IAAMxD,qBAAqBe,MAAMZ,MAAMS,MAAM,EAAET,MAAMqD,EAAE,GAAG;8DAG9E;;;;;;+CAMT,MAAClE;gCAAM0E,WAAU;gCAAMlB,SAAS;gCAAG2B,IAAI;oCAAEC,YAAY;gCAAS;;kDAC5D,KAACnF;wCACCoF,MAAM;wCACNP,MAAK;wCACLQ,OAAM;wCACNC,OAAOtB;wCACPuB,UAAU,CAACC,QAAU1D,UAAU,aAAKD;gDAAQ,CAACjB,MAAMqD,EAAE,CAAC,EAAEuB,MAAMC,MAAM,CAACH,KAAK;;wCAC1EJ,IAAI;4CAAEQ,UAAU,CAACC,QAAUA,MAAMpC,OAAO,CAAC;wCAAI;kDAE5C5B,QAAQkC,MAAM,CAAC/C,GAAG,CAAC,CAACiD,0BACnB,KAACjE;gDAAgCwF,OAAOvB,UAAU1C,MAAM;0DACrD0C,UAAU9C,IAAI;+CADF8C,UAAU1C,MAAM;;kDAKnC,KAAC5B;wCAAeiF,SAASC,QAAQ5B;wCAAa6B,MAAM,EAAE7B,qBAAAA,aAAc;kDAClE,cAAA,KAACnD;4CACCiF,MAAK;4CACLG,UAAU,CAAChB,QAAQjC,SAASnB,MAAMqD,EAAE;4CACpCgB,SAAS,IACP,KAAK9C,IAAIvB,MAAMqD,EAAE,EAAE,IAAMzD,uBAAuBgB,MAAMwC,MAAMpD,MAAMqD,EAAE,GAAG;sDAGxE;;;;;;uBAxDCrD,MAAMqD,EAAE;gBA+DxB;;;;AAIR;AAEA,eAAe9C,uBAAsB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/pos-hardware-waiting-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { BlockedControl } from '@aglyn/shared-ui-jsx/components/blocked-control.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport { Button, Divider, MenuItem, Stack, TextField, Typography } from '@mui/material'\nimport { useCallback, useEffect, useState } from 'react'\nimport {\n POS_HARDWARE_WAITING_TEXT as TEXT,\n posHardwareWaitingItems,\n posHardwareWaitingNote,\n} from '../../model/pos-hardware-shop'\nimport { EntitlementUpsell, useCommerceEntitlement } from './entitlement-gate.component'\nimport {\n PosHardwareRequestError,\n posHardwareChooseStore,\n posHardwareMarkSetUp,\n posHardwareWaiting,\n type WaitingReaderOrder,\n type WaitingReaders,\n} from './pos/pos-hardware-api'\n\nexport interface PosHardwareWaitingCardProps {\n hostId: string\n /**\n * Why the member may not set up devices on this store (`posDevices`), or\n * nothing when they may. Passed in, not resolved here: this card is its own\n * chunk, and reaching into the permissions model from it would pull that\n * eagerly loaded module apart.\n */\n devicesBlockedReason?: string\n}\n\nconst items = (order: WaitingReaderOrder) => posHardwareWaitingItems(order.lines)\n\n/**\n * Card readers this workspace bought in person, waiting to be set up\n * (AGL-4038). Each says the one thing it still needs, in order:\n *\n * 1. a plan with the point of sale, which registering a reader needs;\n * 2. the store it is for, when nobody chose one at the sale;\n * 3. adding it on that store's POS devices card by the code it shows —\n * by itself it then moves to Set up when its serial was taken at the\n * sale, and otherwise \"Mark set up\" says it is done.\n *\n * Drawn only while there is such a reader. Loaded on its own.\n */\nfunction PosHardwareWaitingCard(props: PosHardwareWaitingCardProps) {\n const { hostId, devicesBlockedReason } = props\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const plan = useCommerceEntitlement(hostId, 'pos')\n const [waiting, setWaiting] = useState<WaitingReaders | null>(null)\n const [chosen, setChosen] = useState<Record<string, string>>({})\n const [busy, setBusy] = useState('')\n const uid = user?.uid ?? ''\n\n const load = useCallback(async () => {\n if (!user) return\n try {\n setWaiting(await posHardwareWaiting(user, hostId))\n } catch {\n setWaiting(null)\n }\n // Keyed on the person, not the session object.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [uid, hostId])\n\n useEffect(() => {\n void load()\n }, [load])\n\n const act = async (orderId: string, run: () => Promise<unknown>, done: string) => {\n setBusy(orderId)\n try {\n await run()\n enqueueSnackbar(done, { variant: 'success', persist: false })\n await load()\n } catch (error) {\n enqueueSnackbar(error instanceof PosHardwareRequestError ? error.message : TEXT.failed, {\n variant: 'warning',\n persist: false,\n })\n } finally {\n setBusy('')\n }\n }\n\n if (!user || !waiting?.orders.length) return null\n const devicesReason = devicesBlockedReason || undefined\n const planReason = waiting.posPlan ? undefined : TEXT.planReason\n\n return (\n <CardDisplay\n header={TEXT.header}\n subheader={TEXT.subheader}\n help={pluginDocsHelp('posHardware', { anchor: '#card-readers-to-set-up' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2} divider={<Divider flexItem />}>\n {waiting.posPlan ? null : (\n <EntitlementUpsell planLabel={plan.planLabel} upgradeHref={plan.upgradeHref}>\n {TEXT.planPrompt}\n </EntitlementUpsell>\n )}\n {waiting.orders.map((order) => {\n const store = waiting.stores.find((candidate) => candidate.hostId === order.hostId)\n const pick = chosen[order.id] ?? waiting.stores[0]?.hostId ?? ''\n return (\n <Stack key={order.id} spacing={1}>\n <Typography variant=\"subtitle2\">{items(order)}</Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`Order ${order.number} · bought ${new Date(order.createdAtMs).toLocaleDateString()}`}\n </Typography>\n {store ? (\n <>\n <Typography variant=\"body2\">\n {posHardwareWaitingNote({\n storeName: store.name,\n serialsTaken: order.serialsTaken,\n hasLocation: store.hasLocation,\n })}\n </Typography>\n <Stack direction=\"row\" spacing={1}>\n <BlockedControl blocked={Boolean(planReason ?? devicesReason)} reason={planReason ?? devicesReason ?? ''}>\n <Button variant=\"contained\" size=\"small\" href={store.setupUrl}>\n {TEXT.openDevices}\n </Button>\n </BlockedControl>\n <BlockedControl blocked={Boolean(planReason ?? devicesReason)} reason={planReason ?? devicesReason ?? ''}>\n <Button\n size=\"small\"\n disabled={busy === order.id}\n onClick={() =>\n void act(order.id, () => posHardwareMarkSetUp(user, order.hostId, order.id), TEXT.marked)\n }\n >\n {TEXT.markSetUp}\n </Button>\n </BlockedControl>\n </Stack>\n </>\n ) : (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <TextField\n select\n size=\"small\"\n label={TEXT.whichStore}\n value={pick}\n onChange={(event) => setChosen({ ...chosen, [order.id]: event.target.value })}\n sx={{ minWidth: (theme) => theme.spacing(30) }}\n >\n {waiting.stores.map((candidate) => (\n <MenuItem key={candidate.hostId} value={candidate.hostId}>\n {candidate.name}\n </MenuItem>\n ))}\n </TextField>\n <BlockedControl blocked={Boolean(planReason)} reason={planReason ?? ''}>\n <Button\n size=\"small\"\n disabled={!pick || busy === order.id}\n onClick={() =>\n void act(order.id, () => posHardwareChooseStore(user, pick, order.id), TEXT.chosen)\n }\n >\n {TEXT.choose}\n </Button>\n </BlockedControl>\n </Stack>\n )}\n </Stack>\n )\n })}\n </Stack>\n </CardDisplay>\n )\n}\n\nexport default PosHardwareWaitingCard\n"],"names":["pluginDocsHelp","CardDisplay","BlockedControl","useSnackbar","useUser","Button","Divider","MenuItem","Stack","TextField","Typography","useCallback","useEffect","useState","POS_HARDWARE_WAITING_TEXT","TEXT","posHardwareWaitingItems","posHardwareWaitingNote","EntitlementUpsell","useCommerceEntitlement","PosHardwareRequestError","posHardwareChooseStore","posHardwareMarkSetUp","posHardwareWaiting","items","order","lines","PosHardwareWaitingCard","props","hostId","devicesBlockedReason","data","user","enqueueSnackbar","plan","waiting","setWaiting","chosen","setChosen","busy","setBusy","uid","load","act","orderId","run","done","variant","persist","error","message","failed","orders","length","devicesReason","undefined","planReason","posPlan","header","subheader","help","anchor","contentGutterX","contentGutterY","spacing","divider","flexItem","planLabel","upgradeHref","planPrompt","map","store","stores","find","candidate","pick","id","color","number","Date","createdAtMs","toLocaleDateString","storeName","name","serialsTaken","hasLocation","direction","blocked","Boolean","reason","size","href","setupUrl","openDevices","disabled","onClick","marked","markSetUp","sx","alignItems","select","label","whichStore","value","onChange","event","target","minWidth","theme","choose"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,cAAc,QAAQ,eAAc;AAC7C,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SAASC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAe;AACvF,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AACxD,SACEC,6BAA6BC,IAAI,EACjCC,uBAAuB,EACvBC,sBAAsB,QACjB,mCAA+B;AACtC,SAASC,iBAAiB,EAAEC,sBAAsB,QAAQ,kCAA8B;AACxF,SACEC,uBAAuB,EACvBC,sBAAsB,EACtBC,oBAAoB,EACpBC,kBAAkB,QAGb,4BAAwB;AAa/B,MAAMC,QAAQ,CAACC,QAA8BT,wBAAwBS,MAAMC,KAAK;AAEhF;;;;;;;;;;;CAWC,GACD,SAASC,uBAAuBC,KAAkC;;IAChE,MAAM,EAAEC,MAAM,EAAEC,oBAAoB,EAAE,GAAGF;IACzC,MAAM,EAAEG,MAAMC,IAAI,EAAE,GAAG5B;IAC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gBAgExB;;;;AAIR;AAEA,eAAejD,uBAAsB"}
|
|
@@ -68,27 +68,7 @@ const SUPPLIER_CEILING = 50;
|
|
|
68
68
|
'title',
|
|
69
69
|
'description'
|
|
70
70
|
];
|
|
71
|
-
/**
|
|
72
|
-
* A product nobody has saved yet, as the editor starts one: at the default
|
|
73
|
-
* price (AGL-3676), for the owner to change or clear.
|
|
74
|
-
*/ function blankProduct() {
|
|
75
|
-
return {
|
|
76
|
-
name: '',
|
|
77
|
-
slug: '',
|
|
78
|
-
type: 'physical',
|
|
79
|
-
status: 'draft',
|
|
80
|
-
variants: [
|
|
81
|
-
{
|
|
82
|
-
id: 'default',
|
|
83
|
-
priceUsd: CommerceModel.COMMERCE_DEFAULT_PRICE_USD
|
|
84
|
-
}
|
|
85
|
-
]
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
71
|
/** What the editor says while a variant has no price (AGL-3676): savable, not sellable. */ export const PRODUCT_PRICE_EMPTY_NOTICE = 'Visitors will see “Price coming soon” and can’t buy this yet. Set a price to start selling it.';
|
|
89
|
-
/** Stable key for matching variants across matrix regenerations. */ function comboKey(options) {
|
|
90
|
-
return Object.entries(options != null ? options : {}).sort(([a], [b])=>a.localeCompare(b)).map(([name, value])=>`${name}:${value}`).join('|');
|
|
91
|
-
}
|
|
92
72
|
function comboLabel(options) {
|
|
93
73
|
const values = Object.values(options != null ? options : {});
|
|
94
74
|
return values.length ? values.join(' / ') : 'Default';
|
|
@@ -1194,7 +1174,7 @@ const MemoPaidDownloadAddButton = /*#__PURE__*/ memo(PaidDownloadAddButton);
|
|
|
1194
1174
|
* dialog opened on the cache's replaces it under every field nobody
|
|
1195
1175
|
* touched, and Save is held until it has (`checking`). Lazy-init per open;
|
|
1196
1176
|
* the parent remounts via `key` on product change.
|
|
1197
|
-
*/ const seed = useMemo(()=>lifted != null ? lifted :
|
|
1177
|
+
*/ const seed = useMemo(()=>lifted != null ? lifted : CommerceModel.blankProductDraft(), [
|
|
1198
1178
|
lifted
|
|
1199
1179
|
]);
|
|
1200
1180
|
const form = useSeedEdits(seed);
|
|
@@ -1480,28 +1460,9 @@ const MemoPaidDownloadAddButton = /*#__PURE__*/ memo(PaidDownloadAddButton);
|
|
|
1480
1460
|
options
|
|
1481
1461
|
};
|
|
1482
1462
|
// Regenerate the matrix, carrying data over by option-combo key so
|
|
1483
|
-
// edits to prices/SKUs survive option tweaks.
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
variant
|
|
1487
|
-
]));
|
|
1488
|
-
const fallback = at.variants[0];
|
|
1489
|
-
const variants = CommerceModel.expandVariantMatrix(options).map((combo, comboIndex)=>{
|
|
1490
|
-
var _ref;
|
|
1491
|
-
const existing = previous.get(comboKey(combo));
|
|
1492
|
-
return existing != null ? existing : // An unpriced variant is stored with no `priceUsd` (AGL-3676),
|
|
1493
|
-
// as a proposed product's are; the type names the priced shape.
|
|
1494
|
-
_extends({
|
|
1495
|
-
id: `v${Date.now().toString(36)}${comboIndex}`,
|
|
1496
|
-
options: combo
|
|
1497
|
-
}, fallback ? CommerceModel.variantHasPrice(fallback) ? {
|
|
1498
|
-
priceUsd: fallback.priceUsd
|
|
1499
|
-
} : {} : {
|
|
1500
|
-
priceUsd: CommerceModel.COMMERCE_DEFAULT_PRICE_USD
|
|
1501
|
-
}, {
|
|
1502
|
-
inventory: (_ref = fallback == null ? void 0 : fallback.inventory) != null ? _ref : null
|
|
1503
|
-
});
|
|
1504
|
-
});
|
|
1463
|
+
// edits to prices/SKUs survive option tweaks. The same rebuild the
|
|
1464
|
+
// public API's product writes make (AGL-4235).
|
|
1465
|
+
const variants = CommerceModel.variantsForOptions(at, options, Date.now());
|
|
1505
1466
|
return {
|
|
1506
1467
|
options,
|
|
1507
1468
|
variants
|