@aglyn/plugins-commerce 1.29.3 → 1.30.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/pos-item-dialog.component.js +12 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -1
- package/src/lib/components/console/pos-kiosk-page.component.js +3 -5
- package/src/lib/components/console/pos-kiosk-page.component.js.map +1 -1
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +11 -0
- package/src/lib/components/console/product-add-ons-fields.component.js +229 -13
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.js +38 -0
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/product-add-ons.d.ts +21 -0
- package/src/lib/components/product-add-ons.js +77 -1
- package/src/lib/components/product-add-ons.js.map +1 -1
- package/src/lib/components/product-builder-mockup.d.ts +1 -1
- package/src/lib/components/product-builder-mockup.js +17 -5
- package/src/lib/components/product-builder-mockup.js.map +1 -1
- package/src/lib/components/product-choice-cards.js +14 -2
- package/src/lib/components/product-choice-cards.js.map +1 -1
- package/src/lib/model/commerce-pos-kiosk.js +8 -2
- package/src/lib/model/commerce-pos-kiosk.js.map +1 -1
- package/src/lib/model/commerce-pos-offline.d.ts +1 -1
- package/src/lib/model/commerce-pos-offline.js +8 -2
- package/src/lib/model/commerce-pos-offline.js.map +1 -1
- package/src/lib/model/commerce-quote-request.d.ts +1 -0
- package/src/lib/model/commerce-quote-request.js +6 -2
- package/src/lib/model/commerce-quote-request.js.map +1 -1
- package/src/lib/model/commerce-quotes.js +10 -5
- package/src/lib/model/commerce-quotes.js.map +1 -1
- package/src/lib/model/commerce.js +1 -1
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/product-modifiers.d.ts +53 -2
- package/src/lib/model/product-modifiers.js +127 -27
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/server/pos-kiosk.js +1 -4
- package/src/lib/server/pos-kiosk.js.map +1 -1
- package/src/lib/server/product.d.ts +5 -0
- package/src/lib/server/product.js +10 -2
- package/src/lib/server/product.js.map +1 -1
- package/src/lib/transfer/product-register-cells.d.ts +7 -0
- package/src/lib/transfer/product-register-cells.js +88 -10
- package/src/lib/transfer/product-register-cells.js.map +1 -1
|
@@ -58,6 +58,39 @@ function newId(prefix) {
|
|
|
58
58
|
]
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* A new write-in (write-ins): one field the shopper types into,
|
|
63
|
+
* such as a name to print or an engraving. Required, shown on the website,
|
|
64
|
+
* free until the merchant sets what it adds.
|
|
65
|
+
*/ export function newWriteInGroup() {
|
|
66
|
+
return {
|
|
67
|
+
id: newId('g'),
|
|
68
|
+
name: '',
|
|
69
|
+
kind: 'text',
|
|
70
|
+
min: 1,
|
|
71
|
+
max: 1,
|
|
72
|
+
maxLength: CommerceModel.DEFAULT_WRITE_IN_LENGTH,
|
|
73
|
+
online: true,
|
|
74
|
+
options: [
|
|
75
|
+
{
|
|
76
|
+
id: newId('o'),
|
|
77
|
+
name: '',
|
|
78
|
+
priceCents: 0
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A write-in renamed: its one option carries the same name, so every reader
|
|
85
|
+
* that names a pick by its option names the field.
|
|
86
|
+
*/ export function withWriteInName(group, name) {
|
|
87
|
+
return {
|
|
88
|
+
name,
|
|
89
|
+
options: group.options.map((option, at)=>at === 0 ? _extends({}, option, {
|
|
90
|
+
name
|
|
91
|
+
}) : option)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
61
94
|
/**
|
|
62
95
|
* A choice's prices by variant with one variant's price set or cleared. A
|
|
63
96
|
* cleared price follows the choice's own; with none left the field is
|
|
@@ -100,6 +133,148 @@ function newId(prefix) {
|
|
|
100
133
|
}
|
|
101
134
|
return next;
|
|
102
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* One write-in in the editor (write-ins): what the field is
|
|
138
|
+
* called, how long an answer can be, what a filled one adds, the note under
|
|
139
|
+
* it, and whether it is required, numbers only and asked on the website.
|
|
140
|
+
*/ function WriteInFields(props) {
|
|
141
|
+
var _group_maxLength, _ref;
|
|
142
|
+
const { group, edit, remove } = props;
|
|
143
|
+
const option = group.options[0];
|
|
144
|
+
const editOption = (next)=>edit({
|
|
145
|
+
options: group.options.map((entry, at)=>at === 0 ? next : entry)
|
|
146
|
+
});
|
|
147
|
+
const example = `${group.name || 'Engraving'}: ${group.digitsOnly ? '27' : 'For Sam'}`;
|
|
148
|
+
return /*#__PURE__*/ _jsxs(Stack, {
|
|
149
|
+
spacing: 1.5,
|
|
150
|
+
children: [
|
|
151
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
152
|
+
variant: "overline",
|
|
153
|
+
color: "text.secondary",
|
|
154
|
+
children: 'Write-in'
|
|
155
|
+
}),
|
|
156
|
+
/*#__PURE__*/ _jsxs(Stack, {
|
|
157
|
+
direction: "row",
|
|
158
|
+
spacing: 1,
|
|
159
|
+
sx: {
|
|
160
|
+
alignItems: 'flex-start',
|
|
161
|
+
flexWrap: 'wrap',
|
|
162
|
+
rowGap: 1
|
|
163
|
+
},
|
|
164
|
+
children: [
|
|
165
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
166
|
+
label: "Field name",
|
|
167
|
+
size: "small",
|
|
168
|
+
value: group.name,
|
|
169
|
+
placeholder: "Engraving",
|
|
170
|
+
onChange: (event)=>edit(withWriteInName(group, event.target.value)),
|
|
171
|
+
sx: {
|
|
172
|
+
flex: 1,
|
|
173
|
+
minWidth: (theme)=>theme.spacing(20)
|
|
174
|
+
}
|
|
175
|
+
}),
|
|
176
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
177
|
+
label: "Longest answer",
|
|
178
|
+
size: "small",
|
|
179
|
+
value: (_group_maxLength = group.maxLength) != null ? _group_maxLength : CommerceModel.DEFAULT_WRITE_IN_LENGTH,
|
|
180
|
+
onChange: (event)=>edit({
|
|
181
|
+
maxLength: Math.min(CommerceModel.MAX_WRITE_IN_LENGTH, Math.max(1, Math.round(Number(event.target.value) || 1)))
|
|
182
|
+
}),
|
|
183
|
+
helperText: "Characters",
|
|
184
|
+
sx: {
|
|
185
|
+
width: (theme)=>theme.spacing(15)
|
|
186
|
+
},
|
|
187
|
+
slotProps: {
|
|
188
|
+
htmlInput: {
|
|
189
|
+
inputMode: 'numeric'
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
194
|
+
label: "Adds ($)",
|
|
195
|
+
size: "small",
|
|
196
|
+
defaultValue: dollarsFromCents(option == null ? void 0 : option.priceCents),
|
|
197
|
+
placeholder: "0.00",
|
|
198
|
+
onBlur: (event)=>option && editOption(_extends({}, option, {
|
|
199
|
+
priceCents: centsFromDollars(event.target.value)
|
|
200
|
+
})),
|
|
201
|
+
helperText: "When filled in",
|
|
202
|
+
sx: {
|
|
203
|
+
width: (theme)=>theme.spacing(15)
|
|
204
|
+
},
|
|
205
|
+
slotProps: {
|
|
206
|
+
htmlInput: {
|
|
207
|
+
inputMode: 'decimal'
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}),
|
|
211
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
212
|
+
color: "error",
|
|
213
|
+
onClick: remove,
|
|
214
|
+
children: 'Remove write-in'
|
|
215
|
+
})
|
|
216
|
+
]
|
|
217
|
+
}),
|
|
218
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
219
|
+
label: "Note",
|
|
220
|
+
size: "small",
|
|
221
|
+
defaultValue: (_ref = option == null ? void 0 : option.note) != null ? _ref : '',
|
|
222
|
+
placeholder: "Exactly as it should read",
|
|
223
|
+
onBlur: (event)=>option && editOption(withChoiceCard(option, {
|
|
224
|
+
note: event.target.value
|
|
225
|
+
})),
|
|
226
|
+
helperText: "Shown under the field on the product’s page.",
|
|
227
|
+
slotProps: {
|
|
228
|
+
htmlInput: {
|
|
229
|
+
maxLength: PRODUCT_CHOICE_NOTE_MAX
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}),
|
|
233
|
+
/*#__PURE__*/ _jsxs(Stack, {
|
|
234
|
+
direction: "row",
|
|
235
|
+
spacing: 2,
|
|
236
|
+
sx: {
|
|
237
|
+
flexWrap: 'wrap',
|
|
238
|
+
rowGap: 0.5
|
|
239
|
+
},
|
|
240
|
+
children: [
|
|
241
|
+
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
242
|
+
control: /*#__PURE__*/ _jsx(Switch, {
|
|
243
|
+
checked: group.min > 0,
|
|
244
|
+
onChange: (event)=>edit({
|
|
245
|
+
min: event.target.checked ? 1 : 0
|
|
246
|
+
})
|
|
247
|
+
}),
|
|
248
|
+
label: "Required"
|
|
249
|
+
}),
|
|
250
|
+
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
251
|
+
control: /*#__PURE__*/ _jsx(Switch, {
|
|
252
|
+
checked: group.digitsOnly === true,
|
|
253
|
+
onChange: (event)=>edit({
|
|
254
|
+
digitsOnly: event.target.checked
|
|
255
|
+
})
|
|
256
|
+
}),
|
|
257
|
+
label: "Numbers only"
|
|
258
|
+
}),
|
|
259
|
+
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
260
|
+
control: /*#__PURE__*/ _jsx(Switch, {
|
|
261
|
+
checked: group.online === true,
|
|
262
|
+
onChange: (event)=>edit({
|
|
263
|
+
online: event.target.checked
|
|
264
|
+
})
|
|
265
|
+
}),
|
|
266
|
+
label: "Show on the website"
|
|
267
|
+
})
|
|
268
|
+
]
|
|
269
|
+
}),
|
|
270
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
271
|
+
variant: "caption",
|
|
272
|
+
color: "text.secondary",
|
|
273
|
+
children: `The answer goes on the order, the receipt and your order emails, like “${example}”.` + (group.online === true ? '' : ' Asked at the register only.')
|
|
274
|
+
})
|
|
275
|
+
]
|
|
276
|
+
});
|
|
277
|
+
}
|
|
103
278
|
/**
|
|
104
279
|
* The product's add-ons (AGL-4100, from the register's modifiers of
|
|
105
280
|
* AGL-3607): choices added to the item that are not stocked variants — walls
|
|
@@ -140,9 +315,11 @@ function newId(prefix) {
|
|
|
140
315
|
id: helpId,
|
|
141
316
|
variant: "body2",
|
|
142
317
|
color: "text.secondary",
|
|
143
|
-
children: 'Add-ons are choices added to the item that don’t need their own stock, such as walls or ' + 'printing on a canopy, or a milk in a latte. Each can be free or add to the price, and can ' + 'cost more on a larger size. Show a group on the website to offer it on the product’s page; ' + 'the register offers every group.'
|
|
318
|
+
children: 'Add-ons are choices added to the item that don’t need their own stock, such as walls or ' + 'printing on a canopy, or a milk in a latte. Each can be free or add to the price, and can ' + 'cost more on a larger size. Show a group on the website to offer it on the product’s page; ' + 'the register offers every group. A write-in asks the customer to type an answer, such as ' + 'a name to print, an engraving or a cake message, and puts it on the order.'
|
|
144
319
|
}),
|
|
145
|
-
modifierGroups.map((group, groupIndex)
|
|
320
|
+
modifierGroups.map((group, groupIndex)=>{
|
|
321
|
+
var _group_options_, _group_options_1;
|
|
322
|
+
return /*#__PURE__*/ _jsx(Box, {
|
|
146
323
|
role: "group",
|
|
147
324
|
"aria-label": group.name || 'Add-on group',
|
|
148
325
|
sx: {
|
|
@@ -151,7 +328,11 @@ function newId(prefix) {
|
|
|
151
328
|
borderRadius: 1,
|
|
152
329
|
p: 2
|
|
153
330
|
},
|
|
154
|
-
children: /*#__PURE__*/
|
|
331
|
+
children: CommerceModel.modifierGroupIsWriteIn(group) ? /*#__PURE__*/ _jsx(WriteInFields, {
|
|
332
|
+
group: group,
|
|
333
|
+
edit: (patch)=>editGroup(groupIndex, patch),
|
|
334
|
+
remove: ()=>setGroups(modifierGroups.filter((_group, at)=>at !== groupIndex))
|
|
335
|
+
}) : /*#__PURE__*/ _jsxs(Stack, {
|
|
155
336
|
spacing: 1.5,
|
|
156
337
|
children: [
|
|
157
338
|
/*#__PURE__*/ _jsxs(Stack, {
|
|
@@ -229,6 +410,20 @@ function newId(prefix) {
|
|
|
229
410
|
color: "text.secondary",
|
|
230
411
|
children: group.online === true ? 'Offered on the product’s page and at the register.' : 'Offered at the register only.'
|
|
231
412
|
}),
|
|
413
|
+
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
414
|
+
control: /*#__PURE__*/ _jsx(Switch, {
|
|
415
|
+
checked: group.nameOnOrder === true,
|
|
416
|
+
onChange: (event)=>editGroup(groupIndex, {
|
|
417
|
+
nameOnOrder: event.target.checked
|
|
418
|
+
})
|
|
419
|
+
}),
|
|
420
|
+
label: "Name the group on the order"
|
|
421
|
+
}),
|
|
422
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
423
|
+
variant: "caption",
|
|
424
|
+
color: "text.secondary",
|
|
425
|
+
children: group.nameOnOrder === true ? `The order says “${group.name || 'Size'}: ${((_group_options_ = group.options[0]) == null ? void 0 : _group_options_.name) || 'M'}”.` : `The order says “${((_group_options_1 = group.options[0]) == null ? void 0 : _group_options_1.name) || 'M'}”. Turn this on when a choice ` + 'doesn’t say what it is on its own, like a size.'
|
|
426
|
+
}),
|
|
232
427
|
group.options.map((option, optionIndex)=>{
|
|
233
428
|
var _pricedByVariant_optionKey, _option_priceCentsByVariant, _cardOpen_optionKey, _option_note;
|
|
234
429
|
var _option_includes;
|
|
@@ -419,17 +614,38 @@ function newId(prefix) {
|
|
|
419
614
|
})
|
|
420
615
|
]
|
|
421
616
|
})
|
|
422
|
-
}, group.id)
|
|
617
|
+
}, group.id);
|
|
618
|
+
}),
|
|
423
619
|
/*#__PURE__*/ _jsx(Box, {
|
|
424
|
-
children: /*#__PURE__*/
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
620
|
+
children: /*#__PURE__*/ _jsxs(Stack, {
|
|
621
|
+
direction: "row",
|
|
622
|
+
spacing: 1,
|
|
623
|
+
sx: {
|
|
624
|
+
flexWrap: 'wrap',
|
|
625
|
+
rowGap: 1
|
|
626
|
+
},
|
|
627
|
+
children: [
|
|
628
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
629
|
+
variant: "outlined",
|
|
630
|
+
"aria-describedby": helpId,
|
|
631
|
+
onClick: ()=>setGroups([
|
|
632
|
+
...modifierGroups,
|
|
633
|
+
newAddOnGroup()
|
|
634
|
+
]),
|
|
635
|
+
disabled: modifierGroups.length >= CommerceModel.POS_MAX_MODIFIER_GROUPS,
|
|
636
|
+
children: 'New add-on group'
|
|
637
|
+
}),
|
|
638
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
639
|
+
variant: "outlined",
|
|
640
|
+
"aria-describedby": helpId,
|
|
641
|
+
onClick: ()=>setGroups([
|
|
642
|
+
...modifierGroups,
|
|
643
|
+
newWriteInGroup()
|
|
644
|
+
]),
|
|
645
|
+
disabled: modifierGroups.length >= CommerceModel.POS_MAX_MODIFIER_GROUPS,
|
|
646
|
+
children: 'New write-in'
|
|
647
|
+
})
|
|
648
|
+
]
|
|
433
649
|
})
|
|
434
650
|
}),
|
|
435
651
|
problem && modifierGroups.length ? /*#__PURE__*/ _jsx(Typography, {
|
|
@@ -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'\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,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
+
{"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 new write-in (write-ins): one field the shopper types into,\n * such as a name to print or an engraving. Required, shown on the website,\n * free until the merchant sets what it adds.\n */\nexport function newWriteInGroup(): CommerceModel.ProductModifierGroup {\n return {\n id: newId('g'),\n name: '',\n kind: 'text',\n min: 1,\n max: 1,\n maxLength: CommerceModel.DEFAULT_WRITE_IN_LENGTH,\n online: true,\n options: [{ id: newId('o'), name: '', priceCents: 0 }],\n }\n}\n\n/**\n * A write-in renamed: its one option carries the same name, so every reader\n * that names a pick by its option names the field.\n */\nexport function withWriteInName(\n group: CommerceModel.ProductModifierGroup,\n name: string,\n): Partial<CommerceModel.ProductModifierGroup> {\n return { name, options: group.options.map((option, at) => (at === 0 ? { ...option, name } : option)) }\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\ninterface WriteInFieldsProps {\n group: CommerceModel.ProductModifierGroup\n edit: (patch: Partial<CommerceModel.ProductModifierGroup>) => void\n remove: () => void\n}\n\n/**\n * One write-in in the editor (write-ins): what the field is\n * called, how long an answer can be, what a filled one adds, the note under\n * it, and whether it is required, numbers only and asked on the website.\n */\nfunction WriteInFields(props: WriteInFieldsProps) {\n const { group, edit, remove } = props\n const option = group.options[0]\n const editOption = (next: CommerceModel.ProductModifierOption) =>\n edit({ options: group.options.map((entry, at) => (at === 0 ? next : entry)) })\n const example = `${group.name || 'Engraving'}: ${group.digitsOnly ? '27' : 'For Sam'}`\n return (\n <Stack spacing={1.5}>\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'Write-in'}\n </Typography>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'flex-start', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Field name\"\n size=\"small\"\n value={group.name}\n placeholder=\"Engraving\"\n onChange={(event) => edit(withWriteInName(group, event.target.value))}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"Longest answer\"\n size=\"small\"\n value={group.maxLength ?? CommerceModel.DEFAULT_WRITE_IN_LENGTH}\n onChange={(event) =>\n edit({\n maxLength: Math.min(\n CommerceModel.MAX_WRITE_IN_LENGTH,\n Math.max(1, Math.round(Number(event.target.value) || 1)),\n ),\n })\n }\n helperText=\"Characters\"\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <TextField\n label=\"Adds ($)\"\n size=\"small\"\n defaultValue={dollarsFromCents(option?.priceCents)}\n placeholder=\"0.00\"\n onBlur={(event) => option && editOption({ ...option, priceCents: centsFromDollars(event.target.value) })}\n helperText=\"When filled in\"\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <Button color=\"error\" onClick={remove}>\n {'Remove write-in'}\n </Button>\n </Stack>\n <TextField\n label=\"Note\"\n size=\"small\"\n defaultValue={option?.note ?? ''}\n placeholder=\"Exactly as it should read\"\n onBlur={(event) => option && editOption(withChoiceCard(option, { note: event.target.value }))}\n helperText=\"Shown under the field on the product’s page.\"\n slotProps={{ htmlInput: { maxLength: PRODUCT_CHOICE_NOTE_MAX } }}\n />\n <Stack direction=\"row\" spacing={2} sx={{ flexWrap: 'wrap', rowGap: 0.5 }}>\n <FormControlLabel\n control={<Switch checked={group.min > 0} onChange={(event) => edit({ min: event.target.checked ? 1 : 0 })} />}\n label=\"Required\"\n />\n <FormControlLabel\n control={\n <Switch checked={group.digitsOnly === true} onChange={(event) => edit({ digitsOnly: event.target.checked })} />\n }\n label=\"Numbers only\"\n />\n <FormControlLabel\n control={<Switch checked={group.online === true} onChange={(event) => edit({ online: event.target.checked })} />}\n label=\"Show on the website\"\n />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`The answer goes on the order, the receipt and your order emails, like “${example}”.` +\n (group.online === true ? '' : ' Asked at the register only.')}\n </Typography>\n </Stack>\n )\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. A write-in asks the customer to type an answer, such as ' +\n 'a name to print, an engraving or a cake message, and puts it on the order.'}\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 {CommerceModel.modifierGroupIsWriteIn(group) ? (\n <WriteInFields\n group={group}\n edit={(patch) => editGroup(groupIndex, patch)}\n remove={() => setGroups(modifierGroups.filter((_group, at) => at !== groupIndex))}\n />\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 <FormControlLabel\n control={\n <Switch\n checked={group.nameOnOrder === true}\n onChange={(event) => editGroup(groupIndex, { nameOnOrder: event.target.checked })}\n />\n }\n label=\"Name the group on the order\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {group.nameOnOrder === true\n ? `The order says “${group.name || 'Size'}: ${group.options[0]?.name || 'M'}”.`\n : `The order says “${group.options[0]?.name || 'M'}”. Turn this on when a choice ` +\n 'doesn’t say what it is on its own, like a size.'}\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 )}\n </Box>\n ))}\n <Box>\n <Stack direction=\"row\" spacing={1} sx={{ flexWrap: 'wrap', rowGap: 1 }}>\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 <Button\n variant=\"outlined\"\n aria-describedby={helpId}\n onClick={() => setGroups([...modifierGroups, newWriteInGroup()])}\n disabled={modifierGroups.length >= CommerceModel.POS_MAX_MODIFIER_GROUPS}\n >\n {'New write-in'}\n </Button>\n </Stack>\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","newWriteInGroup","kind","maxLength","DEFAULT_WRITE_IN_LENGTH","withWriteInName","group","map","at","withVariantPrice","variantId","raw","priceCentsByVariant","rest","next","Object","keys","withChoiceCard","patch","url","imageUrl","note","items","includes","split","item","Boolean","WriteInFields","props","edit","remove","editOption","entry","example","digitsOnly","spacing","variant","color","direction","sx","alignItems","flexWrap","rowGap","label","size","placeholder","onChange","event","target","flex","minWidth","theme","MAX_WRITE_IN_LENGTH","helperText","width","slotProps","htmlInput","inputMode","defaultValue","onBlur","onClick","control","checked","ProductAddOnsFields","modifierGroups","variants","update","pick","helpId","pricedByVariant","setPricedByVariant","cardOpen","setCardOpen","setGroups","groups","editGroup","index","replaceOption","groupIndex","optionIndex","problem","modifierGroupsProblem","variesByVariant","byLabel","role","aria-label","border","borderColor","borderRadius","p","modifierGroupIsWriteIn","_group","nameOnOrder","optionKey","byVariantOpen","hasCard","cardShown","choiceLabel","aria-expanded","open","_option","in","unmountOnExit","pl","pt","display","gridTemplateColumns","xs","sm","gap","variantPriceLabel","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,QAA+B,wCAAoC;AAe5F,SAASC,MAAMC,M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;;;mBAjPF/G,MAAMV,EAAE;;0BAwPjB,KAAC7C;0BACC,cAAA,MAACK;oBAAMkF,WAAU;oBAAMH,SAAS;oBAAGI,IAAI;wBAAEE,UAAU;wBAAQC,QAAQ;oBAAE;;sCACnE,KAAC1F;4BACCoF,SAAQ;4BACRkF,oBAAkBlD;4BAClBR,SAAS,IAAMa,UAAU;uCAAIT;oCAAgBrE;iCAAgB;4BAC7DyH,UAAUpD,eAAevE,MAAM,IAAI7B,cAAc2J,uBAAuB;sCAEvE;;sCAEH,KAACvK;4BACCoF,SAAQ;4BACRkF,oBAAkBlD;4BAClBR,SAAS,IAAMa,UAAU;uCAAIT;oCAAgB/D;iCAAkB;4BAC/DmH,UAAUpD,eAAevE,MAAM,IAAI7B,cAAc2J,uBAAuB;sCAEvE;;;;;YAINvC,WAAWhB,eAAevE,MAAM,iBAC/B,KAAClC;gBAAW6E,SAAQ;gBAAQC,OAAM;0BAC/B2C;iBAED;;;AAGV,GAAE"}
|
|
@@ -1344,6 +1344,44 @@ QuoteEditorDialog.displayName = 'QuoteEditorDialog';
|
|
|
1344
1344
|
}),
|
|
1345
1345
|
groups.map((group)=>{
|
|
1346
1346
|
var _chosen_;
|
|
1347
|
+
// A write-in (write-ins): the answer the customer gave, typed into the quote.
|
|
1348
|
+
if (CommerceModel.modifierGroupIsWriteIn(group)) {
|
|
1349
|
+
var _ref;
|
|
1350
|
+
var _line_modifiers_find;
|
|
1351
|
+
const option = group.options[0];
|
|
1352
|
+
const text = line.kind === 'catalog' ? (_ref = (_line_modifiers_find = line.modifiers.find((pick)=>pick.groupId === group.id)) == null ? void 0 : _line_modifiers_find.text) != null ? _ref : '' : '';
|
|
1353
|
+
const problem = CommerceModel.writeInProblem(group, text);
|
|
1354
|
+
return /*#__PURE__*/ _jsx(TextField, {
|
|
1355
|
+
label: CommerceModel.modifierGroupRequired(group) ? group.name : `${group.name} (optional)`,
|
|
1356
|
+
size: "small",
|
|
1357
|
+
fullWidth: true,
|
|
1358
|
+
value: text,
|
|
1359
|
+
disabled: disabled || !option,
|
|
1360
|
+
error: Boolean(problem),
|
|
1361
|
+
helperText: problem != null ? problem : undefined,
|
|
1362
|
+
slotProps: {
|
|
1363
|
+
htmlInput: {
|
|
1364
|
+
maxLength: CommerceModel.writeInMaxLength(group)
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1367
|
+
onChange: (event)=>{
|
|
1368
|
+
if (line.kind !== 'catalog' || !option) return;
|
|
1369
|
+
const typed = event.target.value;
|
|
1370
|
+
onChange({
|
|
1371
|
+
modifiers: [
|
|
1372
|
+
...line.modifiers.filter((pick)=>pick.groupId !== group.id),
|
|
1373
|
+
...typed.trim() ? [
|
|
1374
|
+
{
|
|
1375
|
+
groupId: group.id,
|
|
1376
|
+
optionId: option.id,
|
|
1377
|
+
text: typed
|
|
1378
|
+
}
|
|
1379
|
+
] : []
|
|
1380
|
+
]
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
}, group.id);
|
|
1384
|
+
}
|
|
1347
1385
|
const chosen = line.kind === 'catalog' ? line.modifiers.filter((pick)=>pick.groupId === group.id).map((pick)=>pick.optionId) : [];
|
|
1348
1386
|
return /*#__PURE__*/ _jsxs(TextField, {
|
|
1349
1387
|
label: CommerceModel.modifierGroupRequired(group) ? group.name : `${group.name} (optional)`,
|