@aglyn/plugins-commerce 1.9.1 → 1.11.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/invoice-send.component.d.ts +9 -2
- package/src/lib/components/console/invoice-send.component.js +58 -30
- package/src/lib/components/console/invoice-send.component.js.map +1 -1
- package/src/lib/components/console/pay-link-readiness-notice.component.d.ts +84 -0
- package/src/lib/components/console/pay-link-readiness-notice.component.js +164 -0
- package/src/lib/components/console/pay-link-readiness-notice.component.js.map +1 -0
- package/src/lib/components/console/quote-editor-dialog.component.js +7 -8
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-pay-link.component.d.ts +3 -0
- package/src/lib/components/console/quote-pay-link.component.js +9 -0
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-send.component.d.ts +3 -0
- package/src/lib/components/console/quote-send.component.js +9 -0
- package/src/lib/components/console/quote-send.component.js.map +1 -1
- package/src/lib/components/quote-page-body.js +5 -3
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/model/commerce-invoices.d.ts +45 -5
- package/src/lib/model/commerce-invoices.js +46 -9
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-quote-pay.d.ts +110 -6
- package/src/lib/model/commerce-quote-pay.js +182 -23
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/server/billing-webhook.js +4 -1
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/checkout.d.ts +7 -0
- package/src/lib/server/checkout.js +15 -4
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/commerce-pdf.js +2 -1
- package/src/lib/server/commerce-pdf.js.map +1 -1
- package/src/lib/server/invoice-email.js +2 -1
- package/src/lib/server/invoice-email.js.map +1 -1
- package/src/lib/server/order-invoice-send.js +1 -1
- package/src/lib/server/order-invoice-send.js.map +1 -1
- package/src/lib/server/order-status.d.ts +5 -1
- package/src/lib/server/order-status.js +19 -5
- package/src/lib/server/order-status.js.map +1 -1
- package/src/lib/server/quote-email.js +2 -1
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-pay.d.ts +39 -0
- package/src/lib/server/quote-pay.js +103 -43
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proofs.js +13 -9
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/utils/invoice-email-content.d.ts +3 -1
- package/src/lib/utils/invoice-email-content.js +1 -1
- package/src/lib/utils/invoice-email-content.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +3 -1
- package/src/lib/utils/quote-email-content.js +3 -3
- package/src/lib/utils/quote-email-content.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-commerce",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.
|
|
31
|
-
"@aglyn/shared-ui-next": "1.
|
|
32
|
-
"@aglyn/shared-ui-snackstack": "1.
|
|
33
|
-
"@aglyn/shared-util-email": "1.
|
|
34
|
-
"@aglyn/shared-util-http": "1.
|
|
35
|
-
"@aglyn/shared-util-timestamp": "1.
|
|
36
|
-
"@aglyn/shared-util-tools": "1.
|
|
37
|
-
"@aglyn/tenant-data-admin": "1.
|
|
38
|
-
"@aglyn/tenant-feature-instance": "1.
|
|
39
|
-
"@aglyn/tenant-runtime": "1.
|
|
28
|
+
"@aglyn/aglyn": "1.11.0",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.11.0",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.11.0",
|
|
31
|
+
"@aglyn/shared-ui-next": "1.11.0",
|
|
32
|
+
"@aglyn/shared-ui-snackstack": "1.11.0",
|
|
33
|
+
"@aglyn/shared-util-email": "1.11.0",
|
|
34
|
+
"@aglyn/shared-util-http": "1.11.0",
|
|
35
|
+
"@aglyn/shared-util-timestamp": "1.11.0",
|
|
36
|
+
"@aglyn/shared-util-tools": "1.11.0",
|
|
37
|
+
"@aglyn/tenant-data-admin": "1.11.0",
|
|
38
|
+
"@aglyn/tenant-feature-instance": "1.11.0",
|
|
39
|
+
"@aglyn/tenant-runtime": "1.11.0",
|
|
40
40
|
"@stripe/react-stripe-js": "^6.12.0",
|
|
41
41
|
"@stripe/stripe-js": "^9.17.0",
|
|
42
42
|
"@swc/helpers": "0.5.23",
|
|
@@ -34,8 +34,15 @@ export interface InvoiceSendDialogProps {
|
|
|
34
34
|
* invoice PDF attached. Unpaid, the email carries a Pay button to the order's
|
|
35
35
|
* lasting pay link on the business's site; paid, it is the customer's record.
|
|
36
36
|
* A quote's invoice lands in the quote's conversation, and an order's in its
|
|
37
|
-
* own.
|
|
38
|
-
*
|
|
37
|
+
* own.
|
|
38
|
+
*
|
|
39
|
+
* The form's body mounts with the dialog's opening, so everything it reads
|
|
40
|
+
* (the site's name and contact email, once; the store's tax choice and its
|
|
41
|
+
* payments, live) is read only while it is open, and the dialog that offers
|
|
42
|
+
* it listens to nothing more. It says what the customer's Pay waits on, if
|
|
43
|
+
* anything (AGL-4162), and judges the send under the store's sales tax choice
|
|
44
|
+
* as the server does: a quote saved before the store chose is sent as the
|
|
45
|
+
* store's choice prices it.
|
|
39
46
|
*/
|
|
40
47
|
export declare function InvoiceSendDialog(props: InvoiceSendDialogProps): import("react").JSX.Element;
|
|
41
48
|
export declare namespace InvoiceSendDialog {
|
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/ 'use client';
|
|
17
|
-
import {
|
|
17
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
18
19
|
import * as CommerceModel from "../../model/index.js";
|
|
19
20
|
import { siteContactEmail, resolveHostToken } from "@aglyn/aglyn/app-utils/host-tokens";
|
|
21
|
+
import { BlockedControl } from "@aglyn/shared-ui-jsx/components/blocked-control.component";
|
|
20
22
|
import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
21
23
|
import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
|
|
22
24
|
import { useFirestore, useUser } from "@aglyn/tenant-feature-instance";
|
|
23
25
|
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Stack, TextField, Typography } from "@mui/material";
|
|
24
26
|
import { doc, getDoc } from "firebase/firestore";
|
|
25
27
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
28
|
+
import { PayLinkReadinessNotice, usePayLinkReadiness } from "./pay-link-readiness-notice.component.js";
|
|
26
29
|
/** `Oct 29, 2026, 3:04 PM`. */ const sentAt = (atMs)=>new Date(atMs).toLocaleString('en-US', {
|
|
27
30
|
dateStyle: 'medium',
|
|
28
31
|
timeStyle: 'short'
|
|
@@ -42,16 +45,38 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
42
45
|
* invoice PDF attached. Unpaid, the email carries a Pay button to the order's
|
|
43
46
|
* lasting pay link on the business's site; paid, it is the customer's record.
|
|
44
47
|
* A quote's invoice lands in the quote's conversation, and an order's in its
|
|
45
|
-
* own.
|
|
46
|
-
*
|
|
48
|
+
* own.
|
|
49
|
+
*
|
|
50
|
+
* The form's body mounts with the dialog's opening, so everything it reads
|
|
51
|
+
* (the site's name and contact email, once; the store's tax choice and its
|
|
52
|
+
* payments, live) is read only while it is open, and the dialog that offers
|
|
53
|
+
* it listens to nothing more. It says what the customer's Pay waits on, if
|
|
54
|
+
* anything (AGL-4162), and judges the send under the store's sales tax choice
|
|
55
|
+
* as the server does: a quote saved before the store chose is sent as the
|
|
56
|
+
* store's choice prices it.
|
|
47
57
|
*/ export function InvoiceSendDialog(props) {
|
|
48
|
-
const { open, onClose
|
|
58
|
+
const { open, onClose } = props;
|
|
59
|
+
const [busy, setBusy] = useState(false);
|
|
60
|
+
return /*#__PURE__*/ _jsx(Dialog, {
|
|
61
|
+
open: open,
|
|
62
|
+
onClose: busy ? undefined : onClose,
|
|
63
|
+
maxWidth: "sm",
|
|
64
|
+
fullWidth: true,
|
|
65
|
+
"aria-labelledby": "invoice-send-title",
|
|
66
|
+
children: /*#__PURE__*/ _jsx(InvoiceSendForm, _extends({}, props, {
|
|
67
|
+
busy: busy,
|
|
68
|
+
setBusy: setBusy
|
|
69
|
+
}))
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** The open form: filled once when it mounts; edits after that are the member's. */ function InvoiceSendForm(props) {
|
|
73
|
+
var _readiness_gaps, _readiness_gaps1;
|
|
74
|
+
const { onClose, hostId, orderId, order, busy, setBusy } = props;
|
|
49
75
|
const firestore = useFirestore();
|
|
50
76
|
const { data: user } = useUser();
|
|
51
77
|
const { enqueueSnackbar } = useSnackbar();
|
|
52
|
-
const [
|
|
53
|
-
const [
|
|
54
|
-
const [subject, setSubject] = useState('');
|
|
78
|
+
const [to, setTo] = useState(()=>CommerceModel.invoiceSendPrefill(order));
|
|
79
|
+
const [subject, setSubject] = useState(()=>CommerceModel.invoiceEmailDefaultSubject(order, '', orderId));
|
|
55
80
|
const [message, setMessage] = useState('');
|
|
56
81
|
const [contact, setContact] = useState(null);
|
|
57
82
|
/*
|
|
@@ -67,11 +92,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
67
92
|
message
|
|
68
93
|
]);
|
|
69
94
|
useEffect(()=>{
|
|
70
|
-
if (!open) return;
|
|
71
95
|
let live = true;
|
|
72
|
-
setTo(CommerceModel.invoiceSendPrefill(order));
|
|
73
|
-
setSubject(CommerceModel.invoiceEmailDefaultSubject(order, '', orderId));
|
|
74
|
-
setMessage('');
|
|
75
96
|
void getDoc(doc(firestore, 'hosts', hostId)).then((snapshot)=>{
|
|
76
97
|
var _snapshot_data, _resolveHostToken;
|
|
77
98
|
if (!live) return;
|
|
@@ -86,13 +107,16 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
86
107
|
};
|
|
87
108
|
// Filled once per opening; edits after that are the member's.
|
|
88
109
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
89
|
-
}, [
|
|
90
|
-
|
|
91
|
-
]);
|
|
110
|
+
}, []);
|
|
111
|
+
const readiness = usePayLinkReadiness(hostId, order);
|
|
92
112
|
const paid = CommerceModel.invoiceIsPaid(order);
|
|
93
|
-
const refused = CommerceModel.invoiceSendRefusal(order, orderId, to.trim());
|
|
94
|
-
// The address is the form's to fix; every other refusal is the order's,
|
|
113
|
+
const refused = CommerceModel.invoiceSendRefusal(order, orderId, to.trim(), readiness.store);
|
|
114
|
+
// The address is the form's to fix; every other refusal is the order's,
|
|
115
|
+
// said up front once the store's settings are read. One the notice already
|
|
116
|
+
// names, with its fix, is not said twice.
|
|
95
117
|
const blocker = refused && refused !== 'no-address' && refused !== 'bad-address' ? refused : null;
|
|
118
|
+
const toldByNotice = blocker === 'tax-undecided' && ((_readiness_gaps = readiness.gaps) == null ? void 0 : _readiness_gaps.includes('tax-undecided')) || blocker === 'tax-save' && ((_readiness_gaps1 = readiness.gaps) == null ? void 0 : _readiness_gaps1.includes('tax-save'));
|
|
119
|
+
const blockerLine = blocker && !readiness.storeLoading && !toldByNotice ? blocker : null;
|
|
96
120
|
const threaded = Boolean(CommerceModel.invoiceEmailThread(order));
|
|
97
121
|
const number = CommerceModel.formatInvoiceNumber(order, orderId);
|
|
98
122
|
const send = useCallback(async ()=>{
|
|
@@ -143,14 +167,10 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
143
167
|
message,
|
|
144
168
|
number,
|
|
145
169
|
enqueueSnackbar,
|
|
146
|
-
onClose
|
|
170
|
+
onClose,
|
|
171
|
+
setBusy
|
|
147
172
|
]);
|
|
148
|
-
return /*#__PURE__*/ _jsxs(
|
|
149
|
-
open: open,
|
|
150
|
-
onClose: busy ? undefined : onClose,
|
|
151
|
-
maxWidth: "sm",
|
|
152
|
-
fullWidth: true,
|
|
153
|
-
"aria-labelledby": "invoice-send-title",
|
|
173
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
154
174
|
children: [
|
|
155
175
|
/*#__PURE__*/ _jsx(DialogTitle, {
|
|
156
176
|
id: "invoice-send-title",
|
|
@@ -163,10 +183,14 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
163
183
|
pt: 1
|
|
164
184
|
},
|
|
165
185
|
children: [
|
|
166
|
-
|
|
186
|
+
/*#__PURE__*/ _jsx(PayLinkReadinessNotice, {
|
|
187
|
+
readiness: readiness,
|
|
188
|
+
noun: "invoice"
|
|
189
|
+
}),
|
|
190
|
+
blockerLine ? /*#__PURE__*/ _jsx(Typography, {
|
|
167
191
|
variant: "body2",
|
|
168
192
|
color: "error",
|
|
169
|
-
children: CommerceModel.invoiceSendRefusalMessage(
|
|
193
|
+
children: CommerceModel.invoiceSendRefusalMessage(blockerLine)
|
|
170
194
|
}) : null,
|
|
171
195
|
/*#__PURE__*/ _jsx(TextField, {
|
|
172
196
|
label: "To",
|
|
@@ -220,11 +244,15 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
220
244
|
disabled: busy,
|
|
221
245
|
children: 'Cancel'
|
|
222
246
|
}),
|
|
223
|
-
/*#__PURE__*/ _jsx(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
247
|
+
/*#__PURE__*/ _jsx(BlockedControl, {
|
|
248
|
+
blocked: Boolean(blocker) && !readiness.storeLoading,
|
|
249
|
+
reason: blocker ? CommerceModel.invoiceSendRefusalMessage(blocker) : '',
|
|
250
|
+
children: /*#__PURE__*/ _jsx(Button, {
|
|
251
|
+
variant: "contained",
|
|
252
|
+
disabled: busy || !to.trim() || Boolean(blocker) || readiness.storeLoading,
|
|
253
|
+
onClick: ()=>void send(),
|
|
254
|
+
children: busy ? 'Sending…' : 'Send'
|
|
255
|
+
})
|
|
228
256
|
})
|
|
229
257
|
]
|
|
230
258
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/invoice-send.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 { siteContactEmail, resolveHostToken, type HostTokenSource } from '@aglyn/aglyn/app-utils/host-tokens'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { useFirestore, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { doc, getDoc } from 'firebase/firestore'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\n/** `Oct 29, 2026, 3:04 PM`. */\nconst sentAt = (atMs: number) =>\n new Date(atMs).toLocaleString('en-US', { dateStyle: 'medium', timeStyle: 'short' })\n\n/**\n * The order's (or the quote's) last invoice email, as the console says it:\n * `Invoice sent Oct 29, 2026, 3:04 PM to jordan@example.com.` Null when none\n * was sent.\n */\nexport function invoiceSentLine(order: Pick<CommerceModel.HostOrder, 'invoiceSends'>): string | null {\n const last = CommerceModel.lastInvoiceSend(order)\n if (!last) return null\n return `${last.paid ? 'Paid invoice' : 'Invoice'} sent ${sentAt(Number(last.atMs))} to ${last.to || 'the customer'}.`\n}\n\nexport interface InvoiceSendDialogProps {\n open: boolean\n onClose: () => void\n hostId: string\n orderId: string\n order: CommerceModel.HostOrder\n}\n\n/**\n * Send invoice (AGL-4099), for an order or a quote: a short form (To,\n * Subject, Message) that emails the invoice in the site's look with the\n * invoice PDF attached. Unpaid, the email carries a Pay button to the order's\n * lasting pay link on the business's site; paid, it is the customer's record.\n * A quote's invoice lands in the quote's conversation, and an order's in its\n * own. The site's name and contact email are read once when the form opens,\n * so the dialog that offers it listens to nothing more.\n */\nexport function InvoiceSendDialog(props: InvoiceSendDialogProps) {\n const { open, onClose, hostId, orderId, order } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const [busy, setBusy] = useState(false)\n const [to, setTo] = useState('')\n const [subject, setSubject] = useState('')\n const [message, setMessage] = useState('')\n const [contact, setContact] = useState<string | null>(null)\n\n /*\n * One attempt per form (AGL-1697's rule): a retried Send presents the same\n * key and is answered from the first, so the customer never gets two; a\n * changed form is a new attempt.\n */\n const attemptKey = useRef('')\n useEffect(() => {\n attemptKey.current = ''\n }, [to, subject, message])\n\n useEffect(() => {\n if (!open) return\n let live = true\n setTo(CommerceModel.invoiceSendPrefill(order))\n setSubject(CommerceModel.invoiceEmailDefaultSubject(order, '', orderId))\n setMessage('')\n void getDoc(doc(firestore, 'hosts', hostId))\n .then((snapshot) => {\n if (!live) return\n const host = (snapshot.data() ?? {}) as Record<string, unknown>\n const businessName = String(resolveHostToken('businessName', host as HostTokenSource) ?? '').trim()\n setSubject(CommerceModel.invoiceEmailDefaultSubject(order, businessName, orderId))\n const listed = siteContactEmail(host as never)\n setContact(listed && /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(listed) ? listed : null)\n })\n .catch(() => undefined)\n return () => {\n live = false\n }\n // Filled once per opening; edits after that are the member's.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open])\n\n const paid = CommerceModel.invoiceIsPaid(order)\n const refused = CommerceModel.invoiceSendRefusal(order, orderId, to.trim())\n // The address is the form's to fix; every other refusal is the order's, said up front.\n const blocker = refused && refused !== 'no-address' && refused !== 'bad-address' ? refused : null\n const threaded = Boolean(CommerceModel.invoiceEmailThread(order))\n const number = CommerceModel.formatInvoiceNumber(order, orderId)\n\n const send = useCallback(async () => {\n setBusy(true)\n try {\n if (!attemptKey.current) {\n attemptKey.current = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`\n }\n const response = await authorizedFetch(user, '/api/commerce/order-invoice-send', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'Idempotency-Key': attemptKey.current },\n body: JSON.stringify({ hostId, orderId, to, subject, message }),\n })\n const payload = await response.json().catch(() => ({}))\n if (!response.ok) {\n return void enqueueSnackbar(payload?.error ?? 'The invoice could not be sent', { variant: 'error', allowDuplicate: true })\n }\n enqueueSnackbar(`${number} sent to ${String(payload.to ?? to)}`, { variant: 'success', persist: false })\n onClose()\n } finally {\n setBusy(false)\n }\n }, [user, hostId, orderId, to, subject, message, number, enqueueSnackbar, onClose])\n\n return (\n <Dialog open={open} onClose={busy ? undefined : onClose} maxWidth=\"sm\" fullWidth aria-labelledby=\"invoice-send-title\">\n <DialogTitle id=\"invoice-send-title\">{`Send invoice: ${number}`}</DialogTitle>\n <DialogContent>\n <Stack spacing={2} sx={{ pt: 1 }}>\n {blocker ? (\n <Typography variant=\"body2\" color=\"error\">\n {CommerceModel.invoiceSendRefusalMessage(blocker)}\n </Typography>\n ) : null}\n <TextField\n label=\"To\"\n type=\"email\"\n value={to}\n onChange={(event) => setTo(event.target.value)}\n required\n fullWidth\n disabled={busy}\n />\n <TextField\n label=\"Subject\"\n value={subject}\n onChange={(event) => setSubject(event.target.value)}\n fullWidth\n disabled={busy}\n slotProps={{ htmlInput: { maxLength: CommerceModel.QUOTE_MAX_SEND_SUBJECT } }}\n helperText={\n threaded\n ? 'Keep the subject the same to keep these emails in one conversation in your customer’s inbox.'\n : undefined\n }\n />\n <TextField\n label=\"Message\"\n value={message}\n onChange={(event) => setMessage(event.target.value)}\n multiline\n minRows={4}\n fullWidth\n disabled={busy}\n slotProps={{ htmlInput: { maxLength: CommerceModel.QUOTE_MAX_SEND_MESSAGE } }}\n helperText=\"Shown at the top of the email, in your words.\"\n />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {(paid\n ? 'The email shows the invoice as paid, with the date it was paid, for your customer’s records. '\n : 'The email shows the invoice number, date, total and what is due, with a button to pay it by card on your site. The button keeps working until it is paid. ') +\n `The invoice is attached as a PDF. Replies go to ${contact || 'your email'}.`}\n </Typography>\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy || !to.trim() || Boolean(blocker)} onClick={() => void send()}>\n {busy ? 'Sending…' : 'Send'}\n </Button>\n </DialogActions>\n </Dialog>\n )\n}\nInvoiceSendDialog.displayName = 'InvoiceSendDialog'\n\nexport default InvoiceSendDialog\n"],"names":["CommerceModel","siteContactEmail","resolveHostToken","useSnackbar","authorizedFetch","useFirestore","useUser","Button","Dialog","DialogActions","DialogContent","DialogTitle","Stack","TextField","Typography","doc","getDoc","useCallback","useEffect","useRef","useState","sentAt","atMs","Date","toLocaleString","dateStyle","timeStyle","invoiceSentLine","order","last","lastInvoiceSend","paid","Number","to","InvoiceSendDialog","props","open","onClose","hostId","orderId","firestore","data","user","enqueueSnackbar","busy","setBusy","setTo","subject","setSubject","message","setMessage","contact","setContact","attemptKey","current","live","invoiceSendPrefill","invoiceEmailDefaultSubject","then","snapshot","host","businessName","String","trim","listed","test","catch","undefined","invoiceIsPaid","refused","invoiceSendRefusal","blocker","threaded","Boolean","invoiceEmailThread","number","formatInvoiceNumber","send","payload","globalThis","crypto","randomUUID","now","Math","random","toString","slice","response","method","headers","body","JSON","stringify","json","ok","error","variant","allowDuplicate","persist","maxWidth","fullWidth","aria-labelledby","id","spacing","sx","pt","color","invoiceSendRefusalMessage","label","type","value","onChange","event","target","required","disabled","slotProps","htmlInput","maxLength","QUOTE_MAX_SEND_SUBJECT","helperText","multiline","minRows","QUOTE_MAX_SEND_MESSAGE","onClick","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;AAEA,YAAYA,mBAAmB,uBAAa;AAC5C,SAASC,gBAAgB,EAAEC,gBAAgB,QAA8B,qCAAoC;AAC7G,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,YAAY,EAAEC,OAAO,QAAQ,iCAAgC;AACtE,SACEC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,GAAG,EAAEC,MAAM,QAAQ,qBAAoB;AAChD,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEhE,6BAA6B,GAC7B,MAAMC,SAAS,CAACC,OACd,IAAIC,KAAKD,MAAME,cAAc,CAAC,SAAS;QAAEC,WAAW;QAAUC,WAAW;IAAQ;AAEnF;;;;CAIC,GACD,OAAO,SAASC,gBAAgBC,KAAoD;IAClF,MAAMC,OAAO7B,cAAc8B,eAAe,CAACF;IAC3C,IAAI,CAACC,MAAM,OAAO;IAClB,OAAO,GAAGA,KAAKE,IAAI,GAAG,iBAAiB,UAAU,MAAM,EAAEV,OAAOW,OAAOH,KAAKP,IAAI,GAAG,IAAI,EAAEO,KAAKI,EAAE,IAAI,eAAe,CAAC,CAAC;AACvH;AAUA;;;;;;;;CAQC,GACD,OAAO,SAASC,kBAAkBC,KAA6B;IAC7D,MAAM,EAAEC,IAA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;sCAC/B,AAAC3E,CAAAA,OACE,kGACA,4JAA2J,IAC7J,CAAC,gDAAgD,EAAEoB,WAAW,aAAa,CAAC,CAAC;;;;;0BAIrF,MAAC1C;;kCACC,KAACF;wBAAOqH,SAASvF;wBAAS8E,UAAUvE;kCACjC;;kCAEH,KAACrC;wBAAOyF,SAAQ;wBAAYmB,UAAUvE,QAAQ,CAACX,GAAG8B,IAAI,MAAMU,QAAQF;wBAAUqD,SAAS,IAAM,KAAK/C;kCAC/FjC,OAAO,aAAa;;;;;;AAK/B;AACAV,kBAAkB2F,WAAW,GAAG;AAEhC,eAAe3F,kBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/invoice-send.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 { siteContactEmail, resolveHostToken, type HostTokenSource } from '@aglyn/aglyn/app-utils/host-tokens'\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 { useFirestore, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { doc, getDoc } from 'firebase/firestore'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { PayLinkReadinessNotice, usePayLinkReadiness } from './pay-link-readiness-notice.component'\n\n/** `Oct 29, 2026, 3:04 PM`. */\nconst sentAt = (atMs: number) =>\n new Date(atMs).toLocaleString('en-US', { dateStyle: 'medium', timeStyle: 'short' })\n\n/**\n * The order's (or the quote's) last invoice email, as the console says it:\n * `Invoice sent Oct 29, 2026, 3:04 PM to jordan@example.com.` Null when none\n * was sent.\n */\nexport function invoiceSentLine(order: Pick<CommerceModel.HostOrder, 'invoiceSends'>): string | null {\n const last = CommerceModel.lastInvoiceSend(order)\n if (!last) return null\n return `${last.paid ? 'Paid invoice' : 'Invoice'} sent ${sentAt(Number(last.atMs))} to ${last.to || 'the customer'}.`\n}\n\nexport interface InvoiceSendDialogProps {\n open: boolean\n onClose: () => void\n hostId: string\n orderId: string\n order: CommerceModel.HostOrder\n}\n\n/**\n * Send invoice (AGL-4099), for an order or a quote: a short form (To,\n * Subject, Message) that emails the invoice in the site's look with the\n * invoice PDF attached. Unpaid, the email carries a Pay button to the order's\n * lasting pay link on the business's site; paid, it is the customer's record.\n * A quote's invoice lands in the quote's conversation, and an order's in its\n * own.\n *\n * The form's body mounts with the dialog's opening, so everything it reads\n * (the site's name and contact email, once; the store's tax choice and its\n * payments, live) is read only while it is open, and the dialog that offers\n * it listens to nothing more. It says what the customer's Pay waits on, if\n * anything (AGL-4162), and judges the send under the store's sales tax choice\n * as the server does: a quote saved before the store chose is sent as the\n * store's choice prices it.\n */\nexport function InvoiceSendDialog(props: InvoiceSendDialogProps) {\n const { open, onClose } = props\n const [busy, setBusy] = useState(false)\n return (\n <Dialog open={open} onClose={busy ? undefined : onClose} maxWidth=\"sm\" fullWidth aria-labelledby=\"invoice-send-title\">\n <InvoiceSendForm {...props} busy={busy} setBusy={setBusy} />\n </Dialog>\n )\n}\n\n/** The open form: filled once when it mounts; edits after that are the member's. */\nfunction InvoiceSendForm(\n props: InvoiceSendDialogProps & { busy: boolean; setBusy: (busy: boolean) => void },\n) {\n const { onClose, hostId, orderId, order, busy, setBusy } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const [to, setTo] = useState(() => CommerceModel.invoiceSendPrefill(order))\n const [subject, setSubject] = useState(() => CommerceModel.invoiceEmailDefaultSubject(order, '', orderId))\n const [message, setMessage] = useState('')\n const [contact, setContact] = useState<string | null>(null)\n\n /*\n * One attempt per form (AGL-1697's rule): a retried Send presents the same\n * key and is answered from the first, so the customer never gets two; a\n * changed form is a new attempt.\n */\n const attemptKey = useRef('')\n useEffect(() => {\n attemptKey.current = ''\n }, [to, subject, message])\n\n useEffect(() => {\n let live = true\n void getDoc(doc(firestore, 'hosts', hostId))\n .then((snapshot) => {\n if (!live) return\n const host = (snapshot.data() ?? {}) as Record<string, unknown>\n const businessName = String(resolveHostToken('businessName', host as HostTokenSource) ?? '').trim()\n setSubject(CommerceModel.invoiceEmailDefaultSubject(order, businessName, orderId))\n const listed = siteContactEmail(host as never)\n setContact(listed && /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(listed) ? listed : null)\n })\n .catch(() => undefined)\n return () => {\n live = false\n }\n // Filled once per opening; edits after that are the member's.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const readiness = usePayLinkReadiness(hostId, order)\n const paid = CommerceModel.invoiceIsPaid(order)\n const refused = CommerceModel.invoiceSendRefusal(order, orderId, to.trim(), readiness.store)\n // The address is the form's to fix; every other refusal is the order's,\n // said up front once the store's settings are read. One the notice already\n // names, with its fix, is not said twice.\n const blocker = refused && refused !== 'no-address' && refused !== 'bad-address' ? refused : null\n const toldByNotice =\n (blocker === 'tax-undecided' && readiness.gaps?.includes('tax-undecided')) ||\n (blocker === 'tax-save' && readiness.gaps?.includes('tax-save'))\n const blockerLine = blocker && !readiness.storeLoading && !toldByNotice ? blocker : null\n const threaded = Boolean(CommerceModel.invoiceEmailThread(order))\n const number = CommerceModel.formatInvoiceNumber(order, orderId)\n\n const send = useCallback(async () => {\n setBusy(true)\n try {\n if (!attemptKey.current) {\n attemptKey.current = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`\n }\n const response = await authorizedFetch(user, '/api/commerce/order-invoice-send', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'Idempotency-Key': attemptKey.current },\n body: JSON.stringify({ hostId, orderId, to, subject, message }),\n })\n const payload = await response.json().catch(() => ({}))\n if (!response.ok) {\n return void enqueueSnackbar(payload?.error ?? 'The invoice could not be sent', { variant: 'error', allowDuplicate: true })\n }\n enqueueSnackbar(`${number} sent to ${String(payload.to ?? to)}`, { variant: 'success', persist: false })\n onClose()\n } finally {\n setBusy(false)\n }\n }, [user, hostId, orderId, to, subject, message, number, enqueueSnackbar, onClose, setBusy])\n\n return (\n <>\n <DialogTitle id=\"invoice-send-title\">{`Send invoice: ${number}`}</DialogTitle>\n <DialogContent>\n <Stack spacing={2} sx={{ pt: 1 }}>\n <PayLinkReadinessNotice readiness={readiness} noun=\"invoice\" />\n {blockerLine ? (\n <Typography variant=\"body2\" color=\"error\">\n {CommerceModel.invoiceSendRefusalMessage(blockerLine)}\n </Typography>\n ) : null}\n <TextField\n label=\"To\"\n type=\"email\"\n value={to}\n onChange={(event) => setTo(event.target.value)}\n required\n fullWidth\n disabled={busy}\n />\n <TextField\n label=\"Subject\"\n value={subject}\n onChange={(event) => setSubject(event.target.value)}\n fullWidth\n disabled={busy}\n slotProps={{ htmlInput: { maxLength: CommerceModel.QUOTE_MAX_SEND_SUBJECT } }}\n helperText={\n threaded\n ? 'Keep the subject the same to keep these emails in one conversation in your customer’s inbox.'\n : undefined\n }\n />\n <TextField\n label=\"Message\"\n value={message}\n onChange={(event) => setMessage(event.target.value)}\n multiline\n minRows={4}\n fullWidth\n disabled={busy}\n slotProps={{ htmlInput: { maxLength: CommerceModel.QUOTE_MAX_SEND_MESSAGE } }}\n helperText=\"Shown at the top of the email, in your words.\"\n />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {(paid\n ? 'The email shows the invoice as paid, with the date it was paid, for your customer’s records. '\n : 'The email shows the invoice number, date, total and what is due, with a button to pay it by card on your site. The button keeps working until it is paid. ') +\n `The invoice is attached as a PDF. Replies go to ${contact || 'your email'}.`}\n </Typography>\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose} disabled={busy}>\n {'Cancel'}\n </Button>\n <BlockedControl\n blocked={Boolean(blocker) && !readiness.storeLoading}\n reason={blocker ? CommerceModel.invoiceSendRefusalMessage(blocker) : ''}\n >\n <Button\n variant=\"contained\"\n disabled={busy || !to.trim() || Boolean(blocker) || readiness.storeLoading}\n onClick={() => void send()}\n >\n {busy ? 'Sending…' : 'Send'}\n </Button>\n </BlockedControl>\n </DialogActions>\n </>\n )\n}\n\nInvoiceSendDialog.displayName = 'InvoiceSendDialog'\n\nexport default InvoiceSendDialog\n"],"names":["CommerceModel","siteContactEmail","resolveHostToken","BlockedControl","useSnackbar","authorizedFetch","useFirestore","useUser","Button","Dialog","DialogActions","DialogContent","DialogTitle","Stack","TextField","Typography","doc","getDoc","useCallback","useEffect","useRef","useState","PayLinkReadinessNotice","usePayLinkReadiness","sentAt","atMs","Date","toLocaleString","dateStyle","timeStyle","invoiceSentLine","order","last","lastInvoiceSend","paid","Number","to","InvoiceSendDialog","props","open","onClose","busy","setBusy","undefined","maxWidth","fullWidth","aria-labelledby","InvoiceSendForm","readiness","hostId","orderId","firestore","data","user","enqueueSnackbar","setTo","invoiceSendPrefill","subject","setSubject","invoiceEmailDefaultSubject","message","setMessage","contact","setContact","attemptKey","current","live","then","snapshot","host","businessName","String","trim","listed","test","catch","invoiceIsPaid","refused","invoiceSendRefusal","store","blocker","toldByNotice","gaps","includes","blockerLine","storeLoading","threaded","Boolean","invoiceEmailThread","number","formatInvoiceNumber","send","payload","globalThis","crypto","randomUUID","now","Math","random","toString","slice","response","method","headers","body","JSON","stringify","json","ok","error","variant","allowDuplicate","persist","id","spacing","sx","pt","noun","color","invoiceSendRefusalMessage","label","type","value","onChange","event","target","required","disabled","slotProps","htmlInput","maxLength","QUOTE_MA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AAK;4BAClD7E,SAAS;4BACTkF,UAAUtF;4BACVuF,WAAW;gCAAEC,WAAW;oCAAEC,WAAWlI,cAAcmI,sBAAsB;gCAAC;4BAAE;4BAC5EC,YACE9C,WACI,iGACA3C;;sCAGR,KAAC7B;4BACC0G,OAAM;4BACNE,OAAO9D;4BACP+D,UAAU,CAACC,QAAU/D,WAAW+D,MAAMC,MAAM,CAACH,KAAK;4BAClDW,SAAS;4BACTC,SAAS;4BACTzF,SAAS;4BACTkF,UAAUtF;4BACVuF,WAAW;gCAAEC,WAAW;oCAAEC,WAAWlI,cAAcuI,sBAAsB;gCAAC;4BAAE;4BAC5EH,YAAW;;sCAEb,KAACrH;4BAAW+F,SAAQ;4BAAQQ,OAAM;sCAC/B,AAACpF,CAAAA,OACE,kGACA,4JAA2J,IAC7J,CAAC,gDAAgD,EAAE4B,WAAW,aAAa,CAAC,CAAC;;;;;0BAIrF,MAACpD;;kCACC,KAACF;wBAAOgI,SAAShG;wBAASuF,UAAUtF;kCACjC;;kCAEH,KAACtC;wBACCsI,SAASlD,QAAQP,YAAY,CAAChC,UAAUqC,YAAY;wBACpDqD,QAAQ1D,UAAUhF,cAAcuH,yBAAyB,CAACvC,WAAW;kCAErE,cAAA,KAACxE;4BACCsG,SAAQ;4BACRiB,UAAUtF,QAAQ,CAACL,GAAGoC,IAAI,MAAMe,QAAQP,YAAYhC,UAAUqC,YAAY;4BAC1EmD,SAAS,IAAM,KAAK7C;sCAEnBlD,OAAO,aAAa;;;;;;;AAMjC;AAEAJ,kBAAkBsG,WAAW,GAAG;AAEhC,eAAetG,kBAAiB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
import { type AlertProps } from '@mui/material';
|
|
19
|
+
/** An order the pay link may charge: a quote or a draft order; null for a quote not saved yet. */
|
|
20
|
+
export type PayLinkNoticeOrder = (Pick<CommerceModel.HostOrder, 'status' | 'channel'> & Partial<Pick<CommerceModel.HostOrder, 'quote'>>) | null;
|
|
21
|
+
/** Where a pay link stands with the business's setup, as the console reads it. */
|
|
22
|
+
export interface PayLinkReadiness {
|
|
23
|
+
/** What the notice names (`payLinkGaps`); null while anything is still being read. */
|
|
24
|
+
gaps: CommerceModel.PayLinkGap[] | null;
|
|
25
|
+
/** The store's sales tax choice; undefined while it is read, or when it can't be. */
|
|
26
|
+
store: CommerceModel.PayLinkStore | undefined;
|
|
27
|
+
/** The store's settings are still being read. */
|
|
28
|
+
storeLoading: boolean;
|
|
29
|
+
/** Why the workspace can't take card payments, in `useMerchantPayments`'s words. */
|
|
30
|
+
paymentsReason: string | null;
|
|
31
|
+
/** The site's Payments settings page. */
|
|
32
|
+
paymentsHref: string | null;
|
|
33
|
+
/** The site's Taxes settings page. */
|
|
34
|
+
taxesHref: string | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether customers can pay an order's pay link, for the console's notice
|
|
38
|
+
* (AGL-4162): the workspace owner's payment account (`useMerchantPayments`,
|
|
39
|
+
* the client's copy of the check the page and Pay make) and the store's
|
|
40
|
+
* sales tax choice, read live. Without a site nothing is read and nothing is
|
|
41
|
+
* answered, so a form can hold its reads until it opens.
|
|
42
|
+
*/
|
|
43
|
+
export declare function usePayLinkReadiness(hostId: string | undefined, order: PayLinkNoticeOrder): PayLinkReadiness;
|
|
44
|
+
/** The notice's first line: `Customers can’t pay this quote online yet.` */
|
|
45
|
+
export declare function payLinkNoticeTitle(noun: 'quote' | 'invoice'): string;
|
|
46
|
+
/** What the notice says about one gap, and the button that fixes it where a page does. */
|
|
47
|
+
export declare function payLinkGapLine(gap: CommerceModel.PayLinkGap, input: Pick<PayLinkReadiness, 'paymentsReason' | 'paymentsHref' | 'taxesHref'> & {
|
|
48
|
+
noun: 'quote' | 'invoice';
|
|
49
|
+
}): {
|
|
50
|
+
text: string;
|
|
51
|
+
action: string | null;
|
|
52
|
+
href: string | null;
|
|
53
|
+
};
|
|
54
|
+
export interface PayLinkReadinessNoticeProps {
|
|
55
|
+
readiness: PayLinkReadiness;
|
|
56
|
+
/** What the customer's page calls it: a quote, or an invoice in the Send invoice form. */
|
|
57
|
+
noun: 'quote' | 'invoice';
|
|
58
|
+
sx?: AlertProps['sx'];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* "Customers can't pay this quote online yet." (AGL-4162), naming each setup
|
|
62
|
+
* step a customer's Pay waits on, with a button to the page that fixes it.
|
|
63
|
+
* Drawn only once both answers are in, and only when something is missing.
|
|
64
|
+
* The notice holds nothing back itself: the quote can still be sent and its
|
|
65
|
+
* link copied, for a business that takes the payment another way.
|
|
66
|
+
*/
|
|
67
|
+
export declare function PayLinkReadinessNotice(props: PayLinkReadinessNoticeProps): import("react").JSX.Element;
|
|
68
|
+
export declare namespace PayLinkReadinessNotice {
|
|
69
|
+
var displayName: string;
|
|
70
|
+
}
|
|
71
|
+
export interface PayLinkReadinessNoticeForProps extends Omit<PayLinkReadinessNoticeProps, 'readiness'> {
|
|
72
|
+
hostId: string;
|
|
73
|
+
order: PayLinkNoticeOrder;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The notice with its own reads ({@link usePayLinkReadiness}), for a surface
|
|
77
|
+
* that mounts it only while it is on screen: a form's body, or a section
|
|
78
|
+
* drawn only for an unpaid quote.
|
|
79
|
+
*/
|
|
80
|
+
export declare function PayLinkReadinessNoticeFor(props: PayLinkReadinessNoticeForProps): import("react").JSX.Element;
|
|
81
|
+
export declare namespace PayLinkReadinessNoticeFor {
|
|
82
|
+
var displayName: string;
|
|
83
|
+
}
|
|
84
|
+
export default PayLinkReadinessNotice;
|
|
@@ -0,0 +1,164 @@
|
|
|
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 { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
|
+
import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
import * as CommerceModel from "../../model/index.js";
|
|
21
|
+
import { AppLink } from "@aglyn/shared-ui-jsx/components/app-link";
|
|
22
|
+
import { PrerequisiteNotice } from "@aglyn/shared-ui-jsx/components/prerequisite-notice.component";
|
|
23
|
+
import { firestoreDocPhase, useFirestore, useFirestoreDoc, useMerchantPayments, useStoreSettingsHref } from "@aglyn/tenant-feature-instance";
|
|
24
|
+
import { AlertTitle, Stack } from "@mui/material";
|
|
25
|
+
import { doc } from "firebase/firestore";
|
|
26
|
+
/**
|
|
27
|
+
* Whether customers can pay an order's pay link, for the console's notice
|
|
28
|
+
* (AGL-4162): the workspace owner's payment account (`useMerchantPayments`,
|
|
29
|
+
* the client's copy of the check the page and Pay make) and the store's
|
|
30
|
+
* sales tax choice, read live. Without a site nothing is read and nothing is
|
|
31
|
+
* answered, so a form can hold its reads until it opens.
|
|
32
|
+
*/ export function usePayLinkReadiness(hostId, order) {
|
|
33
|
+
const firestore = useFirestore();
|
|
34
|
+
const payments = useMerchantPayments(hostId);
|
|
35
|
+
const taxesHref = useStoreSettingsHref(hostId, 'taxes');
|
|
36
|
+
const read = useFirestoreDoc(()=>hostId ? doc(firestore, 'hosts', hostId, 'settings', 'store') : null, [
|
|
37
|
+
firestore,
|
|
38
|
+
hostId
|
|
39
|
+
]);
|
|
40
|
+
const phase = firestoreDocPhase(read);
|
|
41
|
+
const store = phase === 'ready' ? CommerceModel.payLinkStoreOf(read.data) : phase === 'missing' ? CommerceModel.payLinkStoreOf(null) : undefined;
|
|
42
|
+
const gaps = hostId ? CommerceModel.payLinkGaps({
|
|
43
|
+
order,
|
|
44
|
+
paymentsReady: payments.settled ? payments.ready : null,
|
|
45
|
+
store
|
|
46
|
+
}) : null;
|
|
47
|
+
return {
|
|
48
|
+
gaps,
|
|
49
|
+
store,
|
|
50
|
+
storeLoading: !hostId || phase === 'loading',
|
|
51
|
+
paymentsReason: payments.reason,
|
|
52
|
+
paymentsHref: payments.href,
|
|
53
|
+
taxesHref
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** The notice's first line: `Customers can’t pay this quote online yet.` */ export function payLinkNoticeTitle(noun) {
|
|
57
|
+
return `Customers can’t pay this ${noun} online yet.`;
|
|
58
|
+
}
|
|
59
|
+
/** What the notice says about one gap, and the button that fixes it where a page does. */ export function payLinkGapLine(gap, input) {
|
|
60
|
+
switch(gap){
|
|
61
|
+
case 'payments':
|
|
62
|
+
var _input_paymentsReason;
|
|
63
|
+
return {
|
|
64
|
+
text: (_input_paymentsReason = input.paymentsReason) != null ? _input_paymentsReason : 'Connect a payment account to take card payments.',
|
|
65
|
+
action: 'Open Payments',
|
|
66
|
+
href: input.paymentsHref
|
|
67
|
+
};
|
|
68
|
+
case 'tax-undecided':
|
|
69
|
+
return {
|
|
70
|
+
text: 'Choose how this store handles sales tax.',
|
|
71
|
+
action: 'Open Taxes',
|
|
72
|
+
href: input.taxesHref
|
|
73
|
+
};
|
|
74
|
+
case 'tax-save':
|
|
75
|
+
return {
|
|
76
|
+
text: `${input.noun === 'quote' ? 'Save this quote' : 'Save the quote'} again to apply the store’s sales tax setting.`,
|
|
77
|
+
action: null,
|
|
78
|
+
href: null
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* "Customers can't pay this quote online yet." (AGL-4162), naming each setup
|
|
84
|
+
* step a customer's Pay waits on, with a button to the page that fixes it.
|
|
85
|
+
* Drawn only once both answers are in, and only when something is missing.
|
|
86
|
+
* The notice holds nothing back itself: the quote can still be sent and its
|
|
87
|
+
* link copied, for a business that takes the payment another way.
|
|
88
|
+
*/ export function PayLinkReadinessNotice(props) {
|
|
89
|
+
var _readiness_gaps;
|
|
90
|
+
const { readiness, noun, sx } = props;
|
|
91
|
+
if (!((_readiness_gaps = readiness.gaps) == null ? void 0 : _readiness_gaps.length)) return null;
|
|
92
|
+
return /*#__PURE__*/ _jsxs(PrerequisiteNotice, {
|
|
93
|
+
severity: "warning",
|
|
94
|
+
sx: sx,
|
|
95
|
+
children: [
|
|
96
|
+
/*#__PURE__*/ _jsx(AlertTitle, {
|
|
97
|
+
children: payLinkNoticeTitle(noun)
|
|
98
|
+
}),
|
|
99
|
+
/*#__PURE__*/ _jsx(Stack, {
|
|
100
|
+
component: "ul",
|
|
101
|
+
spacing: 1,
|
|
102
|
+
sx: {
|
|
103
|
+
m: 0,
|
|
104
|
+
p: 0,
|
|
105
|
+
listStyle: 'none'
|
|
106
|
+
},
|
|
107
|
+
children: readiness.gaps.map((gap)=>{
|
|
108
|
+
const line = payLinkGapLine(gap, _extends({}, readiness, {
|
|
109
|
+
noun
|
|
110
|
+
}));
|
|
111
|
+
return /*#__PURE__*/ _jsxs(Stack, {
|
|
112
|
+
component: "li",
|
|
113
|
+
direction: {
|
|
114
|
+
xs: 'column',
|
|
115
|
+
sm: 'row'
|
|
116
|
+
},
|
|
117
|
+
spacing: 1,
|
|
118
|
+
sx: {
|
|
119
|
+
alignItems: {
|
|
120
|
+
xs: 'flex-start',
|
|
121
|
+
sm: 'center'
|
|
122
|
+
},
|
|
123
|
+
justifyContent: 'space-between'
|
|
124
|
+
},
|
|
125
|
+
children: [
|
|
126
|
+
/*#__PURE__*/ _jsx("span", {
|
|
127
|
+
children: line.text
|
|
128
|
+
}),
|
|
129
|
+
line.action && line.href ? /*#__PURE__*/ _jsx(AppLink, {
|
|
130
|
+
componentVariant: "button",
|
|
131
|
+
color: "inherit",
|
|
132
|
+
size: "small",
|
|
133
|
+
href: line.href,
|
|
134
|
+
sx: {
|
|
135
|
+
flexShrink: 0
|
|
136
|
+
},
|
|
137
|
+
children: line.action
|
|
138
|
+
}) : null
|
|
139
|
+
]
|
|
140
|
+
}, gap);
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
PayLinkReadinessNotice.displayName = 'PayLinkReadinessNotice';
|
|
147
|
+
/**
|
|
148
|
+
* The notice with its own reads ({@link usePayLinkReadiness}), for a surface
|
|
149
|
+
* that mounts it only while it is on screen: a form's body, or a section
|
|
150
|
+
* drawn only for an unpaid quote.
|
|
151
|
+
*/ export function PayLinkReadinessNoticeFor(props) {
|
|
152
|
+
const { hostId, order } = props, rest = _object_without_properties_loose(props, [
|
|
153
|
+
"hostId",
|
|
154
|
+
"order"
|
|
155
|
+
]);
|
|
156
|
+
const readiness = usePayLinkReadiness(hostId, order);
|
|
157
|
+
return /*#__PURE__*/ _jsx(PayLinkReadinessNotice, _extends({
|
|
158
|
+
readiness: readiness
|
|
159
|
+
}, rest));
|
|
160
|
+
}
|
|
161
|
+
PayLinkReadinessNoticeFor.displayName = 'PayLinkReadinessNoticeFor';
|
|
162
|
+
export default PayLinkReadinessNotice;
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=pay-link-readiness-notice.component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/pay-link-readiness-notice.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 { AppLink } from '@aglyn/shared-ui-jsx/components/app-link'\nimport { PrerequisiteNotice } from '@aglyn/shared-ui-jsx/components/prerequisite-notice.component'\nimport {\n firestoreDocPhase,\n useFirestore,\n useFirestoreDoc,\n useMerchantPayments,\n useStoreSettingsHref,\n} from '@aglyn/tenant-feature-instance'\nimport { AlertTitle, Stack, type AlertProps } from '@mui/material'\nimport { doc } from 'firebase/firestore'\n\n/** An order the pay link may charge: a quote or a draft order; null for a quote not saved yet. */\nexport type PayLinkNoticeOrder =\n | (Pick<CommerceModel.HostOrder, 'status' | 'channel'> & Partial<Pick<CommerceModel.HostOrder, 'quote'>>)\n | null\n\n/** Where a pay link stands with the business's setup, as the console reads it. */\nexport interface PayLinkReadiness {\n /** What the notice names (`payLinkGaps`); null while anything is still being read. */\n gaps: CommerceModel.PayLinkGap[] | null\n /** The store's sales tax choice; undefined while it is read, or when it can't be. */\n store: CommerceModel.PayLinkStore | undefined\n /** The store's settings are still being read. */\n storeLoading: boolean\n /** Why the workspace can't take card payments, in `useMerchantPayments`'s words. */\n paymentsReason: string | null\n /** The site's Payments settings page. */\n paymentsHref: string | null\n /** The site's Taxes settings page. */\n taxesHref: string | null\n}\n\n/**\n * Whether customers can pay an order's pay link, for the console's notice\n * (AGL-4162): the workspace owner's payment account (`useMerchantPayments`,\n * the client's copy of the check the page and Pay make) and the store's\n * sales tax choice, read live. Without a site nothing is read and nothing is\n * answered, so a form can hold its reads until it opens.\n */\nexport function usePayLinkReadiness(hostId: string | undefined, order: PayLinkNoticeOrder): PayLinkReadiness {\n const firestore = useFirestore()\n const payments = useMerchantPayments(hostId)\n const taxesHref = useStoreSettingsHref(hostId, 'taxes')\n const read = useFirestoreDoc<{ tax?: unknown }>(\n () => (hostId ? doc(firestore, 'hosts', hostId, 'settings', 'store') : null),\n [firestore, hostId],\n )\n const phase = firestoreDocPhase(read)\n const store =\n phase === 'ready'\n ? CommerceModel.payLinkStoreOf(read.data)\n : phase === 'missing'\n ? CommerceModel.payLinkStoreOf(null)\n : undefined\n const gaps = hostId\n ? CommerceModel.payLinkGaps({ order, paymentsReady: payments.settled ? payments.ready : null, store })\n : null\n return {\n gaps,\n store,\n storeLoading: !hostId || phase === 'loading',\n paymentsReason: payments.reason,\n paymentsHref: payments.href,\n taxesHref,\n }\n}\n\n/** The notice's first line: `Customers can’t pay this quote online yet.` */\nexport function payLinkNoticeTitle(noun: 'quote' | 'invoice'): string {\n return `Customers can’t pay this ${noun} online yet.`\n}\n\n/** What the notice says about one gap, and the button that fixes it where a page does. */\nexport function payLinkGapLine(\n gap: CommerceModel.PayLinkGap,\n input: Pick<PayLinkReadiness, 'paymentsReason' | 'paymentsHref' | 'taxesHref'> & { noun: 'quote' | 'invoice' },\n): { text: string; action: string | null; href: string | null } {\n switch (gap) {\n case 'payments':\n return {\n text: input.paymentsReason ?? 'Connect a payment account to take card payments.',\n action: 'Open Payments',\n href: input.paymentsHref,\n }\n case 'tax-undecided':\n return { text: 'Choose how this store handles sales tax.', action: 'Open Taxes', href: input.taxesHref }\n case 'tax-save':\n return {\n text: `${input.noun === 'quote' ? 'Save this quote' : 'Save the quote'} again to apply the store’s sales tax setting.`,\n action: null,\n href: null,\n }\n }\n}\n\nexport interface PayLinkReadinessNoticeProps {\n readiness: PayLinkReadiness\n /** What the customer's page calls it: a quote, or an invoice in the Send invoice form. */\n noun: 'quote' | 'invoice'\n sx?: AlertProps['sx']\n}\n\n/**\n * \"Customers can't pay this quote online yet.\" (AGL-4162), naming each setup\n * step a customer's Pay waits on, with a button to the page that fixes it.\n * Drawn only once both answers are in, and only when something is missing.\n * The notice holds nothing back itself: the quote can still be sent and its\n * link copied, for a business that takes the payment another way.\n */\nexport function PayLinkReadinessNotice(props: PayLinkReadinessNoticeProps) {\n const { readiness, noun, sx } = props\n if (!readiness.gaps?.length) return null\n return (\n <PrerequisiteNotice severity=\"warning\" sx={sx}>\n <AlertTitle>{payLinkNoticeTitle(noun)}</AlertTitle>\n <Stack component=\"ul\" spacing={1} sx={{ m: 0, p: 0, listStyle: 'none' }}>\n {readiness.gaps.map((gap) => {\n const line = payLinkGapLine(gap, { ...readiness, noun })\n return (\n <Stack\n key={gap}\n component=\"li\"\n direction={{ xs: 'column', sm: 'row' }}\n spacing={1}\n sx={{ alignItems: { xs: 'flex-start', sm: 'center' }, justifyContent: 'space-between' }}\n >\n <span>{line.text}</span>\n {line.action && line.href ? (\n <AppLink componentVariant=\"button\" color=\"inherit\" size=\"small\" href={line.href} sx={{ flexShrink: 0 }}>\n {line.action}\n </AppLink>\n ) : null}\n </Stack>\n )\n })}\n </Stack>\n </PrerequisiteNotice>\n )\n}\nPayLinkReadinessNotice.displayName = 'PayLinkReadinessNotice'\n\nexport interface PayLinkReadinessNoticeForProps extends Omit<PayLinkReadinessNoticeProps, 'readiness'> {\n hostId: string\n order: PayLinkNoticeOrder\n}\n\n/**\n * The notice with its own reads ({@link usePayLinkReadiness}), for a surface\n * that mounts it only while it is on screen: a form's body, or a section\n * drawn only for an unpaid quote.\n */\nexport function PayLinkReadinessNoticeFor(props: PayLinkReadinessNoticeForProps) {\n const { hostId, order, ...rest } = props\n const readiness = usePayLinkReadiness(hostId, order)\n return <PayLinkReadinessNotice readiness={readiness} {...rest} />\n}\nPayLinkReadinessNoticeFor.displayName = 'PayLinkReadinessNoticeFor'\n\nexport default PayLinkReadinessNotice\n"],"names":["CommerceModel","AppLink","PrerequisiteNotice","firestoreDocPhase","useFirestore","useFirestoreDoc","useMerchantPayments","useStoreSettingsHref","AlertTitle","Stack","doc","usePayLinkReadiness","hostId","order","firestore","payments","taxesHref","read","phase","store","payLinkStoreOf","data","undefined","gaps","payLinkGaps","paymentsReady","settled","ready","storeLoading","paymentsReason","reason","paymentsHref","href","payLinkNoticeTitle","noun","payLinkGapLine","gap","input","text","action","PayLinkReadinessNotice","props","readiness","sx","length","severity","component","spacing","m","p","listStyle","map","line","direction","xs","sm","alignItems","justifyContent","span","componentVariant","color","size","flexShrink","displayName","PayLinkReadinessNoticeFor","rest"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;AAEA,YAAYA,mBAAmB,uBAAa;AAC5C,SAASC,OAAO,QAAQ,2CAA0C;AAClE,SAASC,kBAAkB,QAAQ,gEAA+D;AAClG,SACEC,iBAAiB,EACjBC,YAAY,EACZC,eAAe,EACfC,mBAAmB,EACnBC,oBAAoB,QACf,iCAAgC;AACvC,SAASC,UAAU,EAAEC,KAAK,QAAyB,gBAAe;AAClE,SAASC,GAAG,QAAQ,qBAAoB;AAuBxC;;;;;;CAMC,GACD,OAAO,SAASC,oBAAoBC,MAA0B,EAAEC,KAAyB;IACvF,MAAMC,YAAYV;IAClB,MAAMW,WAAWT,oBAAoBM;IACrC,MAAMI,YAAYT,qBAAqBK,QAAQ;IAC/C,MAAMK,OAAOZ,gBACX,IAAOO,SAASF,IAAII,WAAW,SAASF,QAAQ,YAAY,WAAW,MACvE;QAACE;QAAWF;KAAO;IAErB,MAAMM,QAAQf,kBAAkBc;IAChC,MA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qC,WAAU;gBAAKC,SAAS;gBAAGJ,IAAI;oBAAEK,GAAG;oBAAGC,GAAG;oBAAGC,WAAW;gBAAO;0BACnER,UAAUnB,IAAI,CAAC4B,GAAG,CAAC,CAACf;oBACnB,MAAMgB,OAAOjB,eAAeC,KAAK,aAAKM;wBAAWR;;oBACjD,qBACE,MAACzB;wBAECqC,WAAU;wBACVO,WAAW;4BAAEC,IAAI;4BAAUC,IAAI;wBAAM;wBACrCR,SAAS;wBACTJ,IAAI;4BAAEa,YAAY;gCAAEF,IAAI;gCAAcC,IAAI;4BAAS;4BAAGE,gBAAgB;wBAAgB;;0CAEtF,KAACC;0CAAMN,KAAKd,IAAI;;4BACfc,KAAKb,MAAM,IAAIa,KAAKpB,IAAI,iBACvB,KAAC/B;gCAAQ0D,kBAAiB;gCAASC,OAAM;gCAAUC,MAAK;gCAAQ7B,MAAMoB,KAAKpB,IAAI;gCAAEW,IAAI;oCAAEmB,YAAY;gCAAE;0CAClGV,KAAKb,MAAM;iCAEZ;;uBAXCH;gBAcX;;;;AAIR;AACAI,uBAAuBuB,WAAW,GAAG;AAOrC;;;;CAIC,GACD,OAAO,SAASC,0BAA0BvB,KAAqC;IAC7E,MAAM,EAAE7B,MAAM,EAAEC,KAAK,EAAW,GAAG4B,OAATwB,wCAASxB;;;;IACnC,MAAMC,YAAY/B,oBAAoBC,QAAQC;IAC9C,qBAAO,KAAC2B;QAAuBE,WAAWA;OAAeuB;AAC3D;AACAD,0BAA0BD,WAAW,GAAG;AAExC,eAAevB,uBAAsB"}
|
|
@@ -20,14 +20,14 @@ 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
22
|
import { BlockedControl } from "@aglyn/shared-ui-jsx/components/blocked-control.component";
|
|
23
|
-
import { PrerequisiteNotice } from "@aglyn/shared-ui-jsx/components/prerequisite-notice.component";
|
|
24
23
|
import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
25
24
|
import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
|
|
26
|
-
import { useFirestore, useFirestoreDoc,
|
|
25
|
+
import { useFirestore, useFirestoreDoc, useUser } from "@aglyn/tenant-feature-instance";
|
|
27
26
|
import { Alert, Box, Button, Chip, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, FormControlLabel, List, ListItemButton, ListItemText, MenuItem, Paper, Stack, Switch, TextField, Typography } from "@mui/material";
|
|
28
27
|
import { doc } from "firebase/firestore";
|
|
29
28
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
30
29
|
import { downloadCommercePdf } from "./commerce-pdf-download.js";
|
|
30
|
+
import { PayLinkReadinessNoticeFor } from "./pay-link-readiness-notice.component.js";
|
|
31
31
|
import { QuotePayLinkSection } from "./quote-pay-link.component.js";
|
|
32
32
|
import { QuoteProofsSection, QuoteRequestFilesSection } from "./quote-proofs.component.js";
|
|
33
33
|
import { QuoteSendSection } from "./quote-send.component.js";
|
|
@@ -228,7 +228,6 @@ function addressBody(address) {
|
|
|
228
228
|
const firestore = useFirestore();
|
|
229
229
|
const { data: user } = useUser();
|
|
230
230
|
const { enqueueSnackbar } = useSnackbar();
|
|
231
|
-
const taxesHref = useStoreSettingsHref(hostId, 'taxes');
|
|
232
231
|
const { data: store } = useFirestoreDoc(()=>doc(firestore, 'hosts', hostId, 'settings', 'store'), [
|
|
233
232
|
firestore,
|
|
234
233
|
hostId
|
|
@@ -536,11 +535,11 @@ function addressBody(address) {
|
|
|
536
535
|
quoteId: quote.$id,
|
|
537
536
|
quote: quote
|
|
538
537
|
}) : null,
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
})
|
|
538
|
+
quote ? null : /*#__PURE__*/ _jsx(PayLinkReadinessNoticeFor, {
|
|
539
|
+
hostId: hostId,
|
|
540
|
+
order: null,
|
|
541
|
+
noun: "quote"
|
|
542
|
+
}),
|
|
544
543
|
/*#__PURE__*/ _jsx(QuoteCustomerSection, {
|
|
545
544
|
hostId: hostId,
|
|
546
545
|
form: form,
|