@aglyn/plugins-commerce 1.0.0-beta.290 → 1.0.0-beta.291

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.
Files changed (111) hide show
  1. package/README.md +4 -2
  2. package/package.json +13 -13
  3. package/src/lib/components/commerce-console-page.js +2 -1
  4. package/src/lib/components/commerce-console-page.js.map +1 -1
  5. package/src/lib/components/console/host-orders-card.component.d.ts +6 -0
  6. package/src/lib/components/console/host-orders-card.component.js +3 -2
  7. package/src/lib/components/console/host-orders-card.component.js.map +1 -1
  8. package/src/lib/components/console/invoice-send.component.d.ts +44 -0
  9. package/src/lib/components/console/invoice-send.component.js +237 -0
  10. package/src/lib/components/console/invoice-send.component.js.map +1 -0
  11. package/src/lib/components/console/order-detail-dialog.component.d.ts +5 -0
  12. package/src/lib/components/console/order-detail-dialog.component.js +9 -2
  13. package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
  14. package/src/lib/components/console/order-invoice.component.d.ts +9 -0
  15. package/src/lib/components/console/order-invoice.component.js +27 -2
  16. package/src/lib/components/console/order-invoice.component.js.map +1 -1
  17. package/src/lib/components/console/quote-editor-dialog.component.d.ts +29 -0
  18. package/src/lib/components/console/quote-editor-dialog.component.js +102 -4
  19. package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
  20. package/src/lib/components/console/quote-proofs.component.d.ts +11 -0
  21. package/src/lib/components/console/quote-proofs.component.js +68 -0
  22. package/src/lib/components/console/quote-proofs.component.js.map +1 -1
  23. package/src/lib/components/console/quote-send.component.d.ts +42 -0
  24. package/src/lib/components/console/quote-send.component.js +307 -0
  25. package/src/lib/components/console/quote-send.component.js.map +1 -0
  26. package/src/lib/components/console/quote-start.component.d.ts +45 -0
  27. package/src/lib/components/console/quote-start.component.js +182 -0
  28. package/src/lib/components/console/quote-start.component.js.map +1 -0
  29. package/src/lib/components/product-options-field-body.d.ts +44 -0
  30. package/src/lib/components/product-options-field-body.js +260 -0
  31. package/src/lib/components/product-options-field-body.js.map +1 -0
  32. package/src/lib/components/product-options-field.d.ts +32 -0
  33. package/src/lib/components/product-options-field.js +128 -0
  34. package/src/lib/components/product-options-field.js.map +1 -0
  35. package/src/lib/components/quote-page-body.js +39 -20
  36. package/src/lib/components/quote-page-body.js.map +1 -1
  37. package/src/lib/model/commerce-invoices.d.ts +132 -0
  38. package/src/lib/model/commerce-invoices.js +332 -0
  39. package/src/lib/model/commerce-invoices.js.map +1 -0
  40. package/src/lib/model/commerce-orders.d.ts +29 -2
  41. package/src/lib/model/commerce-orders.js.map +1 -1
  42. package/src/lib/model/commerce-product-field.d.ts +23 -0
  43. package/src/lib/model/commerce-product-field.js +26 -0
  44. package/src/lib/model/commerce-product-field.js.map +1 -0
  45. package/src/lib/model/commerce-quote-email.d.ts +67 -0
  46. package/src/lib/model/commerce-quote-email.js +154 -0
  47. package/src/lib/model/commerce-quote-email.js.map +1 -0
  48. package/src/lib/model/commerce-quote-pay.d.ts +49 -6
  49. package/src/lib/model/commerce-quote-pay.js +69 -36
  50. package/src/lib/model/commerce-quote-pay.js.map +1 -1
  51. package/src/lib/model/commerce-quote-request.d.ts +93 -0
  52. package/src/lib/model/commerce-quote-request.js +207 -0
  53. package/src/lib/model/commerce-quote-request.js.map +1 -0
  54. package/src/lib/model/commerce-quotes.d.ts +81 -0
  55. package/src/lib/model/commerce-quotes.js.map +1 -1
  56. package/src/lib/model/index.d.ts +3 -0
  57. package/src/lib/model/index.js +3 -0
  58. package/src/lib/model/index.js.map +1 -1
  59. package/src/lib/plugin.js +19 -0
  60. package/src/lib/plugin.js.map +1 -1
  61. package/src/lib/server/billing-webhook.js +115 -70
  62. package/src/lib/server/billing-webhook.js.map +1 -1
  63. package/src/lib/server/commerce-pdf.d.ts +5 -1
  64. package/src/lib/server/commerce-pdf.js +37 -10
  65. package/src/lib/server/commerce-pdf.js.map +1 -1
  66. package/src/lib/server/draft-order.js +23 -3
  67. package/src/lib/server/draft-order.js.map +1 -1
  68. package/src/lib/server/invoice-email.d.ts +76 -0
  69. package/src/lib/server/invoice-email.js +183 -0
  70. package/src/lib/server/invoice-email.js.map +1 -0
  71. package/src/lib/server/order-invoice-send.d.ts +43 -0
  72. package/src/lib/server/order-invoice-send.js +218 -0
  73. package/src/lib/server/order-invoice-send.js.map +1 -0
  74. package/src/lib/server/order-status.d.ts +11 -0
  75. package/src/lib/server/order-status.js +44 -8
  76. package/src/lib/server/order-status.js.map +1 -1
  77. package/src/lib/server/person-eraser.d.ts +3 -2
  78. package/src/lib/server/person-eraser.js +25 -6
  79. package/src/lib/server/person-eraser.js.map +1 -1
  80. package/src/lib/server/quote-email.d.ts +85 -0
  81. package/src/lib/server/quote-email.js +211 -0
  82. package/src/lib/server/quote-email.js.map +1 -0
  83. package/src/lib/server/quote-link-token.d.ts +11 -0
  84. package/src/lib/server/quote-link-token.js +21 -0
  85. package/src/lib/server/quote-link-token.js.map +1 -1
  86. package/src/lib/server/quote-pay.d.ts +8 -3
  87. package/src/lib/server/quote-pay.js +105 -43
  88. package/src/lib/server/quote-pay.js.map +1 -1
  89. package/src/lib/server/quote.d.ts +11 -0
  90. package/src/lib/server/quote.js +309 -12
  91. package/src/lib/server/quote.js.map +1 -1
  92. package/src/lib/server/site-page-resolver.js +2 -1
  93. package/src/lib/server/site-page-resolver.js.map +1 -1
  94. package/src/lib/server.js +5 -0
  95. package/src/lib/server.js.map +1 -1
  96. package/src/lib/site.js +8 -0
  97. package/src/lib/site.js.map +1 -1
  98. package/src/lib/tenant-emails.js +243 -0
  99. package/src/lib/tenant-emails.js.map +1 -1
  100. package/src/lib/utils/commerce-document-pdf.d.ts +5 -0
  101. package/src/lib/utils/commerce-document-pdf.js +6 -1
  102. package/src/lib/utils/commerce-document-pdf.js.map +1 -1
  103. package/src/lib/utils/invoice-email-content.d.ts +45 -0
  104. package/src/lib/utils/invoice-email-content.js +126 -0
  105. package/src/lib/utils/invoice-email-content.js.map +1 -0
  106. package/src/lib/utils/order-invoice.d.ts +1 -1
  107. package/src/lib/utils/order-invoice.js +14 -6
  108. package/src/lib/utils/order-invoice.js.map +1 -1
  109. package/src/lib/utils/quote-email-content.d.ts +62 -0
  110. package/src/lib/utils/quote-email-content.js +154 -0
  111. package/src/lib/utils/quote-email-content.js.map +1 -0
@@ -622,5 +622,73 @@ function dateTime(atMs) {
622
622
  }
623
623
  QuoteProofsSection.displayName = 'QuoteProofsSection';
624
624
  export default QuoteProofsSection;
625
+ /**
626
+ * The files a quote's request came with (AGL-4098), as the customer's files:
627
+ * a picture for an image, a chip naming anything else, each downloaded
628
+ * through the quote's own route. They stay where the request keeps them, so a
629
+ * request deleted from the Inbox takes them with it.
630
+ */ export function QuoteRequestFilesSection(props) {
631
+ var _quote_quote, _quote_quote1;
632
+ const { hostId, quoteId, quote } = props;
633
+ const { data: user } = useUser();
634
+ const { enqueueSnackbar } = useSnackbar();
635
+ const request = (_quote_quote = quote.quote) == null ? void 0 : _quote_quote.request;
636
+ const files = CommerceModel.quoteRequestFileViews((_quote_quote1 = quote.quote) == null ? void 0 : _quote_quote1.requestFiles);
637
+ const download = useCallback(async (file)=>{
638
+ const blob = await fetchQuoteFile(user, {
639
+ hostId,
640
+ quoteId,
641
+ fileId: file.id
642
+ });
643
+ if (!blob) {
644
+ return void enqueueSnackbar('The file could not be downloaded. The request may have been deleted from the Inbox.', {
645
+ variant: 'error',
646
+ allowDuplicate: true
647
+ });
648
+ }
649
+ const url = URL.createObjectURL(blob);
650
+ const link = document.createElement('a');
651
+ link.href = url;
652
+ link.download = file.name;
653
+ link.click();
654
+ setTimeout(()=>URL.revokeObjectURL(url), 1000);
655
+ }, [
656
+ user,
657
+ hostId,
658
+ quoteId,
659
+ enqueueSnackbar
660
+ ]);
661
+ if (!request || !user) return null;
662
+ const when = request.receivedAtMs ? ` on ${dateTime(request.receivedAtMs)}` : '';
663
+ return /*#__PURE__*/ _jsxs(Stack, {
664
+ spacing: 1,
665
+ children: [
666
+ /*#__PURE__*/ _jsx(Typography, {
667
+ variant: "subtitle2",
668
+ children: 'From the request'
669
+ }),
670
+ /*#__PURE__*/ _jsx(Typography, {
671
+ variant: "body2",
672
+ color: "text.secondary",
673
+ children: `Sent through “${request.formName}”${when}.` + (files.length ? ' The files they sent:' : ' They sent no files.')
674
+ }),
675
+ files.length ? /*#__PURE__*/ _jsx(Stack, {
676
+ direction: "row",
677
+ spacing: 1,
678
+ useFlexGap: true,
679
+ sx: {
680
+ flexWrap: 'wrap'
681
+ },
682
+ children: files.map((file)=>/*#__PURE__*/ _jsx(QuoteFileTile, {
683
+ user: user,
684
+ hostId: hostId,
685
+ quoteId: quoteId,
686
+ file: file,
687
+ onDownload: (picked)=>void download(picked)
688
+ }, file.id))
689
+ }) : null
690
+ ]
691
+ });
692
+ }
625
693
 
626
694
  //# sourceMappingURL=quote-proofs.component.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/quote-proofs.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\n'use client'\n\nimport * as CommerceModel from '../../model'\nimport { commerceSitePermissionRefusal } from '../../model/plugin-permissions'\nimport {\n checkVisitorUploadSelection,\n formatVisitorUploadBytes,\n visitorUploadIsInline,\n VISITOR_UPLOAD_ACCEPT,\n VISITOR_UPLOAD_MAX_BYTES,\n} from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { sendVisitorUpload } from '@aglyn/aglyn/app-utils/visitor-upload-client'\nimport { BlockedControl } from '@aglyn/shared-ui-jsx/components/blocked-control.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Box,\n Button,\n Chip,\n CircularProgress,\n Dialog,\n DialogActions,\n DialogContent,\n DialogContentText,\n DialogTitle,\n Divider,\n Paper,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'\n\nconst REFUSAL = commerceSitePermissionRefusal('commerce.quotes')\n\ntype User = Parameters<typeof authorizedFetch>[0]\n\n/** A file the console lists: a proof, or one the customer sent. Never its storage path. */\ninterface ListedFile {\n id: string\n name: string\n contentType: string\n size: number\n}\n\n/** An earlier revision as the route lists it. */\ntype RevisionView = Omit<CommerceModel.QuoteRevisionSnapshot, 'proofs' | 'responses'> & {\n proofs: ListedFile[]\n responses: Array<Omit<CommerceModel.QuoteCustomerResponse, 'files'> & { files?: ListedFile[] }>\n}\n\nexport interface QuoteProofsSectionProps {\n hostId: string\n quoteId: string\n quote: CommerceModel.HostOrder\n /** Holds \"Create and edit quotes\" (`commerce.quotes`). */\n canEdit: boolean\n /** A change here moved the quote's edit stamp; the editor saves against the new one. */\n onEdited: (updatedAtMs: number) => void\n}\n\nasync function postQuote(user: User, body: Record<string, unknown>): Promise<{ ok: boolean; payload: Record<string, any> }> {\n const response = await authorizedFetch(user, '/api/commerce/quote', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(body),\n })\n return { ok: response.ok, payload: await response.json().catch(() => ({})) }\n}\n\n/** One of the quote's files as a blob, fetched with the member's token; null when refused. */\nasync function fetchQuoteFile(\n user: User,\n body: { hostId: string; quoteId: string; fileId: string; revision?: number },\n): Promise<Blob | null> {\n try {\n const response = await authorizedFetch(user, '/api/commerce/quote', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ action: 'file', ...body }),\n })\n return response.ok ? await response.blob() : null\n } catch {\n return null\n }\n}\n\nfunction dateTime(atMs: number | undefined): string {\n return atMs ? new Date(atMs).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' }) : ''\n}\n\n/** A picture of an image proof, loaded with the member's token. */\nfunction ProofThumbnail(props: { user: User; hostId: string; quoteId: string; file: ListedFile; revision?: number }) {\n const { user, hostId, quoteId, file, revision } = props\n const [src, setSrc] = useState<string | null>(null)\n useEffect(() => {\n let live = true\n let url = ''\n void fetchQuoteFile(user, { hostId, quoteId, fileId: file.id, ...(revision ? { revision } : {}) }).then((blob) => {\n if (!live || !blob) return\n url = URL.createObjectURL(blob)\n setSrc(url)\n })\n return () => {\n live = false\n if (url) URL.revokeObjectURL(url)\n }\n }, [user, hostId, quoteId, file.id, revision])\n return (\n <Box\n sx={(theme) => ({\n width: theme.spacing(16),\n height: theme.spacing(12),\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n bgcolor: 'action.hover',\n borderRadius: 1,\n overflow: 'hidden',\n })}\n >\n {src ? (\n <Box component=\"img\" src={src} alt={file.name} sx={{ maxWidth: 1, maxHeight: 1, objectFit: 'contain' }} />\n ) : (\n <CircularProgress size={20} aria-label={`Loading ${file.name}`} />\n )}\n </Box>\n )\n}\n\n/** A file: a picture for an image, a chip naming it for anything else; both download it. */\nfunction QuoteFileTile(props: {\n user: User\n hostId: string\n quoteId: string\n file: ListedFile\n revision?: number\n onDownload: (file: ListedFile, revision?: number) => void\n onRemove?: () => void\n removeBlocked?: boolean\n}) {\n const { file, revision, onDownload, onRemove, removeBlocked } = props\n const image = visitorUploadIsInline(file.contentType)\n return (\n <Paper variant=\"outlined\" sx={{ p: 1 }}>\n <Stack spacing={1} sx={(theme) => ({ width: image ? theme.spacing(16) : 'auto', maxWidth: theme.spacing(32) })}>\n {image ? <ProofThumbnail {...props} /> : null}\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={`${file.name} · ${formatVisitorUploadBytes(file.size)}`}\n onClick={() => onDownload(file, revision)}\n title={`Download ${file.name}`}\n />\n {onRemove ? (\n <BlockedControl blocked={Boolean(removeBlocked)} reason={REFUSAL}>\n <Button size=\"small\" color=\"inherit\" onClick={onRemove} aria-label={`Remove ${file.name}`}>\n {'Remove'}\n </Button>\n </BlockedControl>\n ) : null}\n </Stack>\n </Paper>\n )\n}\n\n/** What the customer said, with any files they sent. */\nfunction QuoteResponseNote(props: {\n response: Omit<CommerceModel.QuoteCustomerResponse, 'files'> & { files?: ListedFile[] }\n tile: (file: ListedFile) => ReactNode\n}) {\n const { response, tile } = props\n if (response.action === 'approve') {\n return (\n <Alert severity=\"success\">\n <Stack spacing={0.5}>\n <Typography variant=\"body2\">{`Approved by ${response.name || 'the customer'} on ${dateTime(response.atMs)}.`}</Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {[response.ip ? `From ${response.ip}` : '', response.userAgent ?? ''].filter(Boolean).join(' · ')}\n </Typography>\n </Stack>\n </Alert>\n )\n }\n return (\n <Alert severity=\"warning\">\n <Stack spacing={1}>\n <Typography variant=\"body2\">{`Changes requested on ${dateTime(response.atMs)}:`}</Typography>\n <Typography variant=\"body2\" sx={{ whiteSpace: 'pre-line' }}>\n {response.comment}\n </Typography>\n {response.files?.length ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n {response.files.map((file) => tile(file))}\n </Stack>\n ) : null}\n </Stack>\n </Alert>\n )\n}\n\n/**\n * A quote's proofs and revisions (AGL-4096), in its editor: the current\n * revision's proofs (a picture for an image, a chip for a PDF or a design\n * file), Add proof, what the customer last said with any files they sent,\n * \"Start revision N+1\", and every earlier revision as it was kept.\n */\nexport function QuoteProofsSection(props: QuoteProofsSectionProps) {\n const { hostId, quoteId, quote, canEdit, onEdited } = props\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const section = quote.quote\n const revision = Math.max(1, Number(section?.revision ?? 1) || 1)\n const proofs = CommerceModel.currentQuoteProofs(section)\n const latest = CommerceModel.latestQuoteResponse(section)\n const unpaid = CommerceModel.isUnpaidQuote(quote)\n const addRefusal = CommerceModel.quoteProofChangeRefusal(quote, 'add')\n const removable = CommerceModel.quoteProofChangeRefusal(quote, 'remove') === null\n const [sending, setSending] = useState<{ done: number; total: number } | null>(null)\n const [busy, setBusy] = useState(false)\n const [confirmingRevision, setConfirmingRevision] = useState(false)\n const [history, setHistory] = useState<RevisionView[] | null>(null)\n const [historyError, setHistoryError] = useState('')\n const picker = useRef<HTMLInputElement>(null)\n\n const loadHistory = useCallback(async () => {\n setHistoryError('')\n const answer = await postQuote(user, { action: 'revisions', hostId, quoteId }).catch(() => null)\n if (!answer?.ok) {\n setHistoryError(String(answer?.payload?.error ?? 'Earlier revisions could not be loaded.'))\n return\n }\n setHistory(Array.isArray(answer.payload['revisions']) ? (answer.payload['revisions'] as RevisionView[]) : [])\n }, [user, hostId, quoteId])\n\n // Earlier revisions are read when there are some, and again after one is added.\n useEffect(() => {\n if (revision > 1) void loadHistory()\n }, [revision, loadHistory])\n\n const download = useCallback(\n async (file: ListedFile, fromRevision?: number) => {\n const blob = await fetchQuoteFile(user, { hostId, quoteId, fileId: file.id, ...(fromRevision ? { revision: fromRevision } : {}) })\n if (!blob) return void enqueueSnackbar('The file could not be downloaded', { variant: 'error', allowDuplicate: true })\n const url = URL.createObjectURL(blob)\n const link = document.createElement('a')\n link.href = url\n link.download = file.name\n link.click()\n setTimeout(() => URL.revokeObjectURL(url), 1000)\n },\n [user, hostId, quoteId, enqueueSnackbar],\n )\n\n const addProofs = useCallback(\n async (files: File[]) => {\n const problem = checkVisitorUploadSelection(files, proofs.length, CommerceModel.QUOTE_MAX_PROOFS)\n if (problem) return void enqueueSnackbar(problem, { variant: 'error', allowDuplicate: true })\n setSending({ done: 0, total: files.length })\n try {\n for (const [index, file] of files.entries()) {\n let stamp = 0\n const sent = await sendVisitorUpload({\n file,\n requestTicket: async (request) => {\n const answer = await postQuote(user, { action: 'proof-ticket', hostId, quoteId, file: request })\n return answer.ok\n ? (answer.payload as { ticket: string; upload: { url: string; fields: Record<string, string> } })\n : { error: String(answer.payload['error'] ?? 'The proof could not be sent') }\n },\n finalize: async (ticket) => {\n const answer = await postQuote(user, { action: 'proof-finalize', hostId, quoteId, ticket })\n if (!answer.ok) return { error: String(answer.payload['error'] ?? 'The proof could not be kept') }\n stamp = Number(answer.payload['updatedAtMs']) || 0\n return { file: answer.payload['proof'] }\n },\n })\n if ('error' in sent) {\n enqueueSnackbar(sent.error, { variant: 'error', allowDuplicate: true })\n break\n }\n if (stamp) onEdited(stamp)\n setSending({ done: index + 1, total: files.length })\n }\n } finally {\n setSending(null)\n }\n },\n [user, hostId, quoteId, proofs.length, onEdited, enqueueSnackbar],\n )\n\n const removeProof = useCallback(\n async (proofId: string) => {\n setBusy(true)\n try {\n const answer = await postQuote(user, { action: 'proof-remove', hostId, quoteId, proofId })\n if (!answer.ok) {\n return void enqueueSnackbar(String(answer.payload['error'] ?? 'The proof could not be removed'), {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n onEdited(Number(answer.payload['updatedAtMs']) || 0)\n } finally {\n setBusy(false)\n }\n },\n [user, hostId, quoteId, onEdited, enqueueSnackbar],\n )\n\n const startRevision = useCallback(async () => {\n setBusy(true)\n try {\n const answer = await postQuote(user, { action: 'start-revision', hostId, quoteId })\n if (!answer.ok) {\n return void enqueueSnackbar(String(answer.payload['error'] ?? 'The revision could not be started'), {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n onEdited(Number(answer.payload['updatedAtMs']) || 0)\n enqueueSnackbar(`Revision ${Number(answer.payload['revision']) || revision + 1} started`, { variant: 'success', persist: false })\n setConfirmingRevision(false)\n } finally {\n setBusy(false)\n }\n }, [user, hostId, quoteId, revision, onEdited, enqueueSnackbar])\n\n const tile = (file: ListedFile, fromRevision?: number, onRemove?: () => void) => (\n <QuoteFileTile\n key={`${fromRevision ?? 'current'}-${file.id}`}\n user={user}\n hostId={hostId}\n quoteId={quoteId}\n file={file}\n revision={fromRevision}\n onDownload={(picked, at) => void download(picked, at)}\n onRemove={onRemove}\n removeBlocked={!canEdit}\n />\n )\n\n const earlier = (history ?? []).filter((entry) => Number(entry.revision) < revision).reverse()\n\n return (\n <Stack spacing={1.5}>\n <Stack spacing={0.5}>\n <Typography variant=\"subtitle2\">{`Proofs · Revision ${revision}`}</Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {section?.requireProofApproval\n ? 'The customer sees these on the quote page and approves them before they can pay.'\n : 'The customer sees these on the quote page, and can approve them or ask for changes. Paying doesn’t wait on it.'}\n </Typography>\n </Stack>\n\n {latest ? <QuoteResponseNote response={latest} tile={(file) => tile(file)} /> : null}\n\n {proofs.length ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n {proofs.map((proof) =>\n tile(proof, undefined, removable ? () => void removeProof(proof.id) : undefined),\n )}\n </Stack>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No proofs on this revision yet. Add an image, a PDF or a design file for the customer to approve.'}\n </Typography>\n )}\n\n {unpaid ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap', alignItems: 'center' }}>\n <input\n ref={picker}\n type=\"file\"\n multiple\n hidden\n accept={VISITOR_UPLOAD_ACCEPT}\n data-testid=\"quote-proof-picker\"\n onChange={(event) => {\n const files = Array.from(event.target.files ?? [])\n event.target.value = ''\n if (files.length) void addProofs(files)\n }}\n />\n <BlockedControl\n blocked={!canEdit || Boolean(addRefusal)}\n reason={!canEdit ? REFUSAL : addRefusal ? CommerceModel.quoteProofRefusalMessage(addRefusal) : ''}\n >\n <Button variant=\"outlined\" size=\"small\" disabled={busy || Boolean(sending)} onClick={() => picker.current?.click()}>\n {sending ? `Sending ${sending.done + 1} of ${sending.total}…` : 'Add proof'}\n </Button>\n </BlockedControl>\n <BlockedControl blocked={!canEdit} reason={REFUSAL}>\n <Button size=\"small\" disabled={busy || Boolean(sending)} onClick={() => setConfirmingRevision(true)}>\n {`Start revision ${revision + 1}`}\n </Button>\n </BlockedControl>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Up to ${CommerceModel.QUOTE_MAX_PROOFS} files, ${formatVisitorUploadBytes(VISITOR_UPLOAD_MAX_BYTES)} each.`}\n </Typography>\n </Stack>\n ) : null}\n\n {revision > 1 ? (\n <Stack spacing={1.5}>\n <Divider />\n <Typography variant=\"subtitle2\">{'Earlier revisions'}</Typography>\n {historyError ? <Alert severity=\"error\">{historyError}</Alert> : null}\n {history === null && !historyError ? <CircularProgress size={20} aria-label=\"Loading earlier revisions\" /> : null}\n {earlier.map((entry) => (\n <Paper key={entry.revision} variant=\"outlined\" sx={{ p: 2 }}>\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 0.5 }}>\n <Typography variant=\"body2\" sx={{ fontWeight: 'fontWeightMedium' }}>{`Revision ${entry.revision}`}</Typography>\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={CommerceModel.QUOTE_STAGE_LABELS[entry.stage] ?? entry.stage}\n color={CommerceModel.QUOTE_STATUS_COLOR[entry.stage] ?? 'default'}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Replaced ${dateTime(entry.closedAtMs)}`}\n </Typography>\n </Stack>\n {entry.proofs.length ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n {entry.proofs.map((proof) => tile(proof, entry.revision))}\n </Stack>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No proofs.'}\n </Typography>\n )}\n {entry.responses.map((response, index) => (\n <QuoteResponseNote key={index} response={response} tile={(file) => tile(file, entry.revision)} />\n ))}\n </Stack>\n </Paper>\n ))}\n </Stack>\n ) : null}\n\n <Dialog open={confirmingRevision} onClose={() => setConfirmingRevision(false)} maxWidth=\"xs\" fullWidth>\n <DialogTitle>{`Start revision ${revision + 1}?`}</DialogTitle>\n <DialogContent>\n <DialogContentText>\n {`Revision ${revision} is kept as it is now, with its proofs and the customer’s answers. ` +\n `Revision ${revision + 1} starts with no proofs, ready for new ones and any changes to the quote.`}\n </DialogContentText>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setConfirmingRevision(false)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy} onClick={() => void startRevision()}>\n {`Start revision ${revision + 1}`}\n </Button>\n </DialogActions>\n </Dialog>\n </Stack>\n )\n}\nQuoteProofsSection.displayName = 'QuoteProofsSection'\n\nexport default QuoteProofsSection\n"],"names":["CommerceModel","commerceSitePermissionRefusal","checkVisitorUploadSelection","formatVisitorUploadBytes","visitorUploadIsInline","VISITOR_UPLOAD_ACCEPT","VISITOR_UPLOAD_MAX_BYTES","sendVisitorUpload","BlockedControl","useSnackbar","authorizedFetch","useUser","Alert","Box","Button","Chip","CircularProgress","Dialog","DialogActions","DialogContent","DialogContentText","DialogTitle","Divider","Paper","Stack","Typography","useCallback","useEffect","useRef","useState","REFUSAL","postQuote","user","body","response","method","headers","JSON","stringify","ok","payload","json","catch","fetchQuoteFile","action","blob","dateTime","atMs","Date","toLocaleString","undefined","dateStyle","timeStyle","ProofThumbnail","props","hostId","quoteId","file","revision","src","setSrc","live","url","fileId","id","then","URL","createObjectURL","revokeObjectURL","sx","theme","width","spacing","height","display","alignItems","justifyContent","bgcolor","borderRadius","overflow","component","alt","name","maxWidth","maxHeight","objectFit","size","aria-label","QuoteFileTile","onDownload","onRemove","removeBlocked","image","contentType","variant","p","label","onClick","title","blocked","Boolean","reason","color","QuoteResponseNote","tile","severity","ip","userAgent","filter","join","whiteSpace","comment","files","length","direction","useFlexGap","flexWrap","map","QuoteProofsSection","quote","canEdit","onEdited","data","enqueueSnackbar","section","Math","max","Number","proofs","currentQuoteProofs","latest","latestQuoteResponse","unpaid","isUnpaidQuote","addRefusal","quoteProofChangeRefusal","removable","sending","setSending","busy","setBusy","confirmingRevision","setConfirmingRevision","history","setHistory","historyError","setHistoryError","picker","loadHistory","answer","String","error","Array","isArray","download","fromRevision","allowDuplicate","link","document","createElement","href","click","setTimeout","addProofs","problem","QUOTE_MAX_PROOFS","done","total","index","entries","stamp","sent","requestTicket","request","finalize","ticket","removeProof","proofId","startRevision","persist","picked","at","earlier","entry","reverse","requireProofApproval","proof","input","ref","type","multiple","hidden","accept","data-testid","onChange","event","from","target","value","quoteProofRefusalMessage","disabled","current","rowGap","fontWeight","QUOTE_STAGE_LABELS","stage","QUOTE_STATUS_COLOR","closedAtMs","responses","open","onClose","fullWidth","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;AAEA,YAAYA,mBAAmB,uBAAa;AAC5C,SAASC,6BAA6B,QAAQ,oCAAgC;AAC9E,SACEC,2BAA2B,EAC3BC,wBAAwB,EACxBC,qBAAqB,EACrBC,qBAAqB,EACrBC,wBAAwB,QACnB,wCAAuC;AAC9C,SAASC,iBAAiB,QAAQ,+CAA8C;AAChF,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,OAAO,EACPC,KAAK,EACLC,KAAK,EACLC,UAAU,QACL,gBAAe;AACtB,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAwB,QAAO;AAEhF,MAAMC,UAAU7B,8BAA8B;AA4B9C,eAAe8B,UAAUC,IAAU,EAAEC,IAA6B;IAChE,MAAMC,WAAW,MAAMxB,gBAAgBsB,MAAM,uBAAuB;QAClEG,QAAQ;QACRC,SAAS;YAAE,gBAAgB;QAAmB;QAC9CH,MAAMI,KAAKC,SAAS,CAACL;IACvB;IACA,OAAO;QAAEM,IAAIL,SAASK,EAAE;QAAEC,SAAS,MAAMN,SAASO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AAsB;gCAAQ0D,UAAU7D;0CAC5D;;0CAEH,KAAC7H;gCAAOgF,SAAQ;gCAAY0G,UAAU7D;gCAAM1C,SAAS,IAAM,KAAKiF;0CAC7D,CAAC,eAAe,EAAExH,WAAW,GAAG;;;;;;;;AAM7C;AACA4D,mBAAmB8F,WAAW,GAAG;AAEjC,eAAe9F,mBAAkB"}
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/quote-proofs.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\n'use client'\n\nimport * as CommerceModel from '../../model'\nimport { commerceSitePermissionRefusal } from '../../model/plugin-permissions'\nimport {\n checkVisitorUploadSelection,\n formatVisitorUploadBytes,\n visitorUploadIsInline,\n VISITOR_UPLOAD_ACCEPT,\n VISITOR_UPLOAD_MAX_BYTES,\n} from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { sendVisitorUpload } from '@aglyn/aglyn/app-utils/visitor-upload-client'\nimport { BlockedControl } from '@aglyn/shared-ui-jsx/components/blocked-control.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Box,\n Button,\n Chip,\n CircularProgress,\n Dialog,\n DialogActions,\n DialogContent,\n DialogContentText,\n DialogTitle,\n Divider,\n Paper,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'\n\nconst REFUSAL = commerceSitePermissionRefusal('commerce.quotes')\n\ntype User = Parameters<typeof authorizedFetch>[0]\n\n/** A file the console lists: a proof, or one the customer sent. Never its storage path. */\ninterface ListedFile {\n id: string\n name: string\n contentType: string\n size: number\n}\n\n/** An earlier revision as the route lists it. */\ntype RevisionView = Omit<CommerceModel.QuoteRevisionSnapshot, 'proofs' | 'responses'> & {\n proofs: ListedFile[]\n responses: Array<Omit<CommerceModel.QuoteCustomerResponse, 'files'> & { files?: ListedFile[] }>\n}\n\nexport interface QuoteProofsSectionProps {\n hostId: string\n quoteId: string\n quote: CommerceModel.HostOrder\n /** Holds \"Create and edit quotes\" (`commerce.quotes`). */\n canEdit: boolean\n /** A change here moved the quote's edit stamp; the editor saves against the new one. */\n onEdited: (updatedAtMs: number) => void\n}\n\nasync function postQuote(user: User, body: Record<string, unknown>): Promise<{ ok: boolean; payload: Record<string, any> }> {\n const response = await authorizedFetch(user, '/api/commerce/quote', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(body),\n })\n return { ok: response.ok, payload: await response.json().catch(() => ({})) }\n}\n\n/** One of the quote's files as a blob, fetched with the member's token; null when refused. */\nasync function fetchQuoteFile(\n user: User,\n body: { hostId: string; quoteId: string; fileId: string; revision?: number },\n): Promise<Blob | null> {\n try {\n const response = await authorizedFetch(user, '/api/commerce/quote', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ action: 'file', ...body }),\n })\n return response.ok ? await response.blob() : null\n } catch {\n return null\n }\n}\n\nfunction dateTime(atMs: number | undefined): string {\n return atMs ? new Date(atMs).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' }) : ''\n}\n\n/** A picture of an image proof, loaded with the member's token. */\nfunction ProofThumbnail(props: { user: User; hostId: string; quoteId: string; file: ListedFile; revision?: number }) {\n const { user, hostId, quoteId, file, revision } = props\n const [src, setSrc] = useState<string | null>(null)\n useEffect(() => {\n let live = true\n let url = ''\n void fetchQuoteFile(user, { hostId, quoteId, fileId: file.id, ...(revision ? { revision } : {}) }).then((blob) => {\n if (!live || !blob) return\n url = URL.createObjectURL(blob)\n setSrc(url)\n })\n return () => {\n live = false\n if (url) URL.revokeObjectURL(url)\n }\n }, [user, hostId, quoteId, file.id, revision])\n return (\n <Box\n sx={(theme) => ({\n width: theme.spacing(16),\n height: theme.spacing(12),\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n bgcolor: 'action.hover',\n borderRadius: 1,\n overflow: 'hidden',\n })}\n >\n {src ? (\n <Box component=\"img\" src={src} alt={file.name} sx={{ maxWidth: 1, maxHeight: 1, objectFit: 'contain' }} />\n ) : (\n <CircularProgress size={20} aria-label={`Loading ${file.name}`} />\n )}\n </Box>\n )\n}\n\n/** A file: a picture for an image, a chip naming it for anything else; both download it. */\nfunction QuoteFileTile(props: {\n user: User\n hostId: string\n quoteId: string\n file: ListedFile\n revision?: number\n onDownload: (file: ListedFile, revision?: number) => void\n onRemove?: () => void\n removeBlocked?: boolean\n}) {\n const { file, revision, onDownload, onRemove, removeBlocked } = props\n const image = visitorUploadIsInline(file.contentType)\n return (\n <Paper variant=\"outlined\" sx={{ p: 1 }}>\n <Stack spacing={1} sx={(theme) => ({ width: image ? theme.spacing(16) : 'auto', maxWidth: theme.spacing(32) })}>\n {image ? <ProofThumbnail {...props} /> : null}\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={`${file.name} · ${formatVisitorUploadBytes(file.size)}`}\n onClick={() => onDownload(file, revision)}\n title={`Download ${file.name}`}\n />\n {onRemove ? (\n <BlockedControl blocked={Boolean(removeBlocked)} reason={REFUSAL}>\n <Button size=\"small\" color=\"inherit\" onClick={onRemove} aria-label={`Remove ${file.name}`}>\n {'Remove'}\n </Button>\n </BlockedControl>\n ) : null}\n </Stack>\n </Paper>\n )\n}\n\n/** What the customer said, with any files they sent. */\nfunction QuoteResponseNote(props: {\n response: Omit<CommerceModel.QuoteCustomerResponse, 'files'> & { files?: ListedFile[] }\n tile: (file: ListedFile) => ReactNode\n}) {\n const { response, tile } = props\n if (response.action === 'approve') {\n return (\n <Alert severity=\"success\">\n <Stack spacing={0.5}>\n <Typography variant=\"body2\">{`Approved by ${response.name || 'the customer'} on ${dateTime(response.atMs)}.`}</Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {[response.ip ? `From ${response.ip}` : '', response.userAgent ?? ''].filter(Boolean).join(' · ')}\n </Typography>\n </Stack>\n </Alert>\n )\n }\n return (\n <Alert severity=\"warning\">\n <Stack spacing={1}>\n <Typography variant=\"body2\">{`Changes requested on ${dateTime(response.atMs)}:`}</Typography>\n <Typography variant=\"body2\" sx={{ whiteSpace: 'pre-line' }}>\n {response.comment}\n </Typography>\n {response.files?.length ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n {response.files.map((file) => tile(file))}\n </Stack>\n ) : null}\n </Stack>\n </Alert>\n )\n}\n\n/**\n * A quote's proofs and revisions (AGL-4096), in its editor: the current\n * revision's proofs (a picture for an image, a chip for a PDF or a design\n * file), Add proof, what the customer last said with any files they sent,\n * \"Start revision N+1\", and every earlier revision as it was kept.\n */\nexport function QuoteProofsSection(props: QuoteProofsSectionProps) {\n const { hostId, quoteId, quote, canEdit, onEdited } = props\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const section = quote.quote\n const revision = Math.max(1, Number(section?.revision ?? 1) || 1)\n const proofs = CommerceModel.currentQuoteProofs(section)\n const latest = CommerceModel.latestQuoteResponse(section)\n const unpaid = CommerceModel.isUnpaidQuote(quote)\n const addRefusal = CommerceModel.quoteProofChangeRefusal(quote, 'add')\n const removable = CommerceModel.quoteProofChangeRefusal(quote, 'remove') === null\n const [sending, setSending] = useState<{ done: number; total: number } | null>(null)\n const [busy, setBusy] = useState(false)\n const [confirmingRevision, setConfirmingRevision] = useState(false)\n const [history, setHistory] = useState<RevisionView[] | null>(null)\n const [historyError, setHistoryError] = useState('')\n const picker = useRef<HTMLInputElement>(null)\n\n const loadHistory = useCallback(async () => {\n setHistoryError('')\n const answer = await postQuote(user, { action: 'revisions', hostId, quoteId }).catch(() => null)\n if (!answer?.ok) {\n setHistoryError(String(answer?.payload?.error ?? 'Earlier revisions could not be loaded.'))\n return\n }\n setHistory(Array.isArray(answer.payload['revisions']) ? (answer.payload['revisions'] as RevisionView[]) : [])\n }, [user, hostId, quoteId])\n\n // Earlier revisions are read when there are some, and again after one is added.\n useEffect(() => {\n if (revision > 1) void loadHistory()\n }, [revision, loadHistory])\n\n const download = useCallback(\n async (file: ListedFile, fromRevision?: number) => {\n const blob = await fetchQuoteFile(user, { hostId, quoteId, fileId: file.id, ...(fromRevision ? { revision: fromRevision } : {}) })\n if (!blob) return void enqueueSnackbar('The file could not be downloaded', { variant: 'error', allowDuplicate: true })\n const url = URL.createObjectURL(blob)\n const link = document.createElement('a')\n link.href = url\n link.download = file.name\n link.click()\n setTimeout(() => URL.revokeObjectURL(url), 1000)\n },\n [user, hostId, quoteId, enqueueSnackbar],\n )\n\n const addProofs = useCallback(\n async (files: File[]) => {\n const problem = checkVisitorUploadSelection(files, proofs.length, CommerceModel.QUOTE_MAX_PROOFS)\n if (problem) return void enqueueSnackbar(problem, { variant: 'error', allowDuplicate: true })\n setSending({ done: 0, total: files.length })\n try {\n for (const [index, file] of files.entries()) {\n let stamp = 0\n const sent = await sendVisitorUpload({\n file,\n requestTicket: async (request) => {\n const answer = await postQuote(user, { action: 'proof-ticket', hostId, quoteId, file: request })\n return answer.ok\n ? (answer.payload as { ticket: string; upload: { url: string; fields: Record<string, string> } })\n : { error: String(answer.payload['error'] ?? 'The proof could not be sent') }\n },\n finalize: async (ticket) => {\n const answer = await postQuote(user, { action: 'proof-finalize', hostId, quoteId, ticket })\n if (!answer.ok) return { error: String(answer.payload['error'] ?? 'The proof could not be kept') }\n stamp = Number(answer.payload['updatedAtMs']) || 0\n return { file: answer.payload['proof'] }\n },\n })\n if ('error' in sent) {\n enqueueSnackbar(sent.error, { variant: 'error', allowDuplicate: true })\n break\n }\n if (stamp) onEdited(stamp)\n setSending({ done: index + 1, total: files.length })\n }\n } finally {\n setSending(null)\n }\n },\n [user, hostId, quoteId, proofs.length, onEdited, enqueueSnackbar],\n )\n\n const removeProof = useCallback(\n async (proofId: string) => {\n setBusy(true)\n try {\n const answer = await postQuote(user, { action: 'proof-remove', hostId, quoteId, proofId })\n if (!answer.ok) {\n return void enqueueSnackbar(String(answer.payload['error'] ?? 'The proof could not be removed'), {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n onEdited(Number(answer.payload['updatedAtMs']) || 0)\n } finally {\n setBusy(false)\n }\n },\n [user, hostId, quoteId, onEdited, enqueueSnackbar],\n )\n\n const startRevision = useCallback(async () => {\n setBusy(true)\n try {\n const answer = await postQuote(user, { action: 'start-revision', hostId, quoteId })\n if (!answer.ok) {\n return void enqueueSnackbar(String(answer.payload['error'] ?? 'The revision could not be started'), {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n onEdited(Number(answer.payload['updatedAtMs']) || 0)\n enqueueSnackbar(`Revision ${Number(answer.payload['revision']) || revision + 1} started`, { variant: 'success', persist: false })\n setConfirmingRevision(false)\n } finally {\n setBusy(false)\n }\n }, [user, hostId, quoteId, revision, onEdited, enqueueSnackbar])\n\n const tile = (file: ListedFile, fromRevision?: number, onRemove?: () => void) => (\n <QuoteFileTile\n key={`${fromRevision ?? 'current'}-${file.id}`}\n user={user}\n hostId={hostId}\n quoteId={quoteId}\n file={file}\n revision={fromRevision}\n onDownload={(picked, at) => void download(picked, at)}\n onRemove={onRemove}\n removeBlocked={!canEdit}\n />\n )\n\n const earlier = (history ?? []).filter((entry) => Number(entry.revision) < revision).reverse()\n\n return (\n <Stack spacing={1.5}>\n <Stack spacing={0.5}>\n <Typography variant=\"subtitle2\">{`Proofs · Revision ${revision}`}</Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {section?.requireProofApproval\n ? 'The customer sees these on the quote page and approves them before they can pay.'\n : 'The customer sees these on the quote page, and can approve them or ask for changes. Paying doesn’t wait on it.'}\n </Typography>\n </Stack>\n\n {latest ? <QuoteResponseNote response={latest} tile={(file) => tile(file)} /> : null}\n\n {proofs.length ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n {proofs.map((proof) =>\n tile(proof, undefined, removable ? () => void removeProof(proof.id) : undefined),\n )}\n </Stack>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No proofs on this revision yet. Add an image, a PDF or a design file for the customer to approve.'}\n </Typography>\n )}\n\n {unpaid ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap', alignItems: 'center' }}>\n <input\n ref={picker}\n type=\"file\"\n multiple\n hidden\n accept={VISITOR_UPLOAD_ACCEPT}\n data-testid=\"quote-proof-picker\"\n onChange={(event) => {\n const files = Array.from(event.target.files ?? [])\n event.target.value = ''\n if (files.length) void addProofs(files)\n }}\n />\n <BlockedControl\n blocked={!canEdit || Boolean(addRefusal)}\n reason={!canEdit ? REFUSAL : addRefusal ? CommerceModel.quoteProofRefusalMessage(addRefusal) : ''}\n >\n <Button variant=\"outlined\" size=\"small\" disabled={busy || Boolean(sending)} onClick={() => picker.current?.click()}>\n {sending ? `Sending ${sending.done + 1} of ${sending.total}…` : 'Add proof'}\n </Button>\n </BlockedControl>\n <BlockedControl blocked={!canEdit} reason={REFUSAL}>\n <Button size=\"small\" disabled={busy || Boolean(sending)} onClick={() => setConfirmingRevision(true)}>\n {`Start revision ${revision + 1}`}\n </Button>\n </BlockedControl>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Up to ${CommerceModel.QUOTE_MAX_PROOFS} files, ${formatVisitorUploadBytes(VISITOR_UPLOAD_MAX_BYTES)} each.`}\n </Typography>\n </Stack>\n ) : null}\n\n {revision > 1 ? (\n <Stack spacing={1.5}>\n <Divider />\n <Typography variant=\"subtitle2\">{'Earlier revisions'}</Typography>\n {historyError ? <Alert severity=\"error\">{historyError}</Alert> : null}\n {history === null && !historyError ? <CircularProgress size={20} aria-label=\"Loading earlier revisions\" /> : null}\n {earlier.map((entry) => (\n <Paper key={entry.revision} variant=\"outlined\" sx={{ p: 2 }}>\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 0.5 }}>\n <Typography variant=\"body2\" sx={{ fontWeight: 'fontWeightMedium' }}>{`Revision ${entry.revision}`}</Typography>\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={CommerceModel.QUOTE_STAGE_LABELS[entry.stage] ?? entry.stage}\n color={CommerceModel.QUOTE_STATUS_COLOR[entry.stage] ?? 'default'}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Replaced ${dateTime(entry.closedAtMs)}`}\n </Typography>\n </Stack>\n {entry.proofs.length ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n {entry.proofs.map((proof) => tile(proof, entry.revision))}\n </Stack>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No proofs.'}\n </Typography>\n )}\n {entry.responses.map((response, index) => (\n <QuoteResponseNote key={index} response={response} tile={(file) => tile(file, entry.revision)} />\n ))}\n </Stack>\n </Paper>\n ))}\n </Stack>\n ) : null}\n\n <Dialog open={confirmingRevision} onClose={() => setConfirmingRevision(false)} maxWidth=\"xs\" fullWidth>\n <DialogTitle>{`Start revision ${revision + 1}?`}</DialogTitle>\n <DialogContent>\n <DialogContentText>\n {`Revision ${revision} is kept as it is now, with its proofs and the customer’s answers. ` +\n `Revision ${revision + 1} starts with no proofs, ready for new ones and any changes to the quote.`}\n </DialogContentText>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setConfirmingRevision(false)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy} onClick={() => void startRevision()}>\n {`Start revision ${revision + 1}`}\n </Button>\n </DialogActions>\n </Dialog>\n </Stack>\n )\n}\nQuoteProofsSection.displayName = 'QuoteProofsSection'\n\nexport default QuoteProofsSection\n\n/**\n * The files a quote's request came with (AGL-4098), as the customer's files:\n * a picture for an image, a chip naming anything else, each downloaded\n * through the quote's own route. They stay where the request keeps them, so a\n * request deleted from the Inbox takes them with it.\n */\nexport function QuoteRequestFilesSection(props: { hostId: string; quoteId: string; quote: CommerceModel.HostOrder }) {\n const { hostId, quoteId, quote } = props\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const request = quote.quote?.request\n const files = CommerceModel.quoteRequestFileViews(quote.quote?.requestFiles)\n const download = useCallback(\n async (file: ListedFile) => {\n const blob = await fetchQuoteFile(user, { hostId, quoteId, fileId: file.id })\n if (!blob) {\n return void enqueueSnackbar('The file could not be downloaded. The request may have been deleted from the Inbox.', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n const url = URL.createObjectURL(blob)\n const link = document.createElement('a')\n link.href = url\n link.download = file.name\n link.click()\n setTimeout(() => URL.revokeObjectURL(url), 1000)\n },\n [user, hostId, quoteId, enqueueSnackbar],\n )\n if (!request || !user) return null\n const when = request.receivedAtMs ? ` on ${dateTime(request.receivedAtMs)}` : ''\n return (\n <Stack spacing={1}>\n <Typography variant=\"subtitle2\">{'From the request'}</Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`Sent through “${request.formName}”${when}.` + (files.length ? ' The files they sent:' : ' They sent no files.')}\n </Typography>\n {files.length ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n {files.map((file) => (\n <QuoteFileTile\n key={file.id}\n user={user}\n hostId={hostId}\n quoteId={quoteId}\n file={file}\n onDownload={(picked) => void download(picked)}\n />\n ))}\n </Stack>\n ) : null}\n </Stack>\n )\n}\n"],"names":["CommerceModel","commerceSitePermissionRefusal","checkVisitorUploadSelection","formatVisitorUploadBytes","visitorUploadIsInline","VISITOR_UPLOAD_ACCEPT","VISITOR_UPLOAD_MAX_BYTES","sendVisitorUpload","BlockedControl","useSnackbar","authorizedFetch","useUser","Alert","Box","Button","Chip","CircularProgress","Dialog","DialogActions","DialogContent","DialogContentText","DialogTitle","Divider","Paper","Stack","Typography","useCallback","useEffect","useRef","useState","REFUSAL","postQuote","user","body","response","method","headers","JSON","stringify","ok","payload","json","catch","fetchQuoteFile","action","blob","dateTime","atMs","Date","toLocaleString","undefined","dateStyle","timeStyle","ProofThumbnail","props","hostId","quoteId","file","revision","src","setSrc","live","url","fileId","id","then","URL","createObjectURL","revokeObjectURL","sx","theme","width","spacing","height","display","alignItems","justifyContent","bgcolor","borderRadius","overflow","component","alt","name","maxWidth","maxHeight","objectFit","size","aria-label","QuoteFileTile","onDownload","onRemove","removeBlocked","image","contentType","variant","p","label","onClick","title","blocked","Boolean","reason","color","QuoteResponseNote","tile","severity","ip","userAgent","filter","join","whiteSpace","comment","files","length","direction","useFlexGap","flexWrap","map","QuoteProofsSection","quote","canEdit","onEdited","data","enqueueSnackbar","section","Math","max","Number","proofs","currentQuoteProofs","latest","latestQuoteResponse","unpaid","isUnpaidQuote","addRefusal","quoteProofChangeRefusal","removable","sending","setSending","busy","setBusy","confirmingRevision","setConfirmingRevision","history","setHistory","historyError","setHistoryError","picker","loadHistory","answer","String","error","Array","isArray","download","fromRevision","allowDuplicate","link","document","createElement","href","click","setTimeout","addProofs","problem","QUOTE_MAX_PROOFS","done","total","index","entries","stamp","sent","requestTicket","request","finalize","ticket","removeProof","proofId","startRevision","persist","picked","at","earlier","entry","reverse","requireProofApproval","proof","input","ref","type","multiple","hidden","accept","data-testid","onChange","event","from","target","value","quoteProofRefusalMessage","disabled","current","rowGap","fontWeight","QUOTE_STAGE_LABELS","stage","QUOTE_STATUS_COLOR","closedAtMs","responses","open","onClose","fullWidth","displayName","QuoteRequestFilesSection","quoteRequestFileViews","requestFiles","when","receivedAtMs","formName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;AAEA,YAAYA,mBAAmB,uBAAa;AAC5C,SAASC,6BAA6B,QAAQ,oCAAgC;AAC9E,SACEC,2BAA2B,E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AG,CAAC,CAAC5D,qBACV,KAAC+B;wBAECxD,MAAMA;wBACNuB,QAAQA;wBACRC,SAASA;wBACTC,MAAMA;wBACNgC,YAAY,CAAC2F,SAAW,KAAK1B,SAAS0B;uBALjC3H,KAAKO,EAAE;iBAShB;;;AAGV"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import * as CommerceModel from '../../model';
18
+ export interface QuoteSendSectionProps {
19
+ hostId: string;
20
+ quoteId: string;
21
+ quote: CommerceModel.HostOrder;
22
+ /** Holds "Send quotes and invoices to customers" (`commerce.quotes.send`). */
23
+ canSend: boolean;
24
+ /** The editor holds changes not saved yet, which the email would not show. */
25
+ edited: boolean;
26
+ }
27
+ /**
28
+ * Emailing the quote to the customer (AGL-4097): when it was last sent and to
29
+ * whom, and Send quote, Send again or Send revision N, which opens a short
30
+ * form (To, Subject, Message). The server writes the email in the site's
31
+ * look with the proof, the PDF and the pay button, in the customer's
32
+ * conversation with the business.
33
+ *
34
+ * Send invoice (AGL-4099) sits beside it: for an unpaid quote, an invoice for
35
+ * a customer who needs one to pay (with the same pay link); for a paid one,
36
+ * the invoice as their record. Both reply into the quote's conversation.
37
+ */
38
+ export declare function QuoteSendSection(props: QuoteSendSectionProps): import("react").JSX.Element;
39
+ export declare namespace QuoteSendSection {
40
+ var displayName: string;
41
+ }
42
+ export default QuoteSendSection;
@@ -0,0 +1,307 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ 'use client';
17
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
+ import * as CommerceModel from "../../model/index.js";
19
+ import { commerceSitePermissionRefusal } from "../../model/plugin-permissions.js";
20
+ import { siteContactEmail, resolveHostToken } from "@aglyn/aglyn/app-utils/host-tokens";
21
+ import { BlockedControl } from "@aglyn/shared-ui-jsx/components/blocked-control.component";
22
+ import { useSnackbar } from "@aglyn/shared-ui-snackstack";
23
+ import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
24
+ import { useFirestore, useFirestoreDoc, useUser } from "@aglyn/tenant-feature-instance";
25
+ import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Stack, TextField, Typography } from "@mui/material";
26
+ import { doc } from "firebase/firestore";
27
+ import { useCallback, useEffect, useRef, useState } from "react";
28
+ import { InvoiceSendDialog, invoiceSentLine } from "./invoice-send.component.js";
29
+ const SEND_REFUSAL = commerceSitePermissionRefusal('commerce.quotes.send');
30
+ /** `Oct 29, 2026, 3:04 PM`. */ const sentAt = (atMs)=>new Date(atMs).toLocaleString('en-US', {
31
+ dateStyle: 'medium',
32
+ timeStyle: 'short'
33
+ });
34
+ /**
35
+ * Emailing the quote to the customer (AGL-4097): when it was last sent and to
36
+ * whom, and Send quote, Send again or Send revision N, which opens a short
37
+ * form (To, Subject, Message). The server writes the email in the site's
38
+ * look with the proof, the PDF and the pay button, in the customer's
39
+ * conversation with the business.
40
+ *
41
+ * Send invoice (AGL-4099) sits beside it: for an unpaid quote, an invoice for
42
+ * a customer who needs one to pay (with the same pay link); for a paid one,
43
+ * the invoice as their record. Both reply into the quote's conversation.
44
+ */ export function QuoteSendSection(props) {
45
+ var _resolveHostToken, _ref;
46
+ const { hostId, quoteId, quote, canSend, edited } = props;
47
+ const firestore = useFirestore();
48
+ const { data: user } = useUser();
49
+ const { enqueueSnackbar } = useSnackbar();
50
+ const { data: host } = useFirestoreDoc(()=>doc(firestore, 'hosts', hostId), [
51
+ firestore,
52
+ hostId
53
+ ]);
54
+ const businessName = String((_resolveHostToken = resolveHostToken('businessName', host != null ? host : {})) != null ? _resolveHostToken : '').trim();
55
+ const section = quote.quote;
56
+ const unpaid = CommerceModel.isUnpaidQuote(quote);
57
+ const last = CommerceModel.lastQuoteSend(section);
58
+ const revision = Number((_ref = section == null ? void 0 : section.revision) != null ? _ref : 1);
59
+ const label = CommerceModel.quoteSendLabel(section);
60
+ const replacesLink = CommerceModel.quoteSendReplacesLink(section);
61
+ const approvalFirst = CommerceModel.quotePaymentBlockedByApproval(section);
62
+ const proofCount = CommerceModel.currentQuoteProofs(section).length;
63
+ const listed = siteContactEmail(host);
64
+ const contact = listed && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(listed) ? listed : null;
65
+ const [open, setOpen] = useState(false);
66
+ const [invoicing, setInvoicing] = useState(false);
67
+ const invoiceLine = invoiceSentLine(quote);
68
+ const closed = quote.status === 'cancelled' || quote.status === 'refunded';
69
+ const [busy, setBusy] = useState(false);
70
+ const [to, setTo] = useState('');
71
+ const [subject, setSubject] = useState('');
72
+ const [message, setMessage] = useState('');
73
+ /*
74
+ * One attempt per form (AGL-1697's rule): a retried Send presents the same
75
+ * key and is answered from the first, so the customer never gets two; a
76
+ * changed form is a new attempt.
77
+ */ const attemptKey = useRef('');
78
+ useEffect(()=>{
79
+ attemptKey.current = '';
80
+ }, [
81
+ to,
82
+ subject,
83
+ message
84
+ ]);
85
+ const openForm = useCallback(()=>{
86
+ var _ref;
87
+ var _section_customer;
88
+ setTo(String((_ref = section == null ? void 0 : (_section_customer = section.customer) == null ? void 0 : _section_customer.email) != null ? _ref : ''));
89
+ setSubject(CommerceModel.quoteEmailDefaultSubject(quote, businessName, quoteId));
90
+ setMessage('');
91
+ setOpen(true);
92
+ }, [
93
+ section,
94
+ quote,
95
+ businessName,
96
+ quoteId
97
+ ]);
98
+ const send = useCallback(async ()=>{
99
+ setBusy(true);
100
+ try {
101
+ var _payload_to;
102
+ if (!attemptKey.current) {
103
+ var _ref;
104
+ var _globalThis_crypto_randomUUID, _globalThis_crypto;
105
+ attemptKey.current = (_ref = (_globalThis_crypto = globalThis.crypto) == null ? void 0 : (_globalThis_crypto_randomUUID = _globalThis_crypto.randomUUID) == null ? void 0 : _globalThis_crypto_randomUUID.call(_globalThis_crypto)) != null ? _ref : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
106
+ }
107
+ const response = await authorizedFetch(user, '/api/commerce/quote', {
108
+ method: 'POST',
109
+ headers: {
110
+ 'Content-Type': 'application/json',
111
+ 'Idempotency-Key': attemptKey.current
112
+ },
113
+ body: JSON.stringify({
114
+ action: 'send',
115
+ hostId,
116
+ quoteId,
117
+ to,
118
+ subject,
119
+ message
120
+ })
121
+ });
122
+ const payload = await response.json().catch(()=>({}));
123
+ if (!response.ok) {
124
+ var _ref1;
125
+ return void enqueueSnackbar((_ref1 = payload == null ? void 0 : payload.error) != null ? _ref1 : 'The quote could not be sent', {
126
+ variant: 'error',
127
+ allowDuplicate: true
128
+ });
129
+ }
130
+ enqueueSnackbar(`${CommerceModel.formatQuoteNumber(quote, quoteId)} sent to ${String((_payload_to = payload.to) != null ? _payload_to : to)}` + (payload.linkReplaced ? '. The link in your earlier email no longer opens the quote.' : ''), {
131
+ variant: 'success',
132
+ persist: false
133
+ });
134
+ setOpen(false);
135
+ } finally{
136
+ setBusy(false);
137
+ }
138
+ }, [
139
+ user,
140
+ hostId,
141
+ quoteId,
142
+ to,
143
+ subject,
144
+ message,
145
+ quote,
146
+ enqueueSnackbar
147
+ ]);
148
+ const status = last ? `Sent ${sentAt(Number(last.atMs))} to ${last.to || 'the customer'}` + (Number(last.revision) < revision ? ` (revision ${last.revision})` : '') + '.' : 'Not sent yet. Email it with your message, the proof and the PDF, or copy the pay link below and send it yourself.';
149
+ return /*#__PURE__*/ _jsxs(Stack, {
150
+ spacing: 1.5,
151
+ children: [
152
+ /*#__PURE__*/ _jsxs(Stack, {
153
+ spacing: 0.5,
154
+ children: [
155
+ /*#__PURE__*/ _jsx(Typography, {
156
+ variant: "subtitle2",
157
+ children: 'Email to customer'
158
+ }),
159
+ /*#__PURE__*/ _jsx(Typography, {
160
+ variant: "body2",
161
+ color: "text.secondary",
162
+ children: unpaid ? status : last ? status : 'This quote was paid without being emailed.'
163
+ }),
164
+ unpaid && replacesLink ? /*#__PURE__*/ _jsx(Typography, {
165
+ variant: "body2",
166
+ color: "text.secondary",
167
+ children: `Sending revision ${revision} gives your customer a new pay link. The link in your earlier email will say the quote was updated.`
168
+ }) : null,
169
+ unpaid && edited ? /*#__PURE__*/ _jsx(Typography, {
170
+ variant: "body2",
171
+ color: "text.secondary",
172
+ children: 'Save your changes first: the email shows the quote as it was last saved.'
173
+ }) : null,
174
+ invoiceLine ? /*#__PURE__*/ _jsx(Typography, {
175
+ variant: "body2",
176
+ color: "text.secondary",
177
+ children: invoiceLine
178
+ }) : null
179
+ ]
180
+ }),
181
+ !closed ? /*#__PURE__*/ _jsxs(Stack, {
182
+ direction: "row",
183
+ spacing: 1,
184
+ children: [
185
+ unpaid ? /*#__PURE__*/ _jsx(BlockedControl, {
186
+ blocked: !canSend,
187
+ reason: SEND_REFUSAL,
188
+ children: /*#__PURE__*/ _jsx(Button, {
189
+ variant: "contained",
190
+ size: "small",
191
+ disabled: busy || edited,
192
+ onClick: openForm,
193
+ children: label
194
+ })
195
+ }) : null,
196
+ /*#__PURE__*/ _jsx(BlockedControl, {
197
+ blocked: !canSend,
198
+ reason: SEND_REFUSAL,
199
+ children: /*#__PURE__*/ _jsx(Button, {
200
+ variant: unpaid ? 'outlined' : 'contained',
201
+ size: "small",
202
+ disabled: busy || unpaid && edited,
203
+ onClick: ()=>setInvoicing(true),
204
+ children: 'Send invoice'
205
+ })
206
+ })
207
+ ]
208
+ }) : null,
209
+ /*#__PURE__*/ _jsx(InvoiceSendDialog, {
210
+ open: invoicing,
211
+ onClose: ()=>setInvoicing(false),
212
+ hostId: hostId,
213
+ orderId: quoteId,
214
+ order: quote
215
+ }),
216
+ /*#__PURE__*/ _jsxs(Dialog, {
217
+ open: open,
218
+ onClose: busy ? undefined : ()=>setOpen(false),
219
+ maxWidth: "sm",
220
+ fullWidth: true,
221
+ "aria-labelledby": "quote-send-title",
222
+ children: [
223
+ /*#__PURE__*/ _jsx(DialogTitle, {
224
+ id: "quote-send-title",
225
+ children: `${label}: ${CommerceModel.formatQuoteNumber(quote, quoteId)}`
226
+ }),
227
+ /*#__PURE__*/ _jsx(DialogContent, {
228
+ children: /*#__PURE__*/ _jsxs(Stack, {
229
+ spacing: 2,
230
+ sx: {
231
+ pt: 1
232
+ },
233
+ children: [
234
+ /*#__PURE__*/ _jsx(TextField, {
235
+ label: "To",
236
+ type: "email",
237
+ value: to,
238
+ onChange: (event)=>setTo(event.target.value),
239
+ required: true,
240
+ fullWidth: true,
241
+ disabled: busy
242
+ }),
243
+ /*#__PURE__*/ _jsx(TextField, {
244
+ label: "Subject",
245
+ value: subject,
246
+ onChange: (event)=>setSubject(event.target.value),
247
+ fullWidth: true,
248
+ disabled: busy,
249
+ slotProps: {
250
+ htmlInput: {
251
+ maxLength: CommerceModel.QUOTE_MAX_SEND_SUBJECT
252
+ }
253
+ },
254
+ helperText: (section == null ? void 0 : section.emailThread) ? 'Keep the subject the same to keep these emails in one conversation in your customer’s inbox.' : undefined
255
+ }),
256
+ /*#__PURE__*/ _jsx(TextField, {
257
+ label: "Message",
258
+ value: message,
259
+ onChange: (event)=>setMessage(event.target.value),
260
+ multiline: true,
261
+ minRows: 4,
262
+ fullWidth: true,
263
+ disabled: busy,
264
+ slotProps: {
265
+ htmlInput: {
266
+ maxLength: CommerceModel.QUOTE_MAX_SEND_MESSAGE
267
+ }
268
+ },
269
+ helperText: "Shown at the top of the email, in your words."
270
+ }),
271
+ /*#__PURE__*/ _jsx(Typography, {
272
+ variant: "body2",
273
+ color: "text.secondary",
274
+ children: `The email shows the quote number, revision ${revision} and total` + (proofCount ? ', the proof' : '') + `, with the quote attached as a PDF and a button to ${approvalFirst ? 'approve the proof' : 'pay'} on your site. ` + `Replies go to ${contact || 'your email'}.`
275
+ }),
276
+ replacesLink ? /*#__PURE__*/ _jsx(Typography, {
277
+ variant: "body2",
278
+ color: "text.secondary",
279
+ children: 'This sends a new pay link. The link in your earlier email will say the quote was updated.'
280
+ }) : null
281
+ ]
282
+ })
283
+ }),
284
+ /*#__PURE__*/ _jsxs(DialogActions, {
285
+ children: [
286
+ /*#__PURE__*/ _jsx(Button, {
287
+ onClick: ()=>setOpen(false),
288
+ disabled: busy,
289
+ children: 'Cancel'
290
+ }),
291
+ /*#__PURE__*/ _jsx(Button, {
292
+ variant: "contained",
293
+ disabled: busy || !to.trim(),
294
+ onClick: ()=>void send(),
295
+ children: busy ? 'Sending…' : 'Send'
296
+ })
297
+ ]
298
+ })
299
+ ]
300
+ })
301
+ ]
302
+ });
303
+ }
304
+ QuoteSendSection.displayName = 'QuoteSendSection';
305
+ export default QuoteSendSection;
306
+
307
+ //# sourceMappingURL=quote-send.component.js.map