@aglyn/plugins-commerce 1.15.2 → 1.17.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/README.md +1 -1
- package/package.json +13 -13
- package/src/lib/components/cart.js +2 -1
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/console/payments-settings-card.component.js +6 -1
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-api.d.ts +5 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -1
- package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +2 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js +13 -6
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-tender-panel.component.js +7 -4
- package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -1
- package/src/lib/components/console/pos-cellular-control.component.d.ts +5 -0
- package/src/lib/components/console/pos-cellular-control.component.js +29 -15
- package/src/lib/components/console/pos-cellular-control.component.js.map +1 -1
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
- package/src/lib/components/console/product-add-ons-fields.component.js +96 -3
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/product-builder-fields.component.d.ts +39 -0
- package/src/lib/components/console/product-builder-fields.component.js +195 -0
- package/src/lib/components/console/product-builder-fields.component.js.map +1 -0
- package/src/lib/components/console/product-editor-dialog.component.js +35 -2
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.js +43 -6
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-messages.component.d.ts +21 -0
- package/src/lib/components/console/quote-messages.component.js +185 -0
- package/src/lib/components/console/quote-messages.component.js.map +1 -0
- package/src/lib/components/console/quote-pay-link.component.js +1 -1
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-proofs.component.js +30 -3
- package/src/lib/components/console/quote-proofs.component.js.map +1 -1
- package/src/lib/components/console/quote-settings-card.component.d.ts +7 -3
- package/src/lib/components/console/quote-settings-card.component.js +154 -24
- package/src/lib/components/console/quote-settings-card.component.js.map +1 -1
- package/src/lib/components/product-builder-context.d.ts +22 -0
- package/src/lib/components/product-builder-context.js +21 -0
- package/src/lib/components/product-builder-context.js.map +1 -0
- package/src/lib/components/product-builder-mockup.d.ts +42 -0
- package/src/lib/components/product-builder-mockup.js +120 -0
- package/src/lib/components/product-builder-mockup.js.map +1 -0
- package/src/lib/components/product-builder-sample.d.ts +63 -0
- package/src/lib/components/product-builder-sample.js +96 -0
- package/src/lib/components/product-builder-sample.js.map +1 -0
- package/src/lib/components/product-choice-cards.d.ts +51 -0
- package/src/lib/components/product-choice-cards.js +311 -0
- package/src/lib/components/product-choice-cards.js.map +1 -0
- package/src/lib/components/product-detail-panels.d.ts +42 -0
- package/src/lib/components/product-detail-panels.js +185 -0
- package/src/lib/components/product-detail-panels.js.map +1 -0
- package/src/lib/components/product-detail.d.ts +20 -12
- package/src/lib/components/product-detail.js +136 -221
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.d.ts +7 -0
- package/src/lib/components/product-grid.js +13 -9
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/product-name-lines.d.ts +37 -0
- package/src/lib/components/product-name-lines.js +36 -0
- package/src/lib/components/product-name-lines.js.map +1 -0
- package/src/lib/components/product-options-field-body.d.ts +9 -8
- package/src/lib/components/product-options-field-body.js +152 -3
- package/src/lib/components/product-options-field-body.js.map +1 -1
- package/src/lib/components/product-options-field.js +1 -1
- package/src/lib/components/product-options-field.js.map +1 -1
- package/src/lib/components/product-photo-fit.d.ts +49 -0
- package/src/lib/components/product-photo-fit.js +58 -0
- package/src/lib/components/product-photo-fit.js.map +1 -0
- package/src/lib/components/product-restock-notify.d.ts +12 -0
- package/src/lib/components/product-restock-notify.js +86 -0
- package/src/lib/components/product-restock-notify.js.map +1 -0
- package/src/lib/components/quote-messages-panel.d.ts +21 -0
- package/src/lib/components/quote-messages-panel.js +191 -0
- package/src/lib/components/quote-messages-panel.js.map +1 -0
- package/src/lib/components/quote-page-body.js +15 -1
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/components/quote-proof-panel.d.ts +6 -3
- package/src/lib/components/quote-proof-panel.js +139 -14
- package/src/lib/components/quote-proof-panel.js.map +1 -1
- package/src/lib/components/related-products.d.ts +7 -0
- package/src/lib/components/related-products.js +10 -7
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/constants/quote-page.d.ts +8 -0
- package/src/lib/constants/quote-page.js +11 -0
- package/src/lib/constants/quote-page.js.map +1 -1
- package/src/lib/model/commerce-cart.d.ts +6 -1
- package/src/lib/model/commerce-cart.js +5 -1
- package/src/lib/model/commerce-cart.js.map +1 -1
- package/src/lib/model/commerce-invoices.js +5 -1
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-pos-ops.d.ts +3 -0
- package/src/lib/model/commerce-pos-ops.js +3 -0
- package/src/lib/model/commerce-pos-ops.js.map +1 -1
- package/src/lib/model/commerce-pos.d.ts +8 -0
- package/src/lib/model/commerce-pos.js.map +1 -1
- package/src/lib/model/commerce-quote-messages.d.ts +106 -0
- package/src/lib/model/commerce-quote-messages.js +146 -0
- package/src/lib/model/commerce-quote-messages.js.map +1 -0
- package/src/lib/model/commerce-quote-pay.d.ts +31 -2
- package/src/lib/model/commerce-quote-pay.js +31 -7
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/model/commerce-quote-proofs.d.ts +47 -8
- package/src/lib/model/commerce-quote-proofs.js +73 -18
- package/src/lib/model/commerce-quote-proofs.js.map +1 -1
- package/src/lib/model/commerce-quote-request.d.ts +14 -4
- package/src/lib/model/commerce-quote-request.js +25 -2
- package/src/lib/model/commerce-quote-request.js.map +1 -1
- package/src/lib/model/commerce-quotes.d.ts +56 -3
- package/src/lib/model/commerce-quotes.js +47 -2
- package/src/lib/model/commerce-quotes.js.map +1 -1
- package/src/lib/model/commerce.d.ts +12 -1
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +1 -0
- package/src/lib/model/index.js +1 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/pos-cellular.d.ts +36 -4
- package/src/lib/model/pos-cellular.js +39 -4
- package/src/lib/model/pos-cellular.js.map +1 -1
- package/src/lib/model/product-card-rules.d.ts +41 -0
- package/src/lib/model/product-card-rules.js +90 -0
- package/src/lib/model/product-card-rules.js.map +1 -0
- package/src/lib/model/product-modifiers.d.ts +11 -0
- package/src/lib/model/product-modifiers.js +10 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/model/product-write.d.ts +3 -0
- package/src/lib/server/billing-webhook.js +6 -2
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +15 -0
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/channel-order-updates.js +15 -1
- package/src/lib/server/channel-order-updates.js.map +1 -1
- package/src/lib/server/channel-orders.js +20 -0
- package/src/lib/server/channel-orders.js.map +1 -1
- package/src/lib/server/checkout.js +1 -1
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/local-fulfillment.js +1 -1
- package/src/lib/server/local-fulfillment.js.map +1 -1
- package/src/lib/server/pos-cellular-billing.d.ts +5 -4
- package/src/lib/server/pos-cellular-billing.js +24 -12
- package/src/lib/server/pos-cellular-billing.js.map +1 -1
- package/src/lib/server/pos-cellular.d.ts +3 -1
- package/src/lib/server/pos-cellular.js +55 -33
- package/src/lib/server/pos-cellular.js.map +1 -1
- package/src/lib/server/pos-offline-sync.d.ts +3 -3
- package/src/lib/server/pos-offline-sync.js +17 -4
- package/src/lib/server/pos-offline-sync.js.map +1 -1
- package/src/lib/server/pos-order.js +17 -6
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-payment.js +27 -11
- package/src/lib/server/pos-payment.js.map +1 -1
- package/src/lib/server/pos-reader-splash.js +10 -5
- package/src/lib/server/pos-reader-splash.js.map +1 -1
- package/src/lib/server/pos-readers.js +42 -12
- package/src/lib/server/pos-readers.js.map +1 -1
- package/src/lib/server/pos-return.js +19 -3
- package/src/lib/server/pos-return.js.map +1 -1
- package/src/lib/server/pos-stripe.d.ts +14 -0
- package/src/lib/server/pos-stripe.js +6 -2
- package/src/lib/server/pos-stripe.js.map +1 -1
- package/src/lib/server/pos-terminal-connection-token.js +23 -9
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
- package/src/lib/server/pos-terminal.d.ts +80 -14
- package/src/lib/server/pos-terminal.js +393 -123
- package/src/lib/server/pos-terminal.js.map +1 -1
- package/src/lib/server/product-drafts.d.ts +1 -1
- package/src/lib/server/product-drafts.js +4 -3
- package/src/lib/server/product-drafts.js.map +1 -1
- package/src/lib/server/product-writer.js +5 -4
- package/src/lib/server/product-writer.js.map +1 -1
- package/src/lib/server/product.d.ts +11 -0
- package/src/lib/server/product.js +18 -3
- package/src/lib/server/product.js.map +1 -1
- package/src/lib/server/products-write.js +4 -3
- package/src/lib/server/products-write.js.map +1 -1
- package/src/lib/server/quote-email.d.ts +26 -0
- package/src/lib/server/quote-email.js +73 -7
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-messages.d.ts +72 -0
- package/src/lib/server/quote-messages.js +356 -0
- package/src/lib/server/quote-messages.js.map +1 -0
- package/src/lib/server/quote-pay.d.ts +42 -0
- package/src/lib/server/quote-pay.js +81 -4
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proofs.d.ts +1 -1
- package/src/lib/server/quote-proofs.js +63 -19
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/server/quote.d.ts +12 -0
- package/src/lib/server/quote.js +69 -16
- package/src/lib/server/quote.js.map +1 -1
- package/src/lib/server/refund.js +3 -1
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/reserve-stock.js +9 -0
- package/src/lib/server/reserve-stock.js.map +1 -1
- package/src/lib/server/returns.js +15 -1
- package/src/lib/server/returns.js.map +1 -1
- package/src/lib/server/reviews.js +15 -0
- package/src/lib/server/reviews.js.map +1 -1
- package/src/lib/server/sold-out-drop.d.ts +58 -0
- package/src/lib/server/sold-out-drop.js +81 -0
- package/src/lib/server/sold-out-drop.js.map +1 -0
- package/src/lib/server/stock-levels.js +9 -0
- package/src/lib/server/stock-levels.js.map +1 -1
- package/src/lib/server/stripe-refund.d.ts +7 -0
- package/src/lib/server/stripe-refund.js +26 -7
- package/src/lib/server/stripe-refund.js.map +1 -1
- package/src/lib/server.d.ts +15 -0
- package/src/lib/server.js +30 -1
- package/src/lib/server.js.map +1 -1
- package/src/lib/tenant-emails.js +85 -2
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-seller-payment-account.d.ts +29 -0
- package/src/lib/testing/fake-seller-payment-account.js +40 -0
- package/src/lib/testing/fake-seller-payment-account.js.map +1 -0
- package/src/lib/transfer/product-transfer.js +6 -5
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.js +4 -3
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +6 -0
- package/src/lib/utils/quote-email-content.js +6 -3
- package/src/lib/utils/quote-email-content.js.map +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2026 Aglyn LLC
|
|
@@ -32,6 +32,11 @@ const readersText = (count)=>`${count} S710 reader${count === 1 ? '' : 's'}`;
|
|
|
32
32
|
* than hiding. A store whose 4G was turned off for an unpaid month says
|
|
33
33
|
* which, and how to turn it back on. Loaded only where 4G is offered and the
|
|
34
34
|
* store has an S710.
|
|
35
|
+
*
|
|
36
|
+
* A store on its own Stripe account is billed for 4G by Stripe, on that
|
|
37
|
+
* account, and never by the workspace: the row names no price (the only one
|
|
38
|
+
* known here is the platform's), turning it on asks for no agreement and no
|
|
39
|
+
* "Manage billing", and it says who bills it instead.
|
|
35
40
|
*/ export function PosCellularControl({ hostId, cellular, blocked, onChanged }) {
|
|
36
41
|
var _cellular_turnOnBlocked;
|
|
37
42
|
const { data: user } = useUser();
|
|
@@ -39,9 +44,11 @@ const readersText = (count)=>`${count} S710 reader${count === 1 ? '' : 's'}`;
|
|
|
39
44
|
const [dialog, setDialog] = useState(null);
|
|
40
45
|
const [agreed, setAgreed] = useState(false);
|
|
41
46
|
const [busy, setBusy] = useState(false);
|
|
42
|
-
const
|
|
47
|
+
const ownAccount = cellular.ownAccount === true;
|
|
48
|
+
const price = cellular.readerMonthlyCents === null ? '' : usd(cellular.readerMonthlyCents);
|
|
43
49
|
// Off needs only the card's key; on is charged to the workspace, so billing too.
|
|
44
50
|
const reason = blocked != null ? blocked : cellular.enabled ? null : (_cellular_turnOnBlocked = cellular.turnOnBlocked) != null ? _cellular_turnOnBlocked : null;
|
|
51
|
+
const caption = ownAccount ? cellular.enabled ? `On for every S710 reader at this store (${readersText(cellular.readers)} now). Stripe bills its 4G price for each one to this store’s own Stripe account.` : 'An S710 reader can use 4G service when Wi-Fi drops. It turns on for every S710 at this store, and Stripe bills its 4G price for each one to this store’s own Stripe account.' : cellular.enabled ? `On for every S710 reader at this store (${readersText(cellular.readers)} now). Each is charged ${price} a month.` : `An S710 reader can use 4G service when Wi-Fi drops. It turns on for every S710 at this store, at ${price} a month each.`;
|
|
45
52
|
const change = async (enabled)=>{
|
|
46
53
|
if (!user) return;
|
|
47
54
|
setBusy(true);
|
|
@@ -50,7 +57,7 @@ const readersText = (count)=>`${count} S710 reader${count === 1 ? '' : 's'}`;
|
|
|
50
57
|
action: 'cellular',
|
|
51
58
|
hostId,
|
|
52
59
|
enabled
|
|
53
|
-
}, enabled ? {
|
|
60
|
+
}, enabled && !ownAccount ? {
|
|
54
61
|
consent: agreed
|
|
55
62
|
} : {}));
|
|
56
63
|
setDialog(null);
|
|
@@ -95,7 +102,7 @@ const readersText = (count)=>`${count} S710 reader${count === 1 ? '' : 's'}`;
|
|
|
95
102
|
variant: "caption",
|
|
96
103
|
color: "text.secondary",
|
|
97
104
|
component: "p",
|
|
98
|
-
children:
|
|
105
|
+
children: caption
|
|
99
106
|
})
|
|
100
107
|
]
|
|
101
108
|
}),
|
|
@@ -140,16 +147,23 @@ const readersText = (count)=>`${count} S710 reader${count === 1 ? '' : 's'}`;
|
|
|
140
147
|
variant: "body2",
|
|
141
148
|
children: `Every S710 reader at this store gets 4G service and uses it whenever Wi-Fi and Ethernet are not available. That is ${readersText(cellular.readers)} now, and any S710 you add here later.`
|
|
142
149
|
}),
|
|
143
|
-
/*#__PURE__*/ _jsx(Typography, {
|
|
150
|
+
ownAccount ? /*#__PURE__*/ _jsx(Typography, {
|
|
144
151
|
variant: "body2",
|
|
145
|
-
children:
|
|
146
|
-
}),
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
children: 'Stripe bills its 4G price for each S710 to this store’s own Stripe account, under the store’s agreement with Stripe, for every calendar month it has 4G. This workspace is not charged for it. Turning 4G off stops it from the next month.'
|
|
153
|
+
}) : /*#__PURE__*/ _jsxs(_Fragment, {
|
|
154
|
+
children: [
|
|
155
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
156
|
+
variant: "body2",
|
|
157
|
+
children: `Each S710 is charged ${price} a month, plus any sales tax, for every calendar month it has 4G. The charge goes to this workspace's card at the start of the next month. Turning 4G off stops the charge from the next month. If a month's charge isn't paid, 4G is turned off after a grace period, until it's paid and turned on again.`
|
|
158
|
+
}),
|
|
159
|
+
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
160
|
+
control: /*#__PURE__*/ _jsx(Checkbox, {
|
|
161
|
+
checked: agreed,
|
|
162
|
+
onChange: (event)=>setAgreed(event.target.checked)
|
|
163
|
+
}),
|
|
164
|
+
label: `I agree to ${price} a month for each S710 reader at this store while 4G is on.`
|
|
165
|
+
})
|
|
166
|
+
]
|
|
153
167
|
})
|
|
154
168
|
]
|
|
155
169
|
}),
|
|
@@ -162,7 +176,7 @@ const readersText = (count)=>`${count} S710 reader${count === 1 ? '' : 's'}`;
|
|
|
162
176
|
}),
|
|
163
177
|
/*#__PURE__*/ _jsx(Button, {
|
|
164
178
|
variant: "contained",
|
|
165
|
-
disabled: busy || !agreed,
|
|
179
|
+
disabled: busy || !ownAccount && !agreed,
|
|
166
180
|
onClick: ()=>void change(true),
|
|
167
181
|
children: 'Turn on 4G'
|
|
168
182
|
})
|
|
@@ -182,7 +196,7 @@ const readersText = (count)=>`${count} S710 reader${count === 1 ? '' : 's'}`;
|
|
|
182
196
|
/*#__PURE__*/ _jsx(DialogContent, {
|
|
183
197
|
children: /*#__PURE__*/ _jsx(Typography, {
|
|
184
198
|
variant: "body2",
|
|
185
|
-
children: 'The S710 readers at this store stop using 4G the next time they connect, and use Wi-Fi or Ethernet only. This month is still charged for each reader that had 4G in it.'
|
|
199
|
+
children: ownAccount ? 'The S710 readers at this store stop using 4G the next time they connect, and use Wi-Fi or Ethernet only. Stripe still bills this month for each reader that had 4G in it.' : 'The S710 readers at this store stop using 4G the next time they connect, and use Wi-Fi or Ethernet only. This month is still charged for each reader that had 4G in it.'
|
|
186
200
|
})
|
|
187
201
|
}),
|
|
188
202
|
/*#__PURE__*/ _jsxs(DialogActions, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/pos-cellular-control.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\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 {\n Alert,\n Box,\n Button,\n Checkbox,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n FormControlLabel,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useState } from 'react'\nimport type { PosCellularView } from '../../model/pos-cellular'\nimport { posReadersCall, PosRequestError, usd } from './pos/pos-api'\n\nexport interface PosCellularControlProps {\n hostId: string\n cellular: PosCellularView\n /** Why the viewer may not change it (\"Registers and devices\"), or null. */\n blocked: string | null\n /** Reload the card once it changed. */\n onChanged: () => void | Promise<void>\n}\n\nconst readersText = (count: number) => `${count} S710 reader${count === 1 ? '' : 's'}`\n\n/**\n * 4G for a store's S710 readers (AGL-4038), on the POS devices card.\n * Stripe turns cellular service on for a store's reader Location, so this is\n * one switch for the store: it says plainly that every S710 at the store\n * gets 4G and that each one is charged, and turning it on takes an explicit\n * agreement to the monthly price. Turning it ON is charged to the workspace,\n * so it also takes \"Manage billing\": without it the control says so rather\n * than hiding. A store whose 4G was turned off for an unpaid month says\n * which, and how to turn it back on. Loaded only where 4G is offered and the\n * store has an S710.\n */\nexport function PosCellularControl({ hostId, cellular, blocked, onChanged }: PosCellularControlProps) {\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const [dialog, setDialog] = useState<'on' | 'off' | null>(null)\n const [agreed, setAgreed] = useState(false)\n const [busy, setBusy] = useState(false)\n const price = usd(cellular.readerMonthlyCents)\n // Off needs only the card's key; on is charged to the workspace, so billing too.\n const reason = blocked ?? (cellular.enabled ? null : (cellular.turnOnBlocked ?? null))\n\n const change = async (enabled: boolean) => {\n if (!user) return\n setBusy(true)\n try {\n await posReadersCall(user, { action: 'cellular', hostId, enabled, ...(enabled ? { consent: agreed } : {}) })\n setDialog(null)\n setAgreed(false)\n enqueueSnackbar(enabled ? '4G is on for this store’s S710 readers' : '4G is off for this store', {\n variant: 'success',\n persist: false,\n })\n await onChanged()\n } catch (error) {\n enqueueSnackbar(error instanceof PosRequestError ? error.message : '4G could not be changed. Try again.', {\n variant: 'warning',\n persist: false,\n })\n } finally {\n setBusy(false)\n }\n }\n\n return (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 1 }}>\n <Box sx={{ flex: 1, minWidth: 220 }}>\n <Typography variant=\"body2\" sx={{ fontWeight: 'fontWeightMedium' }}>\n {'4G (cellular)'}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {cellular.enabled\n ? `On for every S710 reader at this store (${readersText(cellular.readers)} now). Each is charged ${price} a month.`\n : `An S710 reader can use 4G service when Wi-Fi drops. It turns on for every S710 at this store, at ${price} a month each.`}\n </Typography>\n </Box>\n <Chip size=\"small\" label={cellular.enabled ? 'On' : 'Off'} color={cellular.enabled ? 'success' : 'default'} />\n <BlockedControl blocked={Boolean(reason)} reason={reason ?? ''}>\n <Button size=\"small\" onClick={() => setDialog(cellular.enabled ? 'off' : 'on')}>\n {cellular.enabled ? 'Turn off 4G' : 'Turn on 4G'}\n </Button>\n </BlockedControl>\n {cellular.suspended ? (\n <Alert severity=\"warning\" sx={{ flexBasis: '100%' }}>\n {`4G was turned off because the 4G charge for ${cellular.suspended.month} wasn't paid. Pay it on the Billing page, then turn 4G on again here.`}\n </Alert>\n ) : null}\n\n <Dialog open={dialog === 'on'} onClose={() => (busy ? undefined : setDialog(null))} maxWidth=\"sm\" fullWidth>\n <DialogTitle>{'Turn on 4G for this store?'}</DialogTitle>\n <DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 1.5 }}>\n <Typography variant=\"body2\">\n {`Every S710 reader at this store gets 4G service and uses it whenever Wi-Fi and Ethernet are not available. That is ${readersText(cellular.readers)} now, and any S710 you add here later.`}\n </Typography>\n <Typography variant=\"body2\">\n {`Each S710 is charged ${price} a month, plus any sales tax, for every calendar month it has 4G. The charge goes to this workspace's card at the start of the next month. Turning 4G off stops the charge from the next month. If a month's charge isn't paid, 4G is turned off after a grace period, until it's paid and turned on again.`}\n </Typography>\n <FormControlLabel\n control={<Checkbox checked={agreed} onChange={(event) => setAgreed(event.target.checked)} />}\n label={`I agree to ${price} a month for each S710 reader at this store while 4G is on.`}\n />\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDialog(null)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy || !agreed} onClick={() => void change(true)}>\n {'Turn on 4G'}\n </Button>\n </DialogActions>\n </Dialog>\n\n <Dialog open={dialog === 'off'} onClose={() => (busy ? undefined : setDialog(null))} maxWidth=\"xs\" fullWidth>\n <DialogTitle>{'Turn off 4G?'}</DialogTitle>\n <DialogContent>\n <Typography variant=\"body2\">\n {'The S710 readers at this store stop using 4G the next time they connect, and use Wi-Fi or Ethernet only. This month is still charged for each reader that had 4G in it.'}\n </Typography>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDialog(null)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy} onClick={() => void change(false)}>\n {'Turn off 4G'}\n </Button>\n </DialogActions>\n </Dialog>\n </Stack>\n )\n}\nPosCellularControl.displayName = 'PosCellularControl'\n\nexport default PosCellularControl\n"],"names":["BlockedControl","useSnackbar","useUser","Alert","Box","Button","Checkbox","Chip","Dialog","DialogActions","DialogContent","DialogTitle","FormControlLabel","Stack","Typography","useState","posReadersCall","PosRequestError","usd","readersText","count","PosCellularControl","hostId","cellular","blocked","onChanged","data","user","enqueueSnackbar","dialog","setDialog","agreed","setAgreed","busy","setBusy","price","readerMonthlyCents","reason","enabled","turnOnBlocked","change","action","consent","variant","persist","error","message","direction","spacing","sx","alignItems","flexWrap","rowGap","flex","minWidth","fontWeight","color","component","readers","size","label","Boolean","onClick","suspended","severity","flexBasis","month","open","onClose","undefined","maxWidth","fullWidth","display","flexDirection","gap","control","checked","onChange","event","target","disabled","displayName"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,QAAQ,EACRC,IAAI,EACJC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,gBAAgB,EAChBC,KAAK,EACLC,UAAU,QACL,gBAAe;AACtB,SAASC,QAAQ,QAAQ,QAAO;AAEhC,SAASC,cAAc,EAAEC,eAAe,EAAEC,GAAG,QAAQ,mBAAe;AAWpE,MAAMC,cAAc,CAACC,QAAkB,GAAGA,MAAM,YAAY,EAAEA,UAAU,IAAI,KAAK,KAAK;AAEtF;;;;;;;;;;CAUC,GACD,OAAO,SAASC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,SAAS,EAA2B;QAQ5CF;IAPtD,MAAM,EAAEG,MAAMC,IAAI,EAAE,GAAGzB;IACvB,MAAM,EAAE0B,eAAe,EAAE,GAAG3B;IAC5B,MAAM,CAAC4B,QAAQC,UAAU,GAAGf,SAA8B;IAC1D,MAAM,CAACgB,QAAQC,UAAU,GAAGjB,SAAS;IACrC,MAAM,CAACkB,MAAMC,QAAQ,GAAGnB,SAAS;IACjC,MAAMoB,QAAQjB,IAAIK,SAASa,kBAAkB;IAC7C,iFAAiF;IACjF,MAAMC,SAASb,kBAAAA,UAAYD,SAASe,OAAO,GAAG,QAAQf,0BAAAA,SAASgB,aAAa,YAAtBhB,0BAA0B;IAEhF,MAAMiB,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;gCAAOkD,UAAU/C;0CAC/C;;0CAEH,KAAC5B;gCAAOsC,SAAQ;gCAAYqC,UAAU/C;gCAAM6B,SAAS,IAAM,KAAKtB,OAAO;0CACpE;;;;;;;;AAMb;AACAnB,mBAAmB4D,WAAW,GAAG;AAEjC,eAAe5D,mBAAkB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/pos-cellular-control.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\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 {\n Alert,\n Box,\n Button,\n Checkbox,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n FormControlLabel,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useState } from 'react'\nimport type { PosCellularView } from '../../model/pos-cellular'\nimport { posReadersCall, PosRequestError, usd } from './pos/pos-api'\n\nexport interface PosCellularControlProps {\n hostId: string\n cellular: PosCellularView\n /** Why the viewer may not change it (\"Registers and devices\"), or null. */\n blocked: string | null\n /** Reload the card once it changed. */\n onChanged: () => void | Promise<void>\n}\n\nconst readersText = (count: number) => `${count} S710 reader${count === 1 ? '' : 's'}`\n\n/**\n * 4G for a store's S710 readers (AGL-4038), on the POS devices card.\n * Stripe turns cellular service on for a store's reader Location, so this is\n * one switch for the store: it says plainly that every S710 at the store\n * gets 4G and that each one is charged, and turning it on takes an explicit\n * agreement to the monthly price. Turning it ON is charged to the workspace,\n * so it also takes \"Manage billing\": without it the control says so rather\n * than hiding. A store whose 4G was turned off for an unpaid month says\n * which, and how to turn it back on. Loaded only where 4G is offered and the\n * store has an S710.\n *\n * A store on its own Stripe account is billed for 4G by Stripe, on that\n * account, and never by the workspace: the row names no price (the only one\n * known here is the platform's), turning it on asks for no agreement and no\n * \"Manage billing\", and it says who bills it instead.\n */\nexport function PosCellularControl({ hostId, cellular, blocked, onChanged }: PosCellularControlProps) {\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const [dialog, setDialog] = useState<'on' | 'off' | null>(null)\n const [agreed, setAgreed] = useState(false)\n const [busy, setBusy] = useState(false)\n const ownAccount = cellular.ownAccount === true\n const price = cellular.readerMonthlyCents === null ? '' : usd(cellular.readerMonthlyCents)\n // Off needs only the card's key; on is charged to the workspace, so billing too.\n const reason = blocked ?? (cellular.enabled ? null : (cellular.turnOnBlocked ?? null))\n const caption = ownAccount\n ? cellular.enabled\n ? `On for every S710 reader at this store (${readersText(cellular.readers)} now). Stripe bills its 4G price for each one to this store’s own Stripe account.`\n : 'An S710 reader can use 4G service when Wi-Fi drops. It turns on for every S710 at this store, and Stripe bills its 4G price for each one to this store’s own Stripe account.'\n : cellular.enabled\n ? `On for every S710 reader at this store (${readersText(cellular.readers)} now). Each is charged ${price} a month.`\n : `An S710 reader can use 4G service when Wi-Fi drops. It turns on for every S710 at this store, at ${price} a month each.`\n\n const change = async (enabled: boolean) => {\n if (!user) return\n setBusy(true)\n try {\n await posReadersCall(user, {\n action: 'cellular',\n hostId,\n enabled,\n ...(enabled && !ownAccount ? { consent: agreed } : {}),\n })\n setDialog(null)\n setAgreed(false)\n enqueueSnackbar(enabled ? '4G is on for this store’s S710 readers' : '4G is off for this store', {\n variant: 'success',\n persist: false,\n })\n await onChanged()\n } catch (error) {\n enqueueSnackbar(error instanceof PosRequestError ? error.message : '4G could not be changed. Try again.', {\n variant: 'warning',\n persist: false,\n })\n } finally {\n setBusy(false)\n }\n }\n\n return (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 1 }}>\n <Box sx={{ flex: 1, minWidth: 220 }}>\n <Typography variant=\"body2\" sx={{ fontWeight: 'fontWeightMedium' }}>\n {'4G (cellular)'}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {caption}\n </Typography>\n </Box>\n <Chip size=\"small\" label={cellular.enabled ? 'On' : 'Off'} color={cellular.enabled ? 'success' : 'default'} />\n <BlockedControl blocked={Boolean(reason)} reason={reason ?? ''}>\n <Button size=\"small\" onClick={() => setDialog(cellular.enabled ? 'off' : 'on')}>\n {cellular.enabled ? 'Turn off 4G' : 'Turn on 4G'}\n </Button>\n </BlockedControl>\n {cellular.suspended ? (\n <Alert severity=\"warning\" sx={{ flexBasis: '100%' }}>\n {`4G was turned off because the 4G charge for ${cellular.suspended.month} wasn't paid. Pay it on the Billing page, then turn 4G on again here.`}\n </Alert>\n ) : null}\n\n <Dialog open={dialog === 'on'} onClose={() => (busy ? undefined : setDialog(null))} maxWidth=\"sm\" fullWidth>\n <DialogTitle>{'Turn on 4G for this store?'}</DialogTitle>\n <DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 1.5 }}>\n <Typography variant=\"body2\">\n {`Every S710 reader at this store gets 4G service and uses it whenever Wi-Fi and Ethernet are not available. That is ${readersText(cellular.readers)} now, and any S710 you add here later.`}\n </Typography>\n {ownAccount ? (\n <Typography variant=\"body2\">\n {'Stripe bills its 4G price for each S710 to this store’s own Stripe account, under the store’s agreement with Stripe, for every calendar month it has 4G. This workspace is not charged for it. Turning 4G off stops it from the next month.'}\n </Typography>\n ) : (\n <>\n <Typography variant=\"body2\">\n {`Each S710 is charged ${price} a month, plus any sales tax, for every calendar month it has 4G. The charge goes to this workspace's card at the start of the next month. Turning 4G off stops the charge from the next month. If a month's charge isn't paid, 4G is turned off after a grace period, until it's paid and turned on again.`}\n </Typography>\n <FormControlLabel\n control={<Checkbox checked={agreed} onChange={(event) => setAgreed(event.target.checked)} />}\n label={`I agree to ${price} a month for each S710 reader at this store while 4G is on.`}\n />\n </>\n )}\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDialog(null)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy || (!ownAccount && !agreed)} onClick={() => void change(true)}>\n {'Turn on 4G'}\n </Button>\n </DialogActions>\n </Dialog>\n\n <Dialog open={dialog === 'off'} onClose={() => (busy ? undefined : setDialog(null))} maxWidth=\"xs\" fullWidth>\n <DialogTitle>{'Turn off 4G?'}</DialogTitle>\n <DialogContent>\n <Typography variant=\"body2\">\n {ownAccount\n ? 'The S710 readers at this store stop using 4G the next time they connect, and use Wi-Fi or Ethernet only. Stripe still bills this month for each reader that had 4G in it.'\n : 'The S710 readers at this store stop using 4G the next time they connect, and use Wi-Fi or Ethernet only. This month is still charged for each reader that had 4G in it.'}\n </Typography>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDialog(null)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy} onClick={() => void change(false)}>\n {'Turn off 4G'}\n </Button>\n </DialogActions>\n </Dialog>\n </Stack>\n )\n}\nPosCellularControl.displayName = 'PosCellularControl'\n\nexport default PosCellularControl\n"],"names":["BlockedControl","useSnackbar","useUser","Alert","Box","Button","Checkbox","Chip","Dialog","DialogActions","DialogContent","DialogTitle","FormControlLabel","Stack","Typography","useState","posReadersCall","PosRequestError","usd","readersText","count","PosCellularControl","hostId","cellular","blocked","onChanged","data","user","enqueueSnackbar","dialog","setDialog","agreed","setAgreed","busy","setBusy","ownAccount","price","readerMonthlyCents","reason","enabled","turnOnBlocked","caption","readers","change","action","consent","variant","persist","error","message","direction","spacing","sx","alignItems","flexWrap","rowGap","flex","minWidth","fontWeight","color","component","size","label","Boolean","onClick","suspended","severity","flexBasis","month","open","onClose","undefined","maxWidth","fullWidth","display","flexDirection","gap","control","checked","onChange","event","target","dis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BAAWgC,SAAQ;sCACjBX,aACG,8KACA;;;kCAGR,MAAC1B;;0CACC,KAACJ;gCAAO2D,SAAS,IAAMlC,UAAU;gCAAOoD,UAAUjD;0CAC/C;;0CAEH,KAAC5B;gCAAOyC,SAAQ;gCAAYoC,UAAUjD;gCAAM+B,SAAS,IAAM,KAAKrB,OAAO;0CACpE;;;;;;;;AAMb;AACAtB,mBAAmB8D,WAAW,GAAG;AAEjC,eAAe9D,mBAAkB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as CommerceModel from '../../model';
|
|
2
|
+
import { type ProductMediaPick } from './product-builder-fields.component';
|
|
2
3
|
type Patch = Partial<CommerceModel.HostProduct>;
|
|
3
4
|
export interface ProductAddOnsFieldsProps {
|
|
4
5
|
modifierGroups: readonly CommerceModel.ProductModifierGroup[];
|
|
@@ -7,6 +8,8 @@ export interface ProductAddOnsFieldsProps {
|
|
|
7
8
|
/** The product's variants, each of which a choice may be priced on. */
|
|
8
9
|
variants: readonly Pick<CommerceModel.ProductVariant, 'id' | 'options'>[];
|
|
9
10
|
update: (patch: Patch) => void;
|
|
11
|
+
/** Opens the media browser for a choice's picture (AGL-4205); without it, no picture is chosen. */
|
|
12
|
+
pick?: ProductMediaPick;
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
15
|
* What a choice's per-variant prices are called (AGL-4100): by the one
|
|
@@ -22,6 +25,16 @@ export declare function newAddOnGroup(): CommerceModel.ProductModifierGroup;
|
|
|
22
25
|
* which refuses one).
|
|
23
26
|
*/
|
|
24
27
|
export declare function withVariantPrice(option: CommerceModel.ProductModifierOption, variantId: string, raw: string): CommerceModel.ProductModifierOption;
|
|
28
|
+
/**
|
|
29
|
+
* A choice with its card changed (AGL-4205): its picture, its note, or what
|
|
30
|
+
* it includes as a combo, typed one item per line. A cleared field is
|
|
31
|
+
* dropped, never stored as `undefined`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function withChoiceCard(option: CommerceModel.ProductModifierOption, patch: {
|
|
34
|
+
imageUrl?: string | null;
|
|
35
|
+
note?: string | null;
|
|
36
|
+
includes?: string | null;
|
|
37
|
+
}): CommerceModel.ProductModifierOption;
|
|
25
38
|
/**
|
|
26
39
|
* The product's add-ons (AGL-4100, from the register's modifiers of
|
|
27
40
|
* AGL-3607): choices added to the item that are not stocked variants — walls
|
|
@@ -20,6 +20,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
20
20
|
import { Box, Button, Collapse, FormControlLabel, IconButton, Stack, Switch, TextField, Typography } from "@mui/material";
|
|
21
21
|
import { memo, useCallback, useId, useState } from "react";
|
|
22
22
|
import * as CommerceModel from "../../model/index.js";
|
|
23
|
+
import { PRODUCT_CHOICE_NOTE_MAX, PRODUCT_COMBO_ITEM_MAX, PRODUCT_COMBO_MAX_ITEMS } from "../../model/product-card-rules.js";
|
|
24
|
+
import { CardPictureField } from "./product-builder-fields.component.js";
|
|
23
25
|
function newId(prefix) {
|
|
24
26
|
return `${prefix}${Math.random().toString(36).slice(2, 10)}`;
|
|
25
27
|
}
|
|
@@ -72,6 +74,32 @@ function newId(prefix) {
|
|
|
72
74
|
priceCentsByVariant: next
|
|
73
75
|
}) : rest;
|
|
74
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* A choice with its card changed (AGL-4205): its picture, its note, or what
|
|
79
|
+
* it includes as a combo, typed one item per line. A cleared field is
|
|
80
|
+
* dropped, never stored as `undefined`.
|
|
81
|
+
*/ export function withChoiceCard(option, patch) {
|
|
82
|
+
const next = _extends({}, option);
|
|
83
|
+
if ('imageUrl' in patch) {
|
|
84
|
+
var _patch_imageUrl;
|
|
85
|
+
const url = String((_patch_imageUrl = patch.imageUrl) != null ? _patch_imageUrl : '').trim();
|
|
86
|
+
if (url) next.imageUrl = url;
|
|
87
|
+
else delete next.imageUrl;
|
|
88
|
+
}
|
|
89
|
+
if ('note' in patch) {
|
|
90
|
+
var _patch_note;
|
|
91
|
+
const note = String((_patch_note = patch.note) != null ? _patch_note : '').trim().slice(0, PRODUCT_CHOICE_NOTE_MAX);
|
|
92
|
+
if (note) next.note = note;
|
|
93
|
+
else delete next.note;
|
|
94
|
+
}
|
|
95
|
+
if ('includes' in patch) {
|
|
96
|
+
var _patch_includes;
|
|
97
|
+
const items = String((_patch_includes = patch.includes) != null ? _patch_includes : '').split('\n').map((item)=>item.trim().slice(0, PRODUCT_COMBO_ITEM_MAX)).filter(Boolean).slice(0, PRODUCT_COMBO_MAX_ITEMS);
|
|
98
|
+
if (items.length) next.includes = items;
|
|
99
|
+
else delete next.includes;
|
|
100
|
+
}
|
|
101
|
+
return next;
|
|
102
|
+
}
|
|
75
103
|
/**
|
|
76
104
|
* The product's add-ons (AGL-4100, from the register's modifiers of
|
|
77
105
|
* AGL-3607): choices added to the item that are not stocked variants — walls
|
|
@@ -85,9 +113,10 @@ function newId(prefix) {
|
|
|
85
113
|
* the product, so editing it takes exactly what editing the product takes.
|
|
86
114
|
* Memoized on its own props like every section of this editor (AGL-3423).
|
|
87
115
|
*/ export const ProductAddOnsFields = /*#__PURE__*/ memo(function ProductAddOnsFields(props) {
|
|
88
|
-
const { modifierGroups, options, variants, update } = props;
|
|
116
|
+
const { modifierGroups, options, variants, update, pick } = props;
|
|
89
117
|
const helpId = useId();
|
|
90
118
|
const [pricedByVariant, setPricedByVariant] = useState({});
|
|
119
|
+
const [cardOpen, setCardOpen] = useState({});
|
|
91
120
|
const setGroups = useCallback((groups)=>update({
|
|
92
121
|
modifierGroups: groups
|
|
93
122
|
}), [
|
|
@@ -201,9 +230,13 @@ function newId(prefix) {
|
|
|
201
230
|
children: group.online === true ? 'Offered on the product’s page and at the register.' : 'Offered at the register only.'
|
|
202
231
|
}),
|
|
203
232
|
group.options.map((option, optionIndex)=>{
|
|
204
|
-
var _pricedByVariant_optionKey, _option_priceCentsByVariant;
|
|
233
|
+
var _pricedByVariant_optionKey, _option_priceCentsByVariant, _cardOpen_optionKey, _option_note;
|
|
234
|
+
var _option_includes;
|
|
205
235
|
const optionKey = `${group.id}:${option.id}`;
|
|
206
236
|
const byVariantOpen = (_pricedByVariant_optionKey = pricedByVariant[optionKey]) != null ? _pricedByVariant_optionKey : Object.keys((_option_priceCentsByVariant = option.priceCentsByVariant) != null ? _option_priceCentsByVariant : {}).length > 0;
|
|
237
|
+
const hasCard = Boolean(option.imageUrl || option.note || ((_option_includes = option.includes) == null ? void 0 : _option_includes.length));
|
|
238
|
+
const cardShown = (_cardOpen_optionKey = cardOpen[optionKey]) != null ? _cardOpen_optionKey : hasCard;
|
|
239
|
+
const choiceLabel = option.name || 'this choice';
|
|
207
240
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
208
241
|
children: [
|
|
209
242
|
/*#__PURE__*/ _jsxs(Stack, {
|
|
@@ -252,6 +285,14 @@ function newId(prefix) {
|
|
|
252
285
|
})),
|
|
253
286
|
children: byLabel
|
|
254
287
|
}) : null,
|
|
288
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
289
|
+
size: "small",
|
|
290
|
+
"aria-expanded": cardShown,
|
|
291
|
+
onClick: ()=>setCardOpen((open)=>_extends({}, open, {
|
|
292
|
+
[optionKey]: !cardShown
|
|
293
|
+
})),
|
|
294
|
+
children: 'Picture & combo'
|
|
295
|
+
}),
|
|
255
296
|
/*#__PURE__*/ _jsx(IconButton, {
|
|
256
297
|
"aria-label": `Remove ${option.name || 'choice'}`,
|
|
257
298
|
onClick: ()=>editGroup(groupIndex, {
|
|
@@ -304,7 +345,59 @@ function newId(prefix) {
|
|
|
304
345
|
})
|
|
305
346
|
]
|
|
306
347
|
})
|
|
307
|
-
}) : null
|
|
348
|
+
}) : null,
|
|
349
|
+
/*#__PURE__*/ _jsx(Collapse, {
|
|
350
|
+
in: cardShown,
|
|
351
|
+
unmountOnExit: true,
|
|
352
|
+
children: /*#__PURE__*/ _jsxs(Stack, {
|
|
353
|
+
spacing: 1,
|
|
354
|
+
sx: {
|
|
355
|
+
pl: 2,
|
|
356
|
+
pt: 1.5
|
|
357
|
+
},
|
|
358
|
+
children: [
|
|
359
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
360
|
+
variant: "caption",
|
|
361
|
+
color: "text.secondary",
|
|
362
|
+
children: `What “${choiceLabel}” shows on its picture card. List what it includes to make it ` + 'a combo: shoppers can open the list on its card.'
|
|
363
|
+
}),
|
|
364
|
+
/*#__PURE__*/ _jsx(CardPictureField, {
|
|
365
|
+
imageUrl: option.imageUrl,
|
|
366
|
+
label: choiceLabel,
|
|
367
|
+
pick: pick,
|
|
368
|
+
onChange: (imageUrl)=>replaceOption(groupIndex, optionIndex, withChoiceCard(modifierGroups[groupIndex].options[optionIndex], {
|
|
369
|
+
imageUrl
|
|
370
|
+
}))
|
|
371
|
+
}),
|
|
372
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
373
|
+
label: "Note",
|
|
374
|
+
size: "small",
|
|
375
|
+
defaultValue: (_option_note = option.note) != null ? _option_note : '',
|
|
376
|
+
placeholder: "Blocks wind on one side",
|
|
377
|
+
onBlur: (event)=>replaceOption(groupIndex, optionIndex, withChoiceCard(modifierGroups[groupIndex].options[optionIndex], {
|
|
378
|
+
note: event.target.value
|
|
379
|
+
})),
|
|
380
|
+
slotProps: {
|
|
381
|
+
htmlInput: {
|
|
382
|
+
maxLength: PRODUCT_CHOICE_NOTE_MAX
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}),
|
|
386
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
387
|
+
label: "Combo: what it includes",
|
|
388
|
+
size: "small",
|
|
389
|
+
multiline: true,
|
|
390
|
+
minRows: 2,
|
|
391
|
+
defaultValue: Array.isArray(option.includes) ? option.includes.join('\n') : '',
|
|
392
|
+
placeholder: 'Full wall ×2\nSteel weights ×4\nRoller bag',
|
|
393
|
+
helperText: `One item per line, up to ${PRODUCT_COMBO_MAX_ITEMS}. Leave it empty for a single choice.`,
|
|
394
|
+
onBlur: (event)=>replaceOption(groupIndex, optionIndex, withChoiceCard(modifierGroups[groupIndex].options[optionIndex], {
|
|
395
|
+
includes: event.target.value
|
|
396
|
+
}))
|
|
397
|
+
})
|
|
398
|
+
]
|
|
399
|
+
})
|
|
400
|
+
})
|
|
308
401
|
]
|
|
309
402
|
}, option.id);
|
|
310
403
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/product-add-ons-fields.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 {\n Box,\n Button,\n Collapse,\n FormControlLabel,\n IconButton,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { memo, useCallback, useId, useState } from 'react'\nimport * as CommerceModel from '../../model'\n\ntype Patch = Partial<CommerceModel.HostProduct>\n\nexport interface ProductAddOnsFieldsProps {\n modifierGroups: readonly CommerceModel.ProductModifierGroup[]\n /** The product's options, to name what a choice is priced by. */\n options: readonly CommerceModel.ProductOption[]\n /** The product's variants, each of which a choice may be priced on. */\n variants: readonly Pick<CommerceModel.ProductVariant, 'id' | 'options'>[]\n update: (patch: Patch) => void\n}\n\nfunction newId(prefix: string): string {\n return `${prefix}${Math.random().toString(36).slice(2, 10)}`\n}\n\n/** Dollars as typed, to whole cents; blank is free. */\nfunction centsFromDollars(value: string): number {\n const number = Math.round(Number(String(value).replace(/[^0-9.]/g, '')) * 100)\n return Number.isFinite(number) && number > 0 ? number : 0\n}\n\n/** Cents as the price field shows them; blank for free. */\nfunction dollarsFromCents(cents: number | undefined): string {\n return cents ? (cents / 100).toFixed(2) : ''\n}\n\n/**\n * What a choice's per-variant prices are called (AGL-4100): by the one\n * option a product varies by (\"Price by size\"), else by variant.\n */\nexport function priceByLabel(options: readonly Pick<CommerceModel.ProductOption, 'name'>[]): string {\n const named = options.filter((option) => option.name?.trim())\n return named.length === 1 ? `Price by ${named[0].name.trim().toLowerCase()}` : 'Price by variant'\n}\n\n/** A new group, as the console makes it from now on: shown on the website (AGL-4100). */\nexport function newAddOnGroup(): CommerceModel.ProductModifierGroup {\n return {\n id: newId('g'),\n name: '',\n min: 0,\n max: 1,\n online: true,\n options: [{ id: newId('o'), name: '', priceCents: 0 }],\n }\n}\n\n/**\n * A choice's prices by variant with one variant's price set or cleared. A\n * cleared price follows the choice's own; with none left the field is\n * dropped, never stored as `undefined` (the save is a client-direct write,\n * which refuses one).\n */\nexport function withVariantPrice(\n option: CommerceModel.ProductModifierOption,\n variantId: string,\n raw: string,\n): CommerceModel.ProductModifierOption {\n const { priceCentsByVariant, ...rest } = option\n const next = { ...(priceCentsByVariant ?? {}) }\n if (raw.trim() === '') delete next[variantId]\n else next[variantId] = centsFromDollars(raw)\n return Object.keys(next).length ? { ...rest, priceCentsByVariant: next } : rest\n}\n\n/**\n * The product's add-ons (AGL-4100, from the register's modifiers of\n * AGL-3607): choices added to the item that are not stocked variants — walls\n * and printing on a canopy, a milk in a latte — each free or adding to the\n * price, and able to cost more on one variant than another. A group with a\n * minimum of 1 or more must be answered before the item is added. Each group\n * says whether the website's product page offers it; the register always\n * does.\n *\n * Offered on every store, with or without the point of sale, and saved with\n * the product, so editing it takes exactly what editing the product takes.\n * Memoized on its own props like every section of this editor (AGL-3423).\n */\nexport const ProductAddOnsFields = memo(function ProductAddOnsFields(\n props: ProductAddOnsFieldsProps,\n) {\n const { modifierGroups, options, variants, update } = props\n const helpId = useId()\n const [pricedByVariant, setPricedByVariant] = useState<Record<string, boolean>>({})\n const setGroups = useCallback(\n (groups: CommerceModel.ProductModifierGroup[]) => update({ modifierGroups: groups }),\n [update],\n )\n const editGroup = (index: number, patch: Partial<CommerceModel.ProductModifierGroup>) =>\n setGroups(modifierGroups.map((group, at) => (at === index ? { ...group, ...patch } : group)))\n const replaceOption = (\n groupIndex: number,\n optionIndex: number,\n next: CommerceModel.ProductModifierOption,\n ) => {\n const group = modifierGroups[groupIndex]\n editGroup(groupIndex, {\n options: group.options.map((option, at) => (at === optionIndex ? next : option)),\n })\n }\n const editOption = (\n groupIndex: number,\n optionIndex: number,\n patch: Partial<CommerceModel.ProductModifierOption>,\n ) => replaceOption(groupIndex, optionIndex, { ...modifierGroups[groupIndex].options[optionIndex], ...patch })\n const problem = CommerceModel.modifierGroupsProblem(modifierGroups)\n const variesByVariant = variants.length > 1\n const byLabel = priceByLabel(options)\n\n return (\n <Stack spacing={2}>\n <Typography id={helpId} variant=\"body2\" color=\"text.secondary\">\n {'Add-ons are choices added to the item that don’t need their own stock, such as walls or ' +\n 'printing on a canopy, or a milk in a latte. Each can be free or add to the price, and can ' +\n 'cost more on a larger size. Show a group on the website to offer it on the product’s page; ' +\n 'the register offers every group.'}\n </Typography>\n {modifierGroups.map((group, groupIndex) => (\n <Box\n key={group.id}\n role=\"group\"\n aria-label={group.name || 'Add-on group'}\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 2 }}\n >\n <Stack spacing={1.5}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'flex-start', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Group name\"\n size=\"small\"\n value={group.name}\n onChange={(event) => editGroup(groupIndex, { name: event.target.value })}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"At least\"\n size=\"small\"\n value={group.min}\n onChange={(event) =>\n editGroup(groupIndex, { min: Math.max(0, Math.round(Number(event.target.value) || 0)) })\n }\n helperText={group.min > 0 ? 'Required' : 'Optional'}\n sx={{ width: (theme) => theme.spacing(12) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <TextField\n label=\"At most\"\n size=\"small\"\n value={group.max}\n onChange={(event) =>\n editGroup(groupIndex, { max: Math.max(1, Math.round(Number(event.target.value) || 1)) })\n }\n sx={{ width: (theme) => theme.spacing(12) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <Button\n color=\"error\"\n onClick={() => setGroups(modifierGroups.filter((_group, at) => at !== groupIndex))}\n >\n {'Remove group'}\n </Button>\n </Stack>\n <FormControlLabel\n control={\n <Switch\n checked={group.online === true}\n onChange={(event) => editGroup(groupIndex, { online: event.target.checked })}\n />\n }\n label=\"Show on the website\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {group.online === true\n ? 'Offered on the product’s page and at the register.'\n : 'Offered at the register only.'}\n </Typography>\n {group.options.map((option, optionIndex) => {\n const optionKey = `${group.id}:${option.id}`\n const byVariantOpen =\n pricedByVariant[optionKey] ?? Object.keys(option.priceCentsByVariant ?? {}).length > 0\n return (\n <Box key={option.id}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Choice\"\n size=\"small\"\n value={option.name}\n onChange={(event) => editOption(groupIndex, optionIndex, { name: event.target.value })}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"Adds ($)\"\n size=\"small\"\n defaultValue={dollarsFromCents(option.priceCents)}\n placeholder=\"0.00\"\n onBlur={(event) =>\n editOption(groupIndex, optionIndex, { priceCents: centsFromDollars(event.target.value) })\n }\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {variesByVariant ? (\n <Button\n size=\"small\"\n aria-expanded={byVariantOpen}\n onClick={() =>\n setPricedByVariant((open) => ({ ...open, [optionKey]: !byVariantOpen }))\n }\n >\n {byLabel}\n </Button>\n ) : null}\n <IconButton\n aria-label={`Remove ${option.name || 'choice'}`}\n onClick={() =>\n editGroup(groupIndex, {\n options: group.options.filter((_option, at) => at !== optionIndex),\n max: Math.max(1, Math.min(group.max, group.options.length - 1)),\n })\n }\n >\n {'✕'}\n </IconButton>\n </Stack>\n {variesByVariant ? (\n <Collapse in={byVariantOpen} unmountOnExit>\n <Stack spacing={1} sx={{ pl: 2, pt: 1.5 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`What “${option.name || 'this choice'}” adds on each. Leave one blank to use ` +\n 'the price above.'}\n </Typography>\n <Box\n sx={{\n display: 'grid',\n gridTemplateColumns: { xs: '1fr', sm: 'repeat(2, minmax(0, 1fr))' },\n gap: 1,\n }}\n >\n {variants.map((variant) => (\n <TextField\n key={variant.id}\n label={CommerceModel.variantPriceLabel(variant)}\n size=\"small\"\n defaultValue={dollarsFromCents(option.priceCentsByVariant?.[variant.id])}\n placeholder={dollarsFromCents(option.priceCents) || '0.00'}\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withVariantPrice(\n modifierGroups[groupIndex].options[optionIndex],\n variant.id,\n event.target.value,\n ),\n )\n }\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ))}\n </Box>\n </Stack>\n </Collapse>\n ) : null}\n </Box>\n )\n })}\n <Box>\n <Button\n onClick={() =>\n editGroup(groupIndex, {\n options: [...group.options, { id: newId('o'), name: '', priceCents: 0 }],\n })\n }\n disabled={group.options.length >= CommerceModel.POS_MAX_MODIFIER_OPTIONS}\n >\n {'Add choice'}\n </Button>\n </Box>\n </Stack>\n </Box>\n ))}\n <Box>\n <Button\n variant=\"outlined\"\n aria-describedby={helpId}\n onClick={() => setGroups([...modifierGroups, newAddOnGroup()])}\n disabled={modifierGroups.length >= CommerceModel.POS_MAX_MODIFIER_GROUPS}\n >\n {'New add-on group'}\n </Button>\n </Box>\n {problem && modifierGroups.length ? (\n <Typography variant=\"body2\" color=\"warning.main\">\n {problem}\n </Typography>\n ) : null}\n </Stack>\n )\n})\n"],"names":["Box","Button","Collapse","FormControlLabel","IconButton","Stack","Switch","TextField","Typography","memo","useCallback","useId","useState","CommerceModel","newId","prefix","Math","random","toString","slice","centsFromDollars","value","number","round","Number","String","replace","isFinite","dollarsFromCents","cents","toFixed","priceByLabel","options","named","filter","option","name","trim","length","toLowerCase","newAddOnGroup","id","min","max","online","priceCents","withVariantPrice","variantId","raw","priceCentsByVariant","rest","next","Object","keys","ProductAddOnsFields","props","modifierGroups","variants","update","helpId","pricedByVariant","setPricedByVariant","setGroups","groups","editGroup","index","patch","map","group","at","replaceOption","groupIndex","optionIndex","editOption","problem","modifierGroupsProblem","variesByVariant","byLabel","spacing","variant","color","role","aria-label","sx","border","borderColor","borderRadius","p","direction","alignItems","flexWrap","rowGap","label","size","onChange","event","target","flex","minWidth","theme","helperText","width","slotProps","htmlInput","inputMode","onClick","_group","control","checked","optionKey","byVariantOpen","defaultValue","placeholder","onBlur","aria-expanded","open","_option","in","unmountOnExit","pl","pt","display","gridTemplateColumns","xs","sm","gap","variantPriceLabel","disabled","POS_MAX_MODIFIER_OPTIONS","aria-describedby","POS_MAX_MODIFIER_GROUPS"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;;AAEA,SACEA,GAAG,EACHC,MAAM,EACNC,QAAQ,EACRC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,IAAI,EAAEC,WAAW,EAAEC,KAAK,EAAEC,QAAQ,QAAQ,QAAO;AAC1D,YAAYC,mBAAmB,uBAAa;AAa5C,SAASC,MAAMC,MAAc;IAC3B,OAAO,GAAGA,SAASC,KAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,KAAK,CAAC,GAAG,KAAK;AAC9D;AAEA,qDAAqD,GACrD,SAASC,iBAAiBC,KAAa;IACrC,MAAMC,SAASN,KAAKO,KAAK,CAACC,OAAOC,OAAOJ,OAAOK,OAAO,CAAC,YAAY,OAAO;IAC1E,OAAOF,OAAOG,QAAQ,CAACL,WAAWA,SAAS,IAAIA,SAAS;AAC1D;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C3E,KAAK;gEAIxBiF,WAAW;oEAAEC,WAAW;wEAAEC,WAAW;oEAAU;gEAAE;+DAhB5CzB,QAAQtC,EAAE;;;;;6CAsBvB;;mCAjFIN,OAAOM,EAAE;4BAoFvB;0CACA,KAACzC;0CACC,cAAA,KAACC;oCACCwG,SAAS,IACPzC,UAAUO,YAAY;4CACpBvC,SAAS;mDAAIoC,MAAMpC,OAAO;gDAAE;oDAAES,IAAI3B,MAAM;oDAAMsB,MAAM;oDAAIS,YAAY;gDAAE;6CAAE;wCAC1E;oCAEFkF,UAAU3D,MAAMpC,OAAO,CAACM,MAAM,IAAIzB,cAAcmH,wBAAwB;8CAEvE;;;;;mBA3JF5D,MAAM3B,EAAE;0BAiKjB,KAACzC;0BACC,cAAA,KAACC;oBACC8E,SAAQ;oBACRkD,oBAAkBtE;oBAClB8C,SAAS,IAAM3C,UAAU;+BAAIN;4BAAgBhB;yBAAgB;oBAC7DuF,UAAUvE,eAAelB,MAAM,IAAIzB,cAAcqH,uBAAuB;8BAEvE;;;YAGJxD,WAAWlB,eAAelB,MAAM,iBAC/B,KAAC9B;gBAAWuE,SAAQ;gBAAQC,OAAM;0BAC/BN;iBAED;;;AAGV,GAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/product-add-ons-fields.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 {\n Box,\n Button,\n Collapse,\n FormControlLabel,\n IconButton,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { memo, useCallback, useId, useState } from 'react'\nimport * as CommerceModel from '../../model'\nimport { PRODUCT_CHOICE_NOTE_MAX, PRODUCT_COMBO_ITEM_MAX, PRODUCT_COMBO_MAX_ITEMS } from '../../model/product-card-rules'\nimport { CardPictureField, type ProductMediaPick } from './product-builder-fields.component'\n\ntype Patch = Partial<CommerceModel.HostProduct>\n\nexport interface ProductAddOnsFieldsProps {\n modifierGroups: readonly CommerceModel.ProductModifierGroup[]\n /** The product's options, to name what a choice is priced by. */\n options: readonly CommerceModel.ProductOption[]\n /** The product's variants, each of which a choice may be priced on. */\n variants: readonly Pick<CommerceModel.ProductVariant, 'id' | 'options'>[]\n update: (patch: Patch) => void\n /** Opens the media browser for a choice's picture (AGL-4205); without it, no picture is chosen. */\n pick?: ProductMediaPick\n}\n\nfunction newId(prefix: string): string {\n return `${prefix}${Math.random().toString(36).slice(2, 10)}`\n}\n\n/** Dollars as typed, to whole cents; blank is free. */\nfunction centsFromDollars(value: string): number {\n const number = Math.round(Number(String(value).replace(/[^0-9.]/g, '')) * 100)\n return Number.isFinite(number) && number > 0 ? number : 0\n}\n\n/** Cents as the price field shows them; blank for free. */\nfunction dollarsFromCents(cents: number | undefined): string {\n return cents ? (cents / 100).toFixed(2) : ''\n}\n\n/**\n * What a choice's per-variant prices are called (AGL-4100): by the one\n * option a product varies by (\"Price by size\"), else by variant.\n */\nexport function priceByLabel(options: readonly Pick<CommerceModel.ProductOption, 'name'>[]): string {\n const named = options.filter((option) => option.name?.trim())\n return named.length === 1 ? `Price by ${named[0].name.trim().toLowerCase()}` : 'Price by variant'\n}\n\n/** A new group, as the console makes it from now on: shown on the website (AGL-4100). */\nexport function newAddOnGroup(): CommerceModel.ProductModifierGroup {\n return {\n id: newId('g'),\n name: '',\n min: 0,\n max: 1,\n online: true,\n options: [{ id: newId('o'), name: '', priceCents: 0 }],\n }\n}\n\n/**\n * A choice's prices by variant with one variant's price set or cleared. A\n * cleared price follows the choice's own; with none left the field is\n * dropped, never stored as `undefined` (the save is a client-direct write,\n * which refuses one).\n */\nexport function withVariantPrice(\n option: CommerceModel.ProductModifierOption,\n variantId: string,\n raw: string,\n): CommerceModel.ProductModifierOption {\n const { priceCentsByVariant, ...rest } = option\n const next = { ...(priceCentsByVariant ?? {}) }\n if (raw.trim() === '') delete next[variantId]\n else next[variantId] = centsFromDollars(raw)\n return Object.keys(next).length ? { ...rest, priceCentsByVariant: next } : rest\n}\n\n/**\n * A choice with its card changed (AGL-4205): its picture, its note, or what\n * it includes as a combo, typed one item per line. A cleared field is\n * dropped, never stored as `undefined`.\n */\nexport function withChoiceCard(\n option: CommerceModel.ProductModifierOption,\n patch: { imageUrl?: string | null; note?: string | null; includes?: string | null },\n): CommerceModel.ProductModifierOption {\n const next: CommerceModel.ProductModifierOption = { ...option }\n if ('imageUrl' in patch) {\n const url = String(patch.imageUrl ?? '').trim()\n if (url) next.imageUrl = url\n else delete next.imageUrl\n }\n if ('note' in patch) {\n const note = String(patch.note ?? '').trim().slice(0, PRODUCT_CHOICE_NOTE_MAX)\n if (note) next.note = note\n else delete next.note\n }\n if ('includes' in patch) {\n const items = String(patch.includes ?? '')\n .split('\\n')\n .map((item) => item.trim().slice(0, PRODUCT_COMBO_ITEM_MAX))\n .filter(Boolean)\n .slice(0, PRODUCT_COMBO_MAX_ITEMS)\n if (items.length) next.includes = items\n else delete next.includes\n }\n return next\n}\n\n/**\n * The product's add-ons (AGL-4100, from the register's modifiers of\n * AGL-3607): choices added to the item that are not stocked variants — walls\n * and printing on a canopy, a milk in a latte — each free or adding to the\n * price, and able to cost more on one variant than another. A group with a\n * minimum of 1 or more must be answered before the item is added. Each group\n * says whether the website's product page offers it; the register always\n * does.\n *\n * Offered on every store, with or without the point of sale, and saved with\n * the product, so editing it takes exactly what editing the product takes.\n * Memoized on its own props like every section of this editor (AGL-3423).\n */\nexport const ProductAddOnsFields = memo(function ProductAddOnsFields(\n props: ProductAddOnsFieldsProps,\n) {\n const { modifierGroups, options, variants, update, pick } = props\n const helpId = useId()\n const [pricedByVariant, setPricedByVariant] = useState<Record<string, boolean>>({})\n const [cardOpen, setCardOpen] = useState<Record<string, boolean>>({})\n const setGroups = useCallback(\n (groups: CommerceModel.ProductModifierGroup[]) => update({ modifierGroups: groups }),\n [update],\n )\n const editGroup = (index: number, patch: Partial<CommerceModel.ProductModifierGroup>) =>\n setGroups(modifierGroups.map((group, at) => (at === index ? { ...group, ...patch } : group)))\n const replaceOption = (\n groupIndex: number,\n optionIndex: number,\n next: CommerceModel.ProductModifierOption,\n ) => {\n const group = modifierGroups[groupIndex]\n editGroup(groupIndex, {\n options: group.options.map((option, at) => (at === optionIndex ? next : option)),\n })\n }\n const editOption = (\n groupIndex: number,\n optionIndex: number,\n patch: Partial<CommerceModel.ProductModifierOption>,\n ) => replaceOption(groupIndex, optionIndex, { ...modifierGroups[groupIndex].options[optionIndex], ...patch })\n const problem = CommerceModel.modifierGroupsProblem(modifierGroups)\n const variesByVariant = variants.length > 1\n const byLabel = priceByLabel(options)\n\n return (\n <Stack spacing={2}>\n <Typography id={helpId} variant=\"body2\" color=\"text.secondary\">\n {'Add-ons are choices added to the item that don’t need their own stock, such as walls or ' +\n 'printing on a canopy, or a milk in a latte. Each can be free or add to the price, and can ' +\n 'cost more on a larger size. Show a group on the website to offer it on the product’s page; ' +\n 'the register offers every group.'}\n </Typography>\n {modifierGroups.map((group, groupIndex) => (\n <Box\n key={group.id}\n role=\"group\"\n aria-label={group.name || 'Add-on group'}\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 2 }}\n >\n <Stack spacing={1.5}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'flex-start', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Group name\"\n size=\"small\"\n value={group.name}\n onChange={(event) => editGroup(groupIndex, { name: event.target.value })}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"At least\"\n size=\"small\"\n value={group.min}\n onChange={(event) =>\n editGroup(groupIndex, { min: Math.max(0, Math.round(Number(event.target.value) || 0)) })\n }\n helperText={group.min > 0 ? 'Required' : 'Optional'}\n sx={{ width: (theme) => theme.spacing(12) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <TextField\n label=\"At most\"\n size=\"small\"\n value={group.max}\n onChange={(event) =>\n editGroup(groupIndex, { max: Math.max(1, Math.round(Number(event.target.value) || 1)) })\n }\n sx={{ width: (theme) => theme.spacing(12) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <Button\n color=\"error\"\n onClick={() => setGroups(modifierGroups.filter((_group, at) => at !== groupIndex))}\n >\n {'Remove group'}\n </Button>\n </Stack>\n <FormControlLabel\n control={\n <Switch\n checked={group.online === true}\n onChange={(event) => editGroup(groupIndex, { online: event.target.checked })}\n />\n }\n label=\"Show on the website\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {group.online === true\n ? 'Offered on the product’s page and at the register.'\n : 'Offered at the register only.'}\n </Typography>\n {group.options.map((option, optionIndex) => {\n const optionKey = `${group.id}:${option.id}`\n const byVariantOpen =\n pricedByVariant[optionKey] ?? Object.keys(option.priceCentsByVariant ?? {}).length > 0\n const hasCard = Boolean(option.imageUrl || option.note || option.includes?.length)\n const cardShown = cardOpen[optionKey] ?? hasCard\n const choiceLabel = option.name || 'this choice'\n return (\n <Box key={option.id}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Choice\"\n size=\"small\"\n value={option.name}\n onChange={(event) => editOption(groupIndex, optionIndex, { name: event.target.value })}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"Adds ($)\"\n size=\"small\"\n defaultValue={dollarsFromCents(option.priceCents)}\n placeholder=\"0.00\"\n onBlur={(event) =>\n editOption(groupIndex, optionIndex, { priceCents: centsFromDollars(event.target.value) })\n }\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {variesByVariant ? (\n <Button\n size=\"small\"\n aria-expanded={byVariantOpen}\n onClick={() =>\n setPricedByVariant((open) => ({ ...open, [optionKey]: !byVariantOpen }))\n }\n >\n {byLabel}\n </Button>\n ) : null}\n <Button\n size=\"small\"\n aria-expanded={cardShown}\n onClick={() => setCardOpen((open) => ({ ...open, [optionKey]: !cardShown }))}\n >\n {'Picture & combo'}\n </Button>\n <IconButton\n aria-label={`Remove ${option.name || 'choice'}`}\n onClick={() =>\n editGroup(groupIndex, {\n options: group.options.filter((_option, at) => at !== optionIndex),\n max: Math.max(1, Math.min(group.max, group.options.length - 1)),\n })\n }\n >\n {'✕'}\n </IconButton>\n </Stack>\n {variesByVariant ? (\n <Collapse in={byVariantOpen} unmountOnExit>\n <Stack spacing={1} sx={{ pl: 2, pt: 1.5 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`What “${option.name || 'this choice'}” adds on each. Leave one blank to use ` +\n 'the price above.'}\n </Typography>\n <Box\n sx={{\n display: 'grid',\n gridTemplateColumns: { xs: '1fr', sm: 'repeat(2, minmax(0, 1fr))' },\n gap: 1,\n }}\n >\n {variants.map((variant) => (\n <TextField\n key={variant.id}\n label={CommerceModel.variantPriceLabel(variant)}\n size=\"small\"\n defaultValue={dollarsFromCents(option.priceCentsByVariant?.[variant.id])}\n placeholder={dollarsFromCents(option.priceCents) || '0.00'}\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withVariantPrice(\n modifierGroups[groupIndex].options[optionIndex],\n variant.id,\n event.target.value,\n ),\n )\n }\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ))}\n </Box>\n </Stack>\n </Collapse>\n ) : null}\n <Collapse in={cardShown} unmountOnExit>\n <Stack spacing={1} sx={{ pl: 2, pt: 1.5 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`What “${choiceLabel}” shows on its picture card. List what it includes to make it ` +\n 'a combo: shoppers can open the list on its card.'}\n </Typography>\n <CardPictureField\n imageUrl={option.imageUrl}\n label={choiceLabel}\n pick={pick}\n onChange={(imageUrl) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withChoiceCard(modifierGroups[groupIndex].options[optionIndex], { imageUrl }),\n )\n }\n />\n <TextField\n label=\"Note\"\n size=\"small\"\n defaultValue={option.note ?? ''}\n placeholder=\"Blocks wind on one side\"\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withChoiceCard(modifierGroups[groupIndex].options[optionIndex], {\n note: event.target.value,\n }),\n )\n }\n slotProps={{ htmlInput: { maxLength: PRODUCT_CHOICE_NOTE_MAX } }}\n />\n <TextField\n label=\"Combo: what it includes\"\n size=\"small\"\n multiline\n minRows={2}\n defaultValue={Array.isArray(option.includes) ? option.includes.join('\\n') : ''}\n placeholder={'Full wall ×2\\nSteel weights ×4\\nRoller bag'}\n helperText={`One item per line, up to ${PRODUCT_COMBO_MAX_ITEMS}. Leave it empty for a single choice.`}\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withChoiceCard(modifierGroups[groupIndex].options[optionIndex], {\n includes: event.target.value,\n }),\n )\n }\n />\n </Stack>\n </Collapse>\n </Box>\n )\n })}\n <Box>\n <Button\n onClick={() =>\n editGroup(groupIndex, {\n options: [...group.options, { id: newId('o'), name: '', priceCents: 0 }],\n })\n }\n disabled={group.options.length >= CommerceModel.POS_MAX_MODIFIER_OPTIONS}\n >\n {'Add choice'}\n </Button>\n </Box>\n </Stack>\n </Box>\n ))}\n <Box>\n <Button\n variant=\"outlined\"\n aria-describedby={helpId}\n onClick={() => setGroups([...modifierGroups, newAddOnGroup()])}\n disabled={modifierGroups.length >= CommerceModel.POS_MAX_MODIFIER_GROUPS}\n >\n {'New add-on group'}\n </Button>\n </Box>\n {problem && modifierGroups.length ? (\n <Typography variant=\"body2\" color=\"warning.main\">\n {problem}\n </Typography>\n ) : null}\n </Stack>\n )\n})\n"],"names":["Box","Button","Collapse","FormControlLabel","IconButton","Stack","Switch","TextField","Typography","memo","useCallback","useId","useState","CommerceModel","PRODUCT_CHOICE_NOTE_MAX","PRODUCT_COMBO_ITEM_MAX","PRODUCT_COMBO_MAX_ITEMS","CardPictureField","newId","prefix","Math","random","toString","slice","centsFromDollars","value","number","round","Number","String","replace","isFinite","dollarsFromCents","cents","toFixed","priceByLabel","options","named","filter","option","name","trim","length","toLowerCase","newAddOnGroup","id","min","max","online","priceCents","withVariantPrice","variantId","raw","priceCentsByVariant","rest","next","Object","keys","withChoiceCard","patch","url","imageUrl","note","items","includes","split","map","item","Boolean","ProductAddOnsFields","props","modifierGroups","variants","update","pick","helpId","pricedByVariant","setPricedByVariant","cardOpen","setCardOpen","setGroups","groups","editGroup","index","group","at","replaceOption","groupIndex","optionIndex","editOption","problem","modifierGroupsProblem","variesByVariant","byLabel","spacing","variant","color","role","aria-label","sx","border","borderColor","borderRadius","p","direction","alignItems","flexWrap","rowGap","label","size","onChange","event","target","flex","minWidth","theme","helperText","width","slotProps","htmlInput","inputMode","onClick","_group","control","checked","optionKey","byVariantOpen","hasCard","cardShown","choiceLabel","defaultValue","placeholder","onBlur","aria-expanded","open","_option","in","unmountOnExit","pl","pt","display","gridTemplateColumns","xs","sm","gap","variantPriceLabel","maxLength","multiline","minRows","Array","isArray","join","disabled","POS_MAX_MODIFIER_OPTIONS","aria-describedby","POS_MAX_MODIFIER_GROUPS"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;;AAEA,SACEA,GAAG,EACHC,MAAM,EACNC,QAAQ,EACRC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,IAAI,EAAEC,WAAW,EAAEC,KAAK,EAAEC,QAAQ,QAAQ,QAAO;AAC1D,YAAYC,mBAAmB,uBAAa;AAC5C,SAASC,uBAAuB,EAAEC,sBAAsB,EAAEC,uBAAuB,QAAQ,oCAAgC;AACzH,SAASC,gBAAgB,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aglyn';
|
|
2
|
+
import * as CommerceModel from '../../model';
|
|
3
|
+
/** Opens the media browser and hands what was chosen to `apply`. */
|
|
4
|
+
export type ProductMediaPick = (apply: (media: PickedMedia) => void) => Promise<void>;
|
|
5
|
+
type Patch = Partial<CommerceModel.HostProduct>;
|
|
6
|
+
type ProductUpdate = (patch: Patch | ((product: CommerceModel.HostProduct) => Patch)) => void;
|
|
7
|
+
/** A variant as this section reads it: what names it and what its card shows. */
|
|
8
|
+
export type VariantCardSlice = Pick<CommerceModel.ProductVariant, 'id' | 'options' | 'imageUrl' | 'note'>;
|
|
9
|
+
/**
|
|
10
|
+
* The variants with one variant's card changed. A cleared picture or note is
|
|
11
|
+
* dropped, never stored as `undefined` (the save is a client-direct write,
|
|
12
|
+
* which refuses one).
|
|
13
|
+
*/
|
|
14
|
+
export declare function withVariantCard(variants: readonly CommerceModel.ProductVariant[], variantId: string, patch: {
|
|
15
|
+
imageUrl?: string | null;
|
|
16
|
+
note?: string | null;
|
|
17
|
+
}): CommerceModel.ProductVariant[];
|
|
18
|
+
/** A small picture with Choose and Remove beside it: the card's picture field. */
|
|
19
|
+
export declare function CardPictureField(props: {
|
|
20
|
+
imageUrl: string | undefined;
|
|
21
|
+
/** Who the picture is of, for the buttons' names. */
|
|
22
|
+
label: string;
|
|
23
|
+
pick: ProductMediaPick | undefined;
|
|
24
|
+
onChange: (imageUrl: string | null) => void;
|
|
25
|
+
}): import("react").JSX.Element;
|
|
26
|
+
export interface ProductBuilderFieldsProps {
|
|
27
|
+
/** Each variant's id, options and card, and nothing else (AGL-3423). */
|
|
28
|
+
variants: readonly VariantCardSlice[];
|
|
29
|
+
mockupRequests: boolean;
|
|
30
|
+
update: ProductUpdate;
|
|
31
|
+
pick: ProductMediaPick | undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The "Product page" section of the product editor: the free-mockup switch
|
|
35
|
+
* and each variant's picture card. Memoized on its own slice of the product,
|
|
36
|
+
* like every section of this editor, so a keystroke in a price leaves it be.
|
|
37
|
+
*/
|
|
38
|
+
export declare const ProductBuilderFields: import("react").MemoExoticComponent<(props: ProductBuilderFieldsProps) => import("react").JSX.Element>;
|
|
39
|
+
export {};
|