@greatapps/common 1.1.792 → 1.1.794
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/components/account/AccountHubLinkHandler.mjs +16 -4
- package/dist/components/account/AccountHubLinkHandler.mjs.map +1 -1
- package/dist/components/account/hooks/useAccountHubActions.mjs +15 -0
- package/dist/components/account/hooks/useAccountHubActions.mjs.map +1 -1
- package/dist/components/account/sections/subscription/PaymentConfirmationDialog.mjs +3 -2
- package/dist/components/account/sections/subscription/PaymentConfirmationDialog.mjs.map +1 -1
- package/dist/components/ui/data-display/SuccessConfettiIcon.mjs +148 -0
- package/dist/components/ui/data-display/SuccessConfettiIcon.mjs.map +1 -0
- package/dist/enums/AccountHubFlow.mjs +1 -0
- package/dist/enums/AccountHubFlow.mjs.map +1 -1
- package/dist/index.mjs +9 -1
- package/dist/index.mjs.map +1 -1
- package/dist/modules/accounts/constants/account-hub-link.constants.mjs +9 -1
- package/dist/modules/accounts/constants/account-hub-link.constants.mjs.map +1 -1
- package/dist/modules/accounts/utils/build-account-hub-url.mjs +13 -1
- package/dist/modules/accounts/utils/build-account-hub-url.mjs.map +1 -1
- package/dist/modules/accounts/utils/is-billing-period.mjs +8 -0
- package/dist/modules/accounts/utils/is-billing-period.mjs.map +1 -0
- package/dist/modules/accounts/utils/parse-account-hub-link.mjs +21 -2
- package/dist/modules/accounts/utils/parse-account-hub-link.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/account/AccountHubLinkHandler.tsx +15 -3
- package/src/components/account/hooks/useAccountHubActions.ts +17 -1
- package/src/components/account/sections/subscription/PaymentConfirmationDialog.tsx +3 -2
- package/src/components/ui/data-display/SuccessConfettiIcon.tsx +177 -0
- package/src/enums/AccountHubFlow.ts +1 -0
- package/src/index.ts +5 -1
- package/src/modules/accounts/constants/account-hub-link.constants.ts +4 -0
- package/src/modules/accounts/types/account-hub-link.type.ts +9 -0
- package/src/modules/accounts/utils/build-account-hub-url.ts +14 -0
- package/src/modules/accounts/utils/is-billing-period.ts +7 -0
- package/src/modules/accounts/utils/parse-account-hub-link.ts +25 -2
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Selo de sucesso com confetes — a arte de sempre, agora animada.
|
|
7
|
+
*
|
|
8
|
+
* A cada mount o selo entra com spring enquanto o contorno se desenha, o check risca em
|
|
9
|
+
* seguida e os confetes explodem do centro pra fora (os mais próximos primeiro), desenhando
|
|
10
|
+
* o traço no voo; depois ficam flutuando devagar, cada um no seu ritmo.
|
|
11
|
+
*
|
|
12
|
+
* ANIMAÇÃO: CSS puro injetado pelo próprio componente (mesmo padrão do `ImageCropModal`), e
|
|
13
|
+
* não classes vindas do `globals.css` de cada app como no `AiCreditsOfferModal`. Aqui isso
|
|
14
|
+
* importa: é um ícone folha que qualquer app pode renderizar, então carregar o CSS junto
|
|
15
|
+
* evita ter que replicar um bloco de keyframes nos quatro consumidores e mantê-los em sincronia.
|
|
16
|
+
*
|
|
17
|
+
* Comprimento de traço e vetor de explosão dependem da geometria de cada path, então são
|
|
18
|
+
* medidos no cliente (`getTotalLength`/`getBBox`) e injetados como CSS vars por elemento. Só
|
|
19
|
+
* ligamos a classe de play depois de medir — antes disso os traços ficam invisíveis, o que
|
|
20
|
+
* também deixa o `useEffect` (em vez de `useLayoutEffect`) seguro: não há flash de conteúdo
|
|
21
|
+
* não animado, e a lib não precisa supor se o consumidor renderiza no servidor.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const ANIMATION_CSS = `
|
|
25
|
+
.gp-confetti {
|
|
26
|
+
--gp-confetti-spring: linear(0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%,
|
|
27
|
+
1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%,
|
|
28
|
+
1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%,
|
|
29
|
+
1.003 76.9%, 1.004 83.8%, 1);
|
|
30
|
+
--gp-confetti-out: cubic-bezier(0.22, 1, 0.36, 1);
|
|
31
|
+
overflow: visible;
|
|
32
|
+
}
|
|
33
|
+
@supports not (animation-timing-function: linear(0, 1)) {
|
|
34
|
+
.gp-confetti { --gp-confetti-spring: cubic-bezier(0.34, 1.56, 0.64, 1); }
|
|
35
|
+
}
|
|
36
|
+
.gp-confetti path {
|
|
37
|
+
stroke-dasharray: var(--gp-len) calc(var(--gp-len) + 4px);
|
|
38
|
+
stroke-dashoffset: calc(var(--gp-len) + 2px);
|
|
39
|
+
transform-box: fill-box;
|
|
40
|
+
transform-origin: center;
|
|
41
|
+
opacity: 0;
|
|
42
|
+
}
|
|
43
|
+
.gp-confetti-seal {
|
|
44
|
+
transform-box: fill-box;
|
|
45
|
+
transform-origin: center;
|
|
46
|
+
opacity: 0;
|
|
47
|
+
transform: scale(0.4);
|
|
48
|
+
}
|
|
49
|
+
.gp-confetti--play .gp-confetti-seal {
|
|
50
|
+
animation:
|
|
51
|
+
gp-confetti-seal-pop 670ms var(--gp-confetti-spring) 80ms both,
|
|
52
|
+
gp-confetti-seal-breathe 3600ms ease-in-out 930ms infinite alternate;
|
|
53
|
+
}
|
|
54
|
+
.gp-confetti--play .gp-confetti-seal path { opacity: 1; }
|
|
55
|
+
.gp-confetti--play .gp-confetti-badge {
|
|
56
|
+
animation: gp-confetti-draw 470ms var(--gp-confetti-out) 95ms both;
|
|
57
|
+
}
|
|
58
|
+
.gp-confetti--play .gp-confetti-check {
|
|
59
|
+
animation: gp-confetti-draw 320ms var(--gp-confetti-out) 310ms both;
|
|
60
|
+
}
|
|
61
|
+
.gp-confetti-piece {
|
|
62
|
+
--gp-confetti-delay: calc(375ms + var(--gp-i, 0) * 28ms);
|
|
63
|
+
--gp-confetti-drawtime: 350ms;
|
|
64
|
+
}
|
|
65
|
+
.gp-confetti-squiggle { --gp-confetti-drawtime: 600ms; }
|
|
66
|
+
.gp-confetti--play .gp-confetti-piece {
|
|
67
|
+
animation:
|
|
68
|
+
gp-confetti-pop 735ms var(--gp-confetti-spring) var(--gp-confetti-delay) both,
|
|
69
|
+
gp-confetti-draw var(--gp-confetti-drawtime) var(--gp-confetti-out) var(--gp-confetti-delay) both,
|
|
70
|
+
gp-confetti-float var(--gp-fd, 3200ms) ease-in-out calc(var(--gp-confetti-delay) + 735ms) infinite alternate;
|
|
71
|
+
}
|
|
72
|
+
@keyframes gp-confetti-seal-pop { to { opacity: 1; transform: scale(1); } }
|
|
73
|
+
@keyframes gp-confetti-seal-breathe { from { transform: scale(1); } to { transform: scale(1.025); } }
|
|
74
|
+
@keyframes gp-confetti-draw { to { stroke-dashoffset: 0; } }
|
|
75
|
+
@keyframes gp-confetti-pop {
|
|
76
|
+
from { opacity: 0; transform: translate(var(--gp-tx, 0px), var(--gp-ty, 0px)) scale(0.2) rotate(var(--gp-rot0, 0deg)); }
|
|
77
|
+
to { opacity: var(--gp-op, 1); transform: translate(0, 0) scale(1) rotate(0deg); }
|
|
78
|
+
}
|
|
79
|
+
@keyframes gp-confetti-float {
|
|
80
|
+
from { opacity: var(--gp-op, 1); transform: translate(0, 0) rotate(0deg); }
|
|
81
|
+
to { opacity: calc(var(--gp-op, 1) * 0.55); transform: translate(var(--gp-fx, 0px), var(--gp-fy, 0px)) rotate(var(--gp-fr, 0deg)); }
|
|
82
|
+
}
|
|
83
|
+
@media (prefers-reduced-motion: reduce) {
|
|
84
|
+
.gp-confetti path,
|
|
85
|
+
.gp-confetti-seal { animation: none !important; }
|
|
86
|
+
.gp-confetti-seal { opacity: 1 !important; transform: none !important; }
|
|
87
|
+
.gp-confetti path {
|
|
88
|
+
opacity: var(--gp-op, 1) !important;
|
|
89
|
+
stroke-dashoffset: 0 !important;
|
|
90
|
+
transform: none !important;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
/** Centro do selo no viewBox — os confetes explodem a partir daqui. */
|
|
96
|
+
const CENTER = { x: 74.5, y: 41.5 };
|
|
97
|
+
|
|
98
|
+
const rand = (min: number, max: number) => min + Math.random() * (max - min);
|
|
99
|
+
|
|
100
|
+
export function SuccessConfettiIcon({ className }: { className?: string }) {
|
|
101
|
+
const ref = useRef<SVGSVGElement>(null);
|
|
102
|
+
const [play, setPlay] = useState(false);
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
const svg = ref.current;
|
|
106
|
+
if (!svg) return;
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
svg.querySelectorAll<SVGPathElement>('path').forEach((path) => {
|
|
110
|
+
path.style.setProperty('--gp-len', `${path.getTotalLength().toFixed(2)}px`);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
Array.from(svg.querySelectorAll<SVGPathElement>('.gp-confetti-piece'))
|
|
114
|
+
.map((path) => {
|
|
115
|
+
const box = path.getBBox();
|
|
116
|
+
const dx = box.x + box.width / 2 - CENTER.x;
|
|
117
|
+
const dy = box.y + box.height / 2 - CENTER.y;
|
|
118
|
+
return { path, dx, dy, dist: Math.hypot(dx, dy) };
|
|
119
|
+
})
|
|
120
|
+
.sort((a, b) => a.dist - b.dist)
|
|
121
|
+
.forEach(({ path, dx, dy }, i) => {
|
|
122
|
+
path.style.setProperty('--gp-i', String(i));
|
|
123
|
+
// começa mais perto do selo e voa pra posição final
|
|
124
|
+
path.style.setProperty('--gp-tx', `${(-dx * 0.55).toFixed(2)}px`);
|
|
125
|
+
path.style.setProperty('--gp-ty', `${(-dy * 0.55).toFixed(2)}px`);
|
|
126
|
+
path.style.setProperty('--gp-rot0', `${rand(-60, 60).toFixed(1)}deg`);
|
|
127
|
+
// deriva idle: pequena, lenta e diferente pra cada peça
|
|
128
|
+
path.style.setProperty('--gp-fx', `${rand(-2.2, 2.2).toFixed(2)}px`);
|
|
129
|
+
path.style.setProperty('--gp-fy', `${rand(-2.6, 2.6).toFixed(2)}px`);
|
|
130
|
+
path.style.setProperty('--gp-fr', `${rand(-16, 16).toFixed(1)}deg`);
|
|
131
|
+
path.style.setProperty('--gp-fd', `${Math.round(rand(2400, 4200))}ms`);
|
|
132
|
+
});
|
|
133
|
+
} catch {
|
|
134
|
+
// svg sem layout (display:none) — sem medidas o CSS cai pro traço inteiro, só anima pop/float
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
setPlay(true);
|
|
138
|
+
}, []);
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<>
|
|
142
|
+
<style>{ANIMATION_CSS}</style>
|
|
143
|
+
<svg
|
|
144
|
+
ref={ref}
|
|
145
|
+
width="149"
|
|
146
|
+
height="83"
|
|
147
|
+
viewBox="0 0 149 83"
|
|
148
|
+
fill="none"
|
|
149
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
150
|
+
className={['gp-confetti', play && 'gp-confetti--play', className].filter(Boolean).join(' ')}
|
|
151
|
+
aria-hidden
|
|
152
|
+
>
|
|
153
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M18.6348 28.4102C18.6348 30.574 19.9096 30.8716 21.7838 31.1393" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
154
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M109.117 41.4266C110.106 41.3745 110.639 40.9023 110.797 39.957" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
155
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M64.6035 75.1963C62.2234 77.2378 61.7986 79.4524 63.2302 82.1283" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
156
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M108.953 6.33984C106.531 6.40444 105.075 7.59006 104.965 10.072C104.898 11.5735 105.114 12.692 103.285 13.0577" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
157
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M131.021 51.2682C130.631 53.6598 129.26 54.9429 126.786 54.7178C125.289 54.5817 124.21 54.217 123.601 55.9798" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
158
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M34.1753 59.0104C33.2963 61.0245 32.8213 61.1372 30.7893 61.1213C29.7394 61.1131 28.0011 61.8028 27.5653 62.8448" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
159
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 1 } as React.CSSProperties} d="M112.314 25.2715L113.514 24.7026" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
160
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 1 } as React.CSSProperties} d="M51.492 49.2344C51.0065 49.3838 50.6337 49.7823 50.2324 50.0741" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
161
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M77.8867 9.72656C77.4011 9.87596 77.3223 10.0019 77.3223 10.0019" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
162
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M10.7246 56.0059C10.239 56.1553 10.1602 56.2812 10.1602 56.2812" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
163
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M28.3302 80.1108C28.6726 79.7356 28.6766 79.587 28.6766 79.587" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
164
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M128.043 49.0421C127.77 48.6138 127.627 48.5713 127.627 48.5713" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
165
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M135.461 29.4915C134.972 29.6314 134.891 29.7558 134.891 29.7558" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
166
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 0.4 } as React.CSSProperties} d="M52.3396 22.1222C52.0664 21.6939 51.924 21.6514 51.924 21.6514" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
167
|
+
<path className="gp-confetti-piece" style={{ '--gp-op': 1 } as React.CSSProperties} d="M45.9383 40.1115L45.1508 39.1744" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
168
|
+
<path className="gp-confetti-piece gp-confetti-squiggle" style={{ '--gp-op': 0.8 } as React.CSSProperties} d="M97.7421 69.0733C97.1523 69.9712 97.989 71.6124 98.5913 72.3132C99.7005 73.6036 100.945 73.8145 102.199 73.9149C103.234 73.9977 105.21 73.5621 105.476 72.3174C105.948 71.1367 104.935 69.8432 103.934 70.3872C102.571 71.1277 103.112 72.7192 103.73 73.7787C104.604 75.2776 105.879 76.6545 107.249 77.7108C108.333 78.5474 109.732 79.029 110.308 79.0142" stroke="#12B76A" strokeWidth="1.41098" strokeLinecap="round"/>
|
|
169
|
+
<path className="gp-confetti-piece gp-confetti-squiggle" style={{ '--gp-op': 1 } as React.CSSProperties} d="M55.1022 11.4613C55.7297 11.187 55.8499 9.89737 55.7699 9.24592C55.6225 8.04626 55.0286 7.4129 54.3908 6.83895C53.8646 6.36537 52.6539 5.803 52.0797 6.41026C51.4175 6.89618 51.5122 8.05793 52.2377 8.15673C53.2253 8.2912 53.4868 7.15184 53.5227 6.28731C53.5734 5.06421 53.367 3.74644 52.9989 2.5746C52.7073 1.64647 52.1242 0.793399 51.8104 0.565035" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
|
|
170
|
+
<g className="gp-confetti-seal">
|
|
171
|
+
<path className="gp-confetti-badge" fillRule="evenodd" clipRule="evenodd" d="M58.1139 44.0572L60.4163 47.0706L60.9134 50.8219C61.1889 52.9028 62.8247 54.5405 64.9056 54.818L68.6666 55.3208L71.678 57.6214C73.3446 58.8949 75.6548 58.8949 77.3214 57.6214L80.3348 55.3189H80.3309L84.0842 54.8218C86.1651 54.5463 87.8028 52.9105 88.0802 50.8297L88.5812 47.0687C88.5812 47.0706 89.7449 45.5466 90.8836 44.0572C92.1572 42.3906 92.1553 40.0805 90.8836 38.4138L88.585 35.3985L88.0879 31.6472C87.8124 29.5663 86.1766 27.9286 84.0958 27.6512L80.3329 27.1502L77.3214 24.8497C75.6548 23.5761 73.3446 23.5761 71.678 24.8497L68.6646 27.1502H68.6685L64.9152 27.6492C62.8344 27.9248 61.1966 29.5605 60.9192 31.6414L60.4163 35.4024C60.4163 35.4004 59.2526 36.9245 58.1139 38.4138C56.8422 40.0785 56.8422 42.3906 58.1139 44.0572V44.0572Z" stroke="#12B76A" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
|
172
|
+
<path className="gp-confetti-check" d="M79.9009 38.541L73.1554 45.2865L69.1035 41.2384" stroke="#12B76A" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
|
173
|
+
</g>
|
|
174
|
+
</svg>
|
|
175
|
+
</>
|
|
176
|
+
);
|
|
177
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -659,9 +659,13 @@ export {
|
|
|
659
659
|
ACCOUNT_HUB_SECTION_PARAM,
|
|
660
660
|
ACCOUNT_HUB_FLOW_PARAM,
|
|
661
661
|
ACCOUNT_HUB_COUPON_PARAM,
|
|
662
|
+
ACCOUNT_HUB_PLAN_PARAM,
|
|
663
|
+
ACCOUNT_HUB_TOTAL_PARAM,
|
|
664
|
+
ACCOUNT_HUB_PERIOD_PARAM,
|
|
665
|
+
ACCOUNT_HUB_CHARGE_PARAM,
|
|
662
666
|
} from "./modules/accounts/constants/account-hub-link.constants";
|
|
663
667
|
export { LEGACY_ACCOUNT_ROUTES } from "./modules/accounts/constants/legacy-account-routes.constants";
|
|
664
|
-
export type { AccountHubLink, LegacyAccountRouteTarget } from "./modules/accounts/types/account-hub-link.type";
|
|
668
|
+
export type { AccountHubLink, AccountHubPurchase, LegacyAccountRouteTarget } from "./modules/accounts/types/account-hub-link.type";
|
|
665
669
|
export { parseAccountHubLink } from "./modules/accounts/utils/parse-account-hub-link";
|
|
666
670
|
export { buildAccountHubUrl } from "./modules/accounts/utils/build-account-hub-url";
|
|
667
671
|
export { mapLegacyAccountRoute } from "./modules/accounts/utils/map-legacy-account-route";
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export const ACCOUNT_HUB_SECTION_PARAM = 'account';
|
|
2
2
|
export const ACCOUNT_HUB_FLOW_PARAM = 'flow';
|
|
3
3
|
export const ACCOUNT_HUB_COUPON_PARAM = 'coupon';
|
|
4
|
+
export const ACCOUNT_HUB_PLAN_PARAM = 'plan';
|
|
5
|
+
export const ACCOUNT_HUB_TOTAL_PARAM = 'total';
|
|
6
|
+
export const ACCOUNT_HUB_PERIOD_PARAM = 'period';
|
|
7
|
+
export const ACCOUNT_HUB_CHARGE_PARAM = 'charge';
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import type { AccountHubFlow } from '../../../enums/AccountHubFlow';
|
|
2
|
+
import type { BillingPeriod } from '../../subscriptions/types/billing-period.type';
|
|
2
3
|
import type { MyAccountSection } from '../../../store/useAccountModals';
|
|
3
4
|
|
|
5
|
+
export interface AccountHubPurchase {
|
|
6
|
+
planName: string;
|
|
7
|
+
total: number;
|
|
8
|
+
billingPeriod: BillingPeriod;
|
|
9
|
+
immediateChargeTotal: number | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
export interface AccountHubLink {
|
|
5
13
|
section: MyAccountSection;
|
|
6
14
|
flow?: AccountHubFlow;
|
|
7
15
|
couponCode?: string;
|
|
16
|
+
purchase?: AccountHubPurchase;
|
|
8
17
|
}
|
|
9
18
|
|
|
10
19
|
export interface LegacyAccountRouteTarget {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ACCOUNT_HUB_CHARGE_PARAM,
|
|
2
3
|
ACCOUNT_HUB_COUPON_PARAM,
|
|
3
4
|
ACCOUNT_HUB_FLOW_PARAM,
|
|
5
|
+
ACCOUNT_HUB_PERIOD_PARAM,
|
|
6
|
+
ACCOUNT_HUB_PLAN_PARAM,
|
|
4
7
|
ACCOUNT_HUB_SECTION_PARAM,
|
|
8
|
+
ACCOUNT_HUB_TOTAL_PARAM,
|
|
5
9
|
} from '../constants/account-hub-link.constants';
|
|
6
10
|
import type { AccountHubLink } from '../types/account-hub-link.type';
|
|
7
11
|
|
|
@@ -10,5 +14,15 @@ export function buildAccountHubUrl(baseUrl: string, link: AccountHubLink, pathna
|
|
|
10
14
|
url.searchParams.set(ACCOUNT_HUB_SECTION_PARAM, link.section);
|
|
11
15
|
if (link.flow) url.searchParams.set(ACCOUNT_HUB_FLOW_PARAM, link.flow);
|
|
12
16
|
if (link.couponCode) url.searchParams.set(ACCOUNT_HUB_COUPON_PARAM, link.couponCode);
|
|
17
|
+
|
|
18
|
+
if (link.purchase) {
|
|
19
|
+
url.searchParams.set(ACCOUNT_HUB_PLAN_PARAM, link.purchase.planName);
|
|
20
|
+
url.searchParams.set(ACCOUNT_HUB_TOTAL_PARAM, String(link.purchase.total));
|
|
21
|
+
url.searchParams.set(ACCOUNT_HUB_PERIOD_PARAM, link.purchase.billingPeriod);
|
|
22
|
+
if (link.purchase.immediateChargeTotal != null) {
|
|
23
|
+
url.searchParams.set(ACCOUNT_HUB_CHARGE_PARAM, String(link.purchase.immediateChargeTotal));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
13
27
|
return url.toString();
|
|
14
28
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BillingPeriod } from '../../subscriptions/types/billing-period.type';
|
|
2
|
+
|
|
3
|
+
const BILLING_PERIODS: string[] = ['monthly', 'semiannual', 'annual'];
|
|
4
|
+
|
|
5
|
+
export function isBillingPeriod(value: string): value is BillingPeriod {
|
|
6
|
+
return BILLING_PERIODS.includes(value);
|
|
7
|
+
}
|
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import { AccountHubFlow } from '../../../enums/AccountHubFlow';
|
|
2
2
|
import {
|
|
3
|
+
ACCOUNT_HUB_CHARGE_PARAM,
|
|
3
4
|
ACCOUNT_HUB_COUPON_PARAM,
|
|
4
5
|
ACCOUNT_HUB_FLOW_PARAM,
|
|
6
|
+
ACCOUNT_HUB_PERIOD_PARAM,
|
|
7
|
+
ACCOUNT_HUB_PLAN_PARAM,
|
|
5
8
|
ACCOUNT_HUB_SECTION_PARAM,
|
|
9
|
+
ACCOUNT_HUB_TOTAL_PARAM,
|
|
6
10
|
} from '../constants/account-hub-link.constants';
|
|
7
|
-
import type { AccountHubLink } from '../types/account-hub-link.type';
|
|
11
|
+
import type { AccountHubLink, AccountHubPurchase } from '../types/account-hub-link.type';
|
|
8
12
|
import { isAccountHubFlow } from './is-account-hub-flow';
|
|
13
|
+
import { isBillingPeriod } from './is-billing-period';
|
|
9
14
|
import { isMyAccountSection } from './is-my-account-section';
|
|
10
15
|
|
|
16
|
+
function readPurchase(searchParams: URLSearchParams, flow?: AccountHubFlow): AccountHubPurchase | undefined {
|
|
17
|
+
if (flow !== AccountHubFlow.CONFIRMATION) return undefined;
|
|
18
|
+
|
|
19
|
+
const planName = searchParams.get(ACCOUNT_HUB_PLAN_PARAM);
|
|
20
|
+
const total = Number(searchParams.get(ACCOUNT_HUB_TOTAL_PARAM));
|
|
21
|
+
const period = searchParams.get(ACCOUNT_HUB_PERIOD_PARAM);
|
|
22
|
+
if (!planName || !Number.isFinite(total) || !period || !isBillingPeriod(period)) return undefined;
|
|
23
|
+
|
|
24
|
+
const charge = Number(searchParams.get(ACCOUNT_HUB_CHARGE_PARAM));
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
planName,
|
|
28
|
+
total,
|
|
29
|
+
billingPeriod: period,
|
|
30
|
+
immediateChargeTotal: Number.isFinite(charge) && charge > 0 ? charge : null,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
11
34
|
export function parseAccountHubLink(searchParams: URLSearchParams): AccountHubLink | null {
|
|
12
35
|
const section = searchParams.get(ACCOUNT_HUB_SECTION_PARAM);
|
|
13
36
|
if (!section || !isMyAccountSection(section)) return null;
|
|
@@ -17,5 +40,5 @@ export function parseAccountHubLink(searchParams: URLSearchParams): AccountHubLi
|
|
|
17
40
|
const couponCode =
|
|
18
41
|
resolvedFlow === AccountHubFlow.PLANS ? (searchParams.get(ACCOUNT_HUB_COUPON_PARAM) ?? undefined) : undefined;
|
|
19
42
|
|
|
20
|
-
return { section, flow: resolvedFlow, couponCode };
|
|
43
|
+
return { section, flow: resolvedFlow, couponCode, purchase: readPurchase(searchParams, resolvedFlow) };
|
|
21
44
|
}
|