@mx-cartographer/experiences 9.7.133 → 9.7.134

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/core/types/Insights.d.ts +1 -0
  3. package/dist/core/types/Insights.es.js.map +1 -1
  4. package/dist/core/types/localization/InsightsFeedCopy.d.ts +17 -0
  5. package/dist/insights/components/insights/BillAmountNotStandard/BillAmountNotStandard.es.js +4 -4
  6. package/dist/insights/components/insights/BillAmountNotStandard/BillAmountNotStandardMUI.es.js +4 -4
  7. package/dist/insights/components/insights/MonthlySpendingComparisonV2/MonthlySpendingComparisonV2.es.js +4 -4
  8. package/dist/insights/components/insights/WeeklyNoSpendDays/WeeklyNoSpendDays.es.js +8 -8
  9. package/dist/insights/components/shared/Charts/EmptyBarChart.es.js +4 -4
  10. package/dist/insights/components/shared/ZeroState/LinedCardZeroState.es.js +4 -4
  11. package/dist/insights/index.es.js +84 -84
  12. package/dist/insights-v2/actionBlocks/QuizMerchantBlock/QuizMerchantBlock.d.ts +7 -0
  13. package/dist/insights-v2/actionBlocks/QuizMerchantBlock/QuizMerchantBlock.es.js +147 -0
  14. package/dist/insights-v2/actionBlocks/QuizMerchantBlock/QuizMerchantBlock.es.js.map +1 -0
  15. package/dist/insights-v2/actionBlocks/QuizMerchantBlock/index.d.ts +1 -0
  16. package/dist/insights-v2/blocks/ComponentBlocks/QuizBlock/QuizBlock.d.ts +6 -0
  17. package/dist/insights-v2/blocks/ComponentBlocks/QuizBlock/QuizBlock.es.js +220 -0
  18. package/dist/insights-v2/blocks/ComponentBlocks/QuizBlock/QuizBlock.es.js.map +1 -0
  19. package/dist/insights-v2/blocks/ComponentBlocks/QuizBlock/index.d.ts +1 -0
  20. package/dist/insights-v2/blocks/ComponentBlocks/QuizBlock/quiz.d.ts +39 -0
  21. package/dist/insights-v2/blocks/ComponentBlocks/QuizBlock/quiz.es.js +44 -0
  22. package/dist/insights-v2/blocks/ComponentBlocks/QuizBlock/quiz.es.js.map +1 -0
  23. package/dist/insights-v2/blocks/ComponentBlocks/index.d.ts +1 -0
  24. package/dist/insights-v2/components/shared/elevation.d.ts +2 -0
  25. package/dist/insights-v2/components/shared/elevation.es.js +3 -2
  26. package/dist/insights-v2/components/shared/elevation.es.js.map +1 -1
  27. package/dist/insights-v2/ctaActions/ctaConfig.es.js +41 -23
  28. package/dist/insights-v2/ctaActions/ctaConfig.es.js.map +1 -1
  29. package/dist/insights-v2/ctaActions/ctaHandlers.d.ts +2 -0
  30. package/dist/insights-v2/ctaActions/ctaHandlers.es.js +32 -20
  31. package/dist/insights-v2/ctaActions/ctaHandlers.es.js.map +1 -1
  32. package/dist/insights-v2/ctaActions/hostActions.d.ts +1 -1
  33. package/dist/insights-v2/ctaActions/hostActions.es.js.map +1 -1
  34. package/dist/insights-v2/index.es.js +79 -77
  35. package/dist/insights-v2/mappings/actionBlocksKey.d.ts +1 -0
  36. package/dist/insights-v2/mappings/actionBlocksKey.es.js +2 -1
  37. package/dist/insights-v2/mappings/actionBlocksKey.es.js.map +1 -1
  38. package/dist/insights-v2/mappings/blocks.es.js +122 -114
  39. package/dist/insights-v2/mappings/blocks.es.js.map +1 -1
  40. package/package.json +1 -1
@@ -0,0 +1,147 @@
1
+ import { buildDynamicCopy as S } from "../../../core/utils/Localization.es.js";
2
+ import { DATE_FORMATS_INTL as v } from "../../../core/constants/DateFormats.es.js";
3
+ import { useActionContext as D, useGlobalCopyStore as L, useInsightsV2Store as k, useTransactionStore as I } from "../../../common/context/hooks.es.js";
4
+ import { TransactionType as R } from "../../../core/types/Transaction.es.js";
5
+ import { formatIsoDate as O } from "../../../core/utils/DateUtil.es.js";
6
+ import { CURRENCY_FORMAT as A, formatCurrency as w } from "../../../core/utils/NumberFormatting.es.js";
7
+ import z from "../../../common/components/drawer/Drawer.es.js";
8
+ import M from "../../../transactions/components/shared/TransactionList.es.js";
9
+ import { merchantTransactions as B, quizMerchantLogo as F } from "../../blocks/ComponentBlocks/QuizBlock/quiz.es.js";
10
+ import { selectTransactionsByGuids as G } from "../../CommonUtils.es.js";
11
+ import N from "../../components/LogoFromGuid.es.js";
12
+ import { SMALL_CARD_SHADOW as q } from "../../components/shared/elevation.es.js";
13
+ import { calendarDateOf as E } from "../TransactionHistoryBlock/utils.es.js";
14
+ import { TransactionDetailsBlock as W } from "../TransactionDetailsBlock/TransactionDetailsBlock.es.js";
15
+ import $ from "react";
16
+ import { observer as j } from "mobx-react-lite";
17
+ import i from "@mui/material/Stack";
18
+ import { Text as s } from "@mxenabled/mxui";
19
+ import { Icon as H } from "@mxenabled/mx-icons";
20
+ import { Fragment as Q, jsx as o, jsxs as t } from "react/jsx-runtime";
21
+ import f from "@mui/material/Box";
22
+ import U from "@mui/material/Divider";
23
+ var V = (a) => a.reduce((r, { amount: e, transaction_type: c }) => c === R.CREDIT ? r - e : r + e, 0), x = ({ icon: a, label: r, value: e }) => /* @__PURE__ */ t(i, {
24
+ sx: {
25
+ flex: 1,
26
+ gap: 4,
27
+ minWidth: 0,
28
+ px: 12,
29
+ py: 6
30
+ },
31
+ children: [/* @__PURE__ */ o(s, {
32
+ component: "p",
33
+ variant: "h3",
34
+ children: e
35
+ }), /* @__PURE__ */ t(i, {
36
+ direction: "row",
37
+ sx: {
38
+ alignItems: "center",
39
+ color: "text.secondary",
40
+ gap: 4
41
+ },
42
+ children: [/* @__PURE__ */ o(H, {
43
+ "aria-hidden": !0,
44
+ name: a,
45
+ size: 12
46
+ }), /* @__PURE__ */ o(s, {
47
+ color: "text.secondary",
48
+ sx: { letterSpacing: "0.33px" },
49
+ uppercase: !0,
50
+ variant: "caption",
51
+ children: r
52
+ })]
53
+ })]
54
+ }), go = j(function({ beat: r }) {
55
+ const { common: e, insights_feed: c } = L(), l = c?.quiz_block, { setActionContext: p } = k(), m = I(), n = D()?.quiz_merchant, [g, h] = $.useState(!1);
56
+ if (!n) return null;
57
+ const d = B(G(m.detailedTransactions, r.transaction_guids), n), u = E(r.payload?.described_month), T = S(l?.placement ?? "", String(n.rank), u ? O(u, v.MONTH_LONG) : ""), _ = F(n, d), C = (y) => {
58
+ p({ transaction_guid: y }), h(!0);
59
+ }, b = () => {
60
+ h(!1), p({ transaction_guid: void 0 });
61
+ };
62
+ return /* @__PURE__ */ t(Q, { children: [
63
+ /* @__PURE__ */ o(f, {
64
+ sx: {
65
+ pb: 8,
66
+ pt: 24,
67
+ px: 24
68
+ },
69
+ children: /* @__PURE__ */ t(i, {
70
+ sx: {
71
+ bgcolor: "background.paper",
72
+ borderRadius: "8px",
73
+ boxShadow: q,
74
+ gap: 12,
75
+ p: 16
76
+ },
77
+ children: [/* @__PURE__ */ t(i, {
78
+ direction: "row",
79
+ sx: {
80
+ alignItems: "center",
81
+ gap: 12
82
+ },
83
+ children: [/* @__PURE__ */ o(f, {
84
+ "aria-hidden": !0,
85
+ sx: {
86
+ display: "flex",
87
+ flexShrink: 0
88
+ },
89
+ children: /* @__PURE__ */ o(N, {
90
+ logo: _,
91
+ size: 56
92
+ })
93
+ }), /* @__PURE__ */ t(i, {
94
+ sx: { minWidth: 0 },
95
+ children: [/* @__PURE__ */ o(s, {
96
+ component: "h3",
97
+ truncate: !0,
98
+ variant: "h2",
99
+ children: n.label
100
+ }), /* @__PURE__ */ o(s, {
101
+ color: "text.secondary",
102
+ variant: "subtitle2",
103
+ children: T
104
+ })]
105
+ })]
106
+ }), /* @__PURE__ */ t(i, {
107
+ direction: "row",
108
+ divider: /* @__PURE__ */ o(U, {
109
+ flexItem: !0,
110
+ orientation: "vertical"
111
+ }),
112
+ sx: {
113
+ border: 1,
114
+ borderColor: "divider",
115
+ borderRadius: "4px"
116
+ },
117
+ children: [/* @__PURE__ */ o(x, {
118
+ icon: "receipt_long",
119
+ label: l?.transactions ?? "",
120
+ value: String(n.count)
121
+ }), /* @__PURE__ */ o(x, {
122
+ icon: "payments",
123
+ label: l?.spent ?? "",
124
+ value: m.isTransactionDataLoaded ? w(V(d), A.cents) : "—"
125
+ })]
126
+ })]
127
+ })
128
+ }),
129
+ /* @__PURE__ */ o(M, {
130
+ onClick: C,
131
+ showLoader: !m.isTransactionDataLoaded,
132
+ transaction: d
133
+ }),
134
+ /* @__PURE__ */ o(z, {
135
+ ariaLabelClose: e.close_aria,
136
+ isOpen: g,
137
+ onClose: b,
138
+ title: c?.general.transaction_details_title,
139
+ children: /* @__PURE__ */ o(W, { beat: r })
140
+ })
141
+ ] });
142
+ });
143
+ export {
144
+ go as QuizMerchantBlock
145
+ };
146
+
147
+ //# sourceMappingURL=QuizMerchantBlock.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuizMerchantBlock.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/QuizMerchantBlock/QuizMerchantBlock.tsx"],"sourcesContent":["import React from 'react'\n\nimport Box from '@mui/material/Box'\nimport Divider from '@mui/material/Divider'\nimport Stack from '@mui/material/Stack'\n\nimport { Icon } from '@mxenabled/mx-icons'\nimport { Text } from '@mxenabled/mxui'\nimport { observer } from 'mobx-react-lite'\n\nimport {\n Drawer,\n useActionContext,\n useGlobalCopyStore,\n useInsightsV2Store,\n useTransactionStore,\n} from '../../../common'\nimport { DATE_FORMATS_INTL } from '../../../core/constants'\nimport { TransactionType, type Beat, type Transaction } from '../../../core'\nimport { formatIsoDate } from '../../../core/utils/DateUtil'\nimport { buildDynamicCopy } from '../../../core/utils/Localization'\nimport { CURRENCY_FORMAT, formatCurrency } from '../../../core/utils/NumberFormatting'\nimport { TransactionList } from '../../../transactions'\nimport { selectTransactionsByGuids } from '../../CommonUtils'\nimport { calendarDateOf } from '../TransactionHistoryBlock/utils'\nimport LogoFromGuid from '../../components/LogoFromGuid'\nimport { SMALL_CARD_SHADOW } from '../../components/shared/elevation'\nimport {\n merchantTransactions,\n quizMerchantLogo,\n type QuizDrawerContext,\n} from '../../blocks/ComponentBlocks/QuizBlock/quiz'\nimport { TransactionDetailsBlock } from '../TransactionDetailsBlock'\n\n/** Spending is positive; a credit (a refund) takes away from it. */\nconst totalSpent = (transactions: Transaction[]) =>\n transactions.reduce(\n (sum, { amount, transaction_type }) =>\n transaction_type === TransactionType.CREDIT ? sum - amount : sum + amount,\n 0,\n )\n\nconst StatTile = ({ icon, label, value }: { icon: string; label: string; value: string }) => (\n <Stack sx={{ flex: 1, gap: 4, minWidth: 0, px: 12, py: 6 }}>\n <Text component=\"p\" variant=\"h3\">\n {value}\n </Text>\n <Stack direction=\"row\" sx={{ alignItems: 'center', color: 'text.secondary', gap: 4 }}>\n <Icon aria-hidden={true} name={icon} size={12} />\n <Text\n color=\"text.secondary\"\n sx={{ letterSpacing: '0.33px' }}\n uppercase={true}\n variant=\"caption\"\n >\n {label}\n </Text>\n </Stack>\n </Stack>\n)\n\n/** The drawer a quiz result row opens: the merchant's rank, totals and transactions. */\nexport const QuizMerchantBlock = observer(function QuizMerchantBlock({ beat }: { beat: Beat }) {\n const { common: commonCopy, insights_feed: insightsCopy } = useGlobalCopyStore()\n const copy = insightsCopy?.quiz_block\n const { setActionContext } = useInsightsV2Store()\n const transactionStore = useTransactionStore()\n const merchant = useActionContext<QuizDrawerContext>()?.quiz_merchant\n const [isDetailsOpen, setIsDetailsOpen] = React.useState(false)\n\n if (!merchant) return null\n\n const transactions = merchantTransactions(\n selectTransactionsByGuids(transactionStore.detailedTransactions, beat.transaction_guids),\n merchant,\n )\n const month = calendarDateOf(beat.payload?.described_month)\n const placement = buildDynamicCopy(\n copy?.placement ?? '',\n String(merchant.rank),\n month ? formatIsoDate(month, DATE_FORMATS_INTL.MONTH_LONG) : '',\n ) as string\n const logo = quizMerchantLogo(merchant, transactions)\n\n const handleRowClick = (guid: string) => {\n setActionContext({ transaction_guid: guid })\n setIsDetailsOpen(true)\n }\n\n const handleDetailsClose = () => {\n setIsDetailsOpen(false)\n setActionContext({ transaction_guid: undefined })\n }\n\n return (\n <>\n <Box sx={{ pb: 8, pt: 24, px: 24 }}>\n <Stack\n sx={{\n bgcolor: 'background.paper',\n borderRadius: '8px',\n boxShadow: SMALL_CARD_SHADOW,\n gap: 12,\n p: 16,\n }}\n >\n <Stack direction=\"row\" sx={{ alignItems: 'center', gap: 12 }}>\n <Box aria-hidden={true} sx={{ display: 'flex', flexShrink: 0 }}>\n <LogoFromGuid logo={logo} size={56} />\n </Box>\n <Stack sx={{ minWidth: 0 }}>\n <Text component=\"h3\" truncate={true} variant=\"h2\">\n {merchant.label}\n </Text>\n <Text color=\"text.secondary\" variant=\"subtitle2\">\n {placement}\n </Text>\n </Stack>\n </Stack>\n <Stack\n direction=\"row\"\n divider={<Divider flexItem={true} orientation=\"vertical\" />}\n sx={{ border: 1, borderColor: 'divider', borderRadius: '4px' }}\n >\n <StatTile\n icon=\"receipt_long\"\n label={copy?.transactions ?? ''}\n value={String(merchant.count)}\n />\n <StatTile\n icon=\"payments\"\n label={copy?.spent ?? ''}\n value={\n transactionStore.isTransactionDataLoaded\n ? formatCurrency(totalSpent(transactions), CURRENCY_FORMAT.cents)\n : '—'\n }\n />\n </Stack>\n </Stack>\n </Box>\n <TransactionList\n onClick={handleRowClick}\n showLoader={!transactionStore.isTransactionDataLoaded}\n transaction={transactions}\n />\n <Drawer\n ariaLabelClose={commonCopy.close_aria}\n isOpen={isDetailsOpen}\n onClose={handleDetailsClose}\n title={insightsCopy?.general.transaction_details_title}\n >\n <TransactionDetailsBlock beat={beat} />\n </Drawer>\n </>\n )\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAM,IAAA,CAAc,MAClB,EAAa,OAAA,CACV,GAAK,EAAE,QAAA,GAAQ,kBAAA,EAAA,MACd,MAAqB,EAAgB,SAAS,IAAM,IAAS,IAAM,GACrE,CACF,GAEI,IAAA,CAAY,EAAE,MAAA,GAAM,OAAA,GAAO,OAAA,EAAA,MAC/B,gBAAA,EAAC,GAAD;AAAA,EAAO,IAAI;AAAA,IAAE,MAAM;AAAA,IAAG,KAAK;AAAA,IAAG,UAAU;AAAA,IAAG,IAAI;AAAA,IAAI,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;AAAA,YAAE,QAAQ;AAAA,YAAG,aAAa;AAAA,YAAW,cAAc;AAAA,UAAM;AAAA,UAH/D,UAAA,CAKE,gBAAA,EAAC,GAAD;AAAA,YACE,MAAK;AAAA,YACL,OAAO,GAAM,gBAAgB;AAAA,YAC7B,OAAO,OAAO,EAAS,KAAK;AAAA,UAC7B,CAAA,GACD,gBAAA,EAAC,GAAD;AAAA,YACE,MAAK;AAAA,YACL,OAAO,GAAM,SAAS;AAAA,YACtB,OACE,EAAiB,0BACb,EAAe,EAAW,CAAY,GAAG,EAAgB,KAAK,IAC9D;AAAA,UAEP,CAAA,CACI;AAAA,QACF,CAAA,CAAA;AAAA;IACJ,CAAA;AAAA,IACL,gBAAA,EAAC,GAAD;AAAA,MACE,SAAS;AAAA,MACT,YAAY,CAAC,EAAiB;AAAA,MAC9B,aAAa;AAAA,IACd,CAAA;AAAA,IACD,gBAAA,EAAC,GAAD;AAAA,MACE,gBAAgB,EAAW;AAAA,MAC3B,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,OAAO,GAAc,QAAQ;AAAA,MAE7B,UAAA,gBAAA,EAAC,GAAD,EAA+B,MAAA,EAAO,CAAA;AAAA,IAChC,CAAA;AAAA,EACR,EAAA,CAAA;AAEN,CAAC"}
@@ -0,0 +1 @@
1
+ export { QuizMerchantBlock } from './QuizMerchantBlock';
@@ -0,0 +1,6 @@
1
+ import { BlockProps } from '../../types';
2
+ /** Monthly Top Transacted Merchant quiz; its progress lives in beat context for the quiz CTAs. */
3
+ declare const QuizBlock: (({ beatGuid, payload }: BlockProps) => import("react/jsx-runtime").JSX.Element) & {
4
+ displayName: string;
5
+ };
6
+ export default QuizBlock;
@@ -0,0 +1,220 @@
1
+ import { buildDynamicCopy as L, buildPluralCopy as y } from "../../../../core/utils/Localization.es.js";
2
+ import { useGlobalCopyStore as B, useInsightsV2Store as M, useTransactionStore as D } from "../../../../common/context/hooks.es.js";
3
+ import { QUIZ_CONTEXT as c, QUIZ_VARIANTS as O, isTopMerchant as K, merchantKey as S, quizMerchantLogo as q, rankQuizMerchants as Q, readQuizMerchants as W } from "./quiz.es.js";
4
+ import { actionBlocksKey as F } from "../../../mappings/actionBlocksKey.es.js";
5
+ import Z from "../../../components/LogoFromGuid.es.js";
6
+ import { ConfettiOverlay as N } from "../../../components/shared/ConfettiOverlay.es.js";
7
+ import { SMALL_CARD_SHADOW as U } from "../../../components/shared/elevation.es.js";
8
+ import V from "../../../components/LogoTile.es.js";
9
+ import { LinedCardZeroState as j } from "../../../../insights/components/shared/ZeroState/LinedCardZeroState.es.js";
10
+ import { useEffect as E, useState as H } from "react";
11
+ import { observer as A } from "mobx-react-lite";
12
+ import a from "@mui/material/Stack";
13
+ import { Text as d } from "@mxenabled/mxui";
14
+ import { Icon as I } from "@mxenabled/mx-icons";
15
+ import { jsx as r, jsxs as p } from "react/jsx-runtime";
16
+ import { alpha as _ } from "@mui/material/styles";
17
+ import P from "@mui/material/Radio";
18
+ import $ from "@mui/material/ButtonBase";
19
+ var X = 3e3, z = 32, T = {
20
+ alignItems: "center",
21
+ border: 1,
22
+ borderColor: "divider",
23
+ borderRadius: "8px",
24
+ gap: 12,
25
+ height: 50,
26
+ pl: 8,
27
+ width: "100%"
28
+ }, G = (o) => o.map((e) => ({
29
+ item: e,
30
+ order: Math.random()
31
+ })).sort((e, t) => e.order - t.order).map(({ item: e }) => e), R = A(({ merchant: o }) => {
32
+ const { detailedTransactions: e } = D(), t = {
33
+ ...q(o, e),
34
+ alt: ""
35
+ };
36
+ return /* @__PURE__ */ r(V, {
37
+ borderColor: null,
38
+ borderRadius: 4,
39
+ size: z,
40
+ sx: {
41
+ position: "relative",
42
+ textAlign: "left"
43
+ },
44
+ children: /* @__PURE__ */ r(Z, {
45
+ logo: t,
46
+ size: z
47
+ })
48
+ });
49
+ }), J = ({ correct: o, copy: e }) => /* @__PURE__ */ p(a, {
50
+ role: "status",
51
+ sx: {
52
+ alignItems: "center",
53
+ backdropFilter: o ? void 0 : "blur(6px)",
54
+ bgcolor: (t) => o ? "success.main" : _(t.palette.common.black, 0.5),
55
+ borderRadius: "8px",
56
+ boxShadow: o ? U : void 0,
57
+ color: o ? "success.contrastText" : "common.white",
58
+ gap: 18,
59
+ inset: 16,
60
+ justifyContent: "center",
61
+ p: 16,
62
+ position: "absolute",
63
+ zIndex: 2
64
+ },
65
+ children: [/* @__PURE__ */ r(I, {
66
+ "aria-hidden": !0,
67
+ fill: !0,
68
+ name: o ? "check_circle" : "cancel",
69
+ size: 56
70
+ }), /* @__PURE__ */ r(d, {
71
+ component: "p",
72
+ sx: {
73
+ color: "inherit",
74
+ textAlign: "center"
75
+ },
76
+ variant: "h2",
77
+ children: o ? e?.nailed_it : e?.not_quite
78
+ })]
79
+ }), Y = ({ copy: o, merchant: e, onClick: t }) => {
80
+ const l = o ? y(o.transaction_count_one, o.transaction_count, e.count, String(e.count)) : "", f = o ? L(o.rank_aria, String(e.rank), e.label, l) : e.label;
81
+ return /* @__PURE__ */ p(a, {
82
+ "aria-label": f,
83
+ component: $,
84
+ direction: "row",
85
+ onClick: t,
86
+ sx: {
87
+ ...T,
88
+ pr: 8
89
+ },
90
+ children: [
91
+ /* @__PURE__ */ r(R, { merchant: e }),
92
+ /* @__PURE__ */ p(a, {
93
+ sx: {
94
+ flexGrow: 1,
95
+ minWidth: 0,
96
+ textAlign: "left"
97
+ },
98
+ children: [/* @__PURE__ */ r(d, {
99
+ bold: !0,
100
+ noWrap: !0,
101
+ variant: "body1",
102
+ children: e.label
103
+ }), l && /* @__PURE__ */ r(d, {
104
+ variant: "caption",
105
+ children: l
106
+ })]
107
+ }),
108
+ /* @__PURE__ */ r(d, {
109
+ bold: !0,
110
+ variant: "body1",
111
+ children: e.rank
112
+ }),
113
+ /* @__PURE__ */ r(I, {
114
+ "aria-hidden": !0,
115
+ name: "chevron_right",
116
+ size: 16,
117
+ sx: { color: "action.active" }
118
+ })
119
+ ]
120
+ });
121
+ }, vo = A(({ beatGuid: o = "", payload: e }) => {
122
+ const t = B().insights_feed?.quiz_block, { beatContext: l, openActionDrawer: f, setBeatContext: h } = M(), m = W(e.instance_slot.data), [w] = H(() => G(m)), g = l[o] ?? {}, x = g[c.PICK], v = !!g[c.CHECKED], k = e.instance_slot.variant === O.RESULTS || !!g[c.REVEALED], s = v && !k;
123
+ if (E(() => {
124
+ if (!s) return;
125
+ const n = setTimeout(() => h(o, { [c.REVEALED]: !0 }), X);
126
+ return () => clearTimeout(n);
127
+ }, [
128
+ o,
129
+ h,
130
+ s
131
+ ]), E(() => {
132
+ t || console.warn("quiz_block: copy namespace missing; rendering without its labels");
133
+ }, [t]), !m.length) return /* @__PURE__ */ r(j, {});
134
+ if (k) {
135
+ const n = (i) => f({
136
+ guid: o,
137
+ trigger: "inDescriptionCta",
138
+ cta: {
139
+ block: F.QUIZ_MERCHANT_ACTION_BLOCK,
140
+ variant: null
141
+ },
142
+ context: { quiz_merchant: i }
143
+ });
144
+ return /* @__PURE__ */ r(a, {
145
+ sx: {
146
+ gap: 12,
147
+ p: 16
148
+ },
149
+ children: Q(m).map((i) => /* @__PURE__ */ r(Y, {
150
+ copy: t,
151
+ merchant: i,
152
+ onClick: () => n(i)
153
+ }, S(i)))
154
+ });
155
+ }
156
+ const C = !!x && K(m, x ?? "");
157
+ return /* @__PURE__ */ p(a, {
158
+ sx: {
159
+ gap: 12,
160
+ p: 16,
161
+ position: "relative"
162
+ },
163
+ children: [
164
+ s && C && /* @__PURE__ */ r(N, {}),
165
+ s && /* @__PURE__ */ r(J, {
166
+ copy: t,
167
+ correct: C
168
+ }),
169
+ /* @__PURE__ */ r(a, {
170
+ "aria-label": e.title,
171
+ component: "fieldset",
172
+ sx: {
173
+ border: 0,
174
+ gap: 12,
175
+ m: 0,
176
+ p: 0,
177
+ visibility: s && C ? "hidden" : "visible"
178
+ },
179
+ children: w.map((n) => {
180
+ const i = S(n), u = i === x;
181
+ return /* @__PURE__ */ p(a, {
182
+ component: "label",
183
+ direction: "row",
184
+ sx: {
185
+ ...T,
186
+ bgcolor: (b) => u ? _(b.palette.primary.main, 0.16) : "background.paper",
187
+ borderColor: (b) => u ? _(b.palette.primary.main, 0.5) : b.palette.divider,
188
+ borderWidth: u ? 2 : 1,
189
+ cursor: v ? "default" : "pointer",
190
+ pr: 4
191
+ },
192
+ children: [
193
+ /* @__PURE__ */ r(R, { merchant: n }),
194
+ /* @__PURE__ */ r(d, {
195
+ bold: !0,
196
+ noWrap: !0,
197
+ sx: { flexGrow: 1 },
198
+ variant: "body1",
199
+ children: n.label
200
+ }),
201
+ /* @__PURE__ */ r(P, {
202
+ checked: u,
203
+ disabled: v,
204
+ name: `quiz-${o}`,
205
+ onChange: () => h(o, { [c.PICK]: i }),
206
+ size: "small",
207
+ value: i
208
+ })
209
+ ]
210
+ }, i);
211
+ })
212
+ })
213
+ ]
214
+ });
215
+ });
216
+ export {
217
+ vo as default
218
+ };
219
+
220
+ //# sourceMappingURL=QuizBlock.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuizBlock.es.js","names":[],"sources":["../../../../../src/insights-v2/blocks/ComponentBlocks/QuizBlock/QuizBlock.tsx"],"sourcesContent":["import { useEffect, useState } from 'react'\n\nimport ButtonBase from '@mui/material/ButtonBase'\nimport Radio from '@mui/material/Radio'\nimport Stack from '@mui/material/Stack'\nimport { alpha } from '@mui/material/styles'\n\nimport { Icon } from '@mxenabled/mx-icons'\nimport { Text } from '@mxenabled/mxui'\nimport { observer } from 'mobx-react-lite'\n\nimport { useGlobalCopyStore, useInsightsV2Store, useTransactionStore } from '../../../../common'\nimport type { QuizBlockCopy } from '../../../../core/types/localization/InsightsFeedCopy'\nimport { buildDynamicCopy, buildPluralCopy } from '../../../../core/utils/Localization'\nimport { LinedCardZeroState } from '../../../../insights/components/shared/ZeroState/LinedCardZeroState'\nimport LogoFromGuid from '../../../components/LogoFromGuid'\nimport LogoTile from '../../../components/LogoTile'\nimport { ConfettiOverlay } from '../../../components/shared/ConfettiOverlay'\nimport { SMALL_CARD_SHADOW } from '../../../components/shared/elevation'\nimport { actionBlocksKey } from '../../../mappings/actionBlocksKey'\nimport type { BlockProps } from '../../types'\nimport {\n QUIZ_CONTEXT,\n QUIZ_VARIANTS,\n isTopMerchant,\n merchantKey,\n quizMerchantLogo,\n rankQuizMerchants,\n readQuizMerchants,\n type QuizDrawerContext,\n type QuizMerchant,\n type RankedQuizMerchant,\n} from './quiz'\n\n/** How long the \"Nailed it!\" / \"Not quite...\" card shows before the results. */\nconst FEEDBACK_MS = 3000\n\nconst LOGO_SIZE = 32\nconst ROW_SX = {\n alignItems: 'center',\n border: 1,\n borderColor: 'divider',\n borderRadius: '8px',\n gap: 12,\n height: 50,\n pl: 8,\n width: '100%',\n} as const\n\nconst shuffle = <T,>(items: T[]) =>\n items\n .map((item) => ({ item, order: Math.random() }))\n .sort((a, b) => a.order - b.order)\n .map(({ item }) => item)\n\nconst MerchantLogo = observer(({ merchant }: { merchant: QuizMerchant }) => {\n const { detailedTransactions } = useTransactionStore()\n // Empty alt: the merchant's name sits beside it.\n const logo = { ...quizMerchantLogo(merchant, detailedTransactions), alt: '' }\n\n return (\n // mxui's MerchantLogo image is absolute with no left; a button row's centered text pushes it halfway out.\n <LogoTile\n borderColor={null}\n borderRadius={4}\n size={LOGO_SIZE}\n sx={{ position: 'relative', textAlign: 'left' }}\n >\n <LogoFromGuid logo={logo} size={LOGO_SIZE} />\n </LogoTile>\n )\n})\n\nconst FeedbackCard = ({ correct, copy }: { correct: boolean; copy?: QuizBlockCopy }) => (\n <Stack\n role=\"status\"\n sx={{\n alignItems: 'center',\n backdropFilter: correct ? undefined : 'blur(6px)',\n bgcolor: (theme) => (correct ? 'success.main' : alpha(theme.palette.common.black, 0.5)),\n borderRadius: '8px',\n boxShadow: correct ? SMALL_CARD_SHADOW : undefined,\n color: correct ? 'success.contrastText' : 'common.white',\n gap: 18,\n inset: 16,\n justifyContent: 'center',\n p: 16,\n position: 'absolute',\n zIndex: 2,\n }}\n >\n <Icon aria-hidden={true} fill={true} name={correct ? 'check_circle' : 'cancel'} size={56} />\n <Text component=\"p\" sx={{ color: 'inherit', textAlign: 'center' }} variant=\"h2\">\n {correct ? copy?.nailed_it : copy?.not_quite}\n </Text>\n </Stack>\n)\n\nconst ResultRow = ({\n copy,\n merchant,\n onClick,\n}: {\n copy?: QuizBlockCopy\n merchant: RankedQuizMerchant\n onClick: () => void\n}) => {\n const count = copy\n ? (buildPluralCopy(\n copy.transaction_count_one,\n copy.transaction_count,\n merchant.count,\n String(merchant.count),\n ) as string)\n : ''\n const label = copy\n ? (buildDynamicCopy(copy.rank_aria, String(merchant.rank), merchant.label, count) as string)\n : merchant.label\n\n return (\n <Stack\n aria-label={label}\n component={ButtonBase}\n direction=\"row\"\n onClick={onClick}\n sx={{ ...ROW_SX, pr: 8 }}\n >\n <MerchantLogo merchant={merchant} />\n <Stack sx={{ flexGrow: 1, minWidth: 0, textAlign: 'left' }}>\n <Text bold={true} noWrap={true} variant=\"body1\">\n {merchant.label}\n </Text>\n {count && <Text variant=\"caption\">{count}</Text>}\n </Stack>\n <Text bold={true} variant=\"body1\">\n {merchant.rank}\n </Text>\n <Icon aria-hidden={true} name=\"chevron_right\" size={16} sx={{ color: 'action.active' }} />\n </Stack>\n )\n}\n\n/** Monthly Top Transacted Merchant quiz; its progress lives in beat context for the quiz CTAs. */\nconst QuizBlock = observer(({ beatGuid = '', payload }: BlockProps) => {\n const copy = useGlobalCopyStore().insights_feed?.quiz_block\n const { beatContext, openActionDrawer, setBeatContext } = useInsightsV2Store()\n\n const merchants = readQuizMerchants(payload.instance_slot.data)\n const [options] = useState(() => shuffle(merchants))\n\n const context = beatContext[beatGuid] ?? {}\n const pick = context[QUIZ_CONTEXT.PICK] as string | undefined\n const checked = Boolean(context[QUIZ_CONTEXT.CHECKED])\n const revealed =\n payload.instance_slot.variant === QUIZ_VARIANTS.RESULTS ||\n Boolean(context[QUIZ_CONTEXT.REVEALED])\n const showFeedback = checked && !revealed\n\n useEffect(() => {\n if (!showFeedback) return\n const timer = setTimeout(\n () => setBeatContext(beatGuid, { [QUIZ_CONTEXT.REVEALED]: true }),\n FEEDBACK_MS,\n )\n return () => clearTimeout(timer)\n }, [beatGuid, setBeatContext, showFeedback])\n\n useEffect(() => {\n if (!copy) console.warn('quiz_block: copy namespace missing; rendering without its labels')\n }, [copy])\n\n // tupac's zero_state sends no data_series.\n if (!merchants.length) return <LinedCardZeroState />\n\n if (revealed) {\n const openMerchant = (merchant: RankedQuizMerchant) =>\n openActionDrawer({\n guid: beatGuid,\n trigger: 'inDescriptionCta',\n cta: { block: actionBlocksKey.QUIZ_MERCHANT_ACTION_BLOCK, variant: null },\n context: { quiz_merchant: merchant } satisfies QuizDrawerContext,\n })\n\n return (\n <Stack sx={{ gap: 12, p: 16 }}>\n {rankQuizMerchants(merchants).map((merchant) => (\n <ResultRow\n copy={copy}\n key={merchantKey(merchant)}\n merchant={merchant}\n onClick={() => openMerchant(merchant)}\n />\n ))}\n </Stack>\n )\n }\n\n const correct = Boolean(pick) && isTopMerchant(merchants, pick ?? '')\n\n return (\n <Stack sx={{ gap: 12, p: 16, position: 'relative' }}>\n {showFeedback && correct && <ConfettiOverlay />}\n {showFeedback && <FeedbackCard copy={copy} correct={correct} />}\n <Stack\n aria-label={payload.title}\n component=\"fieldset\"\n sx={{\n border: 0,\n gap: 12,\n m: 0,\n p: 0,\n visibility: showFeedback && correct ? 'hidden' : 'visible',\n }}\n >\n {options.map((merchant) => {\n const key = merchantKey(merchant)\n const selected = key === pick\n\n return (\n <Stack\n component=\"label\"\n direction=\"row\"\n key={key}\n sx={{\n ...ROW_SX,\n bgcolor: (theme) =>\n selected ? alpha(theme.palette.primary.main, 0.16) : 'background.paper',\n borderColor: (theme) =>\n selected ? alpha(theme.palette.primary.main, 0.5) : theme.palette.divider,\n borderWidth: selected ? 2 : 1,\n cursor: checked ? 'default' : 'pointer',\n pr: 4,\n }}\n >\n <MerchantLogo merchant={merchant} />\n <Text bold={true} noWrap={true} sx={{ flexGrow: 1 }} variant=\"body1\">\n {merchant.label}\n </Text>\n <Radio\n checked={selected}\n disabled={checked}\n name={`quiz-${beatGuid}`}\n onChange={() => setBeatContext(beatGuid, { [QUIZ_CONTEXT.PICK]: key })}\n size=\"small\"\n value={key}\n />\n </Stack>\n )\n })}\n </Stack>\n </Stack>\n )\n})\n\nexport default QuizBlock\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,IAAM,IAAc,KAEd,IAAY,IACZ,IAAS;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,cAAc;AAAA,EACd,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,OAAO;AACT,GAEM,IAAA,CAAe,MACnB,EACG,IAAA,CAAK,OAAU;AAAA,EAAE,MAAA;AAAA,EAAM,OAAO,KAAK,OAAO;AAAE,EAAE,EAC9C,KAAA,CAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,EAChC,IAAA,CAAK,EAAE,MAAA,EAAA,MAAW,CAAI,GAErB,IAAe,EAAA,CAAU,EAAE,UAAA,EAAA,MAA2C;AAC1E,QAAM,EAAE,sBAAA,EAAA,IAAyB,EAAoB,GAE/C,IAAO;AAAA,IAAE,GAAG,EAAiB,GAAU,CAAoB;AAAA,IAAG,KAAK;AAAA,EAAG;AAE5E,SAEE,gBAAA,EAAC,GAAD;AAAA,IACE,aAAa;AAAA,IACb,cAAc;AAAA,IACd,MAAM;AAAA,IACN,IAAI;AAAA,MAAE,UAAU;AAAA,MAAY,WAAW;AAAA,IAAO;AAAA,IAE9C,UAAA,gBAAA,EAAC,GAAD;AAAA,MAAoB,MAAA;AAAA,MAAM,MAAM;AAAA,IAAY,CAAA;AAAA,EACpC,CAAA;AAEd,CAAC,GAEK,IAAA,CAAgB,EAAE,SAAA,GAAS,MAAA,EAAA,MAC/B,gBAAA,EAAC,GAAD;AAAA,EACE,MAAK;AAAA,EACL,IAAI;AAAA,IACF,YAAY;AAAA,IACZ,gBAAgB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AAW;AAAA,QACnD;AAAA,QAEC,UAAA,EAAQ,IAAA,CAAK,MAAa;AACzB,gBAAM,IAAM,EAAY,CAAQ,GAC1B,IAAW,MAAQ;AAEzB,iBACE,gBAAA,EAAC,GAAD;AAAA,YACE,WAAU;AAAA,YACV,WAAU;AAAA,YAEV,IAAI;AAAA,cACF,GAAG;AAAA,cACH,SAAA,CAAU,MACR,IAAW,EAAM,EAAM,QAAQ,QAAQ,MAAM,IAAI,IAAI;AAAA,cACvD,aAAA,CAAc,MACZ,IAAW,EAAM,EAAM,QAAQ,QAAQ,MAAM,GAAG,IAAI,EAAM,QAAQ;AAAA,cACpE,aAAa,IAAW,IAAI;AAAA,cAC5B,QAAQ,IAAU,YAAY;AAAA,cAC9B,IAAI;AAAA,YACN;AAAA,YAbF,UAAA;AAAA,cAeE,gBAAA,EAAC,GAAD,EAAwB,UAAA,EAAW,CAAA;AAAA,cACnC,gBAAA,EAAC,GAAD;AAAA,gBAAM,MAAM;AAAA,gBAAM,QAAQ;AAAA,gBAAM,IAAI,EAAE,UAAU,EAAE;AAAA,gBAAG,SAAQ;AAAA,gBAC1D,UAAA,EAAS;AAAA,cACN,CAAA;AAAA,cACN,gBAAA,EAAC,GAAD;AAAA,gBACE,SAAS;AAAA,gBACT,UAAU;AAAA,gBACV,MAAM,QAAQ,CAAA;AAAA,gBACd,UAAA,MAAgB,EAAe,GAAU,EAAA,CAAG,EAAa,IAAA,GAAO,EAAI,CAAC;AAAA,gBACrE,MAAK;AAAA,gBACL,OAAO;AAAA,cACR,CAAA;AAAA,YACI;AAAA,UAxBA,GAAA,CAwBA;AAAA,QAEX,CAAC;AAAA,MACI,CAAA;AAAA,IACF;AAAA;AAEX,CAAC"}
@@ -0,0 +1 @@
1
+ export { default as QuizBlock } from './QuizBlock';
@@ -0,0 +1,39 @@
1
+ import { InstanceSlotData, LogoRef, Transaction } from '../../../../core';
2
+ /** One merchant in the month, a row of the backend's `data_series`. */
3
+ export interface QuizMerchant {
4
+ /** `null` for spending with no merchant; the drawer then matches transactions by `label`. */
5
+ guid?: string | null;
6
+ label: string;
7
+ count: number;
8
+ /** The merchant's category: its logo's fallback, and the logo itself when it has no guid. */
9
+ category_guid?: string | null;
10
+ logo?: LogoRef;
11
+ }
12
+ export interface RankedQuizMerchant extends QuizMerchant {
13
+ rank: number;
14
+ }
15
+ /** What a results row hands its drawer through `actionDrawer.context`. */
16
+ export interface QuizDrawerContext {
17
+ quiz_merchant?: RankedQuizMerchant;
18
+ }
19
+ /** The beat-context keys the block and the quiz CTA steps share. */
20
+ export declare const QUIZ_CONTEXT: {
21
+ readonly PICK: "quiz_pick";
22
+ readonly CHECKED: "quiz_checked";
23
+ readonly REVEALED: "quiz_revealed";
24
+ };
25
+ export declare const QUIZ_VARIANTS: {
26
+ readonly RESULTS: "results";
27
+ };
28
+ /** The merchant's transactions: by merchant guid, or by description when it has none. */
29
+ export declare const merchantTransactions: (transactions: Transaction[], merchant: QuizMerchant) => Transaction[];
30
+ /** The merchant logo over its category fallback, or the category icon when it has no merchant guid. */
31
+ export declare const quizMerchantLogo: (merchant: QuizMerchant, transactions?: Transaction[]) => LogoRef;
32
+ /** A merchant's id in the quiz: its guid, else its label. */
33
+ export declare const merchantKey: (merchant: QuizMerchant) => string;
34
+ /** `data_series` rows: tupac's columnar `{ names, data }`, or an array of row objects. */
35
+ export declare const readQuizMerchants: (data: InstanceSlotData | undefined) => QuizMerchant[];
36
+ /** Most transactions first, ties by name; tied counts share a rank (1, 1, 3). */
37
+ export declare const rankQuizMerchants: (merchants: QuizMerchant[]) => RankedQuizMerchant[];
38
+ /** Any merchant tied for the most transactions is a right answer. */
39
+ export declare const isTopMerchant: (merchants: QuizMerchant[], key: string) => boolean;
@@ -0,0 +1,44 @@
1
+ import { CategoryGuids as t } from "../../../../core/constants/Category.es.js";
2
+ import { slot as u } from "../../../../core/types/Insights.es.js";
3
+ import { buildDataSeries as l } from "../../ChartBlocks/BarchartBlock/utils.es.js";
4
+ import { asNumber as s, asText as d } from "../../slotReaders.es.js";
5
+ var f = {
6
+ PICK: "quiz_pick",
7
+ CHECKED: "quiz_checked",
8
+ REVEALED: "quiz_revealed"
9
+ }, E = { RESULTS: "results" }, g = (o) => {
10
+ const { label: r, count: i } = o ?? {};
11
+ return d(r) !== void 0 && s(i) !== void 0;
12
+ }, c = (o, r) => o.filter((i) => r.guid ? i.merchant_guid === r.guid : !i.merchant_guid && i.description === r.label), y = (o, r = []) => {
13
+ const i = c(r, o)[0], a = o.logo?.fallback_guid || o.category_guid || i?.top_level_category_guid || i?.category_guid || t.UNCATEGORIZED, e = o.logo?.guid || o.guid;
14
+ return {
15
+ ...o.logo,
16
+ alt: o.logo?.alt ?? o.label,
17
+ fallback_guid: a,
18
+ guid: e || a
19
+ };
20
+ }, n = (o) => o.guid || o.label, T = (o) => {
21
+ const r = u(o, "data_series");
22
+ return (Array.isArray(r) ? r : l(r)).filter(g);
23
+ }, C = (o) => {
24
+ const r = [...o].sort((i, a) => a.count - i.count || i.label.localeCompare(a.label));
25
+ return r.map((i) => ({
26
+ ...i,
27
+ rank: r.findIndex(({ count: a }) => a === i.count) + 1
28
+ }));
29
+ }, k = (o, r) => {
30
+ const i = Math.max(...o.map(({ count: a }) => a));
31
+ return o.some((a) => n(a) === r && a.count === i);
32
+ };
33
+ export {
34
+ f as QUIZ_CONTEXT,
35
+ E as QUIZ_VARIANTS,
36
+ k as isTopMerchant,
37
+ n as merchantKey,
38
+ c as merchantTransactions,
39
+ y as quizMerchantLogo,
40
+ C as rankQuizMerchants,
41
+ T as readQuizMerchants
42
+ };
43
+
44
+ //# sourceMappingURL=quiz.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quiz.es.js","names":[],"sources":["../../../../../src/insights-v2/blocks/ComponentBlocks/QuizBlock/quiz.ts"],"sourcesContent":["import {\n slot,\n type DataSeries,\n type InstanceSlotData,\n type LogoRef,\n type Transaction,\n} from '../../../../core'\nimport { CategoryGuids } from '../../../../core/constants/Category'\nimport { buildDataSeries } from '../../ChartBlocks/BarchartBlock/utils'\nimport { asNumber, asText } from '../../slotReaders'\n\n/** One merchant in the month, a row of the backend's `data_series`. */\nexport interface QuizMerchant {\n /** `null` for spending with no merchant; the drawer then matches transactions by `label`. */\n guid?: string | null\n label: string\n count: number\n /** The merchant's category: its logo's fallback, and the logo itself when it has no guid. */\n category_guid?: string | null\n logo?: LogoRef\n}\n\nexport interface RankedQuizMerchant extends QuizMerchant {\n rank: number\n}\n\n/** What a results row hands its drawer through `actionDrawer.context`. */\nexport interface QuizDrawerContext {\n quiz_merchant?: RankedQuizMerchant\n}\n\n/** The beat-context keys the block and the quiz CTA steps share. */\nexport const QUIZ_CONTEXT = {\n PICK: 'quiz_pick',\n CHECKED: 'quiz_checked',\n REVEALED: 'quiz_revealed',\n} as const\n\nexport const QUIZ_VARIANTS = { RESULTS: 'results' } as const\n\nconst isMerchant = (row: unknown): row is QuizMerchant => {\n const { label, count } = (row ?? {}) as Record<string, unknown>\n return asText(label) !== undefined && asNumber(count) !== undefined\n}\n\n/** The merchant's transactions: by merchant guid, or by description when it has none. */\nexport const merchantTransactions = (transactions: Transaction[], merchant: QuizMerchant) =>\n transactions.filter((transaction) =>\n merchant.guid\n ? transaction.merchant_guid === merchant.guid\n : !transaction.merchant_guid && transaction.description === merchant.label,\n )\n\n/** The merchant logo over its category fallback, or the category icon when it has no merchant guid. */\nexport const quizMerchantLogo = (\n merchant: QuizMerchant,\n transactions: Transaction[] = [],\n): LogoRef => {\n const transaction = merchantTransactions(transactions, merchant)[0]\n const category =\n merchant.logo?.fallback_guid ||\n merchant.category_guid ||\n transaction?.top_level_category_guid ||\n transaction?.category_guid ||\n CategoryGuids.UNCATEGORIZED\n const guid = merchant.logo?.guid || merchant.guid\n\n return {\n ...merchant.logo,\n alt: merchant.logo?.alt ?? merchant.label,\n fallback_guid: category,\n guid: guid || category,\n }\n}\n\n/** A merchant's id in the quiz: its guid, else its label. */\nexport const merchantKey = (merchant: QuizMerchant) => merchant.guid || merchant.label\n\n/** `data_series` rows: tupac's columnar `{ names, data }`, or an array of row objects. */\nexport const readQuizMerchants = (data: InstanceSlotData | undefined): QuizMerchant[] => {\n const series = slot<unknown[] | DataSeries>(data, 'data_series')\n const rows = Array.isArray(series) ? series : buildDataSeries(series)\n return rows.filter(isMerchant)\n}\n\n/** Most transactions first, ties by name; tied counts share a rank (1, 1, 3). */\nexport const rankQuizMerchants = (merchants: QuizMerchant[]): RankedQuizMerchant[] => {\n const sorted = [...merchants].sort((a, b) => b.count - a.count || a.label.localeCompare(b.label))\n return sorted.map((merchant) => ({\n ...merchant,\n rank: sorted.findIndex(({ count }) => count === merchant.count) + 1,\n }))\n}\n\n/** Any merchant tied for the most transactions is a right answer. */\nexport const isTopMerchant = (merchants: QuizMerchant[], key: string) => {\n const top = Math.max(...merchants.map(({ count }) => count))\n return merchants.some((merchant) => merchantKey(merchant) === key && merchant.count === top)\n}\n"],"mappings":";;;;AAgCA,IAAa,IAAe;AAAA,EAC1B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU;AACZ,GAEa,IAAgB,EAAE,SAAS,UAAU,GAE5C,IAAA,CAAc,MAAsC;AACxD,QAAM,EAAE,OAAA,GAAO,OAAA,EAAA,IAAW,KAAO,CAAC;AAClC,SAAO,EAAO,CAAK,MAAM,UAAa,EAAS,CAAK,MAAM;AAC5D,GAGa,IAAA,CAAwB,GAA6B,MAChE,EAAa,OAAA,CAAQ,MACnB,EAAS,OACL,EAAY,kBAAkB,EAAS,OACvC,CAAC,EAAY,iBAAiB,EAAY,gBAAgB,EAAS,KACzE,GAGW,IAAA,CACX,GACA,IAA8B,CAAC,MACnB;AACZ,QAAM,IAAc,EAAqB,GAAc,CAAQ,EAAE,CAAA,GAC3D,IACJ,EAAS,MAAM,iBACf,EAAS,iBACT,GAAa,2BACb,GAAa,iBACb,EAAc,eACV,IAAO,EAAS,MAAM,QAAQ,EAAS;AAE7C,SAAO;AAAA,IACL,GAAG,EAAS;AAAA,IACZ,KAAK,EAAS,MAAM,OAAO,EAAS;AAAA,IACpC,eAAe;AAAA,IACf,MAAM,KAAQ;AAAA,EAChB;AACF,GAGa,IAAA,CAAe,MAA2B,EAAS,QAAQ,EAAS,OAGpE,IAAA,CAAqB,MAAuD;AACvF,QAAM,IAAS,EAA6B,GAAM,aAAa;AAE/D,UADa,MAAM,QAAQ,CAAM,IAAI,IAAS,EAAgB,CAAM,GACxD,OAAO,CAAU;AAC/B,GAGa,IAAA,CAAqB,MAAoD;AACpF,QAAM,IAAS,CAAC,GAAG,CAAS,EAAE,KAAA,CAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,EAAE,KAAK,CAAC;AAChG,SAAO,EAAO,IAAA,CAAK,OAAc;AAAA,IAC/B,GAAG;AAAA,IACH,MAAM,EAAO,UAAA,CAAW,EAAE,OAAA,EAAA,MAAY,MAAU,EAAS,KAAK,IAAI;AAAA,EACpE,EAAE;AACJ,GAGa,IAAA,CAAiB,GAA2B,MAAgB;AACvE,QAAM,IAAM,KAAK,IAAI,GAAG,EAAU,IAAA,CAAK,EAAE,OAAA,EAAA,MAAY,CAAK,CAAC;AAC3D,SAAO,EAAU,KAAA,CAAM,MAAa,EAAY,CAAQ,MAAM,KAAO,EAAS,UAAU,CAAG;AAC7F"}
@@ -7,6 +7,7 @@ export * from './GasPurchaseBlock';
7
7
  export * from './GoalsBlock';
8
8
  export * from './MerchantBlock';
9
9
  export * from './NoSpendDaysBlock';
10
+ export * from './QuizBlock';
10
11
  export * from './RepeatingTransactionBlock';
11
12
  export * from './SaveExtraBlock';
12
13
  export * from './SavingsOpportunityBlock';
@@ -7,3 +7,5 @@ export declare const ELEVATION_SHADOW: {
7
7
  };
8
8
  /** Soft two-layer card shadow (Figma) for a raised result card; off the numbered scale above. */
9
9
  export declare const RAISED_CARD_SHADOW = "0px 6px 12px rgba(106, 115, 129, 0.16), 0px 3px 8px rgba(87, 102, 117, 0.06)";
10
+ /** Small card shadow (Figma 0 / 2 / blur 4, black @ 0.12): the quiz feedback card and merchant header. */
11
+ export declare const SMALL_CARD_SHADOW = "0px 2px 4px rgba(0, 0, 0, 0.12)";
@@ -1,10 +1,11 @@
1
1
  var p = {
2
2
  1: "0px 2px 8px rgba(0, 0, 0, 0.12)",
3
3
  16: "0px 12px 20px rgba(0, 0, 0, 0.22)"
4
- }, x = "0px 6px 12px rgba(106, 115, 129, 0.16), 0px 3px 8px rgba(87, 102, 117, 0.06)";
4
+ }, x = "0px 6px 12px rgba(106, 115, 129, 0.16), 0px 3px 8px rgba(87, 102, 117, 0.06)", r = "0px 2px 4px rgba(0, 0, 0, 0.12)";
5
5
  export {
6
6
  p as ELEVATION_SHADOW,
7
- x as RAISED_CARD_SHADOW
7
+ x as RAISED_CARD_SHADOW,
8
+ r as SMALL_CARD_SHADOW
8
9
  };
9
10
 
10
11
  //# sourceMappingURL=elevation.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"elevation.es.js","names":[],"sources":["../../../../src/insights-v2/components/shared/elevation.ts"],"sourcesContent":["/** Figma elevation shadows (single drop shadows, not MUI's `shadows[n]`). */\nexport const ELEVATION_SHADOW = {\n /** `elevation/1`: rows on a wash. */\n 1: '0px 2px 8px rgba(0, 0, 0, 0.12)',\n /** `elevation/16`: dialogs, snackbars. */\n 16: '0px 12px 20px rgba(0, 0, 0, 0.22)',\n} as const\n\n/** Soft two-layer card shadow (Figma) for a raised result card; off the numbered scale above. */\nexport const RAISED_CARD_SHADOW =\n '0px 6px 12px rgba(106, 115, 129, 0.16), 0px 3px 8px rgba(87, 102, 117, 0.06)'\n"],"mappings":"AACA,IAAa,IAAmB;AAAA,EAE9B,GAAG;AAAA,EAEH,IAAI;AACN,GAGa,IACX"}
1
+ {"version":3,"file":"elevation.es.js","names":[],"sources":["../../../../src/insights-v2/components/shared/elevation.ts"],"sourcesContent":["/** Figma elevation shadows (single drop shadows, not MUI's `shadows[n]`). */\nexport const ELEVATION_SHADOW = {\n /** `elevation/1`: rows on a wash. */\n 1: '0px 2px 8px rgba(0, 0, 0, 0.12)',\n /** `elevation/16`: dialogs, snackbars. */\n 16: '0px 12px 20px rgba(0, 0, 0, 0.22)',\n} as const\n\n/** Soft two-layer card shadow (Figma) for a raised result card; off the numbered scale above. */\nexport const RAISED_CARD_SHADOW =\n '0px 6px 12px rgba(106, 115, 129, 0.16), 0px 3px 8px rgba(87, 102, 117, 0.06)'\n\n/** Small card shadow (Figma 0 / 2 / blur 4, black @ 0.12): the quiz feedback card and merchant header. */\nexport const SMALL_CARD_SHADOW = '0px 2px 4px rgba(0, 0, 0, 0.12)'\n"],"mappings":"AACA,IAAa,IAAmB;AAAA,EAE9B,GAAG;AAAA,EAEH,IAAI;AACN,GAGa,IACX,gFAGW,IAAoB"}