@bunnyapp/components 1.0.6 → 1.0.7

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/dist/cjs/index.js CHANGED
@@ -3322,1095 +3322,1175 @@ function Quote(_a) {
3322
3322
  }
3323
3323
  var templateObject_1$5;
3324
3324
 
3325
- var DrawerHeader = function (_a) {
3326
- var description = _a.description, onClose = _a.onClose, title = _a.title;
3327
- return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center justify-between gap-2" }, { children: [jsxRuntime.jsx("div", __assign({ className: "text-xl" }, { children: title })), jsxRuntime.jsx("button", __assign({ onClick: onClose, className: "ant-drawer-close" }, { children: jsxRuntime.jsx(CloseOutlined$1, {}) }))] })), description && jsxRuntime.jsx("div", __assign({ className: "text-xs" }, { children: description }))] })));
3328
- };
3329
-
3330
- var LargeCardIcon = function () {
3331
- return (jsxRuntime.jsx("svg", __assign({ width: "72", height: "56", viewBox: "0 0 72 56", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: jsxRuntime.jsx("path", { d: "M8 0H64C68.375 0 72 3.625 72 8V12H0V8C0 3.625 3.5 0 8 0ZM72 24V48C72 52.5 68.375 56 64 56H8C3.5 56 0 52.5 0 48V24H72ZM14 40C12.875 40 12 41 12 42C12 43.125 12.875 44 14 44H22C23 44 24 43.125 24 42C24 41 23 40 22 40H14ZM28 42C28 43.125 28.875 44 30 44H46C47 44 48 43.125 48 42C48 41 47 40 46 40H30C28.875 40 28 41 28 42Z", fill: "#E2E8F0" }) })));
3325
+ var QUOTES_QUERY = function (filter) { return "\n query quotes {\n quotes ".concat(filter ? "(".concat(filter, ")") : "", " {\n pageInfo {\n startCursor\n endCursor\n hasNextPage\n hasPreviousPage\n }\n nodes {\n id\n name\n account {\n name\n id\n }\n applicationDate\n state\n createdAt\n expiresAt\n currencyId\n amount\n number\n }\n }\n }"); };
3326
+ var getQuotes = function (_a) {
3327
+ var token = _a.token, subdomain = _a.subdomain, filter = _a.filter;
3328
+ return __awaiter(void 0, void 0, void 0, function () {
3329
+ var response;
3330
+ return __generator(this, function (_b) {
3331
+ switch (_b.label) {
3332
+ case 0: return [4 /*yield*/, common.gqlRequest({
3333
+ query: QUOTES_QUERY(filter),
3334
+ token: token,
3335
+ vars: {},
3336
+ subdomain: subdomain,
3337
+ })];
3338
+ case 1:
3339
+ response = _b.sent();
3340
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.quotes];
3341
+ }
3342
+ });
3343
+ });
3332
3344
  };
3333
3345
 
3334
- var PlusIcon = function (_a) {
3335
- var color = _a.color;
3336
- return (jsxRuntime.jsxs("svg", __assign({ width: "14", height: "15", viewBox: "0 0 14 15", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: [jsxRuntime.jsx("path", { d: "M2.9165 7.5H11.0832", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }), jsxRuntime.jsx("path", { d: "M7 3.41663V11.5833", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })] })));
3337
- };
3346
+ var transactionMutation = function (filter) { return "\nquery transactions {\n transactions ".concat(filter ? "(".concat(filter, ")") : "", " {\n nodes {\n amount\n createdAt\n currencyId\n description\n id\n kind\n state\n transactionableId\n transactionable {\n ...on Payment { amount }\n ...on Invoice { amount number }\n }\n }\n }\n}"); };
3347
+ var getTransactions = function (filter, token, subdomain, kindsToShow) { return __awaiter(void 0, void 0, void 0, function () {
3348
+ var response, _a, data, errors, transactions;
3349
+ var _b, _c;
3350
+ return __generator(this, function (_d) {
3351
+ switch (_d.label) {
3352
+ case 0: return [4 /*yield*/, fetch(subdomain + "/graphql", {
3353
+ method: "POST",
3354
+ headers: {
3355
+ "Content-type": "application/json; charset=utf-8",
3356
+ Authorization: "Bearer ".concat(token),
3357
+ },
3358
+ body: JSON.stringify({
3359
+ query: transactionMutation(filter),
3360
+ }),
3361
+ })];
3362
+ case 1:
3363
+ response = _d.sent();
3364
+ return [4 /*yield*/, response.json()];
3365
+ case 2:
3366
+ _a = _d.sent(), data = _a.data, errors = _a.errors;
3367
+ if (errors) {
3368
+ throw new Error(errors[0].message);
3369
+ }
3370
+ transactions = (_c = (_b = data === null || data === void 0 ? void 0 : data.transactions) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.filter(function (transaction) { return kindsToShow.includes(transaction.kind); });
3371
+ return [2 /*return*/, transactions === null || transactions === void 0 ? void 0 : transactions.reverse()];
3372
+ }
3373
+ });
3374
+ }); };
3338
3375
 
3339
- var PaymentMethodContext = React.createContext({});
3376
+ var pageContentRefState = recoil.atom({
3377
+ key: "pageContentRefState",
3378
+ default: undefined,
3379
+ });
3340
3380
 
3341
- var Card = function (_a) {
3381
+ var PageContent = function (_a) {
3342
3382
  var children = _a.children, className = _a.className, style = _a.style;
3343
- var darkMode = React.useContext(BunnyContext).darkMode;
3344
- return (jsxRuntime.jsx("div", __assign({ className: "flex flex-col rounded-md shadow-md ".concat(className), style: __assign(__assign({}, style), { backgroundColor: darkMode
3345
- ? "var(--row-background-dark)"
3346
- : "var(--row-background)" }) }, { children: children })));
3383
+ var pageContentRef = React.useRef(null);
3384
+ var setPageContentRef = recoil.useSetRecoilState(pageContentRefState);
3385
+ React.useEffect(function () {
3386
+ setPageContentRef(pageContentRef === null || pageContentRef === void 0 ? void 0 : pageContentRef.current);
3387
+ }, [pageContentRef, setPageContentRef]);
3388
+ return (jsxRuntime.jsx("div", __assign({ className: className, ref: pageContentRef, style: style }, { children: children })));
3347
3389
  };
3348
3390
 
3349
3391
  var Text$b = antd.Typography.Text;
3350
- var CreditCard = function (_a) {
3351
- var _b, _c, _d;
3352
- var onClickRemove = _a.onClickRemove, onClickUpdate = _a.onClickUpdate, paymentMethodData = _a.paymentMethodData;
3353
- var isExpired = function (paymentMethodData) {
3354
- // paymentMethodData.expirationDate
3355
- var expDate = dayjs(paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.expirationDate);
3356
- return expDate.isBefore(dayjs());
3357
- };
3392
+ var PageHeaderWithActions = function (_a) {
3393
+ var children = _a.children, title = _a.title;
3358
3394
  var isMobile = common.useIsMobile();
3359
- var processPublicUrl = React.useContext(PaymentMethodContext).processPublicUrl;
3360
- return (jsxRuntime.jsxs(Card, __assign({ className: "shadow-md m-0" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center justify-between gap-4 p-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-2" }, { children: [getCardImage((_b = paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.metadata) === null || _b === void 0 ? void 0 : _b.issuer) && (jsxRuntime.jsx("img", { alt: "Card", width: "24px", src: "".concat(processPublicUrl, "/").concat(getCardImage((_c = paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.metadata) === null || _c === void 0 ? void 0 : _c.issuer)) })), jsxRuntime.jsx(Text$b, { children: (_d = paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.metadata) === null || _d === void 0 ? void 0 : _d.description })] })), jsxRuntime.jsx(antd.Tag, __assign({ color: isExpired(paymentMethodData) ? "red" : "green" }, { children: isExpired(paymentMethodData) ? "Expired" : "Valid" }))] })), !isMobile && (jsxRuntime.jsx(CardActions, { onClickRemove: onClickRemove, onClickUpdate: onClickUpdate }))] })), dayjs(paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.expirationDate).isValid() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(antd.Divider, {}), jsxRuntime.jsxs("div", __assign({ className: "flex flex-col p-4" }, { children: [jsxRuntime.jsx(CardAttribute, { title: "EXPIRATION", value: dayjs(paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.expirationDate).format("MM/YY") }), isMobile && (jsxRuntime.jsx(CardActions, { onClickRemove: onClickRemove, onClickUpdate: onClickUpdate }))] }))] }))] })));
3395
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex pb-4 shadow-padding-x ".concat(isMobile ? "flex-col gap-2" : "items-center justify-between h-8") }, { children: [jsxRuntime.jsx(PageSubTitle, { title: title }), children] })));
3361
3396
  };
3362
- var CardAttribute = function (_a) {
3363
- var title = _a.title, value = _a.value;
3364
- return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-2" }, { children: [jsxRuntime.jsx("div", __assign({ className: "text-slate-400", style: { fontSize: "11px" } }, { children: title })), jsxRuntime.jsx(Text$b, { children: value })] })));
3397
+ var PageSubTitle = function (_a) {
3398
+ var title = _a.title;
3399
+ var secondaryColor = React.useContext(BrandContext).secondaryColor;
3400
+ var darkMode = React.useContext(BunnyContext).darkMode;
3401
+ return (jsxRuntime.jsx(Text$b, __assign({ className: "shrink-0 font-medium", style: { color: darkMode ? undefined : secondaryColor } }, { children: title })));
3365
3402
  };
3366
- var CardActions = function (_a) {
3367
- var onClickRemove = _a.onClickRemove, onClickUpdate = _a.onClickUpdate;
3368
- var isMobile = common.useIsMobile();
3369
- return (jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-6 ".concat(isMobile ? "justify-center mt-4" : "") }, { children: [jsxRuntime.jsx(antd.Popconfirm, __assign({ title: "Remove card?", onConfirm: onClickRemove }, { children: jsxRuntime.jsx(antd.Button, __assign({ className: "font-normal p-0", type: "link" }, { children: "Remove payment method" })) })), jsxRuntime.jsx(antd.Divider, { style: { height: "24px" }, type: "vertical" }), jsxRuntime.jsx(antd.Button, __assign({ onClick: onClickUpdate, type: "primary" }, { children: "Update" }))] })));
3403
+
3404
+ var StateTag = function (_a) {
3405
+ var state = _a.state;
3406
+ return jsxRuntime.jsx(antd.Tag, __assign({ color: getColor(state) }, { children: lodash.capitalize(lodash.startCase(state)) }));
3370
3407
  };
3371
- var EmptyCard = function (_a) {
3372
- var onClick = _a.onClick;
3373
- var brandColor = React.useContext(BrandContext).brandColor;
3374
- return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col items-center justify-center w-full pt-8 px-4 pb-6 cursor-pointer bg-white shadow-md rounded-md", onClick: onClick }, { children: [jsxRuntime.jsx(LargeCardIcon, {}), jsxRuntime.jsx("div", __assign({ className: "text-slate-400 pt-4 pb-8" }, { children: "No payment methods" })), jsxRuntime.jsx(antd.Button, __assign({ type: "link" }, { children: jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-1" }, { children: [jsxRuntime.jsx(PlusIcon, { color: brandColor }), "Add payment method"] })) }))] })));
3408
+ var getColor = function (state) {
3409
+ switch (state) {
3410
+ case common.FrontendTransaction.TransactionState.not_due:
3411
+ return "yellow";
3412
+ case common.FrontendTransaction.TransactionState.voided:
3413
+ return "black";
3414
+ case common.FrontendTransaction.TransactionState.ready:
3415
+ return "orange";
3416
+ case common.FrontendTransaction.TransactionState.preparing:
3417
+ return "purple";
3418
+ case common.FrontendTransaction.TransactionState.unapplied:
3419
+ case common.FrontendTransaction.TransactionState.partially_applied:
3420
+ case common.FrontendTransaction.TransactionState.applied:
3421
+ return "blue";
3422
+ case common.FrontendTransaction.TransactionState.due:
3423
+ case common.FrontendTransaction.TransactionState.unpaid:
3424
+ return "orange";
3425
+ case common.FrontendTransaction.TransactionState.failed:
3426
+ return "red";
3427
+ case common.FrontendTransaction.TransactionState.paid:
3428
+ return "green";
3429
+ default:
3430
+ return "blue";
3431
+ }
3375
3432
  };
3376
- var getCardImage = function (issuer) {
3377
- if (issuer === "visa")
3378
- return "Visa_Brandmark_Blue_RGB_2021.png";
3379
- else if (issuer === "mastercard")
3380
- return "mc_symbol_opt_73_3x.png";
3433
+
3434
+ var TransactionGridCell = styled__default["default"].div.withConfig({
3435
+ shouldForwardProp: function (prop) {
3436
+ return !["gridColumn", "padding", "right"].includes(prop);
3437
+ },
3438
+ })(templateObject_1$4 || (templateObject_1$4 = __makeTemplateObject(["\n ", "\n\n display: flex;\n align-items: center;\n justify-content: ", ";\n\n text-align: ", ";\n white-space: nowrap;\n font-size: 14px;\n color: ", ";\n\n background-color: inherit;\n\n padding: 1rem;\n min-width: 48px;\n"], ["\n ", "\n\n display: flex;\n align-items: center;\n justify-content: ", ";\n\n text-align: ", ";\n white-space: nowrap;\n font-size: 14px;\n color: ", ";\n\n background-color: inherit;\n\n padding: 1rem;\n min-width: 48px;\n"])), function (props) { return props.gridColumn && "grid-column: ".concat(props.gridColumn, ";"); }, function (props) { return (props.right ? "flex-end" : "flex-start"); }, function (props) { return (props.right ? "right" : "left"); }, common.SLATE_600);
3439
+ var templateObject_1$4;
3440
+
3441
+ var Text$a = antd.Typography.Text;
3442
+ var TransactionDate = function (_a) {
3443
+ var date = _a.date;
3444
+ return jsxRuntime.jsx(Text$a, __assign({ className: "text-sm" }, { children: common.Misc.formatDate(date) }));
3381
3445
  };
3382
3446
 
3383
- var ActualPaymentMethod = function () {
3384
- var _a = React.useContext(BunnyContext), token = _a.token, subdomain = _a.subdomain, graphQLClient = _a.graphQLClient;
3385
- var accountId = React.useContext(PaymentContext).accountId;
3386
- // Hooks
3387
- var queryClient = reactQuery.useQueryClient();
3388
- var paymentPlugins = common.usePaymentPlugins({ subdomain: subdomain, token: token }).paymentPlugins;
3389
- var showErrorNotification = common.NotificationUtils.useErrorNotification();
3390
- var showSuccessNotification = common.NotificationUtils.useSuccessNotification();
3391
- var handleAllErrorFormats = common.NotificationUtils.useAllErrorFormats(function () {
3392
- console.log("Navigation in PaymentMethod.tsx useAllErrorFormats not implemented");
3393
- });
3394
- var isMobile = common.useIsMobile();
3395
- var data = usePaymentMethod(graphQLClient).data;
3396
- // Local state
3397
- var _b = React.useState(false), showModal = _b[0], setShowModal = _b[1];
3398
- var _c = React.useState(false), isSaving = _c[0], setIsSaving = _c[1];
3399
- // Queries
3400
- reactQuery.useQuery({
3401
- queryKey: common.QueryKeyFactory.default.currentUserKey,
3402
- queryFn: function () { return getCurrentUserData({ token: token, subdomain: subdomain }); },
3403
- });
3404
- var plugin = paymentPlugins === null || paymentPlugins === void 0 ? void 0 : paymentPlugins.find(function (paymentPlugin) { var _a; return String(paymentPlugin.id) === ((_a = data === null || data === void 0 ? void 0 : data.plugin) === null || _a === void 0 ? void 0 : _a.id); });
3405
- var onClickRemove = function () {
3406
- if (data && plugin) {
3407
- common.invokePlugin({
3408
- plugin: plugin,
3409
- method: "remove_payment_method",
3410
- payload: {
3411
- payment_method_id: data.id,
3412
- account_id: accountId,
3413
- },
3414
- token: token,
3415
- subdomain: subdomain,
3416
- })
3417
- .then(function () {
3418
- showSuccessNotification("Payment method was removed", "Success");
3419
- queryClient.setQueryData(common.QueryKeyFactory.default.accountPaymentMethodKey, null);
3420
- })
3421
- .catch(function (error) {
3422
- showErrorNotification(error.message, "Error removing Payment Method");
3423
- });
3424
- }
3425
- };
3426
- var onSuccess = function () {
3427
- queryClient.invalidateQueries({
3428
- queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey,
3429
- });
3430
- setShowModal(false);
3431
- showSuccessNotification("Your payment method has been saved");
3432
- };
3433
- if (data === undefined)
3447
+ var isInvoice = function (transaction) {
3448
+ return transaction.kind === "INVOICE";
3449
+ };
3450
+ var isQuote = function (transaction) {
3451
+ return transaction.kind === "QUOTE";
3452
+ };
3453
+ var TransactionRowTitle = function (_a) {
3454
+ var transaction = _a.transaction;
3455
+ if (!isInvoice(transaction) && !isQuote(transaction)) {
3434
3456
  return jsxRuntime.jsx(jsxRuntime.Fragment, {});
3435
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [data ? (jsxRuntime.jsx(CreditCard, { onClickRemove: onClickRemove, onClickUpdate: function () { return setShowModal(true); }, paymentMethodData: data })) : (jsxRuntime.jsx(EmptyCard, { onClick: function () { return setShowModal(true); } })), jsxRuntime.jsx(antd.Drawer, __assign({ closeIcon: null, onClose: function () { return setShowModal(false); }, open: showModal, styles: {
3436
- body: isMobile
3437
- ? {
3438
- padding: "1rem 0 0",
3439
- }
3440
- : {},
3441
- wrapper: isMobile ? { width: "100vw" } : { width: "min-content" },
3442
- }, title: jsxRuntime.jsx(DrawerHeader, { onClose: function () { return setShowModal(false); }, title: "New payment method" }) }, { children: jsxRuntime.jsx(PaymentForm, { isSaving: isSaving, onFail: function (error) {
3443
- handleAllErrorFormats(error);
3444
- setIsSaving(false);
3445
- }, onPaymentSuccess: function () {
3446
- onSuccess();
3447
- setIsSaving(false);
3448
- }, setIsSaving: setIsSaving }) }))] }));
3457
+ }
3458
+ return (jsxRuntime.jsx("span", __assign({ className: "text-slate-400", style: { fontSize: "11px" } }, { children: transaction.transactionable.number })));
3449
3459
  };
3450
- function PaymentMethod(_a) {
3451
- var footer = _a.footer, processPublicUrl = _a.processPublicUrl;
3452
- return (jsxRuntime.jsx(PaymentMethodContext.Provider, __assign({ value: { footer: footer, processPublicUrl: processPublicUrl } }, { children: jsxRuntime.jsx(ActualPaymentMethod, {}) })));
3453
- }
3454
3460
 
3455
- var MUTATION$5 = "\nmutation accountUpdate(\n $id: ID!,\n $attributes: AccountAttributes!) {\n accountUpdate(\n id: $id,\n attributes: $attributes\n ) {\n account { id }\n errors\n }\n }\n";
3456
- var accountUpdate = function (_a) {
3457
- var accountId = _a.accountId, attributes = _a.attributes, token = _a.token;
3458
- return __awaiter(void 0, void 0, void 0, function () {
3459
- var vars, response, errors;
3460
- var _b;
3461
- return __generator(this, function (_c) {
3462
- switch (_c.label) {
3463
- case 0:
3464
- vars = { id: accountId, attributes: attributes };
3465
- return [4 /*yield*/, common.gqlRequest({ query: MUTATION$5, token: token, vars: vars })];
3466
- case 1:
3467
- response = _c.sent();
3468
- errors = (_b = response === null || response === void 0 ? void 0 : response.accountUpdate) === null || _b === void 0 ? void 0 : _b.errors;
3469
- if (errors)
3470
- throw errors;
3471
- return [2 /*return*/, response.accountUpdate];
3472
- }
3473
- });
3474
- });
3461
+ // TODO: delete
3462
+ var ArrowDownToLine = function (_a) {
3463
+ var className = _a.className, _b = _a.color, color = _b === void 0 ? common.SLATE_600 : _b;
3464
+ return (jsxRuntime.jsxs("svg", __assign({ className: className, fill: "none", height: "16", viewBox: "0 0 16 16", width: "16", xmlns: "http://www.w3.org/2000/svg" }, { children: [jsxRuntime.jsx("path", { d: "M8 11.3333V2", stroke: color, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), jsxRuntime.jsx("path", { d: "M4 7.33301L8 11.333L12 7.33301", stroke: color, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), jsxRuntime.jsx("path", { d: "M12.6654 14H3.33203", stroke: color, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })));
3475
3465
  };
3476
3466
 
3477
- var COUNTRIES_REQUIRING_STATE = ["US", "CA"];
3478
- var TaxationForm = function (_a) {
3479
- var account = _a.account, quote = _a.quote;
3480
- // Hooks
3481
- var queryClient = reactQuery.useQueryClient();
3482
- var token = React.useContext(BunnyContext).token;
3483
- var form = antd.Form.useForm()[0];
3484
- // Mutations
3485
- var _b = reactQuery.useMutation({
3486
- mutationFn: function (changedFormData) { return __awaiter(void 0, void 0, void 0, function () {
3487
- var account;
3488
- return __generator(this, function (_a) {
3489
- switch (_a.label) {
3490
- case 0: return [4 /*yield*/, accountUpdate({
3491
- accountId: quote.accountId,
3492
- attributes: changedFormData,
3493
- token: token,
3494
- })];
3495
- case 1:
3496
- account = _a.sent();
3497
- return [2 /*return*/, account];
3498
- }
3499
- });
3500
- }); },
3501
- onSuccess: function () {
3502
- queryClient.invalidateQueries({
3503
- queryKey: ["getTaxationRequiredAccountFields", token],
3504
- });
3505
- },
3506
- }), updateAccount = _b.mutate, isUpdatingAccount = _b.isPending;
3507
- return (jsxRuntime.jsxs(antd.Form, __assign({ className: "flex flex-col gap-4", form: form, initialValues: account, layout: "vertical", onFinish: updateAccount }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing street", name: "billingStreet" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Street" }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing city", name: "billingCity" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "City" }) })), jsxRuntime.jsx(FormBillingState, { form: form }), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing country", name: "billingCountry", rules: [{ required: true }] }, { children: jsxRuntime.jsx(antd.Select, { options: common.Lists.COUNTRY_LIST, placeholder: "Select a country", showSearch: true, filterOption: function (input, option) {
3508
- var _a, _b;
3509
- return ((_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : "").toLowerCase().includes(input.toLowerCase()) ||
3510
- ((_b = option === null || option === void 0 ? void 0 : option.value) !== null && _b !== void 0 ? _b : "").toLowerCase().includes(input.toLowerCase());
3511
- } }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing zip", name: "billingZip" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Zip" }) })), jsxRuntime.jsx(antd.Form.Item, { children: jsxRuntime.jsx(antd.Button, __assign({ className: "w-full", disabled: isUpdatingAccount, htmlType: "submit", type: "primary" }, { children: "Submit" })) })] })));
3467
+ var TransactionsListContext = React.createContext({});
3468
+
3469
+ var TransactionDownload = function (_a) {
3470
+ var transaction = _a.transaction, token = _a.token, subdomain = _a.subdomain;
3471
+ var darkMode = React.useContext(BunnyContext).darkMode;
3472
+ var downloadTransactionLink = React.useContext(TransactionsListContext).downloadTransactionLink;
3473
+ var downloadFile = common.useDownloadFile();
3474
+ var isMobile = common.useIsMobile();
3475
+ var isClickable = transaction.kind === "INVOICE" || downloadTransactionLink !== undefined;
3476
+ var downloadLink = downloadTransactionLink
3477
+ ? downloadTransactionLink(transaction.transactionableId)
3478
+ : "".concat(subdomain, "/api/pdf/invoice/").concat(transaction.transactionableId);
3479
+ if (!isClickable)
3480
+ return null;
3481
+ return (jsxRuntime.jsx("div", __assign({ onClick: function (e) {
3482
+ e.stopPropagation();
3483
+ downloadFile(downloadLink, token);
3484
+ } }, { children: jsxRuntime.jsx(ArrowDownToLine, { className: "".concat(isMobile ? "" : "show-on-hover"), color: darkMode ? common.WHITE : common.SLATE_600 }) })));
3512
3485
  };
3513
- var FormBillingState = function (_a) {
3514
- _a.form;
3515
- var billingCountry = antd.Form.useWatch("billingCountry");
3516
- var billingStateRequired = COUNTRIES_REQUIRING_STATE.includes(billingCountry);
3517
- return (jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing state", name: "billingState", rules: [{ required: billingStateRequired }] }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "State" }) })));
3486
+
3487
+ var Text$9 = antd.Typography.Text;
3488
+ var TransactionsEmptyState = function () {
3489
+ var noTransactionsMessage = React.useContext(TransactionsListContext).noTransactionsMessage;
3490
+ return (jsxRuntime.jsx(Text$9, __assign({ className: "flex justify-center p-4 text-base" }, { children: noTransactionsMessage || "There are no transactions" })));
3518
3491
  };
3519
3492
 
3520
- var QuoteCheckout = function (_a) {
3521
- var account = _a.account, isSaving = _a.isSaving, onSuccess = _a.onSuccess, onFail = _a.onFail, quote = _a.quote, setIsSaving = _a.setIsSaving, taxationRequiredAccountFields = _a.taxationRequiredAccountFields; _a.storedPaymentMethod;
3522
- // Context
3523
- var isMobile = common.useIsMobile();
3524
- var _b = React.useContext(BunnyContext), subdomain = _b.subdomain, token = _b.token;
3525
- var paymentRequired = getQuoteAmountDue(quote) > 0;
3526
- var checkoutMutation = reactQuery.useMutation({
3527
- mutationFn: function (_a) {
3528
- var pluginPaymentMethod = _a.pluginPaymentMethod, savedPaymentMethod = _a.storedPaymentMethod;
3529
- if (!quote)
3530
- throw new Error("Quote is required");
3531
- if (!paymentRequired)
3532
- return checkout({ quoteId: quote.id, token: token, subdomain: subdomain });
3533
- if (savedPaymentMethod) {
3534
- var paymentMethodId = savedPaymentMethod.paymentMethodId;
3535
- return checkout({
3536
- quoteId: quote.id,
3537
- paymentMethodId: paymentMethodId,
3538
- token: token,
3539
- subdomain: subdomain,
3540
- });
3541
- }
3542
- if (pluginPaymentMethod) {
3543
- var plugin = pluginPaymentMethod.plugin, savePaymentMethod = pluginPaymentMethod.savePaymentMethod, metadata = pluginPaymentMethod.metadata;
3544
- var paymentToken = pluginPaymentMethod.token;
3545
- return checkout({
3546
- quoteId: quote.id,
3547
- paymentMethodData: {
3548
- metadata: metadata,
3549
- pluginGuid: plugin.guid,
3550
- savePaymentMethod: savePaymentMethod,
3551
- token: paymentToken,
3552
- },
3553
- token: token,
3554
- subdomain: subdomain,
3555
- });
3556
- }
3557
- throw new Error("Pay payment method provided");
3558
- },
3559
- onSuccess: onSuccess,
3560
- onError: onFail,
3561
- });
3562
- // Handlers
3563
- var handleCheckout = function (_a) {
3564
- var pluginPaymentResponse = _a.pluginPaymentResponse, savedPaymentMethodResponse = _a.savedPaymentMethodResponse;
3565
- return __awaiter(void 0, void 0, void 0, function () {
3566
- var token_1, plugin, savePaymentMethod, metadata, paymentMethodId;
3567
- return __generator(this, function (_b) {
3568
- if (pluginPaymentResponse) {
3569
- token_1 = pluginPaymentResponse.token, plugin = pluginPaymentResponse.plugin, savePaymentMethod = pluginPaymentResponse.savePaymentMethod, metadata = pluginPaymentResponse.metadata;
3570
- checkoutMutation.mutate({
3571
- pluginPaymentMethod: {
3572
- savePaymentMethod: savePaymentMethod,
3573
- plugin: plugin,
3574
- metadata: metadata,
3575
- token: token_1,
3576
- },
3577
- });
3578
- }
3579
- else if (savedPaymentMethodResponse) {
3580
- paymentMethodId = savedPaymentMethodResponse.paymentMethodId;
3581
- checkoutMutation.mutate({
3582
- storedPaymentMethod: {
3583
- paymentMethodId: paymentMethodId,
3584
- },
3585
- });
3586
- }
3587
- else {
3588
- checkoutMutation.mutate({});
3589
- }
3590
- return [2 /*return*/];
3591
- });
3592
- });
3493
+ function capitalizeFirstLetter(string) {
3494
+ return string.charAt(0).toUpperCase() + string.slice(1);
3495
+ }
3496
+ var WARREN_STATE_LS_KEY = "warrenState";
3497
+ var CURRENT_WARREN_ID_LS_KEY = "currentWarrenId";
3498
+ var getIsCapacitorApp = function () {
3499
+ var isAndroid = window.location.origin === "http://localhost";
3500
+ var isIOS = window.location.protocol === "capacitor:";
3501
+ return isAndroid || isIOS;
3502
+ };
3503
+ var getLocalStorageSubdomain = function () {
3504
+ var warrenState = JSON.parse(window.localStorage.getItem(WARREN_STATE_LS_KEY) || "{}");
3505
+ var subdomain = warrenState[CURRENT_WARREN_ID_LS_KEY];
3506
+ if (!subdomain) {
3507
+ console.warn("ERROR_MESSAGE_NO_SUBDOMAIN_DEFINED");
3508
+ //throw new Error(ERROR_MESSAGE_NO_SUBDOMAIN_DEFINED);
3509
+ }
3510
+ return subdomain;
3511
+ };
3512
+ var getApiHost = function (subdomain) {
3513
+ var isLocalHost = window.location.href.indexOf(".internal") > 0;
3514
+ var sub = subdomain || getLocalStorageSubdomain();
3515
+ if (getIsCapacitorApp()) {
3516
+ return isLocalHost || process.env.REACT_APP_IS_INTERNAL === "true"
3517
+ ? "https://".concat(sub, ".bunny.internal")
3518
+ : "https://".concat(sub, ".").concat(process.env.REACT_APP_ROOT_DOMAIN);
3519
+ }
3520
+ return "";
3521
+ };
3522
+ var getGraphQLBase = function () {
3523
+ if (getIsCapacitorApp()) {
3524
+ return "".concat(getApiHost(), "/graphql");
3525
+ }
3526
+ return "/graphql";
3527
+ };
3528
+ var createRequestHeaders = function (token) {
3529
+ var bearerToken = "Bearer ".concat(token);
3530
+ var headers = {
3531
+ "Content-type": "application/json; charset=utf-8",
3593
3532
  };
3594
- if (taxationRequiredAccountFields)
3595
- return (jsxRuntime.jsx(PaymentFormWrapper, __assign({ setMaxHeight: false }, { children: jsxRuntime.jsx(TaxationForm, { account: account, quote: quote }) })));
3596
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: paymentRequired ? (jsxRuntime.jsx(PaymentForm, { isSaving: isSaving, onFail: onFail, onPaymentSuccess: handleCheckout, quote: quote, setIsSaving: setIsSaving })) : (jsxRuntime.jsx(PaymentFormWrapper, __assign({ setMaxHeight: false }, { children: jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-2 ".concat(isMobile ? "shadow-padding-x" : "") }, { children: [jsxRuntime.jsx(antd.Button, __assign({ disabled: isSaving, onClick: function () {
3597
- setIsSaving(true);
3598
- handleCheckout({});
3599
- }, type: "primary" }, { children: isSaving ? "Processing..." : "Complete order" })), jsxRuntime.jsx("div", __assign({ className: "text-xs text-slate-500" }, { children: "No payment is required" }))] })) }))) }));
3533
+ headers["Authorization"] = bearerToken;
3534
+ return headers;
3600
3535
  };
3536
+ var useGraphQLRequest = function () { return function (query, token, variables) { return __awaiter(void 0, void 0, void 0, function () {
3537
+ var error_1;
3538
+ return __generator(this, function (_a) {
3539
+ switch (_a.label) {
3540
+ case 0:
3541
+ _a.trys.push([0, 2, , 3]);
3542
+ return [4 /*yield*/, request__default["default"](getGraphQLBase(), query, variables, createRequestHeaders(token))];
3543
+ case 1: return [2 /*return*/, _a.sent()];
3544
+ case 2:
3545
+ error_1 = _a.sent();
3546
+ throw error_1;
3547
+ case 3: return [2 /*return*/];
3548
+ }
3549
+ });
3550
+ }); }; };
3601
3551
 
3602
- var useHasTaxPlugin = function (_a) {
3603
- var subdomain = _a.subdomain, token = _a.token;
3604
- var plugins = common.usePlugins({
3605
- subdomain: subdomain,
3606
- token: token,
3607
- }).data;
3608
- return Boolean(plugins === null || plugins === void 0 ? void 0 : plugins.some(function (plugin) { return plugin.type === "taxation"; }));
3552
+ var Text$8 = antd.Typography.Text;
3553
+ var TransactionsListDesktop = function (_a) {
3554
+ var transactions = _a.transactions, onTransactionClick = _a.onTransactionClick;
3555
+ var columns = React.useContext(TransactionsListContext).columns;
3556
+ var _b = React.useContext(BunnyContext), token = _b.token, subdomain = _b.subdomain, darkMode = _b.darkMode;
3557
+ var showAmount = columns.includes("amount");
3558
+ var showDateAndTitle = columns.includes("date-and-title");
3559
+ var showDownload = columns.includes("download");
3560
+ var showState = columns.includes("state");
3561
+ if ((transactions === null || transactions === void 0 ? void 0 : transactions.length) === 0)
3562
+ return jsxRuntime.jsx(TransactionsEmptyState, {});
3563
+ return transactions === null || transactions === void 0 ? void 0 : transactions.map(function (transaction, index) {
3564
+ var _a;
3565
+ var isClickable = onTransactionClick !== undefined;
3566
+ return (jsxRuntime.jsxs("div", __assign({ className: "contents ".concat(isClickable && "cursor-pointer", " show-on-hover-container"), onClick: function () {
3567
+ onTransactionClick === null || onTransactionClick === void 0 ? void 0 : onTransactionClick(transaction);
3568
+ }, style: {
3569
+ backgroundColor: index % 2 === 0
3570
+ ? "var(--row-background".concat(darkMode ? "-dark" : "", ")")
3571
+ : "var(--row-background-alternate".concat(darkMode ? "-dark" : "", ")"),
3572
+ } }, { children: [showDateAndTitle && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TransactionGridCell, __assign({ right: false }, { children: jsxRuntime.jsx(TransactionDate, { date: transaction.createdAt }) })), jsxRuntime.jsxs(TransactionGridCell, __assign({ right: false, className: "flex items-center gap-2" }, { children: [jsxRuntime.jsx(Text$8, { children: capitalizeFirstLetter(transaction.kind.toLowerCase()) }), jsxRuntime.jsx(TransactionRowTitle, { transaction: transaction })] }))] })), showDownload && (jsxRuntime.jsx(TransactionGridCell, { children: jsxRuntime.jsx(TransactionDownload, { transaction: transaction, token: token, subdomain: subdomain }) })), showState && (jsxRuntime.jsx(TransactionGridCell, __assign({ right: true }, { children: jsxRuntime.jsx(StateTag, { state: transaction.state }) }))), showAmount && (jsxRuntime.jsx(TransactionGridCell, __assign({ right: true }, { children: jsxRuntime.jsx(Text$8, { children: common.Misc.formatCurrency(((_a = transaction === null || transaction === void 0 ? void 0 : transaction.transactionable) === null || _a === void 0 ? void 0 : _a.amount) || transaction.amount, transaction.currencyId) }) })))] }), index));
3573
+ });
3609
3574
  };
3610
3575
 
3611
- var QUOTE_FIELDS = "quote {\n formattedQuote {\n html\n }\n acceptedByName\n acceptedByTitle\n accountId\n amount\n amountDue\n applicationDate\n applied\n billingDay\n contactId\n createdAt\n credits\n currencyId\n dealId\n discount\n discountValue\n endDate\n evergreen\n expiresAt\n id\n invoiceUntil\n isPendingApprovalRequest\n kind\n message\n name\n netPaymentDays\n notes\n ownerId\n periodAmount\n poNumber\n requiresApproval\n startDate\n state\n subtotal\n taxAmount\n updatedAt\n uuid\n amountsByPeriod {\n amount\n id\n name\n }\n endDateOptions {\n endDate\n label\n }\n invoiceUntilOptions {\n endDate\n label\n }\n quoteChanges {\n id\n priceListId\n charges {\n amount\n amountsByPeriod { amount startDate }\n billingPeriod\n billingPeriodAmounts { id amount prorationRate }\n chargeType\n couponId\n createdAt\n currencyId\n discount\n endDate\n feature { id name code isUnit unitName }\n id\n invoiceLineText\n name\n price\n priceDecimals\n priceTiers { starts price }\n pricingModel\n prorationRate\n quantity\n quantityMax\n quantityMin\n startDate\n tieredAveragePrice\n updatedAt\n }\n }\n}";
3612
-
3613
- var QUOTE_RECALCULATE_TAXES = "\n mutation QuoteRecalculateTaxes($id: ID!) {\n quoteRecalculateTaxes(id: $id) {\n ".concat(QUOTE_FIELDS, "\n errors\n }\n }\n");
3614
- var quoteRecalculateTaxes = function (_a) {
3615
- var quoteId = _a.quoteId, token = _a.token;
3616
- return __awaiter(void 0, void 0, void 0, function () {
3617
- var vars, response, errors;
3618
- var _b, _c;
3619
- return __generator(this, function (_d) {
3620
- switch (_d.label) {
3621
- case 0:
3622
- vars = { id: quoteId };
3623
- return [4 /*yield*/, common.gqlRequest({
3624
- query: QUOTE_RECALCULATE_TAXES,
3625
- token: token,
3626
- vars: vars,
3627
- })];
3628
- case 1:
3629
- response = _d.sent();
3630
- errors = (_b = response === null || response === void 0 ? void 0 : response.quoteRecalculateTaxes) === null || _b === void 0 ? void 0 : _b.errors;
3631
- if (errors)
3632
- throw errors;
3633
- return [2 /*return*/, (_c = response.quoteRecalculateTaxes) === null || _c === void 0 ? void 0 : _c.quote];
3634
- }
3635
- });
3576
+ var Text$7 = antd.Typography.Text;
3577
+ var TransactionsListMobile = function (_a) {
3578
+ var transactions = _a.transactions, onTransactionClick = _a.onTransactionClick;
3579
+ var columns = React.useContext(TransactionsListContext).columns;
3580
+ var _b = React.useContext(BunnyContext), token = _b.token, subdomain = _b.subdomain, darkMode = _b.darkMode;
3581
+ var showAmount = columns.includes("amount");
3582
+ var showDateAndTitle = columns.includes("date-and-title");
3583
+ var showDownload = columns.includes("download");
3584
+ var showState = columns.includes("state");
3585
+ if ((transactions === null || transactions === void 0 ? void 0 : transactions.length) === 0)
3586
+ return jsxRuntime.jsx(TransactionsEmptyState, {});
3587
+ return transactions === null || transactions === void 0 ? void 0 : transactions.map(function (transaction, index) {
3588
+ var isClickable = transaction.kind === "INVOICE";
3589
+ return (jsxRuntime.jsxs("div", __assign({ className: "contents ".concat(isClickable && "cursor-pointer", " show-on-hover-container"), onClick: function () {
3590
+ onTransactionClick(transaction);
3591
+ }, style: {
3592
+ backgroundColor: index % 2 === 0
3593
+ ? "var(--row-background".concat(darkMode ? "-dark" : "", ")")
3594
+ : "var(--row-background-alternate".concat(darkMode ? "-dark" : "", ")"),
3595
+ } }, { children: [jsxRuntime.jsx(TransactionGridCell, { children: jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-2" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-2" }, { children: [showDateAndTitle && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Text$7, { children: capitalizeFirstLetter(transaction.kind.toLowerCase()) }), jsxRuntime.jsx(TransactionRowTitle, { transaction: transaction })] })), showState && jsxRuntime.jsx(StateTag, { state: transaction.state })] })), jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-2" }, { children: [showDateAndTitle && (jsxRuntime.jsx(TransactionDate, { date: transaction.createdAt })), showAmount && showDateAndTitle && jsxRuntime.jsx(Text$7, { children: "\u00B7" }), showAmount && (jsxRuntime.jsx(Text$7, { children: common.Misc.formatCurrency(transaction.transactionable.amount || transaction.amount, transaction.currencyId) }))] }))] })) }), showDownload && (jsxRuntime.jsx(TransactionGridCell, __assign({ right: true }, { children: jsxRuntime.jsx(TransactionDownload, { transaction: transaction, token: token, subdomain: subdomain }) })))] }), index));
3636
3596
  });
3637
3597
  };
3638
3598
 
3639
- var planPickerQuoteDataState = recoil.atom({
3640
- key: "planPickerQuoteDataState",
3641
- default: undefined,
3642
- });
3643
-
3644
- var pageWrapperClassName = function (isMobile) {
3645
- return "flex flex-col grow pt-4 ".concat(isMobile ? "pb-4 overflow-hidden" : "pb-8", " ").concat("content-container");
3646
- };
3647
-
3648
- var queryKeyFactory = common.QueryKeyFactory.default;
3649
- var Checkout = function (_a) {
3650
- var _b, _c;
3651
- var onCancel = _a.onCancel, onSuccess = _a.onSuccess, onFail = _a.onFail, invoice = _a.invoice, open = _a.open, quote = _a.quote, selectedPriceList = _a.selectedPriceList, isMobile = _a.isMobile, token = _a.token, storedPaymentMethod = _a.storedPaymentMethod;
3652
- var subdomain = React.useContext(BunnyContext).subdomain;
3653
- var _d = React.useState(false), isSaving = _d[0], setIsSaving = _d[1];
3654
- var hasTaxPlugin = useHasTaxPlugin({ subdomain: subdomain || "", token: token });
3655
- var queryClient = reactQuery.useQueryClient();
3656
- var quotePreviewData = recoil.useRecoilValue(planPickerQuoteDataState);
3599
+ // Create a client
3600
+ var queryClient = new reactQuery.QueryClient();
3601
+ function Transactions(_a) {
3602
+ var transactionComponent = _a.transactionComponent, _b = _a.showSearchBar, showSearchBar = _b === void 0 ? true : _b, _c = _a.showTitle, showTitle = _c === void 0 ? true : _c, _d = _a.columns, columns = _d === void 0 ? ["date-and-title", "state", "amount"] : _d, className = _a.className, _e = _a.shadow, shadow = _e === void 0 ? "md" : _e, searchBarClassName = _a.searchBarClassName, _f = _a.useModal, useModal = _f === void 0 ? false : _f, onTransactionClick = _a.onTransactionClick, _g = _a.suppressTransactionDisplay, suppressTransactionDisplay = _g === void 0 ? false : _g, _h = _a.kindsToShow, kindsToShow = _h === void 0 ? [
3603
+ common.TransactionKind.INVOICE,
3604
+ common.TransactionKind.PAYMENT,
3605
+ common.TransactionKind.REFUND,
3606
+ common.TransactionKind.WRITE_OFF,
3607
+ ] : _h, style = _a.style, filter = _a.filter, noTransactionsMessage = _a.noTransactionsMessage;
3608
+ var contextValues = {
3609
+ showSearchBar: showSearchBar,
3610
+ showTitle: showTitle,
3611
+ transactionComponent: transactionComponent,
3612
+ columns: columns,
3613
+ className: className,
3614
+ searchBarClassName: searchBarClassName,
3615
+ shadow: shadow,
3616
+ useModal: useModal,
3617
+ onTransactionClick: onTransactionClick,
3618
+ suppressTransactionDisplay: suppressTransactionDisplay,
3619
+ kindsToShow: kindsToShow,
3620
+ style: style,
3621
+ filter: filter,
3622
+ noTransactionsMessage: noTransactionsMessage,
3623
+ };
3624
+ return (jsxRuntime.jsx(reactQuery.QueryClientProvider, __assign({ client: queryClient }, { children: jsxRuntime.jsx(TransactionsListContext.Provider, __assign({ value: contextValues }, { children: jsxRuntime.jsx(TransactionsWrapper, {}) })) })));
3625
+ }
3626
+ function TransactionsWrapper() {
3627
+ var _a = React.useContext(TransactionsListContext), kindsToShow = _a.kindsToShow, filterFromContext = _a.filter;
3628
+ var _b = React.useContext(BunnyContext), token = _b.token, subdomain = _b.subdomain;
3629
+ // Local state
3630
+ var _c = React.useState(""), search = _c[0], setSearch = _c[1];
3631
+ var filter = filterFromContext ||
3632
+ (search ? "filter: \"transaction.transactionableId is ".concat(search, "\"") : "");
3657
3633
  // Queries
3658
- var _e = reactQuery.useQuery({
3659
- queryKey: ["getTaxationRequiredAccountFields", token],
3660
- queryFn: function () { return common.getTaxationRequiredAccountFields({ token: token }); },
3661
- enabled: Boolean(quote),
3662
- staleTime: 0,
3663
- }), taxationRequiredAccountFields = _e.data, isLoadingTaxationRequiredAccountFields = _e.isLoading;
3664
- var _f = reactQuery.useQuery({
3665
- queryKey: ["account", quote === null || quote === void 0 ? void 0 : quote.accountId],
3666
- queryFn: function () {
3667
- return (quote === null || quote === void 0 ? void 0 : quote.accountId) && common.getAccount({ id: quote.accountId, token: token });
3668
- },
3669
- enabled: Boolean(quote === null || quote === void 0 ? void 0 : quote.accountId) &&
3670
- ((taxationRequiredAccountFields === null || taxationRequiredAccountFields === void 0 ? void 0 : taxationRequiredAccountFields.length) || 0) > 0,
3671
- }), account = _f.data, isLoadingAccount = _f.isLoading;
3672
- reactQuery.useQuery({
3673
- queryKey: queryKeyFactory.createQuoteTaxCalculateKey(quote === null || quote === void 0 ? void 0 : quote.id),
3674
- queryFn: function () { return __awaiter(void 0, void 0, void 0, function () {
3675
- var updatedQuote;
3676
- return __generator(this, function (_a) {
3677
- switch (_a.label) {
3678
- case 0:
3679
- if (!quote) return [3 /*break*/, 2];
3680
- return [4 /*yield*/, quoteRecalculateTaxes({
3681
- quoteId: quote.id,
3682
- token: token,
3683
- })];
3684
- case 1:
3685
- updatedQuote = _a.sent();
3686
- if (updatedQuote) {
3687
- queryClient.setQueryData(queryKeyFactory.createObjectKey("editingQuote", updatedQuote.id), updatedQuote);
3688
- queryClient.setQueryData(queryKeyFactory.calculatedPricesKey((quotePreviewData === null || quotePreviewData === void 0 ? void 0 : quotePreviewData.quantity) || 0, selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.id), updatedQuote);
3689
- }
3690
- _a.label = 2;
3691
- case 2: return [2 /*return*/, {}];
3692
- }
3693
- });
3694
- }); },
3695
- // Recalculate taxes if the quote is open, has a tax plugin, and the taxation required account fields are not required
3696
- enabled: Boolean(quote) &&
3697
- open &&
3698
- hasTaxPlugin &&
3699
- !taxationRequiredAccountFields &&
3700
- !isLoadingTaxationRequiredAccountFields,
3701
- staleTime: 0,
3702
- });
3703
- if (!open || isLoadingTaxationRequiredAccountFields || isLoadingAccount)
3704
- return null;
3705
- return (jsxRuntime.jsx("div", __assign({ className: "flex flex-col fixed top-0 left-0 right-0 bottom-0 bg-slate-50 overflow-auto", style: {
3706
- zIndex: 1001,
3707
- } }, { children: jsxRuntime.jsxs("div", __assign({ className: pageWrapperClassName(isMobile) }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex justify-end w-full" }, { children: jsxRuntime.jsx(CloseOutlined$1, { className: "text-base shadow-padding-xb", onClick: onCancel }) })), jsxRuntime.jsxs("div", __assign({ className: "flex justify-end gap-6 pt-4 ".concat(isMobile ? "flex-col" : "shadow-padding-xb") }, { children: [((invoice === null || invoice === void 0 ? void 0 : invoice.html) || ((_b = quote === null || quote === void 0 ? void 0 : quote.formattedQuote) === null || _b === void 0 ? void 0 : _b.html)) && (jsxRuntime.jsx(InvoiceQuoteView, { html: invoice ? invoice.html : quote ? quote.formattedQuote.html : "", isMobile: isMobile })), !isMobile && ((invoice === null || invoice === void 0 ? void 0 : invoice.html) || ((_c = quote === null || quote === void 0 ? void 0 : quote.formattedQuote) === null || _c === void 0 ? void 0 : _c.html)) && (jsxRuntime.jsx(antd.Divider, { className: "h-full", type: "vertical" })), invoice ? (jsxRuntime.jsx(InvoiceCheckout, { invoice: invoice, isSaving: isSaving, onFail: function (error) {
3708
- onFail(error);
3709
- setIsSaving(false);
3710
- }, onSuccess: function (_a) {
3711
- var savePaymentMethod = _a.savePaymentMethod;
3712
- onSuccess({ savePaymentMethod: savePaymentMethod });
3713
- setIsSaving(false);
3714
- }, setIsSaving: setIsSaving })) : quote ? (jsxRuntime.jsx(QuoteCheckout, { account: account, isSaving: isSaving, onFail: function (error) {
3715
- onFail(error);
3716
- setIsSaving(false);
3717
- }, onSuccess: function (_a) {
3718
- var savePaymentMethod = _a.savePaymentMethod;
3719
- onSuccess({ savePaymentMethod: savePaymentMethod });
3720
- setIsSaving(false);
3721
- }, quote: quote, setIsSaving: setIsSaving, taxationRequiredAccountFields: taxationRequiredAccountFields, token: token, storedPaymentMethod: storedPaymentMethod })) : (jsxRuntime.jsx(PaymentForm, { isSaving: isSaving, onFail: function (error) {
3722
- onFail(error);
3723
- setIsSaving(false);
3724
- }, onPaymentSuccess: function (_a) {
3725
- var pluginPaymentResponse = _a.pluginPaymentResponse;
3726
- onSuccess({
3727
- savePaymentMethod: pluginPaymentResponse === null || pluginPaymentResponse === void 0 ? void 0 : pluginPaymentResponse.savePaymentMethod,
3728
- });
3729
- setIsSaving(false);
3730
- }, setIsSaving: setIsSaving }))] }))] })) })));
3731
- };
3732
-
3733
- var MUTATION$4 = function () { return "\nmutation AccountSignup (\n $entityId: ID!,\n $pluginId: String!,\n $paymentMethodId: String,\n $priceListCode: String!,\n $accountId: ID!,\n $quoteId: ID!\n) {\n accountSignup(\n entityId: $entityId,\n pluginId: $pluginId,\n paymentMethodId: $paymentMethodId,\n priceListCode: $priceListCode,\n accountId: $accountId,\n quoteId: $quoteId\n ) {\n errors\n quote {\n acceptedByName\n acceptedByTitle\n accountId\n amount\n amountDue\n applicationDate\n applied\n backdatedPeriods\n backdatedQuote\n billingDay\n contactId\n createdAt\n credits\n currencyId\n dealId\n discount\n discountValue\n endDate\n evergreen\n expiresAt\n id\n invoiceImmediately\n invoiceImmediatelyAvailable\n invoiceUntil\n isPendingApprovalRequest\n kind\n message\n name\n netPaymentDays\n notes\n number\n ownerId\n payableId\n periodAmount\n poNumber\n requiresApproval\n smallUnitAmountDue\n splitInvoice\n startDate\n state\n subtotal\n taxAmount\n taxCode\n updatedAt\n uuid\n }\n }\n}"; };
3734
- var accountSignup = function (_a) {
3735
- var token = _a.token, subdomain = _a.subdomain, entityId = _a.entityId, accountId = _a.accountId, quoteId = _a.quoteId, paymentToken = _a.paymentToken, paymentMethodId = _a.paymentMethodId, pluginId = _a.pluginId, priceListCode = _a.priceListCode;
3736
- return __awaiter(void 0, void 0, void 0, function () {
3737
- var vars, response, errors;
3738
- var _b;
3739
- return __generator(this, function (_c) {
3740
- switch (_c.label) {
3741
- case 0:
3742
- vars = {
3743
- entityId: entityId,
3744
- accountId: accountId,
3745
- quoteId: quoteId,
3746
- paymentToken: paymentToken,
3747
- pluginId: pluginId,
3748
- paymentMethodId: paymentMethodId,
3749
- priceListCode: priceListCode,
3750
- };
3751
- return [4 /*yield*/, common.gqlRequest({
3752
- query: MUTATION$4(),
3753
- token: token,
3754
- vars: vars,
3755
- subdomain: subdomain,
3756
- })];
3757
- case 1:
3758
- response = _c.sent();
3759
- errors = (_b = response === null || response === void 0 ? void 0 : response.accountSignup) === null || _b === void 0 ? void 0 : _b.errors;
3760
- if (errors)
3761
- throw errors;
3762
- return [2 /*return*/, response === null || response === void 0 ? void 0 : response.accountSignup];
3634
+ var data = reactQuery.useQuery({
3635
+ queryKey: ["transactions", token, filter],
3636
+ queryFn: function () { return getTransactions(filter, token, subdomain, kindsToShow); },
3637
+ placeholderData: reactQuery.keepPreviousData,
3638
+ }).data;
3639
+ return (jsxRuntime.jsx(TransactionsDisplay, { transactions: data, onSearchValueChanged: setSearch, search: search }));
3640
+ }
3641
+ function TransactionsDisplay(_a) {
3642
+ var transactions = _a.transactions, onSearchValueChanged = _a.onSearchValueChanged, search = _a.search, title = _a.title;
3643
+ var _b = React.useContext(TransactionsListContext), showSearchBar = _b.showSearchBar, showTitle = _b.showTitle, transactionComponent = _b.transactionComponent, useModal = _b.useModal, suppressTransactionDisplay = _b.suppressTransactionDisplay, className = _b.className, shadow = _b.shadow, searchBarClassName = _b.searchBarClassName, style = _b.style, onTransactionClick = _b.onTransactionClick;
3644
+ var columns = React.useContext(TransactionsListContext).columns;
3645
+ var darkMode = React.useContext(BunnyContext).darkMode;
3646
+ // Local state
3647
+ var _c = React.useState(null), selectedTransaction = _c[0], setSelectedTransaction = _c[1];
3648
+ var _d = React.useState(false), drawerOpen = _d[0], setDrawerOpen = _d[1];
3649
+ // Hooks
3650
+ var isMobile = common.useIsMobile();
3651
+ function handleTransactionClick(transaction) {
3652
+ if (onTransactionClick) {
3653
+ onTransactionClick(transaction);
3654
+ }
3655
+ if (!suppressTransactionDisplay) {
3656
+ setSelectedTransaction(transaction);
3657
+ setDrawerOpen(true);
3658
+ }
3659
+ }
3660
+ // Since the columns are dynamic, we need to calculate the grid template columns
3661
+ var gridTemplateColumns = function () {
3662
+ var templateColumns = [];
3663
+ if (isMobile) {
3664
+ if (columns.includes("date-and-title") ||
3665
+ columns.includes("state") ||
3666
+ columns.includes("amount")) {
3667
+ templateColumns.push("auto");
3763
3668
  }
3764
- });
3765
- });
3766
- };
3767
-
3768
- var MUTATION$3 = function () { return "\nmutation QuoteAccountSignup (\n $accountName: String!,\n $billingContact: ContactAttributes!,\n $entityId: ID!,\n $priceListCode: String!\n) {\n quoteAccountSignup(\n entityId: $entityId,\n priceListCode: $priceListCode,\n accountName: $accountName,\n billingContact: $billingContact\n ) {\n account {\n id\n }\n amount\n currencyId\n quote {\n id\n }\n tenant {\n code\n }\n errors\n }\n}"; };
3769
- var quoteAccountSignup = function (_a) {
3770
- var token = _a.token, subdomain = _a.subdomain, entityId = _a.entityId, priceListCode = _a.priceListCode, accountName = _a.accountName, billingContact = _a.billingContact;
3771
- return __awaiter(void 0, void 0, void 0, function () {
3772
- var vars, response, errors;
3773
- var _b;
3774
- return __generator(this, function (_c) {
3775
- switch (_c.label) {
3776
- case 0:
3777
- vars = {
3778
- entityId: entityId,
3779
- priceListCode: priceListCode,
3780
- accountName: accountName,
3781
- billingContact: billingContact,
3782
- };
3783
- return [4 /*yield*/, common.gqlRequest({
3784
- query: MUTATION$3(),
3785
- token: token,
3786
- vars: vars,
3787
- subdomain: subdomain,
3788
- })];
3789
- case 1:
3790
- response = _c.sent();
3791
- errors = (_b = response === null || response === void 0 ? void 0 : response.quoteAccountSignup) === null || _b === void 0 ? void 0 : _b.errors;
3792
- if (errors)
3793
- throw errors;
3794
- return [2 /*return*/, response === null || response === void 0 ? void 0 : response.quoteAccountSignup];
3669
+ if (columns.includes("download")) {
3670
+ templateColumns.push("auto");
3795
3671
  }
3796
- });
3797
- });
3798
- };
3799
-
3800
- var MUTATION$2 = function () { return "\nquery PriceList($code: String!) {\n priceList (code: $code) {\n basePrice\n code\n createdAt\n currencyId\n id\n isVisible\n name\n periodMonths\n planId\n priceDescription\n productId\n sku\n trialAllowed\n trialLengthDays\n updatedAt\n }\n}"; };
3801
- var getPriceList = function (_a) {
3802
- var token = _a.token, code = _a.code, subdomain = _a.subdomain;
3803
- return __awaiter(void 0, void 0, void 0, function () {
3804
- var response;
3805
- return __generator(this, function (_b) {
3806
- switch (_b.label) {
3807
- case 0: return [4 /*yield*/, common.gqlRequest({
3808
- query: MUTATION$2(),
3809
- token: token,
3810
- vars: { code: code },
3811
- subdomain: subdomain,
3812
- })];
3813
- case 1:
3814
- response = _b.sent();
3815
- return [2 /*return*/, response === null || response === void 0 ? void 0 : response.priceList];
3672
+ }
3673
+ else {
3674
+ if (columns.includes("date-and-title")) {
3675
+ templateColumns.push("auto 3fr");
3816
3676
  }
3817
- });
3818
- });
3819
- };
3820
-
3821
- function PaymentForms(_a) {
3822
- var quote = _a.quote, paying = _a.paying, setIsPaying = _a.setIsPaying, handlePaymentSaveSuccess = _a.handlePaymentSaveSuccess, handlePaymentFail = _a.handlePaymentFail, handleSubmit = _a.handleSubmit, proceedingToPayment = _a.proceedingToPayment, accountId = _a.accountId;
3823
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: quote ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: accountId && (jsxRuntime.jsx(PaymentContext.Provider, __assign({ value: { accountId: accountId, displayPayButtonNameAnyways: true } }, { children: jsxRuntime.jsx(PaymentForm, { isSaving: paying, setIsSaving: setIsPaying, onFail: handlePaymentFail, onPaymentSuccess: handlePaymentSaveSuccess }) }))) })) : (jsxRuntime.jsx(InitialSignupForm, { onSubmit: handleSubmit, submitting: proceedingToPayment })) }));
3824
- }
3825
- function InitialSignupForm(_a) {
3826
- var onSubmit = _a.onSubmit, submitting = _a.submitting;
3827
- var _b = React.useState({
3828
- firstName: "",
3829
- lastName: "",
3830
- email: "",
3831
- accountName: "",
3832
- }), formData = _b[0], setFormData = _b[1];
3833
- var handleInputChange = function (e) {
3834
- var _a;
3835
- var _b = e.target, name = _b.name, value = _b.value;
3836
- setFormData(__assign(__assign({}, formData), (_a = {}, _a[name] = value, _a)));
3677
+ if (columns.includes("download")) {
3678
+ templateColumns.push("auto");
3679
+ }
3680
+ if (columns.includes("state")) {
3681
+ templateColumns.push("auto");
3682
+ }
3683
+ if (columns.includes("amount")) {
3684
+ templateColumns.push("auto");
3685
+ }
3686
+ }
3687
+ return templateColumns.join(" ");
3837
3688
  };
3838
- return (jsxRuntime.jsxs(antd.Form, __assign({ className: "flex w-1/2 flex-col justify-between h-full", onFinish: function () { return onSubmit(formData); } }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex flex-col space-y-2" }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ rules: [{ required: true, message: "Please input your first name!" }], initialValue: formData.firstName }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "First name", value: formData.firstName, onChange: function (e) {
3839
- handleInputChange(e);
3840
- setFormData(__assign(__assign({}, formData), { firstName: e.target.value }));
3841
- } }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ rules: [{ required: true, message: "Please input your last name!" }], initialValue: formData.lastName }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Last name", value: formData.lastName, onChange: function (e) {
3842
- handleInputChange(e);
3843
- setFormData(__assign(__assign({}, formData), { lastName: e.target.value }));
3844
- } }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ rules: [
3845
- { required: true, message: "Please input your email!" },
3846
- { type: "email", message: "Please enter a valid email!" },
3847
- ], initialValue: formData.email }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Email", value: formData.email, onChange: function (e) {
3848
- handleInputChange(e);
3849
- setFormData(__assign(__assign({}, formData), { email: e.target.value }));
3850
- } }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ rules: [
3851
- { required: true, message: "Please input your account name!" },
3852
- ], initialValue: formData.accountName }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Account name", value: formData.accountName, onChange: function (e) {
3853
- handleInputChange(e);
3854
- setFormData(__assign(__assign({}, formData), { accountName: e.target.value }));
3855
- } }) }))] })), jsxRuntime.jsx(antd.Form.Item, { children: jsxRuntime.jsx(antd.Button, __assign({ type: "primary", htmlType: "submit", loading: submitting, className: "w-full mt-4" }, { children: "Proceed to payment" })) })] })));
3689
+ var drawerTitle = function () {
3690
+ if (!selectedTransaction)
3691
+ return "";
3692
+ var kind = selectedTransaction.kind.toLowerCase();
3693
+ return kind.charAt(0).toUpperCase() + kind.slice(1);
3694
+ };
3695
+ return (jsxRuntime.jsxs("div", __assign({ style: style }, { children: [jsxRuntime.jsx(PageHeaderWithActions, __assign({ title: title || (showTitle ? "Past transactions" : undefined) }, { children: showSearchBar && (jsxRuntime.jsx("div", { children: jsxRuntime.jsx(antd.Input, { className: searchBarClassName
3696
+ ? searchBarClassName
3697
+ : "border border-slate-200", onChange: function (e) {
3698
+ if (isNaN(Number(e.target.value))) {
3699
+ return;
3700
+ }
3701
+ onSearchValueChanged(e.target.value);
3702
+ }, prefix: jsxRuntime.jsx(SearchOutlined$1, {}), placeholder: "Search by id #", style: {
3703
+ minWidth: "300px",
3704
+ }, value: search }) })) })), jsxRuntime.jsx(PageContent, __assign({ className: "flex w-full shadow-padding-xb ".concat(isMobile ? "overflow-hidden" : "", " ").concat(className) }, { children: jsxRuntime.jsx("div", __assign({ className: "grid w-full rounded-md overflow-auto ".concat("shadow-".concat(shadow)), style: {
3705
+ gridTemplateColumns: gridTemplateColumns(),
3706
+ backgroundColor: "var(--row-background".concat(darkMode ? "-dark" : "", ")"),
3707
+ } }, { children: isMobile ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: TransactionsListMobile({
3708
+ transactions: transactions,
3709
+ onTransactionClick: handleTransactionClick,
3710
+ }) })) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: TransactionsListDesktop({
3711
+ transactions: transactions,
3712
+ onTransactionClick: handleTransactionClick,
3713
+ }) })) })) })), useModal ? (jsxRuntime.jsx(antd.Modal, __assign({ title: "Basic Modal", open: drawerOpen, onOk: function () { return setDrawerOpen(false); }, onCancel: function () { return setDrawerOpen(false); }, width: 900, footer: null }, { children: jsxRuntime.jsx(Invoice, { id: (selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.transactionableId) || "" }) }))) : (jsxRuntime.jsx(antd.Drawer, __assign({ title: drawerTitle(), onClose: function () { return setDrawerOpen(false); }, open: drawerOpen, width: 900 }, { children: transactionComponent ? (transactionComponent) : (selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.kind) === "INVOICE" ? (jsxRuntime.jsx(Invoice, { id: selectedTransaction.transactionableId })) : (jsxRuntime.jsxs(antd.Card, __assign({ className: "shadow-md" }, { children: [jsxRuntime.jsx(antd.Typography.Title, __assign({ level: 2, className: "mb-4" }, { children: "Transaction Details" })), jsxRuntime.jsxs(antd.Typography.Paragraph, { children: [jsxRuntime.jsx("strong", { children: "Amount:" }), " ", jsxRuntime.jsx(antd.Typography.Text, { children: common.Misc.formatCurrency((selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.amount) || 0, (selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.currencyId) || "USD") })] }), jsxRuntime.jsxs(antd.Typography.Paragraph, { children: [jsxRuntime.jsx("strong", { children: "Description:" }), " ", jsxRuntime.jsx(antd.Typography.Text, { children: selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.description })] }), jsxRuntime.jsxs(antd.Typography.Paragraph, { children: [jsxRuntime.jsx("strong", { children: "Kind:" }), " ", jsxRuntime.jsx(antd.Typography.Text, { children: selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.kind })] }), jsxRuntime.jsxs(antd.Typography.Paragraph, { children: [jsxRuntime.jsx("strong", { children: "State:" }), " ", jsxRuntime.jsx(antd.Typography.Text, { children: selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.state })] })] }))) })))] })));
3856
3714
  }
3857
3715
 
3858
- var Title = antd.Typography.Title, Text$a = antd.Typography.Text;
3859
- function PaymentSuccessDisplay(_a) {
3860
- var className = _a.className, amountPaid = _a.amountPaid, style = _a.style, returnUrl = _a.returnUrl;
3861
- var window = React.useContext(BunnyContext).window;
3862
- var companyName = common.useCurrentUserData().companyName;
3863
- return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col items-center justify-center h-full ".concat(className), style: style }, { children: [jsxRuntime.jsx(CheckCircleFilled$1, { style: { fontSize: "48px", color: "rgb(52 211 153)" } }), jsxRuntime.jsxs(Title, __assign({ level: 3, className: "mt-2 m-0" }, { children: ["Payment of ", common.Misc.formatCurrency(amountPaid, "USD"), " successful"] })), returnUrl && (jsxRuntime.jsxs(Text$a, __assign({ className: "text-slate-500 cursor-pointer underline", onClick: function () { return (window.location.href = returnUrl); } }, { children: ["Back to ", companyName] })))] })));
3716
+ function Quotes(_a) {
3717
+ var filter = _a.filter, quoteComponent = _a.quoteComponent, _b = _a.showSearchBar, showSearchBar = _b === void 0 ? true : _b, _c = _a.showTitle, showTitle = _c === void 0 ? true : _c, _d = _a.columns, columns = _d === void 0 ? ["date-and-title", "amount", "download"] : _d, className = _a.className, _e = _a.shadow, shadow = _e === void 0 ? "md" : _e, searchBarClassName = _a.searchBarClassName, _f = _a.useModal, useModal = _f === void 0 ? false : _f; _a.onQuoteClick; var _g = _a.suppressQuoteDisplay, suppressQuoteDisplay = _g === void 0 ? false : _g, style = _a.style, _h = _a.noQuotesMessage, noQuotesMessage = _h === void 0 ? "There are no quotes" : _h;
3718
+ var subdomain = React.useContext(BunnyContext).subdomain;
3719
+ var _j = React.useState(null), component = _j[0], setComponent = _j[1];
3720
+ var contextValues = {
3721
+ columns: columns,
3722
+ kindsToShow: [],
3723
+ onTransactionClick: handleQuoteClick,
3724
+ transactionComponent: component,
3725
+ showSearchBar: showSearchBar,
3726
+ showTitle: showTitle,
3727
+ className: className,
3728
+ shadow: shadow,
3729
+ searchBarClassName: searchBarClassName,
3730
+ useModal: useModal,
3731
+ suppressTransactionDisplay: suppressQuoteDisplay,
3732
+ style: style,
3733
+ noTransactionsMessage: noQuotesMessage,
3734
+ filter: filter,
3735
+ downloadTransactionLink: function (id) { return "".concat(subdomain, "/api/pdf/quote/").concat(id); },
3736
+ };
3737
+ function handleQuoteClick(quote) {
3738
+ if (quoteComponent) {
3739
+ setComponent(quoteComponent);
3740
+ }
3741
+ else {
3742
+ setComponent(jsxRuntime.jsx(Quote, { id: quote === null || quote === void 0 ? void 0 : quote.transactionableId }));
3743
+ }
3744
+ }
3745
+ return (jsxRuntime.jsx(TransactionsListContext.Provider, __assign({ value: contextValues }, { children: jsxRuntime.jsx(QuotesWrapper, {}) })));
3864
3746
  }
3865
-
3866
- var Text$9 = antd.Typography.Text;
3867
- function PriceListDisplay(_a) {
3868
- var priceListData = _a.priceListData, topNavImageUrl = _a.topNavImageUrl;
3869
- if (!priceListData)
3747
+ function QuotesWrapper() {
3748
+ var _a = React.useContext(BunnyContext), token = _a.token, subdomain = _a.subdomain;
3749
+ var filterFromContext = React.useContext(TransactionsListContext).filter;
3750
+ // Local state
3751
+ var _b = React.useState(""), search = _b[0], setSearch = _b[1];
3752
+ var filter = filterFromContext || (search ? "filter: \"quote.id is ".concat(search, "\"") : "");
3753
+ // Queries
3754
+ var data = reactQuery.useQuery({
3755
+ queryKey: ["quotes", token, filter],
3756
+ queryFn: function () { return getQuotes({ token: token, subdomain: subdomain, filter: filter }); },
3757
+ placeholderData: reactQuery.keepPreviousData,
3758
+ }).data;
3759
+ if (data === undefined)
3870
3760
  return null;
3871
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", __assign({ className: "flex flex-col justify-between h-full my-12" }, { children: jsxRuntime.jsxs("div", __assign({ className: "flex flex-col space-y-8" }, { children: [jsxRuntime.jsx(antd.Image, { width: 24, src: topNavImageUrl, alt: "Logo", preview: false }), jsxRuntime.jsxs("div", __assign({ className: "flex flex-col" }, { children: [jsxRuntime.jsx(Text$9, __assign({ className: "text-slate-500 font-bold text-lg" }, { children: priceListData.name })), jsxRuntime.jsxs(Text$9, __assign({ className: "font-bold text-xl" }, { children: [common.Misc.formatCurrency(priceListData.basePrice, priceListData.currencyId), " ", "/ month"] }))] })), jsxRuntime.jsxs("div", __assign({ className: "flex flex-col" }, { children: [jsxRuntime.jsxs(Text$9, __assign({ style: { fontSize: "16px" }, className: "text-slate-500" }, { children: [priceListData.trialLengthDays, " day trial"] })), jsxRuntime.jsx(Text$9, __assign({ className: "text-slate-500", style: { fontSize: "12px" } }, { children: "You will not be charged until the last day of the trial." }))] }))] })) })) }));
3761
+ var quotesAsTransactions = data.nodes.map(function (quote) { return ({
3762
+ transactionableId: quote.id,
3763
+ state: "unapplied",
3764
+ amount: quote.amount || quote.amountDue,
3765
+ kind: "QUOTE",
3766
+ currencyId: quote.currencyId,
3767
+ transactionable: {
3768
+ number: quote.number,
3769
+ },
3770
+ createdAt: quote.createdAt,
3771
+ }); });
3772
+ return (jsxRuntime.jsx(TransactionsDisplay, { transactions: quotesAsTransactions, onSearchValueChanged: setSearch, search: search, title: "Past quotes" }));
3872
3773
  }
3873
3774
 
3874
- var BunnyFooterIcon = function (_a) {
3775
+ var DrawerHeader = function (_a) {
3776
+ var description = _a.description, onClose = _a.onClose, title = _a.title;
3777
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center justify-between gap-2" }, { children: [jsxRuntime.jsx("div", __assign({ className: "text-xl" }, { children: title })), jsxRuntime.jsx("button", __assign({ onClick: onClose, className: "ant-drawer-close" }, { children: jsxRuntime.jsx(CloseOutlined$1, {}) }))] })), description && jsxRuntime.jsx("div", __assign({ className: "text-xs" }, { children: description }))] })));
3778
+ };
3779
+
3780
+ var LargeCardIcon = function () {
3781
+ return (jsxRuntime.jsx("svg", __assign({ width: "72", height: "56", viewBox: "0 0 72 56", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: jsxRuntime.jsx("path", { d: "M8 0H64C68.375 0 72 3.625 72 8V12H0V8C0 3.625 3.5 0 8 0ZM72 24V48C72 52.5 68.375 56 64 56H8C3.5 56 0 52.5 0 48V24H72ZM14 40C12.875 40 12 41 12 42C12 43.125 12.875 44 14 44H22C23 44 24 43.125 24 42C24 41 23 40 22 40H14ZM28 42C28 43.125 28.875 44 30 44H46C47 44 48 43.125 48 42C48 41 47 40 46 40H30C28.875 40 28 41 28 42Z", fill: "#E2E8F0" }) })));
3782
+ };
3783
+
3784
+ var PlusIcon = function (_a) {
3875
3785
  var color = _a.color;
3876
- return (jsxRuntime.jsxs("svg", __assign({ width: "45", height: "15", viewBox: "0 0 39 13", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: [jsxRuntime.jsxs("g", __assign({ clipPath: "url(#clip0_6_851)" }, { children: [jsxRuntime.jsx("path", { className: "icon-path", d: "M14.5898 7.19708C14.5898 9.35053 13.0926 10.325 11.2495 10.325C9.39955 10.325 7.90234 9.35001 7.90234 7.18967V3.26221H10.1125V7.00052C10.1125 7.87719 10.5855 8.27725 11.2495 8.27725C11.9061 8.27725 12.3865 7.87719 12.3865 7.00052V3.26221H14.5898V7.19708Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M31.8943 12.9625H29.4793L31.8523 8.62816L28.9355 3.26221H31.4708L33.0457 6.35524L34.5924 3.26221H37.0075L31.8943 12.9625Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M15.1602 5.96827C15.1602 3.8148 16.6574 2.84033 18.5005 2.84033C20.3504 2.84033 21.8476 3.81533 21.8476 5.97568V10.1473H19.6374V6.16483C19.6374 5.28815 19.1645 4.8881 18.5005 4.8881C17.8439 4.8881 17.3634 5.28815 17.3634 6.16483V10.1473H15.1602V5.96827Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M22.4316 5.96827C22.4316 3.8148 23.9289 2.84033 25.7719 2.84033C27.6219 2.84033 29.1191 3.81533 29.1191 5.97568V10.1473H26.9089V6.16483C26.9089 5.28815 26.4359 4.8881 25.7719 4.8881C25.1154 4.8881 24.6349 5.28815 24.6349 6.16483V10.1473H22.4316V5.96827Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M7.40511 6.68957C7.40511 8.7236 6.02815 10.3227 4.17816 10.3227C3.23907 10.3227 2.61071 9.94378 2.19358 9.40371V10.1404H0.0605469V0.0405273H2.26381V3.91939C2.68041 3.42158 3.28802 3.07069 4.17763 3.07069C6.02759 3.07069 7.40511 4.66981 7.40511 6.68957ZM2.17229 6.69642C2.17229 7.60802 2.77937 8.2744 3.64823 8.2744C4.53783 8.2744 5.13107 7.59372 5.13107 6.69642C5.13107 5.79912 4.53783 5.11844 3.64823 5.11844C2.77937 5.11844 2.17229 5.78482 2.17229 6.69642Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M38.966 8.94801C38.966 9.76181 38.2668 10.4631 37.4618 10.4631C36.6499 10.4631 35.9434 9.76181 35.9434 8.94801C35.9434 8.14846 36.6494 7.46094 37.4618 7.46094C38.2668 7.46094 38.966 8.14846 38.966 8.94801Z", fill: color })] })), jsxRuntime.jsx("defs", { children: jsxRuntime.jsx("clipPath", __assign({ id: "clip0_6_851" }, { children: jsxRuntime.jsx("rect", { width: "39", height: "13", fill: "white" }) })) })] })));
3786
+ return (jsxRuntime.jsxs("svg", __assign({ width: "14", height: "15", viewBox: "0 0 14 15", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: [jsxRuntime.jsx("path", { d: "M2.9165 7.5H11.0832", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }), jsxRuntime.jsx("path", { d: "M7 3.41663V11.5833", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })] })));
3877
3787
  };
3878
3788
 
3879
- var Footer = function (_a) {
3880
- var className = _a.className;
3881
- var _b = common.useCurrentUserData(), privacyUrl = _b.privacyUrl, termsUrl = _b.termsUrl;
3882
- var window = React.useContext(BunnyContext).window;
3883
- var isMobile = useIsMobile(window);
3884
- var quotePreviewData = recoil.useRecoilValue(planPickerQuoteDataState);
3885
- var selectedPriceList = quotePreviewData === null || quotePreviewData === void 0 ? void 0 : quotePreviewData.priceList;
3886
- if (selectedPriceList && isMobile)
3887
- return null;
3888
- return (jsxRuntime.jsxs("div", __assign({ className: "flex items-center justify-between shrink-0 ".concat(className, " ").concat(isMobile ? "flex-col gap-2 grow" : "") }, { children: [(termsUrl || privacyUrl) && (jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-3" }, { children: [termsUrl && (jsxRuntime.jsx(StyedLink, __assign({ className: "text-xs text-slate-400", href: termsUrl, rel: "noopener noreferrer", target: "_blank", type: "text" }, { children: "Terms" }))), privacyUrl && (jsxRuntime.jsx(StyedLink, __assign({ className: "text-xs text-slate-400", href: privacyUrl, rel: "noopener noreferrer", target: "_blank", type: "text" }, { children: "Privacy" })))] }))), jsxRuntime.jsx(BunnyMarketingLink, {})] })));
3789
+ var PaymentMethodContext = React.createContext({});
3790
+
3791
+ var Card = function (_a) {
3792
+ var children = _a.children, className = _a.className, style = _a.style;
3793
+ var darkMode = React.useContext(BunnyContext).darkMode;
3794
+ return (jsxRuntime.jsx("div", __assign({ className: "flex flex-col rounded-md shadow-md ".concat(className), style: __assign(__assign({}, style), { backgroundColor: darkMode
3795
+ ? "var(--row-background-dark)"
3796
+ : "var(--row-background)" }) }, { children: children })));
3889
3797
  };
3890
- var BunnyMarketingLink = function () {
3891
- var _a = React.useState(false), isHovered = _a[0], setIsHovered = _a[1];
3892
- var window = React.useContext(BunnyContext).window;
3893
- var isMobile = useIsMobile(window);
3894
- return (jsxRuntime.jsx("div", __assign({ className: "flex items-end justify-end ".concat(isMobile ? "" : "grow") }, { children: jsxRuntime.jsx(StyledBunnyLink, __assign({ className: "flex items-end justify-end text-slate-400", href: "https://bunny.com/", rel: "noopener noreferrer", target: "_blank", type: "text" }, { children: jsxRuntime.jsxs("div", __assign({ className: "flex items-center", onMouseEnter: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); } }, { children: ["Powered by\u00A0", jsxRuntime.jsx("div", __assign({ style: { paddingTop: "5px" } }, { children: jsxRuntime.jsx(BunnyFooterIcon, { color: isHovered ? common.PRIMARY_COLOR : common.SLATE_400 }) }))] })) })) })));
3798
+
3799
+ var Text$6 = antd.Typography.Text;
3800
+ var CreditCard = function (_a) {
3801
+ var _b, _c, _d;
3802
+ var onClickRemove = _a.onClickRemove, onClickUpdate = _a.onClickUpdate, paymentMethodData = _a.paymentMethodData;
3803
+ var isExpired = function (paymentMethodData) {
3804
+ // paymentMethodData.expirationDate
3805
+ var expDate = dayjs(paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.expirationDate);
3806
+ return expDate.isBefore(dayjs());
3807
+ };
3808
+ var isMobile = common.useIsMobile();
3809
+ var processPublicUrl = React.useContext(PaymentMethodContext).processPublicUrl;
3810
+ return (jsxRuntime.jsxs(Card, __assign({ className: "shadow-md m-0" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center justify-between gap-4 p-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-2" }, { children: [getCardImage((_b = paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.metadata) === null || _b === void 0 ? void 0 : _b.issuer) && (jsxRuntime.jsx("img", { alt: "Card", width: "24px", src: "".concat(processPublicUrl, "/").concat(getCardImage((_c = paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.metadata) === null || _c === void 0 ? void 0 : _c.issuer)) })), jsxRuntime.jsx(Text$6, { children: (_d = paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.metadata) === null || _d === void 0 ? void 0 : _d.description })] })), jsxRuntime.jsx(antd.Tag, __assign({ color: isExpired(paymentMethodData) ? "red" : "green" }, { children: isExpired(paymentMethodData) ? "Expired" : "Valid" }))] })), !isMobile && (jsxRuntime.jsx(CardActions, { onClickRemove: onClickRemove, onClickUpdate: onClickUpdate }))] })), dayjs(paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.expirationDate).isValid() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(antd.Divider, {}), jsxRuntime.jsxs("div", __assign({ className: "flex flex-col p-4" }, { children: [jsxRuntime.jsx(CardAttribute, { title: "EXPIRATION", value: dayjs(paymentMethodData === null || paymentMethodData === void 0 ? void 0 : paymentMethodData.expirationDate).format("MM/YY") }), isMobile && (jsxRuntime.jsx(CardActions, { onClickRemove: onClickRemove, onClickUpdate: onClickUpdate }))] }))] }))] })));
3811
+ };
3812
+ var CardAttribute = function (_a) {
3813
+ var title = _a.title, value = _a.value;
3814
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-2" }, { children: [jsxRuntime.jsx("div", __assign({ className: "text-slate-400", style: { fontSize: "11px" } }, { children: title })), jsxRuntime.jsx(Text$6, { children: value })] })));
3815
+ };
3816
+ var CardActions = function (_a) {
3817
+ var onClickRemove = _a.onClickRemove, onClickUpdate = _a.onClickUpdate;
3818
+ var isMobile = common.useIsMobile();
3819
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-6 ".concat(isMobile ? "justify-center mt-4" : "") }, { children: [jsxRuntime.jsx(antd.Popconfirm, __assign({ title: "Remove card?", onConfirm: onClickRemove }, { children: jsxRuntime.jsx(antd.Button, __assign({ className: "font-normal p-0", type: "link" }, { children: "Remove payment method" })) })), jsxRuntime.jsx(antd.Divider, { style: { height: "24px" }, type: "vertical" }), jsxRuntime.jsx(antd.Button, __assign({ onClick: onClickUpdate, type: "primary" }, { children: "Update" }))] })));
3820
+ };
3821
+ var EmptyCard = function (_a) {
3822
+ var onClick = _a.onClick;
3823
+ var brandColor = React.useContext(BrandContext).brandColor;
3824
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col items-center justify-center w-full pt-8 px-4 pb-6 cursor-pointer bg-white shadow-md rounded-md", onClick: onClick }, { children: [jsxRuntime.jsx(LargeCardIcon, {}), jsxRuntime.jsx("div", __assign({ className: "text-slate-400 pt-4 pb-8" }, { children: "No payment methods" })), jsxRuntime.jsx(antd.Button, __assign({ type: "link" }, { children: jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-1" }, { children: [jsxRuntime.jsx(PlusIcon, { color: brandColor }), "Add payment method"] })) }))] })));
3825
+ };
3826
+ var getCardImage = function (issuer) {
3827
+ if (issuer === "visa")
3828
+ return "Visa_Brandmark_Blue_RGB_2021.png";
3829
+ else if (issuer === "mastercard")
3830
+ return "mc_symbol_opt_73_3x.png";
3831
+ };
3832
+
3833
+ var ActualPaymentMethod = function () {
3834
+ var _a = React.useContext(BunnyContext), token = _a.token, subdomain = _a.subdomain, graphQLClient = _a.graphQLClient;
3835
+ var accountId = React.useContext(PaymentContext).accountId;
3836
+ // Hooks
3837
+ var queryClient = reactQuery.useQueryClient();
3838
+ var paymentPlugins = common.usePaymentPlugins({ subdomain: subdomain, token: token }).paymentPlugins;
3839
+ var showErrorNotification = common.NotificationUtils.useErrorNotification();
3840
+ var showSuccessNotification = common.NotificationUtils.useSuccessNotification();
3841
+ var handleAllErrorFormats = common.NotificationUtils.useAllErrorFormats(function () {
3842
+ console.log("Navigation in PaymentMethod.tsx useAllErrorFormats not implemented");
3843
+ });
3844
+ var isMobile = common.useIsMobile();
3845
+ var data = usePaymentMethod(graphQLClient).data;
3846
+ // Local state
3847
+ var _b = React.useState(false), showModal = _b[0], setShowModal = _b[1];
3848
+ var _c = React.useState(false), isSaving = _c[0], setIsSaving = _c[1];
3849
+ // Queries
3850
+ reactQuery.useQuery({
3851
+ queryKey: common.QueryKeyFactory.default.currentUserKey,
3852
+ queryFn: function () { return getCurrentUserData({ token: token, subdomain: subdomain }); },
3853
+ });
3854
+ var plugin = paymentPlugins === null || paymentPlugins === void 0 ? void 0 : paymentPlugins.find(function (paymentPlugin) { var _a; return String(paymentPlugin.id) === ((_a = data === null || data === void 0 ? void 0 : data.plugin) === null || _a === void 0 ? void 0 : _a.id); });
3855
+ var onClickRemove = function () {
3856
+ if (data && plugin) {
3857
+ common.invokePlugin({
3858
+ plugin: plugin,
3859
+ method: "remove_payment_method",
3860
+ payload: {
3861
+ payment_method_id: data.id,
3862
+ account_id: accountId,
3863
+ },
3864
+ token: token,
3865
+ subdomain: subdomain,
3866
+ })
3867
+ .then(function () {
3868
+ showSuccessNotification("Payment method was removed", "Success");
3869
+ queryClient.setQueryData(common.QueryKeyFactory.default.accountPaymentMethodKey, null);
3870
+ })
3871
+ .catch(function (error) {
3872
+ showErrorNotification(error.message, "Error removing Payment Method");
3873
+ });
3874
+ }
3875
+ };
3876
+ var onSuccess = function () {
3877
+ queryClient.invalidateQueries({
3878
+ queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey,
3879
+ });
3880
+ setShowModal(false);
3881
+ showSuccessNotification("Your payment method has been saved");
3882
+ };
3883
+ if (data === undefined)
3884
+ return jsxRuntime.jsx(jsxRuntime.Fragment, {});
3885
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [data ? (jsxRuntime.jsx(CreditCard, { onClickRemove: onClickRemove, onClickUpdate: function () { return setShowModal(true); }, paymentMethodData: data })) : (jsxRuntime.jsx(EmptyCard, { onClick: function () { return setShowModal(true); } })), jsxRuntime.jsx(antd.Drawer, __assign({ closeIcon: null, onClose: function () { return setShowModal(false); }, open: showModal, styles: {
3886
+ body: isMobile
3887
+ ? {
3888
+ padding: "1rem 0 0",
3889
+ }
3890
+ : {},
3891
+ wrapper: isMobile ? { width: "100vw" } : { width: "min-content" },
3892
+ }, title: jsxRuntime.jsx(DrawerHeader, { onClose: function () { return setShowModal(false); }, title: "New payment method" }) }, { children: jsxRuntime.jsx(PaymentForm, { isSaving: isSaving, onFail: function (error) {
3893
+ handleAllErrorFormats(error);
3894
+ setIsSaving(false);
3895
+ }, onPaymentSuccess: function () {
3896
+ onSuccess();
3897
+ setIsSaving(false);
3898
+ }, setIsSaving: setIsSaving }) }))] }));
3895
3899
  };
3896
- var StyedLink = styled__default["default"].a(templateObject_1$4 || (templateObject_1$4 = __makeTemplateObject(["\n color: ", ";\n transition: color 0.3s;\n &:hover {\n color: ", ";\n }\n"], ["\n color: ", ";\n transition: color 0.3s;\n &:hover {\n color: ", ";\n }\n"])), common.SLATE_400, common.SLATE_500);
3897
- var StyledBunnyLink = styled__default["default"](StyedLink)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n &:hover {\n color: ", " !important;\n }\n"], ["\n &:hover {\n color: ", " !important;\n }\n"])), common.PRIMARY_COLOR);
3898
- var templateObject_1$4, templateObject_2;
3900
+ function PaymentMethod(_a) {
3901
+ var footer = _a.footer, processPublicUrl = _a.processPublicUrl;
3902
+ return (jsxRuntime.jsx(PaymentMethodContext.Provider, __assign({ value: { footer: footer, processPublicUrl: processPublicUrl } }, { children: jsxRuntime.jsx(ActualPaymentMethod, {}) })));
3903
+ }
3899
3904
 
3900
- var MUTATION$1 = "\n mutation portalSessionCreate ($tenantCode: String!, $expiry: Int!, $returnUrl: String!) {\n portalSessionCreate (tenantCode: $tenantCode, expiry: $expiry, returnUrl: $returnUrl) {\n errors\n token\n }\n }\n";
3901
- var portalSessionCreate = function (_a) {
3902
- var tenantCode = _a.tenantCode, expiry = _a.expiry, returnUrl = _a.returnUrl, token = _a.token, subdomain = _a.subdomain;
3905
+ var MUTATION$5 = "\nmutation accountUpdate(\n $id: ID!,\n $attributes: AccountAttributes!) {\n accountUpdate(\n id: $id,\n attributes: $attributes\n ) {\n account { id }\n errors\n }\n }\n";
3906
+ var accountUpdate = function (_a) {
3907
+ var accountId = _a.accountId, attributes = _a.attributes, token = _a.token;
3903
3908
  return __awaiter(void 0, void 0, void 0, function () {
3904
- var response, errors;
3909
+ var vars, response, errors;
3905
3910
  var _b;
3906
3911
  return __generator(this, function (_c) {
3907
3912
  switch (_c.label) {
3908
- case 0: return [4 /*yield*/, common.gqlRequest({
3909
- query: MUTATION$1,
3910
- token: token,
3911
- vars: { tenantCode: tenantCode, expiry: expiry, returnUrl: returnUrl },
3912
- subdomain: subdomain,
3913
- })];
3913
+ case 0:
3914
+ vars = { id: accountId, attributes: attributes };
3915
+ return [4 /*yield*/, common.gqlRequest({ query: MUTATION$5, token: token, vars: vars })];
3914
3916
  case 1:
3915
3917
  response = _c.sent();
3916
- errors = (response === null || response === void 0 ? void 0 : response.portalSessionCreate).errors;
3918
+ errors = (_b = response === null || response === void 0 ? void 0 : response.accountUpdate) === null || _b === void 0 ? void 0 : _b.errors;
3917
3919
  if (errors)
3918
3920
  throw errors;
3919
- return [2 /*return*/, (_b = response === null || response === void 0 ? void 0 : response.portalSessionCreate) === null || _b === void 0 ? void 0 : _b.token];
3921
+ return [2 /*return*/, response.accountUpdate];
3920
3922
  }
3921
3923
  });
3922
3924
  });
3923
3925
  };
3924
3926
 
3925
- var showErrorNotification = common.NotificationUtils.useErrorNotification();
3926
- function Signup(_a) {
3927
- var priceListCode = _a.priceListCode, returnUrl = _a.returnUrl;
3927
+ var COUNTRIES_REQUIRING_STATE = ["US", "CA"];
3928
+ var TaxationForm = function (_a) {
3929
+ var account = _a.account, quote = _a.quote;
3928
3930
  // Hooks
3929
- var _b = React.useContext(BunnyContext), subdomain = _b.subdomain, token = _b.token, window = _b.window;
3930
- reactQuery.useQuery({
3931
- queryKey: common.QueryKeyFactory.default.currentUserKey,
3932
- queryFn: function () { return getCurrentUserData({ token: token, subdomain: subdomain }); },
3933
- });
3934
- var isMobile = useIsMobile(window);
3935
- var topNavImageUrl = React.useContext(BrandContext).topNavImageUrl;
3936
- var entityId = common.useCurrentUserData().entityId;
3937
- var _c = React.useState(undefined), quote = _c[0], setQuote = _c[1];
3938
- var _d = React.useState(undefined), accountId = _d[0], setAccountId = _d[1];
3939
- var _e = React.useState(undefined), quoteId = _e[0], setQuoteId = _e[1];
3940
- var _f = React.useState(undefined), portalSessionToken = _f[0], setPortalSessionToken = _f[1];
3941
- var _g = React.useState(undefined), formData = _g[0], setFormData = _g[1];
3942
- var _h = React.useState(false), proceedingToPayment = _h[0], setProceedingToPayment = _h[1];
3943
- var _j = React.useState(false), paying = _j[0], setIsPaying = _j[1];
3944
- var _k = React.useState(false), purchaseSucceeded = _k[0], setPurchaseSucceeded = _k[1];
3945
- // Queries
3946
- var priceListData = reactQuery.useQuery({
3947
- queryKey: ["priceList", priceListCode],
3948
- queryFn: function () { return getPriceList({ token: token, subdomain: subdomain, code: priceListCode }); },
3949
- }).data;
3950
- function handleSubmit(formData) {
3951
- return __awaiter(this, void 0, void 0, function () {
3952
- var data, portalSessionToken;
3931
+ var queryClient = reactQuery.useQueryClient();
3932
+ var token = React.useContext(BunnyContext).token;
3933
+ var form = antd.Form.useForm()[0];
3934
+ // Mutations
3935
+ var _b = reactQuery.useMutation({
3936
+ mutationFn: function (changedFormData) { return __awaiter(void 0, void 0, void 0, function () {
3937
+ var account;
3953
3938
  return __generator(this, function (_a) {
3954
3939
  switch (_a.label) {
3955
- case 0:
3956
- setProceedingToPayment(true);
3957
- setFormData(formData);
3958
- return [4 /*yield*/, quoteAccountSignup({
3959
- token: token,
3960
- subdomain: subdomain,
3961
- entityId: entityId,
3962
- priceListCode: priceListCode,
3963
- accountName: formData.accountName,
3964
- billingContact: {
3965
- firstName: formData.firstName,
3966
- lastName: formData.lastName,
3967
- email: formData.email,
3968
- },
3969
- })];
3940
+ case 0: return [4 /*yield*/, accountUpdate({
3941
+ accountId: quote.accountId,
3942
+ attributes: changedFormData,
3943
+ token: token,
3944
+ })];
3970
3945
  case 1:
3971
- data = _a.sent();
3972
- setAccountId(data.account.id);
3973
- return [4 /*yield*/, portalSessionCreate({
3974
- token: token,
3975
- subdomain: subdomain,
3976
- tenantCode: data.tenant.code,
3977
- expiry: 24,
3978
- returnUrl: returnUrl || "",
3979
- })];
3980
- case 2:
3981
- portalSessionToken = _a.sent();
3982
- setPortalSessionToken(portalSessionToken);
3983
- setQuoteId(data.quote.id);
3984
- setProceedingToPayment(false);
3985
- setQuote({
3986
- amountDue: data.quote.amountDue,
3987
- currencyId: data.quote.currencyId,
3988
- });
3989
- return [2 /*return*/];
3946
+ account = _a.sent();
3947
+ return [2 /*return*/, account];
3990
3948
  }
3991
3949
  });
3992
- });
3993
- }
3994
- function handlePaymentSaveSuccess(paymentSuccess) {
3995
- var _a;
3996
- return __awaiter(this, void 0, void 0, function () {
3997
- var response, plugin;
3950
+ }); },
3951
+ onSuccess: function () {
3952
+ queryClient.invalidateQueries({
3953
+ queryKey: ["getTaxationRequiredAccountFields", token],
3954
+ });
3955
+ },
3956
+ }), updateAccount = _b.mutate, isUpdatingAccount = _b.isPending;
3957
+ return (jsxRuntime.jsxs(antd.Form, __assign({ className: "flex flex-col gap-4", form: form, initialValues: account, layout: "vertical", onFinish: updateAccount }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing street", name: "billingStreet" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Street" }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing city", name: "billingCity" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "City" }) })), jsxRuntime.jsx(FormBillingState, { form: form }), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing country", name: "billingCountry", rules: [{ required: true }] }, { children: jsxRuntime.jsx(antd.Select, { options: common.Lists.COUNTRY_LIST, placeholder: "Select a country", showSearch: true, filterOption: function (input, option) {
3958
+ var _a, _b;
3959
+ return ((_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : "").toLowerCase().includes(input.toLowerCase()) ||
3960
+ ((_b = option === null || option === void 0 ? void 0 : option.value) !== null && _b !== void 0 ? _b : "").toLowerCase().includes(input.toLowerCase());
3961
+ } }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing zip", name: "billingZip" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Zip" }) })), jsxRuntime.jsx(antd.Form.Item, { children: jsxRuntime.jsx(antd.Button, __assign({ className: "w-full", disabled: isUpdatingAccount, htmlType: "submit", type: "primary" }, { children: "Submit" })) })] })));
3962
+ };
3963
+ var FormBillingState = function (_a) {
3964
+ _a.form;
3965
+ var billingCountry = antd.Form.useWatch("billingCountry");
3966
+ var billingStateRequired = COUNTRIES_REQUIRING_STATE.includes(billingCountry);
3967
+ return (jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing state", name: "billingState", rules: [{ required: billingStateRequired }] }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "State" }) })));
3968
+ };
3969
+
3970
+ var QuoteCheckout = function (_a) {
3971
+ var account = _a.account, isSaving = _a.isSaving, onSuccess = _a.onSuccess, onFail = _a.onFail, quote = _a.quote, setIsSaving = _a.setIsSaving, taxationRequiredAccountFields = _a.taxationRequiredAccountFields; _a.storedPaymentMethod;
3972
+ // Context
3973
+ var isMobile = common.useIsMobile();
3974
+ var _b = React.useContext(BunnyContext), subdomain = _b.subdomain, token = _b.token;
3975
+ var paymentRequired = getQuoteAmountDue(quote) > 0;
3976
+ var checkoutMutation = reactQuery.useMutation({
3977
+ mutationFn: function (_a) {
3978
+ var pluginPaymentMethod = _a.pluginPaymentMethod, savedPaymentMethod = _a.storedPaymentMethod;
3979
+ if (!quote)
3980
+ throw new Error("Quote is required");
3981
+ if (!paymentRequired)
3982
+ return checkout({ quoteId: quote.id, token: token, subdomain: subdomain });
3983
+ if (savedPaymentMethod) {
3984
+ var paymentMethodId = savedPaymentMethod.paymentMethodId;
3985
+ return checkout({
3986
+ quoteId: quote.id,
3987
+ paymentMethodId: paymentMethodId,
3988
+ token: token,
3989
+ subdomain: subdomain,
3990
+ });
3991
+ }
3992
+ if (pluginPaymentMethod) {
3993
+ var plugin = pluginPaymentMethod.plugin, savePaymentMethod = pluginPaymentMethod.savePaymentMethod, metadata = pluginPaymentMethod.metadata;
3994
+ var paymentToken = pluginPaymentMethod.token;
3995
+ return checkout({
3996
+ quoteId: quote.id,
3997
+ paymentMethodData: {
3998
+ metadata: metadata,
3999
+ pluginGuid: plugin.guid,
4000
+ savePaymentMethod: savePaymentMethod,
4001
+ token: paymentToken,
4002
+ },
4003
+ token: token,
4004
+ subdomain: subdomain,
4005
+ });
4006
+ }
4007
+ throw new Error("Pay payment method provided");
4008
+ },
4009
+ onSuccess: onSuccess,
4010
+ onError: onFail,
4011
+ });
4012
+ // Handlers
4013
+ var handleCheckout = function (_a) {
4014
+ var pluginPaymentResponse = _a.pluginPaymentResponse, savedPaymentMethodResponse = _a.savedPaymentMethodResponse;
4015
+ return __awaiter(void 0, void 0, void 0, function () {
4016
+ var token_1, plugin, savePaymentMethod, metadata, paymentMethodId;
3998
4017
  return __generator(this, function (_b) {
3999
- switch (_b.label) {
4000
- case 0:
4001
- if (!formData) {
4002
- throw new Error("Form data is required");
4003
- }
4004
- response = paymentSuccess.pluginPaymentResponse;
4005
- plugin = response === null || response === void 0 ? void 0 : response.plugin;
4006
- if (!(plugin === null || plugin === void 0 ? void 0 : plugin.id)) {
4007
- throw new Error("Plugin ID is required");
4008
- }
4009
- if (!accountId) {
4010
- throw new Error("Account ID is required");
4011
- }
4012
- if (!portalSessionToken) {
4013
- throw new Error("Portal session token is required");
4014
- }
4015
- return [4 /*yield*/, accountSignup({
4016
- token: portalSessionToken,
4017
- subdomain: subdomain,
4018
- entityId: entityId,
4019
- quoteId: quoteId,
4020
- paymentMethodId: (_a = paymentSuccess.savedPaymentMethodResponse) === null || _a === void 0 ? void 0 : _a.paymentMethodId.toString(),
4021
- pluginId: plugin.id.toString(),
4022
- priceListCode: priceListCode,
4023
- accountId: accountId,
4024
- })];
4025
- case 1:
4026
- _b.sent();
4027
- setIsPaying(false);
4028
- setPurchaseSucceeded(true);
4029
- return [2 /*return*/];
4018
+ if (pluginPaymentResponse) {
4019
+ token_1 = pluginPaymentResponse.token, plugin = pluginPaymentResponse.plugin, savePaymentMethod = pluginPaymentResponse.savePaymentMethod, metadata = pluginPaymentResponse.metadata;
4020
+ checkoutMutation.mutate({
4021
+ pluginPaymentMethod: {
4022
+ savePaymentMethod: savePaymentMethod,
4023
+ plugin: plugin,
4024
+ metadata: metadata,
4025
+ token: token_1,
4026
+ },
4027
+ });
4028
+ }
4029
+ else if (savedPaymentMethodResponse) {
4030
+ paymentMethodId = savedPaymentMethodResponse.paymentMethodId;
4031
+ checkoutMutation.mutate({
4032
+ storedPaymentMethod: {
4033
+ paymentMethodId: paymentMethodId,
4034
+ },
4035
+ });
4036
+ }
4037
+ else {
4038
+ checkoutMutation.mutate({});
4030
4039
  }
4040
+ return [2 /*return*/];
4031
4041
  });
4032
4042
  });
4033
- }
4034
- function handlePaymentFail(error) {
4035
- showErrorNotification(error.message);
4036
- setIsPaying(false);
4037
- }
4038
- if (isMobile) {
4039
- return (jsxRuntime.jsx(Card, __assign({ className: "p-4 flex flex-col" }, { children: purchaseSucceeded ? (jsxRuntime.jsx(PaymentSuccessDisplay, { className: "w-full", amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, returnUrl: returnUrl })) : (jsxRuntime.jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex flex-col items-center" }, { children: jsxRuntime.jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsxRuntime.jsx("div", __assign({ className: "mx-8" }, { children: jsxRuntime.jsx(antd.Divider, { className: "h-full" }) })), jsxRuntime.jsx("div", __assign({ className: "flex items-center justify-center my-12" }, { children: jsxRuntime.jsx(PaymentForms, { quote: quote, paying: paying, setIsPaying: setIsPaying, handlePaymentSaveSuccess: handlePaymentSaveSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId || "" }) }))] }))) })));
4040
- }
4041
- else {
4042
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Card, __assign({ className: "p-4 flex flex-col w-screen h-screen" }, { children: purchaseSucceeded ? (jsxRuntime.jsx(PaymentSuccessDisplay, { className: "w-full", amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, returnUrl: returnUrl })) : (jsxRuntime.jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex flex-col w-1/2 items-center" }, { children: jsxRuntime.jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsxRuntime.jsx("div", __assign({ className: "my-4" }, { children: jsxRuntime.jsx(antd.Divider, { className: "h-full", type: "vertical" }) })), jsxRuntime.jsx("div", __assign({ className: "flex w-1/2 items-center justify-center my-12" }, { children: jsxRuntime.jsx(PaymentForms, { quote: quote, paying: paying, setIsPaying: setIsPaying, handlePaymentSaveSuccess: handlePaymentSaveSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId || "" }) }))] }))) })), jsxRuntime.jsx(Footer, {})] }));
4043
- }
4044
- }
4043
+ };
4044
+ if (taxationRequiredAccountFields)
4045
+ return (jsxRuntime.jsx(PaymentFormWrapper, __assign({ setMaxHeight: false }, { children: jsxRuntime.jsx(TaxationForm, { account: account, quote: quote }) })));
4046
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: paymentRequired ? (jsxRuntime.jsx(PaymentForm, { isSaving: isSaving, onFail: onFail, onPaymentSuccess: handleCheckout, quote: quote, setIsSaving: setIsSaving })) : (jsxRuntime.jsx(PaymentFormWrapper, __assign({ setMaxHeight: false }, { children: jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-2 ".concat(isMobile ? "shadow-padding-x" : "") }, { children: [jsxRuntime.jsx(antd.Button, __assign({ disabled: isSaving, onClick: function () {
4047
+ setIsSaving(true);
4048
+ handleCheckout({});
4049
+ }, type: "primary" }, { children: isSaving ? "Processing..." : "Complete order" })), jsxRuntime.jsx("div", __assign({ className: "text-xs text-slate-500" }, { children: "No payment is required" }))] })) }))) }));
4050
+ };
4045
4051
 
4046
- var transactionMutation = function (filter) { return "\nquery transactions {\n transactions ".concat(filter ? "(".concat(filter, ")") : "", " {\n nodes {\n amount\n createdAt\n currencyId\n description\n id\n kind\n state\n transactionableId\n transactionable {\n ...on Payment { amount }\n ...on Invoice { amount number }\n }\n }\n }\n}"); };
4047
- var getTransactions = function (filter, token, subdomain, kindsToShow) { return __awaiter(void 0, void 0, void 0, function () {
4048
- var response, _a, data, errors, transactions;
4049
- var _b, _c;
4050
- return __generator(this, function (_d) {
4051
- switch (_d.label) {
4052
- case 0: return [4 /*yield*/, fetch(subdomain + "/graphql", {
4053
- method: "POST",
4054
- headers: {
4055
- "Content-type": "application/json; charset=utf-8",
4056
- Authorization: "Bearer ".concat(token),
4057
- },
4058
- body: JSON.stringify({
4059
- query: transactionMutation(filter),
4060
- }),
4061
- })];
4062
- case 1:
4063
- response = _d.sent();
4064
- return [4 /*yield*/, response.json()];
4065
- case 2:
4066
- _a = _d.sent(), data = _a.data, errors = _a.errors;
4067
- if (errors) {
4068
- throw new Error(errors[0].message);
4069
- }
4070
- transactions = (_c = (_b = data === null || data === void 0 ? void 0 : data.transactions) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.filter(function (transaction) { return kindsToShow.includes(transaction.kind); });
4071
- return [2 /*return*/, transactions === null || transactions === void 0 ? void 0 : transactions.reverse()];
4072
- }
4052
+ var useHasTaxPlugin = function (_a) {
4053
+ var subdomain = _a.subdomain, token = _a.token;
4054
+ var plugins = common.usePlugins({
4055
+ subdomain: subdomain,
4056
+ token: token,
4057
+ }).data;
4058
+ return Boolean(plugins === null || plugins === void 0 ? void 0 : plugins.some(function (plugin) { return plugin.type === "taxation"; }));
4059
+ };
4060
+
4061
+ var QUOTE_FIELDS = "quote {\n formattedQuote {\n html\n }\n acceptedByName\n acceptedByTitle\n accountId\n amount\n amountDue\n applicationDate\n applied\n billingDay\n contactId\n createdAt\n credits\n currencyId\n dealId\n discount\n discountValue\n endDate\n evergreen\n expiresAt\n id\n invoiceUntil\n isPendingApprovalRequest\n kind\n message\n name\n netPaymentDays\n notes\n ownerId\n periodAmount\n poNumber\n requiresApproval\n startDate\n state\n subtotal\n taxAmount\n updatedAt\n uuid\n amountsByPeriod {\n amount\n id\n name\n }\n endDateOptions {\n endDate\n label\n }\n invoiceUntilOptions {\n endDate\n label\n }\n quoteChanges {\n id\n priceListId\n charges {\n amount\n amountsByPeriod { amount startDate }\n billingPeriod\n billingPeriodAmounts { id amount prorationRate }\n chargeType\n couponId\n createdAt\n currencyId\n discount\n endDate\n feature { id name code isUnit unitName }\n id\n invoiceLineText\n name\n price\n priceDecimals\n priceTiers { starts price }\n pricingModel\n prorationRate\n quantity\n quantityMax\n quantityMin\n startDate\n tieredAveragePrice\n updatedAt\n }\n }\n}";
4062
+
4063
+ var QUOTE_RECALCULATE_TAXES = "\n mutation QuoteRecalculateTaxes($id: ID!) {\n quoteRecalculateTaxes(id: $id) {\n ".concat(QUOTE_FIELDS, "\n errors\n }\n }\n");
4064
+ var quoteRecalculateTaxes = function (_a) {
4065
+ var quoteId = _a.quoteId, token = _a.token;
4066
+ return __awaiter(void 0, void 0, void 0, function () {
4067
+ var vars, response, errors;
4068
+ var _b, _c;
4069
+ return __generator(this, function (_d) {
4070
+ switch (_d.label) {
4071
+ case 0:
4072
+ vars = { id: quoteId };
4073
+ return [4 /*yield*/, common.gqlRequest({
4074
+ query: QUOTE_RECALCULATE_TAXES,
4075
+ token: token,
4076
+ vars: vars,
4077
+ })];
4078
+ case 1:
4079
+ response = _d.sent();
4080
+ errors = (_b = response === null || response === void 0 ? void 0 : response.quoteRecalculateTaxes) === null || _b === void 0 ? void 0 : _b.errors;
4081
+ if (errors)
4082
+ throw errors;
4083
+ return [2 /*return*/, (_c = response.quoteRecalculateTaxes) === null || _c === void 0 ? void 0 : _c.quote];
4084
+ }
4085
+ });
4073
4086
  });
4074
- }); };
4087
+ };
4075
4088
 
4076
- var pageContentRefState = recoil.atom({
4077
- key: "pageContentRefState",
4089
+ var planPickerQuoteDataState = recoil.atom({
4090
+ key: "planPickerQuoteDataState",
4078
4091
  default: undefined,
4079
4092
  });
4080
4093
 
4081
- var PageContent = function (_a) {
4082
- var children = _a.children, className = _a.className, style = _a.style;
4083
- var pageContentRef = React.useRef(null);
4084
- var setPageContentRef = recoil.useSetRecoilState(pageContentRefState);
4085
- React.useEffect(function () {
4086
- setPageContentRef(pageContentRef === null || pageContentRef === void 0 ? void 0 : pageContentRef.current);
4087
- }, [pageContentRef, setPageContentRef]);
4088
- return (jsxRuntime.jsx("div", __assign({ className: className, ref: pageContentRef, style: style }, { children: children })));
4094
+ var pageWrapperClassName = function (isMobile) {
4095
+ return "flex flex-col grow pt-4 ".concat(isMobile ? "pb-4 overflow-hidden" : "pb-8", " ").concat("content-container");
4089
4096
  };
4090
4097
 
4091
- var Text$8 = antd.Typography.Text;
4092
- var PageHeaderWithActions = function (_a) {
4093
- var children = _a.children, title = _a.title;
4094
- var isMobile = common.useIsMobile();
4095
- return (jsxRuntime.jsxs("div", __assign({ className: "flex pb-4 shadow-padding-x ".concat(isMobile ? "flex-col gap-2" : "items-center justify-between h-8") }, { children: [jsxRuntime.jsx(PageSubTitle, { title: title }), children] })));
4096
- };
4097
- var PageSubTitle = function (_a) {
4098
- var title = _a.title;
4099
- var secondaryColor = React.useContext(BrandContext).secondaryColor;
4100
- var darkMode = React.useContext(BunnyContext).darkMode;
4101
- return (jsxRuntime.jsx(Text$8, __assign({ className: "shrink-0 font-medium", style: { color: darkMode ? undefined : secondaryColor } }, { children: title })));
4098
+ var queryKeyFactory = common.QueryKeyFactory.default;
4099
+ var Checkout = function (_a) {
4100
+ var _b, _c;
4101
+ var onCancel = _a.onCancel, onSuccess = _a.onSuccess, onFail = _a.onFail, invoice = _a.invoice, open = _a.open, quote = _a.quote, selectedPriceList = _a.selectedPriceList, isMobile = _a.isMobile, token = _a.token, storedPaymentMethod = _a.storedPaymentMethod;
4102
+ var subdomain = React.useContext(BunnyContext).subdomain;
4103
+ var _d = React.useState(false), isSaving = _d[0], setIsSaving = _d[1];
4104
+ var hasTaxPlugin = useHasTaxPlugin({ subdomain: subdomain || "", token: token });
4105
+ var queryClient = reactQuery.useQueryClient();
4106
+ var quotePreviewData = recoil.useRecoilValue(planPickerQuoteDataState);
4107
+ // Queries
4108
+ var _e = reactQuery.useQuery({
4109
+ queryKey: ["getTaxationRequiredAccountFields", token],
4110
+ queryFn: function () { return common.getTaxationRequiredAccountFields({ token: token }); },
4111
+ enabled: Boolean(quote),
4112
+ staleTime: 0,
4113
+ }), taxationRequiredAccountFields = _e.data, isLoadingTaxationRequiredAccountFields = _e.isLoading;
4114
+ var _f = reactQuery.useQuery({
4115
+ queryKey: ["account", quote === null || quote === void 0 ? void 0 : quote.accountId],
4116
+ queryFn: function () {
4117
+ return (quote === null || quote === void 0 ? void 0 : quote.accountId) && common.getAccount({ id: quote.accountId, token: token });
4118
+ },
4119
+ enabled: Boolean(quote === null || quote === void 0 ? void 0 : quote.accountId) &&
4120
+ ((taxationRequiredAccountFields === null || taxationRequiredAccountFields === void 0 ? void 0 : taxationRequiredAccountFields.length) || 0) > 0,
4121
+ }), account = _f.data, isLoadingAccount = _f.isLoading;
4122
+ reactQuery.useQuery({
4123
+ queryKey: queryKeyFactory.createQuoteTaxCalculateKey(quote === null || quote === void 0 ? void 0 : quote.id),
4124
+ queryFn: function () { return __awaiter(void 0, void 0, void 0, function () {
4125
+ var updatedQuote;
4126
+ return __generator(this, function (_a) {
4127
+ switch (_a.label) {
4128
+ case 0:
4129
+ if (!quote) return [3 /*break*/, 2];
4130
+ return [4 /*yield*/, quoteRecalculateTaxes({
4131
+ quoteId: quote.id,
4132
+ token: token,
4133
+ })];
4134
+ case 1:
4135
+ updatedQuote = _a.sent();
4136
+ if (updatedQuote) {
4137
+ queryClient.setQueryData(queryKeyFactory.createObjectKey("editingQuote", updatedQuote.id), updatedQuote);
4138
+ queryClient.setQueryData(queryKeyFactory.calculatedPricesKey((quotePreviewData === null || quotePreviewData === void 0 ? void 0 : quotePreviewData.quantity) || 0, selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.id), updatedQuote);
4139
+ }
4140
+ _a.label = 2;
4141
+ case 2: return [2 /*return*/, {}];
4142
+ }
4143
+ });
4144
+ }); },
4145
+ // Recalculate taxes if the quote is open, has a tax plugin, and the taxation required account fields are not required
4146
+ enabled: Boolean(quote) &&
4147
+ open &&
4148
+ hasTaxPlugin &&
4149
+ !taxationRequiredAccountFields &&
4150
+ !isLoadingTaxationRequiredAccountFields,
4151
+ staleTime: 0,
4152
+ });
4153
+ if (!open || isLoadingTaxationRequiredAccountFields || isLoadingAccount)
4154
+ return null;
4155
+ return (jsxRuntime.jsx("div", __assign({ className: "flex flex-col fixed top-0 left-0 right-0 bottom-0 bg-slate-50 overflow-auto", style: {
4156
+ zIndex: 1001,
4157
+ } }, { children: jsxRuntime.jsxs("div", __assign({ className: pageWrapperClassName(isMobile) }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex justify-end w-full" }, { children: jsxRuntime.jsx(CloseOutlined$1, { className: "text-base shadow-padding-xb", onClick: onCancel }) })), jsxRuntime.jsxs("div", __assign({ className: "flex justify-end gap-6 pt-4 ".concat(isMobile ? "flex-col" : "shadow-padding-xb") }, { children: [((invoice === null || invoice === void 0 ? void 0 : invoice.html) || ((_b = quote === null || quote === void 0 ? void 0 : quote.formattedQuote) === null || _b === void 0 ? void 0 : _b.html)) && (jsxRuntime.jsx(InvoiceQuoteView, { html: invoice ? invoice.html : quote ? quote.formattedQuote.html : "", isMobile: isMobile })), !isMobile && ((invoice === null || invoice === void 0 ? void 0 : invoice.html) || ((_c = quote === null || quote === void 0 ? void 0 : quote.formattedQuote) === null || _c === void 0 ? void 0 : _c.html)) && (jsxRuntime.jsx(antd.Divider, { className: "h-full", type: "vertical" })), invoice ? (jsxRuntime.jsx(InvoiceCheckout, { invoice: invoice, isSaving: isSaving, onFail: function (error) {
4158
+ onFail(error);
4159
+ setIsSaving(false);
4160
+ }, onSuccess: function (_a) {
4161
+ var savePaymentMethod = _a.savePaymentMethod;
4162
+ onSuccess({ savePaymentMethod: savePaymentMethod });
4163
+ setIsSaving(false);
4164
+ }, setIsSaving: setIsSaving })) : quote ? (jsxRuntime.jsx(QuoteCheckout, { account: account, isSaving: isSaving, onFail: function (error) {
4165
+ onFail(error);
4166
+ setIsSaving(false);
4167
+ }, onSuccess: function (_a) {
4168
+ var savePaymentMethod = _a.savePaymentMethod;
4169
+ onSuccess({ savePaymentMethod: savePaymentMethod });
4170
+ setIsSaving(false);
4171
+ }, quote: quote, setIsSaving: setIsSaving, taxationRequiredAccountFields: taxationRequiredAccountFields, token: token, storedPaymentMethod: storedPaymentMethod })) : (jsxRuntime.jsx(PaymentForm, { isSaving: isSaving, onFail: function (error) {
4172
+ onFail(error);
4173
+ setIsSaving(false);
4174
+ }, onPaymentSuccess: function (_a) {
4175
+ var pluginPaymentResponse = _a.pluginPaymentResponse;
4176
+ onSuccess({
4177
+ savePaymentMethod: pluginPaymentResponse === null || pluginPaymentResponse === void 0 ? void 0 : pluginPaymentResponse.savePaymentMethod,
4178
+ });
4179
+ setIsSaving(false);
4180
+ }, setIsSaving: setIsSaving }))] }))] })) })));
4102
4181
  };
4103
4182
 
4104
- var StateTag = function (_a) {
4105
- var state = _a.state;
4106
- return jsxRuntime.jsx(antd.Tag, __assign({ color: getColor(state) }, { children: lodash.capitalize(lodash.startCase(state)) }));
4107
- };
4108
- var getColor = function (state) {
4109
- switch (state) {
4110
- case common.FrontendTransaction.TransactionState.not_due:
4111
- return "yellow";
4112
- case common.FrontendTransaction.TransactionState.voided:
4113
- return "black";
4114
- case common.FrontendTransaction.TransactionState.ready:
4115
- return "orange";
4116
- case common.FrontendTransaction.TransactionState.preparing:
4117
- return "purple";
4118
- case common.FrontendTransaction.TransactionState.unapplied:
4119
- case common.FrontendTransaction.TransactionState.partially_applied:
4120
- case common.FrontendTransaction.TransactionState.applied:
4121
- return "blue";
4122
- case common.FrontendTransaction.TransactionState.due:
4123
- case common.FrontendTransaction.TransactionState.unpaid:
4124
- return "orange";
4125
- case common.FrontendTransaction.TransactionState.failed:
4126
- return "red";
4127
- case common.FrontendTransaction.TransactionState.paid:
4128
- return "green";
4129
- default:
4130
- return "blue";
4131
- }
4183
+ var MUTATION$4 = function () { return "\nmutation AccountSignup (\n $entityId: ID!,\n $pluginId: String!,\n $paymentMethodId: String,\n $priceListCode: String!,\n $accountId: ID!,\n $quoteId: ID!\n) {\n accountSignup(\n entityId: $entityId,\n pluginId: $pluginId,\n paymentMethodId: $paymentMethodId,\n priceListCode: $priceListCode,\n accountId: $accountId,\n quoteId: $quoteId\n ) {\n errors\n quote {\n acceptedByName\n acceptedByTitle\n accountId\n amount\n amountDue\n applicationDate\n applied\n backdatedPeriods\n backdatedQuote\n billingDay\n contactId\n createdAt\n credits\n currencyId\n dealId\n discount\n discountValue\n endDate\n evergreen\n expiresAt\n id\n invoiceImmediately\n invoiceImmediatelyAvailable\n invoiceUntil\n isPendingApprovalRequest\n kind\n message\n name\n netPaymentDays\n notes\n number\n ownerId\n payableId\n periodAmount\n poNumber\n requiresApproval\n smallUnitAmountDue\n splitInvoice\n startDate\n state\n subtotal\n taxAmount\n taxCode\n updatedAt\n uuid\n }\n }\n}"; };
4184
+ var accountSignup = function (_a) {
4185
+ var token = _a.token, subdomain = _a.subdomain, entityId = _a.entityId, accountId = _a.accountId, quoteId = _a.quoteId, paymentToken = _a.paymentToken, paymentMethodId = _a.paymentMethodId, pluginId = _a.pluginId, priceListCode = _a.priceListCode;
4186
+ return __awaiter(void 0, void 0, void 0, function () {
4187
+ var vars, response, errors;
4188
+ var _b;
4189
+ return __generator(this, function (_c) {
4190
+ switch (_c.label) {
4191
+ case 0:
4192
+ vars = {
4193
+ entityId: entityId,
4194
+ accountId: accountId,
4195
+ quoteId: quoteId,
4196
+ paymentToken: paymentToken,
4197
+ pluginId: pluginId,
4198
+ paymentMethodId: paymentMethodId,
4199
+ priceListCode: priceListCode,
4200
+ };
4201
+ return [4 /*yield*/, common.gqlRequest({
4202
+ query: MUTATION$4(),
4203
+ token: token,
4204
+ vars: vars,
4205
+ subdomain: subdomain,
4206
+ })];
4207
+ case 1:
4208
+ response = _c.sent();
4209
+ errors = (_b = response === null || response === void 0 ? void 0 : response.accountSignup) === null || _b === void 0 ? void 0 : _b.errors;
4210
+ if (errors)
4211
+ throw errors;
4212
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.accountSignup];
4213
+ }
4214
+ });
4215
+ });
4132
4216
  };
4133
4217
 
4134
- var TransactionGridCell = styled__default["default"].div.withConfig({
4135
- shouldForwardProp: function (prop) {
4136
- return !["gridColumn", "padding", "right"].includes(prop);
4137
- },
4138
- })(templateObject_1$3 || (templateObject_1$3 = __makeTemplateObject(["\n ", "\n\n display: flex;\n align-items: center;\n justify-content: ", ";\n\n text-align: ", ";\n white-space: nowrap;\n font-size: 14px;\n color: ", ";\n\n background-color: inherit;\n\n padding: 1rem;\n min-width: 48px;\n"], ["\n ", "\n\n display: flex;\n align-items: center;\n justify-content: ", ";\n\n text-align: ", ";\n white-space: nowrap;\n font-size: 14px;\n color: ", ";\n\n background-color: inherit;\n\n padding: 1rem;\n min-width: 48px;\n"])), function (props) { return props.gridColumn && "grid-column: ".concat(props.gridColumn, ";"); }, function (props) { return (props.right ? "flex-end" : "flex-start"); }, function (props) { return (props.right ? "right" : "left"); }, common.SLATE_600);
4139
- var templateObject_1$3;
4140
-
4141
- var Text$7 = antd.Typography.Text;
4142
- var TransactionDate = function (_a) {
4143
- var date = _a.date;
4144
- return jsxRuntime.jsx(Text$7, __assign({ className: "text-sm" }, { children: common.Misc.formatDate(date) }));
4218
+ var MUTATION$3 = function () { return "\nmutation QuoteAccountSignup (\n $accountName: String!,\n $billingContact: ContactAttributes!,\n $entityId: ID!,\n $priceListCode: String!\n) {\n quoteAccountSignup(\n entityId: $entityId,\n priceListCode: $priceListCode,\n accountName: $accountName,\n billingContact: $billingContact\n ) {\n account {\n id\n }\n amount\n currencyId\n quote {\n id\n }\n tenant {\n code\n }\n errors\n }\n}"; };
4219
+ var quoteAccountSignup = function (_a) {
4220
+ var token = _a.token, subdomain = _a.subdomain, entityId = _a.entityId, priceListCode = _a.priceListCode, accountName = _a.accountName, billingContact = _a.billingContact;
4221
+ return __awaiter(void 0, void 0, void 0, function () {
4222
+ var vars, response, errors;
4223
+ var _b;
4224
+ return __generator(this, function (_c) {
4225
+ switch (_c.label) {
4226
+ case 0:
4227
+ vars = {
4228
+ entityId: entityId,
4229
+ priceListCode: priceListCode,
4230
+ accountName: accountName,
4231
+ billingContact: billingContact,
4232
+ };
4233
+ return [4 /*yield*/, common.gqlRequest({
4234
+ query: MUTATION$3(),
4235
+ token: token,
4236
+ vars: vars,
4237
+ subdomain: subdomain,
4238
+ })];
4239
+ case 1:
4240
+ response = _c.sent();
4241
+ errors = (_b = response === null || response === void 0 ? void 0 : response.quoteAccountSignup) === null || _b === void 0 ? void 0 : _b.errors;
4242
+ if (errors)
4243
+ throw errors;
4244
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.quoteAccountSignup];
4245
+ }
4246
+ });
4247
+ });
4145
4248
  };
4146
4249
 
4147
- var isInvoice = function (transaction) {
4148
- return transaction.kind === "INVOICE";
4149
- };
4150
- var isQuote = function (transaction) {
4151
- return transaction.kind === "QUOTE";
4152
- };
4153
- var TransactionRowTitle = function (_a) {
4154
- var transaction = _a.transaction;
4155
- if (!isInvoice(transaction) && !isQuote(transaction)) {
4156
- return jsxRuntime.jsx(jsxRuntime.Fragment, {});
4157
- }
4158
- return (jsxRuntime.jsx("span", __assign({ className: "text-slate-400", style: { fontSize: "11px" } }, { children: transaction.transactionable.number })));
4250
+ var MUTATION$2 = function () { return "\nquery PriceList($code: String!) {\n priceList (code: $code) {\n basePrice\n code\n createdAt\n currencyId\n id\n isVisible\n name\n periodMonths\n planId\n priceDescription\n productId\n sku\n trialAllowed\n trialLengthDays\n updatedAt\n }\n}"; };
4251
+ var getPriceList = function (_a) {
4252
+ var token = _a.token, code = _a.code, subdomain = _a.subdomain;
4253
+ return __awaiter(void 0, void 0, void 0, function () {
4254
+ var response;
4255
+ return __generator(this, function (_b) {
4256
+ switch (_b.label) {
4257
+ case 0: return [4 /*yield*/, common.gqlRequest({
4258
+ query: MUTATION$2(),
4259
+ token: token,
4260
+ vars: { code: code },
4261
+ subdomain: subdomain,
4262
+ })];
4263
+ case 1:
4264
+ response = _b.sent();
4265
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.priceList];
4266
+ }
4267
+ });
4268
+ });
4159
4269
  };
4160
4270
 
4161
- // TODO: delete
4162
- var ArrowDownToLine = function (_a) {
4163
- var className = _a.className, _b = _a.color, color = _b === void 0 ? common.SLATE_600 : _b;
4164
- return (jsxRuntime.jsxs("svg", __assign({ className: className, fill: "none", height: "16", viewBox: "0 0 16 16", width: "16", xmlns: "http://www.w3.org/2000/svg" }, { children: [jsxRuntime.jsx("path", { d: "M8 11.3333V2", stroke: color, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), jsxRuntime.jsx("path", { d: "M4 7.33301L8 11.333L12 7.33301", stroke: color, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), jsxRuntime.jsx("path", { d: "M12.6654 14H3.33203", stroke: color, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] })));
4165
- };
4271
+ function PaymentForms(_a) {
4272
+ var quote = _a.quote, paying = _a.paying, setIsPaying = _a.setIsPaying, handlePaymentSaveSuccess = _a.handlePaymentSaveSuccess, handlePaymentFail = _a.handlePaymentFail, handleSubmit = _a.handleSubmit, proceedingToPayment = _a.proceedingToPayment, accountId = _a.accountId;
4273
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: quote ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: accountId && (jsxRuntime.jsx(PaymentContext.Provider, __assign({ value: { accountId: accountId, displayPayButtonNameAnyways: true } }, { children: jsxRuntime.jsx(PaymentForm, { isSaving: paying, setIsSaving: setIsPaying, onFail: handlePaymentFail, onPaymentSuccess: handlePaymentSaveSuccess }) }))) })) : (jsxRuntime.jsx(InitialSignupForm, { onSubmit: handleSubmit, submitting: proceedingToPayment })) }));
4274
+ }
4275
+ function InitialSignupForm(_a) {
4276
+ var onSubmit = _a.onSubmit, submitting = _a.submitting;
4277
+ var _b = React.useState({
4278
+ firstName: "",
4279
+ lastName: "",
4280
+ email: "",
4281
+ accountName: "",
4282
+ }), formData = _b[0], setFormData = _b[1];
4283
+ var handleInputChange = function (e) {
4284
+ var _a;
4285
+ var _b = e.target, name = _b.name, value = _b.value;
4286
+ setFormData(__assign(__assign({}, formData), (_a = {}, _a[name] = value, _a)));
4287
+ };
4288
+ return (jsxRuntime.jsxs(antd.Form, __assign({ className: "flex w-1/2 flex-col justify-between h-full", onFinish: function () { return onSubmit(formData); } }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex flex-col space-y-2" }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ rules: [{ required: true, message: "Please input your first name!" }], initialValue: formData.firstName }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "First name", value: formData.firstName, onChange: function (e) {
4289
+ handleInputChange(e);
4290
+ setFormData(__assign(__assign({}, formData), { firstName: e.target.value }));
4291
+ } }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ rules: [{ required: true, message: "Please input your last name!" }], initialValue: formData.lastName }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Last name", value: formData.lastName, onChange: function (e) {
4292
+ handleInputChange(e);
4293
+ setFormData(__assign(__assign({}, formData), { lastName: e.target.value }));
4294
+ } }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ rules: [
4295
+ { required: true, message: "Please input your email!" },
4296
+ { type: "email", message: "Please enter a valid email!" },
4297
+ ], initialValue: formData.email }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Email", value: formData.email, onChange: function (e) {
4298
+ handleInputChange(e);
4299
+ setFormData(__assign(__assign({}, formData), { email: e.target.value }));
4300
+ } }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ rules: [
4301
+ { required: true, message: "Please input your account name!" },
4302
+ ], initialValue: formData.accountName }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Account name", value: formData.accountName, onChange: function (e) {
4303
+ handleInputChange(e);
4304
+ setFormData(__assign(__assign({}, formData), { accountName: e.target.value }));
4305
+ } }) }))] })), jsxRuntime.jsx(antd.Form.Item, { children: jsxRuntime.jsx(antd.Button, __assign({ type: "primary", htmlType: "submit", loading: submitting, className: "w-full mt-4" }, { children: "Proceed to payment" })) })] })));
4306
+ }
4166
4307
 
4167
- var TransactionsListContext = React.createContext({});
4308
+ var Title = antd.Typography.Title, Text$5 = antd.Typography.Text;
4309
+ function PaymentSuccessDisplay(_a) {
4310
+ var className = _a.className, amountPaid = _a.amountPaid, style = _a.style, returnUrl = _a.returnUrl;
4311
+ var window = React.useContext(BunnyContext).window;
4312
+ var companyName = common.useCurrentUserData().companyName;
4313
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col items-center justify-center h-full ".concat(className), style: style }, { children: [jsxRuntime.jsx(CheckCircleFilled$1, { style: { fontSize: "48px", color: "rgb(52 211 153)" } }), jsxRuntime.jsxs(Title, __assign({ level: 3, className: "mt-2 m-0" }, { children: ["Payment of ", common.Misc.formatCurrency(amountPaid, "USD"), " successful"] })), returnUrl && (jsxRuntime.jsxs(Text$5, __assign({ className: "text-slate-500 cursor-pointer underline", onClick: function () { return (window.location.href = returnUrl); } }, { children: ["Back to ", companyName] })))] })));
4314
+ }
4168
4315
 
4169
- var TransactionDownload = function (_a) {
4170
- var transaction = _a.transaction, token = _a.token, subdomain = _a.subdomain;
4171
- var darkMode = React.useContext(BunnyContext).darkMode;
4172
- var downloadTransactionLink = React.useContext(TransactionsListContext).downloadTransactionLink;
4173
- var downloadFile = common.useDownloadFile();
4174
- var isMobile = common.useIsMobile();
4175
- var isClickable = transaction.kind === "INVOICE" || downloadTransactionLink !== undefined;
4176
- var downloadLink = downloadTransactionLink
4177
- ? downloadTransactionLink(transaction.transactionableId)
4178
- : "".concat(subdomain, "/api/pdf/invoice/").concat(transaction.transactionableId);
4179
- if (!isClickable)
4316
+ var Text$4 = antd.Typography.Text;
4317
+ function PriceListDisplay(_a) {
4318
+ var priceListData = _a.priceListData, topNavImageUrl = _a.topNavImageUrl;
4319
+ if (!priceListData)
4180
4320
  return null;
4181
- return (jsxRuntime.jsx("div", __assign({ onClick: function (e) {
4182
- e.stopPropagation();
4183
- downloadFile(downloadLink, token);
4184
- } }, { children: jsxRuntime.jsx(ArrowDownToLine, { className: "".concat(isMobile ? "" : "show-on-hover"), color: darkMode ? common.WHITE : common.SLATE_600 }) })));
4185
- };
4321
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", __assign({ className: "flex flex-col justify-between h-full my-12" }, { children: jsxRuntime.jsxs("div", __assign({ className: "flex flex-col space-y-8" }, { children: [jsxRuntime.jsx(antd.Image, { width: 24, src: topNavImageUrl, alt: "Logo", preview: false }), jsxRuntime.jsxs("div", __assign({ className: "flex flex-col" }, { children: [jsxRuntime.jsx(Text$4, __assign({ className: "text-slate-500 font-bold text-lg" }, { children: priceListData.name })), jsxRuntime.jsxs(Text$4, __assign({ className: "font-bold text-xl" }, { children: [common.Misc.formatCurrency(priceListData.basePrice, priceListData.currencyId), " ", "/ month"] }))] })), jsxRuntime.jsxs("div", __assign({ className: "flex flex-col" }, { children: [jsxRuntime.jsxs(Text$4, __assign({ style: { fontSize: "16px" }, className: "text-slate-500" }, { children: [priceListData.trialLengthDays, " day trial"] })), jsxRuntime.jsx(Text$4, __assign({ className: "text-slate-500", style: { fontSize: "12px" } }, { children: "You will not be charged until the last day of the trial." }))] }))] })) })) }));
4322
+ }
4186
4323
 
4187
- var Text$6 = antd.Typography.Text;
4188
- var TransactionsEmptyState = function () {
4189
- var noTransactionsMessage = React.useContext(TransactionsListContext).noTransactionsMessage;
4190
- return (jsxRuntime.jsx(Text$6, __assign({ className: "flex justify-center p-4 text-base" }, { children: noTransactionsMessage || "There are no transactions" })));
4324
+ var BunnyFooterIcon = function (_a) {
4325
+ var color = _a.color;
4326
+ return (jsxRuntime.jsxs("svg", __assign({ width: "45", height: "15", viewBox: "0 0 39 13", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: [jsxRuntime.jsxs("g", __assign({ clipPath: "url(#clip0_6_851)" }, { children: [jsxRuntime.jsx("path", { className: "icon-path", d: "M14.5898 7.19708C14.5898 9.35053 13.0926 10.325 11.2495 10.325C9.39955 10.325 7.90234 9.35001 7.90234 7.18967V3.26221H10.1125V7.00052C10.1125 7.87719 10.5855 8.27725 11.2495 8.27725C11.9061 8.27725 12.3865 7.87719 12.3865 7.00052V3.26221H14.5898V7.19708Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M31.8943 12.9625H29.4793L31.8523 8.62816L28.9355 3.26221H31.4708L33.0457 6.35524L34.5924 3.26221H37.0075L31.8943 12.9625Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M15.1602 5.96827C15.1602 3.8148 16.6574 2.84033 18.5005 2.84033C20.3504 2.84033 21.8476 3.81533 21.8476 5.97568V10.1473H19.6374V6.16483C19.6374 5.28815 19.1645 4.8881 18.5005 4.8881C17.8439 4.8881 17.3634 5.28815 17.3634 6.16483V10.1473H15.1602V5.96827Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M22.4316 5.96827C22.4316 3.8148 23.9289 2.84033 25.7719 2.84033C27.6219 2.84033 29.1191 3.81533 29.1191 5.97568V10.1473H26.9089V6.16483C26.9089 5.28815 26.4359 4.8881 25.7719 4.8881C25.1154 4.8881 24.6349 5.28815 24.6349 6.16483V10.1473H22.4316V5.96827Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M7.40511 6.68957C7.40511 8.7236 6.02815 10.3227 4.17816 10.3227C3.23907 10.3227 2.61071 9.94378 2.19358 9.40371V10.1404H0.0605469V0.0405273H2.26381V3.91939C2.68041 3.42158 3.28802 3.07069 4.17763 3.07069C6.02759 3.07069 7.40511 4.66981 7.40511 6.68957ZM2.17229 6.69642C2.17229 7.60802 2.77937 8.2744 3.64823 8.2744C4.53783 8.2744 5.13107 7.59372 5.13107 6.69642C5.13107 5.79912 4.53783 5.11844 3.64823 5.11844C2.77937 5.11844 2.17229 5.78482 2.17229 6.69642Z", fill: color }), jsxRuntime.jsx("path", { className: "icon-path", d: "M38.966 8.94801C38.966 9.76181 38.2668 10.4631 37.4618 10.4631C36.6499 10.4631 35.9434 9.76181 35.9434 8.94801C35.9434 8.14846 36.6494 7.46094 37.4618 7.46094C38.2668 7.46094 38.966 8.14846 38.966 8.94801Z", fill: color })] })), jsxRuntime.jsx("defs", { children: jsxRuntime.jsx("clipPath", __assign({ id: "clip0_6_851" }, { children: jsxRuntime.jsx("rect", { width: "39", height: "13", fill: "white" }) })) })] })));
4191
4327
  };
4192
4328
 
4193
- function capitalizeFirstLetter(string) {
4194
- return string.charAt(0).toUpperCase() + string.slice(1);
4195
- }
4196
- var WARREN_STATE_LS_KEY = "warrenState";
4197
- var CURRENT_WARREN_ID_LS_KEY = "currentWarrenId";
4198
- var getIsCapacitorApp = function () {
4199
- var isAndroid = window.location.origin === "http://localhost";
4200
- var isIOS = window.location.protocol === "capacitor:";
4201
- return isAndroid || isIOS;
4202
- };
4203
- var getLocalStorageSubdomain = function () {
4204
- var warrenState = JSON.parse(window.localStorage.getItem(WARREN_STATE_LS_KEY) || "{}");
4205
- var subdomain = warrenState[CURRENT_WARREN_ID_LS_KEY];
4206
- if (!subdomain) {
4207
- console.warn("ERROR_MESSAGE_NO_SUBDOMAIN_DEFINED");
4208
- //throw new Error(ERROR_MESSAGE_NO_SUBDOMAIN_DEFINED);
4209
- }
4210
- return subdomain;
4211
- };
4212
- var getApiHost = function (subdomain) {
4213
- var isLocalHost = window.location.href.indexOf(".internal") > 0;
4214
- var sub = subdomain || getLocalStorageSubdomain();
4215
- if (getIsCapacitorApp()) {
4216
- return isLocalHost || process.env.REACT_APP_IS_INTERNAL === "true"
4217
- ? "https://".concat(sub, ".bunny.internal")
4218
- : "https://".concat(sub, ".").concat(process.env.REACT_APP_ROOT_DOMAIN);
4219
- }
4220
- return "";
4221
- };
4222
- var getGraphQLBase = function () {
4223
- if (getIsCapacitorApp()) {
4224
- return "".concat(getApiHost(), "/graphql");
4225
- }
4226
- return "/graphql";
4329
+ var Footer = function (_a) {
4330
+ var className = _a.className;
4331
+ var _b = common.useCurrentUserData(), privacyUrl = _b.privacyUrl, termsUrl = _b.termsUrl;
4332
+ var window = React.useContext(BunnyContext).window;
4333
+ var isMobile = useIsMobile(window);
4334
+ var quotePreviewData = recoil.useRecoilValue(planPickerQuoteDataState);
4335
+ var selectedPriceList = quotePreviewData === null || quotePreviewData === void 0 ? void 0 : quotePreviewData.priceList;
4336
+ if (selectedPriceList && isMobile)
4337
+ return null;
4338
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex items-center justify-between shrink-0 ".concat(className, " ").concat(isMobile ? "flex-col gap-2 grow" : "") }, { children: [(termsUrl || privacyUrl) && (jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-3" }, { children: [termsUrl && (jsxRuntime.jsx(StyedLink, __assign({ className: "text-xs text-slate-400", href: termsUrl, rel: "noopener noreferrer", target: "_blank", type: "text" }, { children: "Terms" }))), privacyUrl && (jsxRuntime.jsx(StyedLink, __assign({ className: "text-xs text-slate-400", href: privacyUrl, rel: "noopener noreferrer", target: "_blank", type: "text" }, { children: "Privacy" })))] }))), jsxRuntime.jsx(BunnyMarketingLink, {})] })));
4227
4339
  };
4228
- var createRequestHeaders = function (token) {
4229
- var bearerToken = "Bearer ".concat(token);
4230
- var headers = {
4231
- "Content-type": "application/json; charset=utf-8",
4232
- };
4233
- headers["Authorization"] = bearerToken;
4234
- return headers;
4340
+ var BunnyMarketingLink = function () {
4341
+ var _a = React.useState(false), isHovered = _a[0], setIsHovered = _a[1];
4342
+ var window = React.useContext(BunnyContext).window;
4343
+ var isMobile = useIsMobile(window);
4344
+ return (jsxRuntime.jsx("div", __assign({ className: "flex items-end justify-end ".concat(isMobile ? "" : "grow") }, { children: jsxRuntime.jsx(StyledBunnyLink, __assign({ className: "flex items-end justify-end text-slate-400", href: "https://bunny.com/", rel: "noopener noreferrer", target: "_blank", type: "text" }, { children: jsxRuntime.jsxs("div", __assign({ className: "flex items-center", onMouseEnter: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); } }, { children: ["Powered by\u00A0", jsxRuntime.jsx("div", __assign({ style: { paddingTop: "5px" } }, { children: jsxRuntime.jsx(BunnyFooterIcon, { color: isHovered ? common.PRIMARY_COLOR : common.SLATE_400 }) }))] })) })) })));
4235
4345
  };
4236
- var useGraphQLRequest = function () { return function (query, token, variables) { return __awaiter(void 0, void 0, void 0, function () {
4237
- var error_1;
4238
- return __generator(this, function (_a) {
4239
- switch (_a.label) {
4240
- case 0:
4241
- _a.trys.push([0, 2, , 3]);
4242
- return [4 /*yield*/, request__default["default"](getGraphQLBase(), query, variables, createRequestHeaders(token))];
4243
- case 1: return [2 /*return*/, _a.sent()];
4244
- case 2:
4245
- error_1 = _a.sent();
4246
- throw error_1;
4247
- case 3: return [2 /*return*/];
4248
- }
4249
- });
4250
- }); }; };
4346
+ var StyedLink = styled__default["default"].a(templateObject_1$3 || (templateObject_1$3 = __makeTemplateObject(["\n color: ", ";\n transition: color 0.3s;\n &:hover {\n color: ", ";\n }\n"], ["\n color: ", ";\n transition: color 0.3s;\n &:hover {\n color: ", ";\n }\n"])), common.SLATE_400, common.SLATE_500);
4347
+ var StyledBunnyLink = styled__default["default"](StyedLink)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n &:hover {\n color: ", " !important;\n }\n"], ["\n &:hover {\n color: ", " !important;\n }\n"])), common.PRIMARY_COLOR);
4348
+ var templateObject_1$3, templateObject_2;
4251
4349
 
4252
- var Text$5 = antd.Typography.Text;
4253
- var TransactionsListDesktop = function (_a) {
4254
- var transactions = _a.transactions, onTransactionClick = _a.onTransactionClick;
4255
- var columns = React.useContext(TransactionsListContext).columns;
4256
- var _b = React.useContext(BunnyContext), token = _b.token, subdomain = _b.subdomain, darkMode = _b.darkMode;
4257
- var showAmount = columns.includes("amount");
4258
- var showDateAndTitle = columns.includes("date-and-title");
4259
- var showDownload = columns.includes("download");
4260
- var showState = columns.includes("state");
4261
- if ((transactions === null || transactions === void 0 ? void 0 : transactions.length) === 0)
4262
- return jsxRuntime.jsx(TransactionsEmptyState, {});
4263
- return transactions === null || transactions === void 0 ? void 0 : transactions.map(function (transaction, index) {
4264
- var _a;
4265
- var isClickable = onTransactionClick !== undefined;
4266
- return (jsxRuntime.jsxs("div", __assign({ className: "contents ".concat(isClickable && "cursor-pointer", " show-on-hover-container"), onClick: function () {
4267
- onTransactionClick === null || onTransactionClick === void 0 ? void 0 : onTransactionClick(transaction);
4268
- }, style: {
4269
- backgroundColor: index % 2 === 0
4270
- ? "var(--row-background".concat(darkMode ? "-dark" : "", ")")
4271
- : "var(--row-background-alternate".concat(darkMode ? "-dark" : "", ")"),
4272
- } }, { children: [showDateAndTitle && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TransactionGridCell, __assign({ right: false }, { children: jsxRuntime.jsx(TransactionDate, { date: transaction.createdAt }) })), jsxRuntime.jsxs(TransactionGridCell, __assign({ right: false, className: "flex items-center gap-2" }, { children: [jsxRuntime.jsx(Text$5, { children: capitalizeFirstLetter(transaction.kind.toLowerCase()) }), jsxRuntime.jsx(TransactionRowTitle, { transaction: transaction })] }))] })), showDownload && (jsxRuntime.jsx(TransactionGridCell, { children: jsxRuntime.jsx(TransactionDownload, { transaction: transaction, token: token, subdomain: subdomain }) })), showState && (jsxRuntime.jsx(TransactionGridCell, __assign({ right: true }, { children: jsxRuntime.jsx(StateTag, { state: transaction.state }) }))), showAmount && (jsxRuntime.jsx(TransactionGridCell, __assign({ right: true }, { children: jsxRuntime.jsx(Text$5, { children: common.Misc.formatCurrency(((_a = transaction === null || transaction === void 0 ? void 0 : transaction.transactionable) === null || _a === void 0 ? void 0 : _a.amount) || transaction.amount, transaction.currencyId) }) })))] }), index));
4350
+ var MUTATION$1 = "\n mutation portalSessionCreate ($tenantCode: String!, $expiry: Int!, $returnUrl: String!) {\n portalSessionCreate (tenantCode: $tenantCode, expiry: $expiry, returnUrl: $returnUrl) {\n errors\n token\n }\n }\n";
4351
+ var portalSessionCreate = function (_a) {
4352
+ var tenantCode = _a.tenantCode, expiry = _a.expiry, returnUrl = _a.returnUrl, token = _a.token, subdomain = _a.subdomain;
4353
+ return __awaiter(void 0, void 0, void 0, function () {
4354
+ var response, errors;
4355
+ var _b;
4356
+ return __generator(this, function (_c) {
4357
+ switch (_c.label) {
4358
+ case 0: return [4 /*yield*/, common.gqlRequest({
4359
+ query: MUTATION$1,
4360
+ token: token,
4361
+ vars: { tenantCode: tenantCode, expiry: expiry, returnUrl: returnUrl },
4362
+ subdomain: subdomain,
4363
+ })];
4364
+ case 1:
4365
+ response = _c.sent();
4366
+ errors = (response === null || response === void 0 ? void 0 : response.portalSessionCreate).errors;
4367
+ if (errors)
4368
+ throw errors;
4369
+ return [2 /*return*/, (_b = response === null || response === void 0 ? void 0 : response.portalSessionCreate) === null || _b === void 0 ? void 0 : _b.token];
4370
+ }
4371
+ });
4273
4372
  });
4274
4373
  };
4275
4374
 
4276
- var Text$4 = antd.Typography.Text;
4277
- var TransactionsListMobile = function (_a) {
4278
- var transactions = _a.transactions, onTransactionClick = _a.onTransactionClick;
4279
- var columns = React.useContext(TransactionsListContext).columns;
4280
- var _b = React.useContext(BunnyContext), token = _b.token, subdomain = _b.subdomain, darkMode = _b.darkMode;
4281
- var showAmount = columns.includes("amount");
4282
- var showDateAndTitle = columns.includes("date-and-title");
4283
- var showDownload = columns.includes("download");
4284
- var showState = columns.includes("state");
4285
- if ((transactions === null || transactions === void 0 ? void 0 : transactions.length) === 0)
4286
- return jsxRuntime.jsx(TransactionsEmptyState, {});
4287
- return transactions === null || transactions === void 0 ? void 0 : transactions.map(function (transaction, index) {
4288
- var isClickable = transaction.kind === "INVOICE";
4289
- return (jsxRuntime.jsxs("div", __assign({ className: "contents ".concat(isClickable && "cursor-pointer", " show-on-hover-container"), onClick: function () {
4290
- onTransactionClick(transaction);
4291
- }, style: {
4292
- backgroundColor: index % 2 === 0
4293
- ? "var(--row-background".concat(darkMode ? "-dark" : "", ")")
4294
- : "var(--row-background-alternate".concat(darkMode ? "-dark" : "", ")"),
4295
- } }, { children: [jsxRuntime.jsx(TransactionGridCell, { children: jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-2" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-2" }, { children: [showDateAndTitle && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Text$4, { children: capitalizeFirstLetter(transaction.kind.toLowerCase()) }), jsxRuntime.jsx(TransactionRowTitle, { transaction: transaction })] })), showState && jsxRuntime.jsx(StateTag, { state: transaction.state })] })), jsxRuntime.jsxs("div", __assign({ className: "flex items-center gap-2" }, { children: [showDateAndTitle && (jsxRuntime.jsx(TransactionDate, { date: transaction.createdAt })), showAmount && showDateAndTitle && jsxRuntime.jsx(Text$4, { children: "\u00B7" }), showAmount && (jsxRuntime.jsx(Text$4, { children: common.Misc.formatCurrency(transaction.transactionable.amount || transaction.amount, transaction.currencyId) }))] }))] })) }), showDownload && (jsxRuntime.jsx(TransactionGridCell, __assign({ right: true }, { children: jsxRuntime.jsx(TransactionDownload, { transaction: transaction, token: token, subdomain: subdomain }) })))] }), index));
4375
+ var showErrorNotification = common.NotificationUtils.useErrorNotification();
4376
+ function Signup(_a) {
4377
+ var priceListCode = _a.priceListCode, returnUrl = _a.returnUrl;
4378
+ // Hooks
4379
+ var _b = React.useContext(BunnyContext), subdomain = _b.subdomain, token = _b.token, window = _b.window;
4380
+ reactQuery.useQuery({
4381
+ queryKey: common.QueryKeyFactory.default.currentUserKey,
4382
+ queryFn: function () { return getCurrentUserData({ token: token, subdomain: subdomain }); },
4296
4383
  });
4297
- };
4298
-
4299
- // Create a client
4300
- var queryClient = new reactQuery.QueryClient();
4301
- function Transactions(_a) {
4302
- var transactionComponent = _a.transactionComponent, _b = _a.showSearchBar, showSearchBar = _b === void 0 ? true : _b, _c = _a.showTitle, showTitle = _c === void 0 ? true : _c, _d = _a.columns, columns = _d === void 0 ? ["date-and-title", "state", "amount"] : _d, className = _a.className, _e = _a.shadow, shadow = _e === void 0 ? "md" : _e, searchBarClassName = _a.searchBarClassName, _f = _a.useModal, useModal = _f === void 0 ? false : _f, onTransactionClick = _a.onTransactionClick, _g = _a.suppressTransactionDisplay, suppressTransactionDisplay = _g === void 0 ? false : _g, _h = _a.kindsToShow, kindsToShow = _h === void 0 ? [
4303
- common.TransactionKind.INVOICE,
4304
- common.TransactionKind.PAYMENT,
4305
- common.TransactionKind.REFUND,
4306
- common.TransactionKind.WRITE_OFF,
4307
- ] : _h, style = _a.style, filter = _a.filter, noTransactionsMessage = _a.noTransactionsMessage;
4308
- var contextValues = {
4309
- showSearchBar: showSearchBar,
4310
- showTitle: showTitle,
4311
- transactionComponent: transactionComponent,
4312
- columns: columns,
4313
- className: className,
4314
- searchBarClassName: searchBarClassName,
4315
- shadow: shadow,
4316
- useModal: useModal,
4317
- onTransactionClick: onTransactionClick,
4318
- suppressTransactionDisplay: suppressTransactionDisplay,
4319
- kindsToShow: kindsToShow,
4320
- style: style,
4321
- filter: filter,
4322
- noTransactionsMessage: noTransactionsMessage,
4323
- };
4324
- return (jsxRuntime.jsx(reactQuery.QueryClientProvider, __assign({ client: queryClient }, { children: jsxRuntime.jsx(TransactionsListContext.Provider, __assign({ value: contextValues }, { children: jsxRuntime.jsx(TransactionsWrapper, {}) })) })));
4325
- }
4326
- function TransactionsWrapper() {
4327
- var _a = React.useContext(TransactionsListContext), kindsToShow = _a.kindsToShow, filterFromContext = _a.filter;
4328
- var _b = React.useContext(BunnyContext), token = _b.token, subdomain = _b.subdomain;
4329
- // Local state
4330
- var _c = React.useState(""), search = _c[0], setSearch = _c[1];
4331
- var filter = filterFromContext ||
4332
- (search ? "filter: \"transaction.transactionableId is ".concat(search, "\"") : "");
4384
+ var isMobile = useIsMobile(window);
4385
+ var topNavImageUrl = React.useContext(BrandContext).topNavImageUrl;
4386
+ var entityId = common.useCurrentUserData().entityId;
4387
+ var _c = React.useState(undefined), quote = _c[0], setQuote = _c[1];
4388
+ var _d = React.useState(undefined), accountId = _d[0], setAccountId = _d[1];
4389
+ var _e = React.useState(undefined), quoteId = _e[0], setQuoteId = _e[1];
4390
+ var _f = React.useState(undefined), portalSessionToken = _f[0], setPortalSessionToken = _f[1];
4391
+ var _g = React.useState(undefined), formData = _g[0], setFormData = _g[1];
4392
+ var _h = React.useState(false), proceedingToPayment = _h[0], setProceedingToPayment = _h[1];
4393
+ var _j = React.useState(false), paying = _j[0], setIsPaying = _j[1];
4394
+ var _k = React.useState(false), purchaseSucceeded = _k[0], setPurchaseSucceeded = _k[1];
4333
4395
  // Queries
4334
- var data = reactQuery.useQuery({
4335
- queryKey: ["transactions", token, filter],
4336
- queryFn: function () { return getTransactions(filter, token, subdomain, kindsToShow); },
4337
- placeholderData: reactQuery.keepPreviousData,
4396
+ var priceListData = reactQuery.useQuery({
4397
+ queryKey: ["priceList", priceListCode],
4398
+ queryFn: function () { return getPriceList({ token: token, subdomain: subdomain, code: priceListCode }); },
4338
4399
  }).data;
4339
- return (jsxRuntime.jsx(TransactionsDisplay, { transactions: data, onSearchValueChanged: setSearch, search: search }));
4340
- }
4341
- function TransactionsDisplay(_a) {
4342
- var transactions = _a.transactions, onSearchValueChanged = _a.onSearchValueChanged, search = _a.search, title = _a.title;
4343
- var _b = React.useContext(TransactionsListContext), showSearchBar = _b.showSearchBar, showTitle = _b.showTitle, transactionComponent = _b.transactionComponent, useModal = _b.useModal, suppressTransactionDisplay = _b.suppressTransactionDisplay, className = _b.className, shadow = _b.shadow, searchBarClassName = _b.searchBarClassName, style = _b.style, onTransactionClick = _b.onTransactionClick;
4344
- var columns = React.useContext(TransactionsListContext).columns;
4345
- var darkMode = React.useContext(BunnyContext).darkMode;
4346
- // Local state
4347
- var _c = React.useState(null), selectedTransaction = _c[0], setSelectedTransaction = _c[1];
4348
- var _d = React.useState(false), drawerOpen = _d[0], setDrawerOpen = _d[1];
4349
- // Hooks
4350
- var isMobile = common.useIsMobile();
4351
- function handleTransactionClick(transaction) {
4352
- if (onTransactionClick) {
4353
- onTransactionClick(transaction);
4354
- }
4355
- if (!suppressTransactionDisplay) {
4356
- setSelectedTransaction(transaction);
4357
- setDrawerOpen(true);
4358
- }
4400
+ function handleSubmit(formData) {
4401
+ return __awaiter(this, void 0, void 0, function () {
4402
+ var data, portalSessionToken;
4403
+ return __generator(this, function (_a) {
4404
+ switch (_a.label) {
4405
+ case 0:
4406
+ setProceedingToPayment(true);
4407
+ setFormData(formData);
4408
+ return [4 /*yield*/, quoteAccountSignup({
4409
+ token: token,
4410
+ subdomain: subdomain,
4411
+ entityId: entityId,
4412
+ priceListCode: priceListCode,
4413
+ accountName: formData.accountName,
4414
+ billingContact: {
4415
+ firstName: formData.firstName,
4416
+ lastName: formData.lastName,
4417
+ email: formData.email,
4418
+ },
4419
+ })];
4420
+ case 1:
4421
+ data = _a.sent();
4422
+ setAccountId(data.account.id);
4423
+ return [4 /*yield*/, portalSessionCreate({
4424
+ token: token,
4425
+ subdomain: subdomain,
4426
+ tenantCode: data.tenant.code,
4427
+ expiry: 24,
4428
+ returnUrl: returnUrl || "",
4429
+ })];
4430
+ case 2:
4431
+ portalSessionToken = _a.sent();
4432
+ setPortalSessionToken(portalSessionToken);
4433
+ setQuoteId(data.quote.id);
4434
+ setProceedingToPayment(false);
4435
+ setQuote({
4436
+ amountDue: data.quote.amountDue,
4437
+ currencyId: data.quote.currencyId,
4438
+ });
4439
+ return [2 /*return*/];
4440
+ }
4441
+ });
4442
+ });
4443
+ }
4444
+ function handlePaymentSaveSuccess(paymentSuccess) {
4445
+ var _a;
4446
+ return __awaiter(this, void 0, void 0, function () {
4447
+ var response, plugin;
4448
+ return __generator(this, function (_b) {
4449
+ switch (_b.label) {
4450
+ case 0:
4451
+ if (!formData) {
4452
+ throw new Error("Form data is required");
4453
+ }
4454
+ response = paymentSuccess.pluginPaymentResponse;
4455
+ plugin = response === null || response === void 0 ? void 0 : response.plugin;
4456
+ if (!(plugin === null || plugin === void 0 ? void 0 : plugin.id)) {
4457
+ throw new Error("Plugin ID is required");
4458
+ }
4459
+ if (!accountId) {
4460
+ throw new Error("Account ID is required");
4461
+ }
4462
+ if (!portalSessionToken) {
4463
+ throw new Error("Portal session token is required");
4464
+ }
4465
+ return [4 /*yield*/, accountSignup({
4466
+ token: portalSessionToken,
4467
+ subdomain: subdomain,
4468
+ entityId: entityId,
4469
+ quoteId: quoteId,
4470
+ paymentMethodId: (_a = paymentSuccess.savedPaymentMethodResponse) === null || _a === void 0 ? void 0 : _a.paymentMethodId.toString(),
4471
+ pluginId: plugin.id.toString(),
4472
+ priceListCode: priceListCode,
4473
+ accountId: accountId,
4474
+ })];
4475
+ case 1:
4476
+ _b.sent();
4477
+ setIsPaying(false);
4478
+ setPurchaseSucceeded(true);
4479
+ return [2 /*return*/];
4480
+ }
4481
+ });
4482
+ });
4483
+ }
4484
+ function handlePaymentFail(error) {
4485
+ showErrorNotification(error.message);
4486
+ setIsPaying(false);
4487
+ }
4488
+ if (isMobile) {
4489
+ return (jsxRuntime.jsx(Card, __assign({ className: "p-4 flex flex-col" }, { children: purchaseSucceeded ? (jsxRuntime.jsx(PaymentSuccessDisplay, { className: "w-full", amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, returnUrl: returnUrl })) : (jsxRuntime.jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex flex-col items-center" }, { children: jsxRuntime.jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsxRuntime.jsx("div", __assign({ className: "mx-8" }, { children: jsxRuntime.jsx(antd.Divider, { className: "h-full" }) })), jsxRuntime.jsx("div", __assign({ className: "flex items-center justify-center my-12" }, { children: jsxRuntime.jsx(PaymentForms, { quote: quote, paying: paying, setIsPaying: setIsPaying, handlePaymentSaveSuccess: handlePaymentSaveSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId || "" }) }))] }))) })));
4490
+ }
4491
+ else {
4492
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Card, __assign({ className: "p-4 flex flex-col w-screen h-screen" }, { children: purchaseSucceeded ? (jsxRuntime.jsx(PaymentSuccessDisplay, { className: "w-full", amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, returnUrl: returnUrl })) : (jsxRuntime.jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex flex-col w-1/2 items-center" }, { children: jsxRuntime.jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsxRuntime.jsx("div", __assign({ className: "my-4" }, { children: jsxRuntime.jsx(antd.Divider, { className: "h-full", type: "vertical" }) })), jsxRuntime.jsx("div", __assign({ className: "flex w-1/2 items-center justify-center my-12" }, { children: jsxRuntime.jsx(PaymentForms, { quote: quote, paying: paying, setIsPaying: setIsPaying, handlePaymentSaveSuccess: handlePaymentSaveSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId || "" }) }))] }))) })), jsxRuntime.jsx(Footer, {})] }));
4359
4493
  }
4360
- // Since the columns are dynamic, we need to calculate the grid template columns
4361
- var gridTemplateColumns = function () {
4362
- var templateColumns = [];
4363
- if (isMobile) {
4364
- if (columns.includes("date-and-title") ||
4365
- columns.includes("state") ||
4366
- columns.includes("amount")) {
4367
- templateColumns.push("auto");
4368
- }
4369
- if (columns.includes("download")) {
4370
- templateColumns.push("auto");
4371
- }
4372
- }
4373
- else {
4374
- if (columns.includes("date-and-title")) {
4375
- templateColumns.push("auto 3fr");
4376
- }
4377
- if (columns.includes("download")) {
4378
- templateColumns.push("auto");
4379
- }
4380
- if (columns.includes("state")) {
4381
- templateColumns.push("auto");
4382
- }
4383
- if (columns.includes("amount")) {
4384
- templateColumns.push("auto");
4385
- }
4386
- }
4387
- return templateColumns.join(" ");
4388
- };
4389
- var drawerTitle = function () {
4390
- if (!selectedTransaction)
4391
- return "";
4392
- var kind = selectedTransaction.kind.toLowerCase();
4393
- return kind.charAt(0).toUpperCase() + kind.slice(1);
4394
- };
4395
- return (jsxRuntime.jsxs("div", __assign({ style: style }, { children: [jsxRuntime.jsx(PageHeaderWithActions, __assign({ title: title || (showTitle ? "Past transactions" : undefined) }, { children: showSearchBar && (jsxRuntime.jsx("div", { children: jsxRuntime.jsx(antd.Input, { className: searchBarClassName
4396
- ? searchBarClassName
4397
- : "border border-slate-200", onChange: function (e) {
4398
- if (isNaN(Number(e.target.value))) {
4399
- return;
4400
- }
4401
- onSearchValueChanged(e.target.value);
4402
- }, prefix: jsxRuntime.jsx(SearchOutlined$1, {}), placeholder: "Search by id #", style: {
4403
- minWidth: "300px",
4404
- }, value: search }) })) })), jsxRuntime.jsx(PageContent, __assign({ className: "flex w-full shadow-padding-xb ".concat(isMobile ? "overflow-hidden" : "", " ").concat(className) }, { children: jsxRuntime.jsx("div", __assign({ className: "grid w-full rounded-md overflow-auto ".concat("shadow-".concat(shadow)), style: {
4405
- gridTemplateColumns: gridTemplateColumns(),
4406
- backgroundColor: "var(--row-background".concat(darkMode ? "-dark" : "", ")"),
4407
- } }, { children: isMobile ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: TransactionsListMobile({
4408
- transactions: transactions,
4409
- onTransactionClick: handleTransactionClick,
4410
- }) })) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: TransactionsListDesktop({
4411
- transactions: transactions,
4412
- onTransactionClick: handleTransactionClick,
4413
- }) })) })) })), useModal ? (jsxRuntime.jsx(antd.Modal, __assign({ title: "Basic Modal", open: drawerOpen, onOk: function () { return setDrawerOpen(false); }, onCancel: function () { return setDrawerOpen(false); }, width: 900, footer: null }, { children: jsxRuntime.jsx(Invoice, { id: (selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.transactionableId) || "" }) }))) : (jsxRuntime.jsx(antd.Drawer, __assign({ title: drawerTitle(), onClose: function () { return setDrawerOpen(false); }, open: drawerOpen, width: 900 }, { children: transactionComponent ? (transactionComponent) : (selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.kind) === "INVOICE" ? (jsxRuntime.jsx(Invoice, { id: selectedTransaction.transactionableId })) : (jsxRuntime.jsxs(antd.Card, __assign({ className: "shadow-md" }, { children: [jsxRuntime.jsx(antd.Typography.Title, __assign({ level: 2, className: "mb-4" }, { children: "Transaction Details" })), jsxRuntime.jsxs(antd.Typography.Paragraph, { children: [jsxRuntime.jsx("strong", { children: "Amount:" }), " ", jsxRuntime.jsx(antd.Typography.Text, { children: common.Misc.formatCurrency((selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.amount) || 0, (selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.currencyId) || "USD") })] }), jsxRuntime.jsxs(antd.Typography.Paragraph, { children: [jsxRuntime.jsx("strong", { children: "Description:" }), " ", jsxRuntime.jsx(antd.Typography.Text, { children: selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.description })] }), jsxRuntime.jsxs(antd.Typography.Paragraph, { children: [jsxRuntime.jsx("strong", { children: "Kind:" }), " ", jsxRuntime.jsx(antd.Typography.Text, { children: selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.kind })] }), jsxRuntime.jsxs(antd.Typography.Paragraph, { children: [jsxRuntime.jsx("strong", { children: "State:" }), " ", jsxRuntime.jsx(antd.Typography.Text, { children: selectedTransaction === null || selectedTransaction === void 0 ? void 0 : selectedTransaction.state })] })] }))) })))] })));
4414
4494
  }
4415
4495
 
4416
4496
  var updatingChargeQuantityIdState = recoil.atom({
@@ -5538,6 +5618,7 @@ exports.Checkout = Checkout;
5538
5618
  exports.Invoice = Invoice;
5539
5619
  exports.PaymentMethod = PaymentMethod;
5540
5620
  exports.Quote = Quote;
5621
+ exports.Quotes = Quotes;
5541
5622
  exports.Signup = Signup;
5542
5623
  exports.Subscriptions = Subscriptions;
5543
5624
  exports.Transactions = Transactions;