@aglyn/plugins-commerce 1.12.0 → 1.14.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/catalog-organization-card.component.js +1 -1
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
- package/src/lib/components/console/host-quotes-card.component.js +3 -2
- package/src/lib/components/console/host-quotes-card.component.js.map +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/pay-link-readiness-notice.component.d.ts +1 -1
- package/src/lib/components/console/pay-link-readiness-notice.component.js.map +1 -1
- package/src/lib/components/console/pos-devices-card.component.js +2 -2
- package/src/lib/components/console/pos-devices-card.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js +1 -1
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-day-totals-card.component.js +1 -1
- package/src/lib/components/console/pos-ops/pos-day-totals-card.component.js.map +1 -1
- package/src/lib/components/console/pos-reader-splash-setting.component.js +1 -1
- package/src/lib/components/console/pos-reader-splash-setting.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.d.ts +5 -0
- package/src/lib/components/console/quote-editor-dialog.component.js +104 -16
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-pay-link.component.d.ts +4 -1
- package/src/lib/components/console/quote-pay-link.component.js +23 -12
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-proofs.component.d.ts +3 -2
- package/src/lib/components/console/quote-proofs.component.js +73 -5
- package/src/lib/components/console/quote-proofs.component.js.map +1 -1
- package/src/lib/components/console/quote-send.component.js +9 -6
- package/src/lib/components/console/quote-send.component.js.map +1 -1
- package/src/lib/components/console/site-member-purchases.component.js +1 -1
- package/src/lib/components/console/site-member-purchases.component.js.map +1 -1
- package/src/lib/components/quote-page-body.js +14 -8
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/model/commerce-invoices.d.ts +1 -1
- package/src/lib/model/commerce-invoices.js +4 -1
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-quote-email.d.ts +7 -6
- package/src/lib/model/commerce-quote-email.js +11 -6
- package/src/lib/model/commerce-quote-email.js.map +1 -1
- package/src/lib/model/commerce-quote-pay.d.ts +6 -1
- package/src/lib/model/commerce-quote-pay.js +18 -8
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/model/commerce-quote-proofs.d.ts +28 -1
- package/src/lib/model/commerce-quote-proofs.js +58 -2
- package/src/lib/model/commerce-quote-proofs.js.map +1 -1
- package/src/lib/model/commerce-quotes.d.ts +22 -1
- package/src/lib/model/commerce-quotes.js +25 -5
- package/src/lib/model/commerce-quotes.js.map +1 -1
- package/src/lib/model/plugin-permissions.d.ts +1 -1
- package/src/lib/model/plugin-permissions.js +10 -0
- package/src/lib/model/plugin-permissions.js.map +1 -1
- package/src/lib/server/commerce-pdf.d.ts +1 -1
- package/src/lib/server/commerce-pdf.js +1 -1
- package/src/lib/server/commerce-pdf.js.map +1 -1
- package/src/lib/server/paid-media-delivery.js +1 -1
- package/src/lib/server/paid-media-delivery.js.map +1 -1
- package/src/lib/server/quote-email.js +29 -25
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-pay.js +6 -2
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proof-media.d.ts +63 -0
- package/src/lib/server/quote-proof-media.js +96 -0
- package/src/lib/server/quote-proof-media.js.map +1 -0
- package/src/lib/server/quote-proofs.js +9 -5
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/server/quote-uploads.d.ts +3 -1
- package/src/lib/server/quote-uploads.js +2 -1
- package/src/lib/server/quote-uploads.js.map +1 -1
- package/src/lib/server/quote.d.ts +3 -0
- package/src/lib/server/quote.js +127 -20
- package/src/lib/server/quote.js.map +1 -1
- package/src/lib/tenant-emails.js +16 -9
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/transfer/gift-cards.server.js +9 -11
- package/src/lib/transfer/gift-cards.server.js.map +1 -1
- package/src/lib/utils/commerce-document-pdf.js +12 -9
- package/src/lib/utils/commerce-document-pdf.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +2 -0
- package/src/lib/utils/quote-email-content.js +20 -10
- package/src/lib/utils/quote-email-content.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/pos-reader-splash-setting.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 { useMediaPicker, type PickedMedia } from '@aglyn/aglyn/app-utils/media-picker-context'\nimport { BlockedControl } from '@aglyn/shared-ui-jsx/components/blocked-control.component'\nimport { PrerequisiteNotice } from '@aglyn/shared-ui-jsx/components/prerequisite-notice.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { useConsoleHostRoute, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Box,\n Button,\n FormControlLabel,\n Radio,\n RadioGroup,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useCallback, useEffect, useState } from 'react'\nimport {\n POS_READER_SPLASH_LARGEST,\n posReaderSplashArtworkProblem,\n type PosReaderSplashChoice,\n type PosReaderSplashStatus,\n} from '../../model/pos-reader-splash'\nimport {\n PosReaderSplashRequestError,\n readerSplashStatus,\n saveReaderSplash,\n} from './pos/pos-reader-splash-api'\n\nexport interface PosReaderSplashSettingProps {\n hostId: string\n /** Whether the viewer may change the site's readers (`managePos`, admin or editor). */\n canManagePos: boolean\n}\n\n/** An image's pixel size, read in the browser before anything is saved. */\nfunction imageSize(src: string): Promise<{ width: number; height: number } | null> {\n return new Promise((resolve) => {\n const image = new Image()\n image.onload = () => resolve({ width: image.naturalWidth, height: image.naturalHeight })\n image.onerror = () => resolve(null)\n image.src = src\n })\n}\n\nconst NOT_ALLOWED =\n 'Only an admin or editor with the \"Registers and devices\" point of sale permission can change the readers.'\n\n/**\n * \"Reader start-up screen\" on the POS devices card (AGL-4048): what the\n * store's Stripe smart readers show while they wait for a payment. The\n * platform's default screen, the workspace's logo on a white screen, or a\n * full-screen portrait image from the media library. A white-label\n * workspace is never offered the platform's screen and shows its own logo\n * unless it picks an image.\n *\n * The server applies the choice to the store's readers when it is saved\n * (and again when this opens and finds the logo changed since); readers\n * pick it up within about ten minutes.\n */\nexport function PosReaderSplashSetting({ hostId, canManagePos }: PosReaderSplashSettingProps) {\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const { pickMedia } = useMediaPicker()\n const { orgSlug } = useConsoleHostRoute(hostId)\n const [status, setStatus] = useState<PosReaderSplashStatus | null>(null)\n const [busy, setBusy] = useState(false)\n const [picked, setPicked] = useState<PickedMedia | null>(null)\n const uid = user?.uid ?? ''\n\n useEffect(() => {\n if (!user) return\n let active = true\n readerSplashStatus(user, hostId)\n .then((answer) => {\n if (active) setStatus(answer)\n })\n .catch(() => {\n if (active) setStatus(null)\n })\n return () => {\n active = false\n }\n // Keyed on the person, not the session object (see the register page).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [uid, hostId])\n\n const save = useCallback(\n async (choice: PosReaderSplashChoice, image?: { mediaScope: string; mediaId: string }) => {\n if (!user) return\n setBusy(true)\n try {\n const answer = await saveReaderSplash(user, hostId, choice, image)\n setStatus(answer)\n if (!answer.problem) {\n enqueueSnackbar(\n answer.locationReady\n ? 'Saved. Your readers show it within about ten minutes.'\n : 'Saved. Your readers show it once you add one.',\n { variant: 'success', persist: false },\n )\n }\n } catch (error) {\n enqueueSnackbar(\n error instanceof PosReaderSplashRequestError ? error.message : 'The start-up screen could not be saved',\n { variant: 'warning', persist: false },\n )\n } finally {\n setBusy(false)\n }\n },\n [user, hostId, enqueueSnackbar],\n )\n\n const chooseImage = async () => {\n const media = await pickMedia?.({ kind: 'image' })\n if (!media) return\n if (!media.mediaId || !media.mediaScope) {\n enqueueSnackbar('Choose an image from your media library.', { variant: 'warning', persist: false })\n return\n }\n const size = await imageSize(media.url)\n const problem = posReaderSplashArtworkProblem({\n contentType: media.contentType ?? null,\n width: size?.width ?? 0,\n height: size?.height ?? 0,\n })\n if (problem) {\n enqueueSnackbar(problem, { variant: 'warning', persist: false })\n return\n }\n setPicked(media)\n await save('image', { mediaScope: media.mediaScope, mediaId: media.mediaId })\n }\n\n if (!status?.available) return null\n\n const blockedReason = !canManagePos ? NOT_ALLOWED : busy ? 'Saving…' : null\n const hasLogo = Boolean(status.logoUrl)\n const profileHref = orgSlug ? `/${orgSlug}/settings/profile` : undefined\n const brand = status.productName\n const preview =\n status.effectiveChoice === 'logo' ? status.logoUrl : status.effectiveChoice === 'image' ? (picked?.url ?? status.image?.url ?? null) : null\n\n return (\n <Stack spacing={1}>\n <Typography variant=\"subtitle2\">{'Reader start-up screen'}</Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'What your card readers show while they wait for a payment.'}\n </Typography>\n <RadioGroup\n value={status.effectiveChoice}\n onChange={(event) => {\n const choice = event.target.value as PosReaderSplashChoice\n if (choice === 'image') {\n if (status.image) void save('image', { mediaScope: status.image.mediaScope, mediaId: status.image.mediaId })\n else void chooseImage()\n return\n }\n void save(choice)\n }}\n >\n {status.whiteLabel ? null : (\n <FormControlLabel\n value=\"platform\"\n disabled={Boolean(blockedReason)}\n control={<Radio size=\"small\" />}\n label={\n <Stack>\n <Typography variant=\"body2\">{`The ${brand} start-up screen`}</Typography>\n {status.platformReady ? null : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Until it is ready, your readers show their standard screen.'}\n </Typography>\n )}\n </Stack>\n }\n />\n )}\n <FormControlLabel\n value=\"logo\"\n disabled={Boolean(blockedReason) || !hasLogo}\n control={<Radio size=\"small\" />}\n label={\n <Stack>\n <Typography variant=\"body2\">{'Your logo'}</Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Your organization profile’s logo, centered on a white screen.'}\n </Typography>\n </Stack>\n }\n />\n <FormControlLabel\n value=\"image\"\n disabled={Boolean(blockedReason)}\n control={<Radio size=\"small\" />}\n label={\n <Stack>\n <Typography variant=\"body2\">{'Your own image'}</Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`A full-screen portrait image from your media library, at least ${POS_READER_SPLASH_LARGEST.width} × ${POS_READER_SPLASH_LARGEST.height} pixels.`}\n </Typography>\n </Stack>\n }\n />\n </RadioGroup>\n {hasLogo ? null : (\n <PrerequisiteNotice\n href={profileHref}\n actionLabel=\"Organization profile\"\n severity={status.effectiveChoice === 'logo' ? 'warning' : 'info'}\n >\n {'Add a logo to your organization profile to show it on your card readers.'}\n </PrerequisiteNotice>\n )}\n {status.effectiveChoice === 'image' ? (\n <Box>\n <BlockedControl blocked={Boolean(blockedReason)} reason={blockedReason ?? ''}>\n <Button size=\"small\" onClick={() => void chooseImage()}>\n {status.image ? 'Choose another image' : 'Choose image'}\n </Button>\n </BlockedControl>\n </Box>\n ) : null}\n {preview ? (\n <Box\n component=\"img\"\n src={preview}\n alt=\"\"\n sx={(theme) => ({\n alignSelf: 'flex-start',\n maxWidth: theme.spacing(16),\n maxHeight: theme.spacing(16),\n objectFit: 'contain',\n borderRadius: 1,\n border: 1,\n borderColor: 'divider',\n })}\n />\n ) : null}\n {status.problem && !(status.effectiveChoice === 'logo' && !hasLogo) ? (\n <Alert severity=\"warning\">{status.problem}</Alert>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {!status.locationReady\n ? 'Your readers show it once you add your first one.'\n : status.appliedAtMs\n ? `Sent to your readers ${new Date(status.appliedAtMs).toLocaleString()}. Readers update within about ten minutes.`\n : 'Readers update within about ten minutes of a change.'}\n </Typography>\n )}\n </Stack>\n )\n}\nPosReaderSplashSetting.displayName = 'PosReaderSplashSetting'\n\nexport default PosReaderSplashSetting\n"],"names":["useMediaPicker","BlockedControl","PrerequisiteNotice","useSnackbar","useConsoleHostRoute","useUser","Alert","Box","Button","FormControlLabel","Radio","RadioGroup","Stack","Typography","useCallback","useEffect","useState","POS_READER_SPLASH_LARGEST","posReaderSplashArtworkProblem","PosReaderSplashRequestError","readerSplashStatus","saveReaderSplash","imageSize","src","Promise","resolve","image","Image","onload","width","naturalWidth","height","naturalHeight","onerror","NOT_ALLOWED","PosReaderSplashSetting","hostId","canManagePos","picked","status","data","user","enqueueSnackbar","pickMedia","orgSlug","setStatus","busy","setBusy","setPicked","uid","active","then","answer","catch","save","choice","problem","locationReady","variant","persist","error","message","chooseImage","media","kind","mediaId","mediaScope","size","url","contentType","available","blockedReason","hasLogo","Boolean","logoUrl","profileHref","undefined","brand","productName","preview","effectiveChoice","spacing","color","value","onChange","event","target","whiteLabel","disabled","control","label","platformReady","href","actionLabel","severity","blocked","reason","onClick","component","alt","sx","theme","alignSelf","maxWidth","maxHeight","objectFit","borderRadius","border","borderColor","appliedAtMs","Date","toLocaleString","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SAASA,cAAc,QAA0B,8CAA6C;AAC9F,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,kBAAkB,QAAQ,gEAA+D;AAClG,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,mBAAmB,EAAEC,OAAO,QAAQ,iCAAgC;AAC7E,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EAChBC,KAAK,EACLC,UAAU,EACVC,K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EjB,CAAAA,OAAOyC,eAAe,KAAK,UAAU,CAACR,OAAM,kBAC/D,KAAClE;gBAAMwF,UAAS;0BAAWvD,OAAOiB,OAAO;+BAEzC,KAAC3C;gBAAW6C,SAAQ;gBAAUwB,OAAM;0BACjC,CAAC3C,OAAOkB,aAAa,GAClB,sDACAlB,OAAOsE,WAAW,GAChB,CAAC,qBAAqB,EAAE,IAAIC,KAAKvE,OAAOsE,WAAW,EAAEE,cAAc,GAAG,0CAA0C,CAAC,GACjH;;;;AAKhB;AACA5E,uBAAuB6E,WAAW,GAAG;AAErC,eAAe7E,uBAAsB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/pos-reader-splash-setting.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 { useMediaPicker, type PickedMedia } from '@aglyn/aglyn/app-utils/media-picker-context'\nimport { BlockedControl } from '@aglyn/shared-ui-jsx/components/blocked-control.component'\nimport { PrerequisiteNotice } from '@aglyn/shared-ui-jsx/components/prerequisite-notice.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { useConsoleHostRoute, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Box,\n Button,\n FormControlLabel,\n Radio,\n RadioGroup,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useCallback, useEffect, useState } from 'react'\nimport {\n POS_READER_SPLASH_LARGEST,\n posReaderSplashArtworkProblem,\n type PosReaderSplashChoice,\n type PosReaderSplashStatus,\n} from '../../model/pos-reader-splash'\nimport {\n PosReaderSplashRequestError,\n readerSplashStatus,\n saveReaderSplash,\n} from './pos/pos-reader-splash-api'\n\nexport interface PosReaderSplashSettingProps {\n hostId: string\n /** Whether the viewer may change the site's readers (`managePos`, admin or editor). */\n canManagePos: boolean\n}\n\n/** An image's pixel size, read in the browser before anything is saved. */\nfunction imageSize(src: string): Promise<{ width: number; height: number } | null> {\n return new Promise((resolve) => {\n const image = new Image()\n image.onload = () => resolve({ width: image.naturalWidth, height: image.naturalHeight })\n image.onerror = () => resolve(null)\n image.src = src\n })\n}\n\nconst NOT_ALLOWED =\n 'Changing the readers takes the \"Registers and devices\" permission, which site admins and editors hold by default.'\n\n/**\n * \"Reader start-up screen\" on the POS devices card (AGL-4048): what the\n * store's Stripe smart readers show while they wait for a payment. The\n * platform's default screen, the workspace's logo on a white screen, or a\n * full-screen portrait image from the media library. A white-label\n * workspace is never offered the platform's screen and shows its own logo\n * unless it picks an image.\n *\n * The server applies the choice to the store's readers when it is saved\n * (and again when this opens and finds the logo changed since); readers\n * pick it up within about ten minutes.\n */\nexport function PosReaderSplashSetting({ hostId, canManagePos }: PosReaderSplashSettingProps) {\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const { pickMedia } = useMediaPicker()\n const { orgSlug } = useConsoleHostRoute(hostId)\n const [status, setStatus] = useState<PosReaderSplashStatus | null>(null)\n const [busy, setBusy] = useState(false)\n const [picked, setPicked] = useState<PickedMedia | null>(null)\n const uid = user?.uid ?? ''\n\n useEffect(() => {\n if (!user) return\n let active = true\n readerSplashStatus(user, hostId)\n .then((answer) => {\n if (active) setStatus(answer)\n })\n .catch(() => {\n if (active) setStatus(null)\n })\n return () => {\n active = false\n }\n // Keyed on the person, not the session object (see the register page).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [uid, hostId])\n\n const save = useCallback(\n async (choice: PosReaderSplashChoice, image?: { mediaScope: string; mediaId: string }) => {\n if (!user) return\n setBusy(true)\n try {\n const answer = await saveReaderSplash(user, hostId, choice, image)\n setStatus(answer)\n if (!answer.problem) {\n enqueueSnackbar(\n answer.locationReady\n ? 'Saved. Your readers show it within about ten minutes.'\n : 'Saved. Your readers show it once you add one.',\n { variant: 'success', persist: false },\n )\n }\n } catch (error) {\n enqueueSnackbar(\n error instanceof PosReaderSplashRequestError ? error.message : 'The start-up screen could not be saved',\n { variant: 'warning', persist: false },\n )\n } finally {\n setBusy(false)\n }\n },\n [user, hostId, enqueueSnackbar],\n )\n\n const chooseImage = async () => {\n const media = await pickMedia?.({ kind: 'image' })\n if (!media) return\n if (!media.mediaId || !media.mediaScope) {\n enqueueSnackbar('Choose an image from your media library.', { variant: 'warning', persist: false })\n return\n }\n const size = await imageSize(media.url)\n const problem = posReaderSplashArtworkProblem({\n contentType: media.contentType ?? null,\n width: size?.width ?? 0,\n height: size?.height ?? 0,\n })\n if (problem) {\n enqueueSnackbar(problem, { variant: 'warning', persist: false })\n return\n }\n setPicked(media)\n await save('image', { mediaScope: media.mediaScope, mediaId: media.mediaId })\n }\n\n if (!status?.available) return null\n\n const blockedReason = !canManagePos ? NOT_ALLOWED : busy ? 'Saving…' : null\n const hasLogo = Boolean(status.logoUrl)\n const profileHref = orgSlug ? `/${orgSlug}/settings/profile` : undefined\n const brand = status.productName\n const preview =\n status.effectiveChoice === 'logo' ? status.logoUrl : status.effectiveChoice === 'image' ? (picked?.url ?? status.image?.url ?? null) : null\n\n return (\n <Stack spacing={1}>\n <Typography variant=\"subtitle2\">{'Reader start-up screen'}</Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'What your card readers show while they wait for a payment.'}\n </Typography>\n <RadioGroup\n value={status.effectiveChoice}\n onChange={(event) => {\n const choice = event.target.value as PosReaderSplashChoice\n if (choice === 'image') {\n if (status.image) void save('image', { mediaScope: status.image.mediaScope, mediaId: status.image.mediaId })\n else void chooseImage()\n return\n }\n void save(choice)\n }}\n >\n {status.whiteLabel ? null : (\n <FormControlLabel\n value=\"platform\"\n disabled={Boolean(blockedReason)}\n control={<Radio size=\"small\" />}\n label={\n <Stack>\n <Typography variant=\"body2\">{`The ${brand} start-up screen`}</Typography>\n {status.platformReady ? null : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Until it is ready, your readers show their standard screen.'}\n </Typography>\n )}\n </Stack>\n }\n />\n )}\n <FormControlLabel\n value=\"logo\"\n disabled={Boolean(blockedReason) || !hasLogo}\n control={<Radio size=\"small\" />}\n label={\n <Stack>\n <Typography variant=\"body2\">{'Your logo'}</Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Your organization profile’s logo, centered on a white screen.'}\n </Typography>\n </Stack>\n }\n />\n <FormControlLabel\n value=\"image\"\n disabled={Boolean(blockedReason)}\n control={<Radio size=\"small\" />}\n label={\n <Stack>\n <Typography variant=\"body2\">{'Your own image'}</Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`A full-screen portrait image from your media library, at least ${POS_READER_SPLASH_LARGEST.width} × ${POS_READER_SPLASH_LARGEST.height} pixels.`}\n </Typography>\n </Stack>\n }\n />\n </RadioGroup>\n {hasLogo ? null : (\n <PrerequisiteNotice\n href={profileHref}\n actionLabel=\"Organization profile\"\n severity={status.effectiveChoice === 'logo' ? 'warning' : 'info'}\n >\n {'Add a logo to your organization profile to show it on your card readers.'}\n </PrerequisiteNotice>\n )}\n {status.effectiveChoice === 'image' ? (\n <Box>\n <BlockedControl blocked={Boolean(blockedReason)} reason={blockedReason ?? ''}>\n <Button size=\"small\" onClick={() => void chooseImage()}>\n {status.image ? 'Choose another image' : 'Choose image'}\n </Button>\n </BlockedControl>\n </Box>\n ) : null}\n {preview ? (\n <Box\n component=\"img\"\n src={preview}\n alt=\"\"\n sx={(theme) => ({\n alignSelf: 'flex-start',\n maxWidth: theme.spacing(16),\n maxHeight: theme.spacing(16),\n objectFit: 'contain',\n borderRadius: 1,\n border: 1,\n borderColor: 'divider',\n })}\n />\n ) : null}\n {status.problem && !(status.effectiveChoice === 'logo' && !hasLogo) ? (\n <Alert severity=\"warning\">{status.problem}</Alert>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {!status.locationReady\n ? 'Your readers show it once you add your first one.'\n : status.appliedAtMs\n ? `Sent to your readers ${new Date(status.appliedAtMs).toLocaleString()}. Readers update within about ten minutes.`\n : 'Readers update within about ten minutes of a change.'}\n </Typography>\n )}\n </Stack>\n )\n}\nPosReaderSplashSetting.displayName = 'PosReaderSplashSetting'\n\nexport default PosReaderSplashSetting\n"],"names":["useMediaPicker","BlockedControl","PrerequisiteNotice","useSnackbar","useConsoleHostRoute","useUser","Alert","Box","Button","FormControlLabel","Radio","RadioGroup","Stack","Typography","useCallback","useEffect","useState","POS_READER_SPLASH_LARGEST","posReaderSplashArtworkProblem","PosReaderSplashRequestError","readerSplashStatus","saveReaderSplash","imageSize","src","Promise","resolve","image","Image","onload","width","naturalWidth","height","naturalHeight","onerror","NOT_ALLOWED","PosReaderSplashSetting","hostId","canManagePos","picked","status","data","user","enqueueSnackbar","pickMedia","orgSlug","setStatus","busy","setBusy","setPicked","uid","active","then","answer","catch","save","choice","problem","locationReady","variant","persist","error","message","chooseImage","media","kind","mediaId","mediaScope","size","url","contentType","available","blockedReason","hasLogo","Boolean","logoUrl","profileHref","undefined","brand","productName","preview","effectiveChoice","spacing","color","value","onChange","event","target","whiteLabel","disabled","control","label","platformReady","href","actionLabel","severity","blocked","reason","onClick","component","alt","sx","theme","alignSelf","maxWidth","maxHeight","objectFit","borderRadius","border","borderColor","appliedAtMs","Date","toLocaleString","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SAASA,cAAc,QAA0B,8CAA6C;AAC9F,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,kBAAkB,QAAQ,gEAA+D;AAClG,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,mBAAmB,EAAEC,OAAO,QAAQ,iCAAgC;AAC7E,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EAChBC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E,OAAOiB,OAAO,IAAI,CAAEjB,CAAAA,OAAOyC,eAAe,KAAK,UAAU,CAACR,OAAM,kBAC/D,KAAClE;gBAAMwF,UAAS;0BAAWvD,OAAOiB,OAAO;+BAEzC,KAAC3C;gBAAW6C,SAAQ;gBAAUwB,OAAM;0BACjC,CAAC3C,OAAOkB,aAAa,GAClB,sDACAlB,OAAOsE,WAAW,GAChB,CAAC,qBAAqB,EAAE,IAAIC,KAAKvE,OAAOsE,WAAW,EAAEE,cAAc,GAAG,0CAA0C,CAAC,GACjH;;;;AAKhB;AACA5E,uBAAuB6E,WAAW,GAAG;AAErC,eAAe7E,uBAAsB"}
|
|
@@ -68,6 +68,11 @@ export interface QuoteEditorStart {
|
|
|
68
68
|
* over the same inputs, and a connected tax service's figure arrives on save.
|
|
69
69
|
* A saved quote left as it is shows what its customer's page shows instead
|
|
70
70
|
* (AGL-4162): that is what the customer is charged until a save re-prices it.
|
|
71
|
+
*
|
|
72
|
+
* A quote may be saved with no items when it has a proof (AGL-4184), which is
|
|
73
|
+
* how a design goes out before it has a price: the editor then has no money to
|
|
74
|
+
* show, and an item added later makes it a normal quote. A new quote has
|
|
75
|
+
* nothing to upload a proof for yet, so it takes its first from the media library.
|
|
71
76
|
*/
|
|
72
77
|
export declare function QuoteEditorDialog(props: QuoteEditorDialogProps): import("react").JSX.Element;
|
|
73
78
|
export declare namespace QuoteEditorDialog {
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/ 'use client';
|
|
17
17
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
19
19
|
import * as CommerceModel from "../../model/index.js";
|
|
20
20
|
import { posMoney } from "../../model/commerce-pos-ops.js";
|
|
21
21
|
import { commerceSitePermissionRefusal } from "../../model/plugin-permissions.js";
|
|
22
|
+
import { useMediaPicker } from "@aglyn/aglyn/app-utils/media-picker-context";
|
|
22
23
|
import { BlockedControl } from "@aglyn/shared-ui-jsx/components/blocked-control.component";
|
|
23
24
|
import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
24
25
|
import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
|
|
@@ -187,6 +188,8 @@ function addressBody(address) {
|
|
|
187
188
|
/** What the server is sent: choices, never what a product costs. */ function quoteBody(form) {
|
|
188
189
|
var _centsOf;
|
|
189
190
|
const discountCents = centsOf(form.discountValue);
|
|
191
|
+
// With no lines there is nothing to discount or ship (AGL-4184).
|
|
192
|
+
const priced = form.lines.length > 0;
|
|
190
193
|
return {
|
|
191
194
|
lines: form.lines.map(lineRequest),
|
|
192
195
|
customer: _extends({}, form.customer.record ? {
|
|
@@ -199,14 +202,14 @@ function addressBody(address) {
|
|
|
199
202
|
}),
|
|
200
203
|
shipTo: addressBody(form.shipTo),
|
|
201
204
|
billTo: addressBody(form.billTo),
|
|
202
|
-
discount: form.discountKind === 'amount' ? {
|
|
205
|
+
discount: !priced ? null : form.discountKind === 'amount' ? {
|
|
203
206
|
kind: 'amount',
|
|
204
207
|
amountCents: discountCents != null ? discountCents : Number.NaN
|
|
205
208
|
} : form.discountKind === 'percent' ? {
|
|
206
209
|
kind: 'percent',
|
|
207
210
|
pct: Number(form.discountValue || 0)
|
|
208
211
|
} : null,
|
|
209
|
-
shipping: form.shipping.trim() ? {
|
|
212
|
+
shipping: priced && form.shipping.trim() ? {
|
|
210
213
|
amountCents: (_centsOf = centsOf(form.shipping)) != null ? _centsOf : Number.NaN
|
|
211
214
|
} : null,
|
|
212
215
|
notes: form.notes,
|
|
@@ -222,6 +225,11 @@ function addressBody(address) {
|
|
|
222
225
|
* over the same inputs, and a connected tax service's figure arrives on save.
|
|
223
226
|
* A saved quote left as it is shows what its customer's page shows instead
|
|
224
227
|
* (AGL-4162): that is what the customer is charged until a save re-prices it.
|
|
228
|
+
*
|
|
229
|
+
* A quote may be saved with no items when it has a proof (AGL-4184), which is
|
|
230
|
+
* how a design goes out before it has a price: the editor then has no money to
|
|
231
|
+
* show, and an item added later makes it a normal quote. A new quote has
|
|
232
|
+
* nothing to upload a proof for yet, so it takes its first from the media library.
|
|
225
233
|
*/ export function QuoteEditorDialog(props) {
|
|
226
234
|
var _props_start, _centsOf, _ref, _start_files, _ref1, _ref2, _ref3;
|
|
227
235
|
var _quote_quote, _quote_quote1, _quote_quote2;
|
|
@@ -230,6 +238,8 @@ function addressBody(address) {
|
|
|
230
238
|
const firestore = useFirestore();
|
|
231
239
|
const { data: user } = useUser();
|
|
232
240
|
const { enqueueSnackbar } = useSnackbar();
|
|
241
|
+
const { pickMedia } = useMediaPicker();
|
|
242
|
+
/** A new quote's proofs, chosen from the media library and kept when it is created. */ const [libraryProofs, setLibraryProofs] = useState([]);
|
|
233
243
|
const { data: store } = useFirestoreDoc(()=>doc(firestore, 'hosts', hostId, 'settings', 'store'), [
|
|
234
244
|
firestore,
|
|
235
245
|
hostId
|
|
@@ -269,7 +279,28 @@ function addressBody(address) {
|
|
|
269
279
|
useEffect(()=>{
|
|
270
280
|
attemptKey.current = '';
|
|
271
281
|
}, [
|
|
272
|
-
form
|
|
282
|
+
form,
|
|
283
|
+
libraryProofs
|
|
284
|
+
]);
|
|
285
|
+
const proofOnly = form.lines.length === 0 && (libraryProofs.length > 0 || CommerceModel.currentQuoteProofs(quote == null ? void 0 : quote.quote).length > 0);
|
|
286
|
+
const chooseLibraryProof = useCallback(async ()=>{
|
|
287
|
+
const picked = await (pickMedia == null ? void 0 : pickMedia({
|
|
288
|
+
allowPrivate: true
|
|
289
|
+
}));
|
|
290
|
+
if (!picked) return;
|
|
291
|
+
const problem = CommerceModel.quoteLibraryProofProblem(picked);
|
|
292
|
+
if (problem) return void enqueueSnackbar(problem, {
|
|
293
|
+
variant: 'error',
|
|
294
|
+
allowDuplicate: true
|
|
295
|
+
});
|
|
296
|
+
setEdited(true);
|
|
297
|
+
setLibraryProofs((prev)=>prev.some((entry)=>entry.mediaId === picked.mediaId && entry.mediaScope === picked.mediaScope) ? prev : [
|
|
298
|
+
...prev,
|
|
299
|
+
picked
|
|
300
|
+
]);
|
|
301
|
+
}, [
|
|
302
|
+
pickMedia,
|
|
303
|
+
enqueueSnackbar
|
|
273
304
|
]);
|
|
274
305
|
const productsById = useMemo(()=>new Map(products.map((product)=>[
|
|
275
306
|
String(product.$id),
|
|
@@ -370,7 +401,12 @@ function addressBody(address) {
|
|
|
370
401
|
quote: quoteBody(_extends({}, form, {
|
|
371
402
|
requireProofApproval
|
|
372
403
|
}))
|
|
373
|
-
}
|
|
404
|
+
}, !quote && libraryProofs.length ? {
|
|
405
|
+
libraryProofs: libraryProofs.map(({ mediaScope, mediaId })=>({
|
|
406
|
+
mediaScope,
|
|
407
|
+
mediaId
|
|
408
|
+
}))
|
|
409
|
+
} : {}))
|
|
374
410
|
});
|
|
375
411
|
const payload = await response.json().catch(()=>({}));
|
|
376
412
|
if (!response.ok) {
|
|
@@ -398,6 +434,7 @@ function addressBody(address) {
|
|
|
398
434
|
start,
|
|
399
435
|
form,
|
|
400
436
|
requireProofApproval,
|
|
437
|
+
libraryProofs,
|
|
401
438
|
enqueueSnackbar,
|
|
402
439
|
onClose
|
|
403
440
|
]);
|
|
@@ -500,6 +537,11 @@ function addressBody(address) {
|
|
|
500
537
|
variant: "outlined",
|
|
501
538
|
label: status.label,
|
|
502
539
|
color: CommerceModel.QUOTE_STATUS_COLOR[status.key]
|
|
540
|
+
}) : null,
|
|
541
|
+
proofOnly ? /*#__PURE__*/ _jsx(Chip, {
|
|
542
|
+
size: "small",
|
|
543
|
+
variant: "outlined",
|
|
544
|
+
label: "Proof only"
|
|
503
545
|
}) : null
|
|
504
546
|
]
|
|
505
547
|
})
|
|
@@ -547,7 +589,7 @@ function addressBody(address) {
|
|
|
547
589
|
quoteId: quote.$id,
|
|
548
590
|
quote: quote
|
|
549
591
|
}) : null,
|
|
550
|
-
quote ? null : /*#__PURE__*/ _jsx(PayLinkReadinessNoticeFor, {
|
|
592
|
+
quote || proofOnly ? null : /*#__PURE__*/ _jsx(PayLinkReadinessNoticeFor, {
|
|
551
593
|
hostId: hostId,
|
|
552
594
|
order: null,
|
|
553
595
|
noun: "quote"
|
|
@@ -560,6 +602,48 @@ function addressBody(address) {
|
|
|
560
602
|
customer
|
|
561
603
|
})
|
|
562
604
|
}),
|
|
605
|
+
!quote && pickMedia ? /*#__PURE__*/ _jsxs(Stack, {
|
|
606
|
+
spacing: 1,
|
|
607
|
+
children: [
|
|
608
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
609
|
+
variant: "subtitle2",
|
|
610
|
+
children: 'Proofs'
|
|
611
|
+
}),
|
|
612
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
613
|
+
variant: "body2",
|
|
614
|
+
color: "text.secondary",
|
|
615
|
+
children: 'Sending a design before it has a price? Choose a proof and leave the items empty. ' + 'Your customer sees the proof with no prices, and can approve it or ask for changes. Add items whenever you’re ready.'
|
|
616
|
+
}),
|
|
617
|
+
libraryProofs.length ? /*#__PURE__*/ _jsx(Stack, {
|
|
618
|
+
direction: "row",
|
|
619
|
+
spacing: 1,
|
|
620
|
+
useFlexGap: true,
|
|
621
|
+
sx: {
|
|
622
|
+
flexWrap: 'wrap'
|
|
623
|
+
},
|
|
624
|
+
children: libraryProofs.map((proof)=>/*#__PURE__*/ _jsx(Chip, {
|
|
625
|
+
size: "small",
|
|
626
|
+
variant: "outlined",
|
|
627
|
+
label: proof.fileName || 'Proof',
|
|
628
|
+
onDelete: readOnly ? undefined : ()=>setLibraryProofs((prev)=>prev.filter((entry)=>entry !== proof))
|
|
629
|
+
}, `${proof.mediaScope}-${proof.mediaId}`))
|
|
630
|
+
}) : null,
|
|
631
|
+
/*#__PURE__*/ _jsx(BlockedControl, {
|
|
632
|
+
blocked: !canEdit,
|
|
633
|
+
reason: REFUSAL,
|
|
634
|
+
children: /*#__PURE__*/ _jsx(Button, {
|
|
635
|
+
size: "small",
|
|
636
|
+
variant: "outlined",
|
|
637
|
+
disabled: busy || libraryProofs.length >= CommerceModel.QUOTE_MAX_PROOFS,
|
|
638
|
+
onClick: ()=>void chooseLibraryProof(),
|
|
639
|
+
sx: {
|
|
640
|
+
alignSelf: 'flex-start'
|
|
641
|
+
},
|
|
642
|
+
children: 'From media library'
|
|
643
|
+
})
|
|
644
|
+
})
|
|
645
|
+
]
|
|
646
|
+
}) : null,
|
|
563
647
|
/*#__PURE__*/ _jsxs(Stack, {
|
|
564
648
|
spacing: 1.5,
|
|
565
649
|
children: [
|
|
@@ -635,7 +719,7 @@ function addressBody(address) {
|
|
|
635
719
|
})
|
|
636
720
|
]
|
|
637
721
|
}),
|
|
638
|
-
/*#__PURE__*/ _jsxs(Stack, {
|
|
722
|
+
proofOnly ? null : /*#__PURE__*/ _jsxs(Stack, {
|
|
639
723
|
direction: {
|
|
640
724
|
xs: 'column',
|
|
641
725
|
sm: 'row'
|
|
@@ -740,7 +824,7 @@ function addressBody(address) {
|
|
|
740
824
|
terms: event.target.value
|
|
741
825
|
})
|
|
742
826
|
}),
|
|
743
|
-
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
827
|
+
proofOnly ? null : /*#__PURE__*/ _jsx(FormControlLabel, {
|
|
744
828
|
control: /*#__PURE__*/ _jsx(Switch, {
|
|
745
829
|
checked: requireProofApproval,
|
|
746
830
|
disabled: readOnly || paid,
|
|
@@ -752,11 +836,15 @@ function addressBody(address) {
|
|
|
752
836
|
})
|
|
753
837
|
]
|
|
754
838
|
}),
|
|
755
|
-
/*#__PURE__*/
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
839
|
+
proofOnly ? null : /*#__PURE__*/ _jsxs(_Fragment, {
|
|
840
|
+
children: [
|
|
841
|
+
/*#__PURE__*/ _jsx(Divider, {}),
|
|
842
|
+
/*#__PURE__*/ _jsx(QuoteTotalsSummary, {
|
|
843
|
+
totals: (_ref1 = asSaved == null ? void 0 : asSaved.totals) != null ? _ref1 : totals,
|
|
844
|
+
taxLabel: (_ref2 = asSaved == null ? void 0 : asSaved.taxLabel) != null ? _ref2 : CommerceModel.describeQuoteTax(taxBasis),
|
|
845
|
+
taxAtPayment: (_ref3 = asSaved == null ? void 0 : asSaved.taxAtPayment) != null ? _ref3 : totals.taxAtPayment
|
|
846
|
+
})
|
|
847
|
+
]
|
|
760
848
|
})
|
|
761
849
|
]
|
|
762
850
|
})
|
|
@@ -780,7 +868,7 @@ function addressBody(address) {
|
|
|
780
868
|
children: 'Delete'
|
|
781
869
|
})
|
|
782
870
|
}) : null,
|
|
783
|
-
quote ? /*#__PURE__*/ _jsx(BlockedControl, {
|
|
871
|
+
quote && !proofOnly ? /*#__PURE__*/ _jsx(BlockedControl, {
|
|
784
872
|
blocked: !canEdit || edited,
|
|
785
873
|
reason: edited ? 'Save your changes first: the PDF shows the quote as it was last saved.' : REFUSAL,
|
|
786
874
|
children: /*#__PURE__*/ _jsx(Button, {
|
|
@@ -799,9 +887,9 @@ function addressBody(address) {
|
|
|
799
887
|
reason: REFUSAL,
|
|
800
888
|
children: /*#__PURE__*/ _jsx(Button, {
|
|
801
889
|
variant: "contained",
|
|
802
|
-
disabled: busy || form.lines.length === 0 || problems,
|
|
890
|
+
disabled: busy || form.lines.length === 0 && !proofOnly || problems,
|
|
803
891
|
onClick: ()=>void save(),
|
|
804
|
-
children: quote ? 'Save' : 'Create quote'
|
|
892
|
+
children: quote ? 'Save' : proofOnly ? 'Create proof' : 'Create quote'
|
|
805
893
|
})
|
|
806
894
|
})
|
|
807
895
|
]
|