@greatapps/common 1.1.791 → 1.1.793

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 (59) hide show
  1. package/dist/components/account/AccountHubLinkHandler.mjs +16 -4
  2. package/dist/components/account/AccountHubLinkHandler.mjs.map +1 -1
  3. package/dist/components/account/AccountUnsavedChangesDialog.mjs +34 -0
  4. package/dist/components/account/AccountUnsavedChangesDialog.mjs.map +1 -0
  5. package/dist/components/account/MyAccountModal.mjs +28 -22
  6. package/dist/components/account/MyAccountModal.mjs.map +1 -1
  7. package/dist/components/account/hooks/useAccountHubActions.mjs +15 -0
  8. package/dist/components/account/hooks/useAccountHubActions.mjs.map +1 -1
  9. package/dist/components/account/sections/MyProfileSection.mjs +20 -22
  10. package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
  11. package/dist/components/account/sections/PreferencesSection.mjs +15 -20
  12. package/dist/components/account/sections/PreferencesSection.mjs.map +1 -1
  13. package/dist/components/account/sections/subscription/PaymentConfirmationDialog.mjs +3 -2
  14. package/dist/components/account/sections/subscription/PaymentConfirmationDialog.mjs.map +1 -1
  15. package/dist/components/ui/data-display/SuccessConfettiIcon.mjs +40 -0
  16. package/dist/components/ui/data-display/SuccessConfettiIcon.mjs.map +1 -0
  17. package/dist/enums/AccountHubFlow.mjs +1 -0
  18. package/dist/enums/AccountHubFlow.mjs.map +1 -1
  19. package/dist/i18n/messages/en-us.mjs +5 -0
  20. package/dist/i18n/messages/en-us.mjs.map +1 -1
  21. package/dist/i18n/messages/es-es.mjs +5 -0
  22. package/dist/i18n/messages/es-es.mjs.map +1 -1
  23. package/dist/i18n/messages/pt-br.mjs +5 -0
  24. package/dist/i18n/messages/pt-br.mjs.map +1 -1
  25. package/dist/index.mjs +9 -1
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/middlewares/create-auth-middleware.mjs +1 -1
  28. package/dist/middlewares/create-auth-middleware.mjs.map +1 -1
  29. package/dist/modules/accounts/constants/account-hub-link.constants.mjs +9 -1
  30. package/dist/modules/accounts/constants/account-hub-link.constants.mjs.map +1 -1
  31. package/dist/modules/accounts/utils/build-account-hub-url.mjs +13 -1
  32. package/dist/modules/accounts/utils/build-account-hub-url.mjs.map +1 -1
  33. package/dist/modules/accounts/utils/is-billing-period.mjs +8 -0
  34. package/dist/modules/accounts/utils/is-billing-period.mjs.map +1 -0
  35. package/dist/modules/accounts/utils/parse-account-hub-link.mjs +21 -2
  36. package/dist/modules/accounts/utils/parse-account-hub-link.mjs.map +1 -1
  37. package/dist/store/useAccountUnsavedChanges.mjs +31 -0
  38. package/dist/store/useAccountUnsavedChanges.mjs.map +1 -0
  39. package/package.json +1 -1
  40. package/src/components/account/AccountHubLinkHandler.tsx +15 -3
  41. package/src/components/account/AccountUnsavedChangesDialog.tsx +49 -0
  42. package/src/components/account/MyAccountModal.tsx +41 -34
  43. package/src/components/account/hooks/useAccountHubActions.ts +17 -1
  44. package/src/components/account/sections/MyProfileSection.tsx +24 -20
  45. package/src/components/account/sections/PreferencesSection.tsx +17 -21
  46. package/src/components/account/sections/subscription/PaymentConfirmationDialog.tsx +3 -2
  47. package/src/components/ui/data-display/SuccessConfettiIcon.tsx +33 -0
  48. package/src/enums/AccountHubFlow.ts +1 -0
  49. package/src/i18n/messages/en-us.ts +5 -0
  50. package/src/i18n/messages/es-es.ts +5 -0
  51. package/src/i18n/messages/pt-br.ts +5 -0
  52. package/src/index.ts +5 -1
  53. package/src/middlewares/create-auth-middleware.ts +1 -1
  54. package/src/modules/accounts/constants/account-hub-link.constants.ts +4 -0
  55. package/src/modules/accounts/types/account-hub-link.type.ts +9 -0
  56. package/src/modules/accounts/utils/build-account-hub-url.ts +14 -0
  57. package/src/modules/accounts/utils/is-billing-period.ts +7 -0
  58. package/src/modules/accounts/utils/parse-account-hub-link.ts +25 -2
  59. package/src/store/useAccountUnsavedChanges.ts +52 -0
@@ -29,9 +29,11 @@ import { ProjectsSection } from './sections/ProjectsSection';
29
29
  import { TeamSection } from './sections/TeamSection';
30
30
  import { AffiliatesSection } from './sections/AffiliatesSection';
31
31
  import useMyAccountModal from './hooks/useMyAccountModal';
32
+ import AccountUnsavedChangesDialog from './AccountUnsavedChangesDialog';
32
33
  import { AccountSectionType } from '../../enums/AccountSectionType';
33
34
  import { WorkspaceSectionType } from '../../enums/WorkspaceSectionType';
34
35
  import { useAccountModals, type MyAccountSection } from '../../store/useAccountModals';
36
+ import { useAccountUnsavedChanges } from '../../store/useAccountUnsavedChanges';
35
37
  import { useAuth } from '../../providers/auth.provider';
36
38
  import { useManagementPermissions } from '../../modules/auth/hooks/useManagementPermissions';
37
39
  import { useCurrentSubscription } from '../../modules/subscriptions/hooks/use-current-subscription.hook';
@@ -55,6 +57,7 @@ export default function MyAccountModal() {
55
57
  const { isExternalContracting } = useExternalContracting();
56
58
  const { whitelabel } = useWhitelabel();
57
59
  const { data: { data: [subscription] = [] } = {} } = useCurrentSubscription();
60
+ const guardUnsavedChanges = useAccountUnsavedChanges((state) => state.guard);
58
61
 
59
62
  const open = activeModal === 'account';
60
63
 
@@ -82,14 +85,14 @@ export default function MyAccountModal() {
82
85
  icon: IconUser,
83
86
  label: translate('common.account.profile.title'),
84
87
  visible: true,
85
- content: <MyProfileSection onClose={close} />,
88
+ content: <MyProfileSection />,
86
89
  },
87
90
  {
88
91
  value: AccountSectionType.PREFERENCES,
89
92
  icon: IconSettings2,
90
93
  label: translate('common.preferences.title'),
91
94
  visible: true,
92
- content: <PreferencesSection onClose={close} />,
95
+ content: <PreferencesSection />,
93
96
  },
94
97
  {
95
98
  value: AccountSectionType.TOKEN,
@@ -178,38 +181,42 @@ export default function MyAccountModal() {
178
181
  ));
179
182
 
180
183
  return (
181
- <AccountModalLayout
182
- open={open}
183
- onClose={close}
184
- title={translate('common.account.workspace.title')}
185
- sectionTitle={sectionTitle}
186
- activeSection={activeSection ?? ''}
187
- onSectionChange={setActiveSection}
188
- isLoading={isProfileLoading}
189
- navigation={
190
- <>
191
- {visibleWorkspaceSections.length > 0 && (
192
- <AccountModalNavGroup label={translate('common.account.workspace.groups.workspace')}>
193
- {renderNavItems(visibleWorkspaceSections)}
184
+ <>
185
+ <AccountModalLayout
186
+ open={open}
187
+ onClose={() => guardUnsavedChanges(close)}
188
+ title={translate('common.account.workspace.title')}
189
+ sectionTitle={sectionTitle}
190
+ activeSection={activeSection ?? ''}
191
+ onSectionChange={(section) => guardUnsavedChanges(() => setActiveSection(section))}
192
+ isLoading={isProfileLoading}
193
+ navigation={
194
+ <>
195
+ {visibleWorkspaceSections.length > 0 && (
196
+ <AccountModalNavGroup label={translate('common.account.workspace.groups.workspace')}>
197
+ {renderNavItems(visibleWorkspaceSections)}
198
+ </AccountModalNavGroup>
199
+ )}
200
+ <AccountModalNavGroup label={translate('common.account.workspace.groups.account')}>
201
+ {renderNavItems(visibleAccountSections)}
194
202
  </AccountModalNavGroup>
195
- )}
196
- <AccountModalNavGroup label={translate('common.account.workspace.groups.account')}>
197
- {renderNavItems(visibleAccountSections)}
198
- </AccountModalNavGroup>
199
- </>
200
- }
201
- >
202
- {visibleSections.map((section) => (
203
- <AccountModalSection key={section.value} value={section.value}>
204
- {section.content}
205
- </AccountModalSection>
206
- ))}
207
-
208
- {changePasswordSection.map((section) => (
209
- <AccountModalSection key={section.value} value={section.value}>
210
- {section.content}
211
- </AccountModalSection>
212
- ))}
213
- </AccountModalLayout>
203
+ </>
204
+ }
205
+ >
206
+ {visibleSections.map((section) => (
207
+ <AccountModalSection key={section.value} value={section.value}>
208
+ {section.content}
209
+ </AccountModalSection>
210
+ ))}
211
+
212
+ {changePasswordSection.map((section) => (
213
+ <AccountModalSection key={section.value} value={section.value}>
214
+ {section.content}
215
+ </AccountModalSection>
216
+ ))}
217
+ </AccountModalLayout>
218
+
219
+ <AccountUnsavedChangesDialog />
220
+ </>
214
221
  );
215
222
  }
@@ -2,9 +2,11 @@
2
2
 
3
3
  import { AccountHubFlow } from '../../../enums/AccountHubFlow';
4
4
  import { WorkspaceSectionType } from '../../../enums/WorkspaceSectionType';
5
+ import { useTranslations } from 'next-intl';
5
6
  import { useCouponByCode } from '../../../modules/coupons/hooks/use-coupon-by-code.hook';
6
7
  import { isAccountSectionType } from '../../../modules/accounts/utils/is-account-section';
7
- import type { AccountHubLink } from '../../../modules/accounts/types/account-hub-link.type';
8
+ import type { AccountHubLink, AccountHubPurchase } from '../../../modules/accounts/types/account-hub-link.type';
9
+ import { getBillingPeriodSuffix } from '../../../modules/subscriptions/utils/periodicity';
8
10
  import { useExternalContracting } from '../../../providers/whitelabel.provider';
9
11
  import { useAccountModals, type MyAccountSection } from '../../../store/useAccountModals';
10
12
  import { useProjectFlows } from '../../../store/useProjectFlows';
@@ -19,7 +21,9 @@ export default function useAccountHubActions() {
19
21
  const requestOverdueReceipt = useSubscriptionFlows((state) => state.requestOverdueReceipt);
20
22
  const openCreateProjectFlow = useProjectFlows((state) => state.openCreateProject);
21
23
  const openAddUserFlow = useTeamFlows((state) => state.openAddUser);
24
+ const openPaymentConfirmationFlow = useSubscriptionFlows((state) => state.openPaymentConfirmation);
22
25
  const { redirectToExternal } = useExternalContracting();
26
+ const translate = useTranslations();
23
27
  const { mutate: findCouponByCode } = useCouponByCode();
24
28
 
25
29
  const openSection = (section: MyAccountSection) => {
@@ -72,6 +76,16 @@ export default function useAccountHubActions() {
72
76
  openAddUserFlow();
73
77
  };
74
78
 
79
+ const openPaymentConfirmation = (purchase: AccountHubPurchase) => {
80
+ openWorkspace(WorkspaceSectionType.SUBSCRIPTION);
81
+ openPaymentConfirmationFlow({
82
+ planName: purchase.planName,
83
+ total: purchase.total,
84
+ periodLabel: getBillingPeriodSuffix(purchase.billingPeriod, translate),
85
+ immediateChargeTotal: purchase.immediateChargeTotal,
86
+ });
87
+ };
88
+
75
89
  const openLink = (link: AccountHubLink) => {
76
90
  if (link.flow === AccountHubFlow.PLANS) return openPlansCatalog(link.couponCode);
77
91
  if (link.flow === AccountHubFlow.ADDONS) return openAddons();
@@ -79,6 +93,7 @@ export default function useAccountHubActions() {
79
93
  if (link.flow === AccountHubFlow.RECEIPT) return openOverdueReceipt();
80
94
  if (link.flow === AccountHubFlow.CREATE_PROJECT) return openCreateProject();
81
95
  if (link.flow === AccountHubFlow.ADD_USER) return openAddUser();
96
+ if (link.flow === AccountHubFlow.CONFIRMATION && link.purchase) return openPaymentConfirmation(link.purchase);
82
97
  openSection(link.section);
83
98
  };
84
99
 
@@ -90,6 +105,7 @@ export default function useAccountHubActions() {
90
105
  openOverdueReceipt,
91
106
  openCreateProject,
92
107
  openAddUser,
108
+ openPaymentConfirmation,
93
109
  openLink,
94
110
  };
95
111
  }
@@ -25,6 +25,7 @@ import { ChangeEmailModal } from './ChangeEmailModal';
25
25
  import { NotificationsStep } from './team/steps/NotificationsStep';
26
26
  import { ProjectSelectionStep } from './team/steps/ProjectSelectionStep';
27
27
  import { FormSection } from './shared/FormSection';
28
+ import { useAccountUnsavedChanges } from '../../../store/useAccountUnsavedChanges';
28
29
  import { buildUserFormDefaults, buildUserFormSchema, type UserFormData } from './team/user-form.schema';
29
30
 
30
31
  /** Espaçamento das seções do modal, aplicado dentro de cada aba. */
@@ -40,11 +41,10 @@ const tabContentClasses = cn(
40
41
  const tabTriggerClasses = 'cursor-pointer gap-2 px-3 py-4';
41
42
 
42
43
  interface MyProfileSectionProps {
43
- onClose: () => void;
44
44
  storageUrl?: string;
45
45
  }
46
46
 
47
- export function MyProfileSection({ onClose, storageUrl }: MyProfileSectionProps) {
47
+ export function MyProfileSection({ storageUrl }: MyProfileSectionProps) {
48
48
  const translate = useTranslations();
49
49
  const genderOptions = GENDER_OPTIONS.map((option) => ({
50
50
  ...option,
@@ -60,6 +60,9 @@ export function MyProfileSection({ onClose, storageUrl }: MyProfileSectionProps)
60
60
  const [photoRemoved, setPhotoRemoved] = useState(false);
61
61
  const [changePhoneOpen, setChangePhoneOpen] = useState(false);
62
62
  const [changeEmailOpen, setChangeEmailOpen] = useState(false);
63
+ const setDirtyForm = useAccountUnsavedChanges((state) => state.setDirtyForm);
64
+ const completeSave = useAccountUnsavedChanges((state) => state.completeSave);
65
+ const dismissUnsavedChanges = useAccountUnsavedChanges((state) => state.dismiss);
63
66
 
64
67
  // Mesmo formulário do sheet da equipe: as abas Projetos e Notificações são os passos de lá.
65
68
  const profileFormSchema = useMemo(
@@ -82,7 +85,7 @@ export function MyProfileSection({ onClose, storageUrl }: MyProfileSectionProps)
82
85
  handleSubmit,
83
86
  watch,
84
87
  setValue,
85
- formState: { errors, isSubmitting },
88
+ formState: { errors, isSubmitting, isDirty },
86
89
  } = form;
87
90
 
88
91
  // O usuário autenticado chega por query: repõe os valores quando ele carrega depois da montagem.
@@ -134,7 +137,7 @@ export function MyProfileSection({ onClose, storageUrl }: MyProfileSectionProps)
134
137
  toastId={toastId}
135
138
  />
136
139
  ));
137
- onClose();
140
+ completeSave();
138
141
  } catch (error) {
139
142
  toast.custom((toastId) => (
140
143
  <Toast
@@ -143,9 +146,24 @@ export function MyProfileSection({ onClose, storageUrl }: MyProfileSectionProps)
143
146
  toastId={toastId}
144
147
  />
145
148
  ));
149
+ dismissUnsavedChanges();
146
150
  }
147
151
  };
148
152
 
153
+ const hasChanges = isDirty || selectedPhoto !== null || photoRemoved;
154
+
155
+ const discardChanges = () => {
156
+ form.reset();
157
+ setSelectedPhoto(null);
158
+ setPhotoRemoved(false);
159
+ };
160
+
161
+ useEffect(() => {
162
+ if (!hasChanges) return;
163
+ setDirtyForm({ submit: handleSubmit(onSubmit), discard: discardChanges });
164
+ return () => setDirtyForm(null);
165
+ });
166
+
149
167
  return (
150
168
  <>
151
169
  <FormProvider {...form}>
@@ -311,22 +329,8 @@ export function MyProfileSection({ onClose, storageUrl }: MyProfileSectionProps)
311
329
  </TabsContent>
312
330
  </Tabs>
313
331
 
314
- <div className="fixed bottom-0 left-0 right-0 lg:absolute flex items-center h-20 px-4 lg:px-8 border-t border-gray-200 justify-between bg-white z-10">
315
- <Button
316
- variant="secondary"
317
- className="h-10!"
318
- type="button"
319
- disabled={isSubmitting}
320
- onClick={() => {
321
- form.reset();
322
- setSelectedPhoto(null);
323
- setPhotoRemoved(false);
324
- onClose();
325
- }}
326
- >
327
- {translate('common.actions.cancel')}
328
- </Button>
329
- <Button className="h-10! cursor-pointer" type="submit" disabled={isSubmitting}>
332
+ <div className="fixed bottom-0 left-0 right-0 lg:absolute flex items-center h-20 px-4 lg:px-8 border-t border-gray-200 justify-end bg-white z-10">
333
+ <Button className="h-10! cursor-pointer" type="submit" disabled={!hasChanges || isSubmitting}>
330
334
  {isSubmitting ? translate('common.actions.saving') : translate('common.actions.saveChanges')}
331
335
  </Button>
332
336
  </div>
@@ -32,6 +32,7 @@ import {
32
32
  } from '../constants';
33
33
  import { useTimezones } from '../../../modules/accounts/hooks/useTimezones';
34
34
  import { useCurrencies } from '../../../modules/accounts/hooks/useCurrencies';
35
+ import { useAccountUnsavedChanges } from '../../../store/useAccountUnsavedChanges';
35
36
  import { getCurrencyForGateway } from '../../../utils/format/currency';
36
37
 
37
38
  interface PreferencesFormValues {
@@ -44,11 +45,7 @@ interface PreferencesFormValues {
44
45
  receive_email: boolean;
45
46
  }
46
47
 
47
- interface PreferencesSectionProps {
48
- onClose: () => void;
49
- }
50
-
51
- export function PreferencesSection({ onClose }: PreferencesSectionProps) {
48
+ export function PreferencesSection() {
52
49
  // Padrão raiz: um único `translate` chamado pela chave inteira (`common.<modulo>.<chave>`).
53
50
  const translate = useTranslations();
54
51
  // Exceção: chave dinâmica (option.value) numa lista → namespace escopado.
@@ -80,8 +77,11 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
80
77
  accountFields: UpdateAccountRequest;
81
78
  } | null>(null);
82
79
  const [isSaving, setIsSaving] = useState(false);
80
+ const setDirtyForm = useAccountUnsavedChanges((state) => state.setDirtyForm);
81
+ const completeSave = useAccountUnsavedChanges((state) => state.completeSave);
82
+ const dismissUnsavedChanges = useAccountUnsavedChanges((state) => state.dismiss);
83
83
 
84
- const { watch, setValue, handleSubmit, reset, formState: { dirtyFields } } =
84
+ const { watch, setValue, handleSubmit, reset, formState: { dirtyFields, isDirty } } =
85
85
  useForm<PreferencesFormValues>({
86
86
  defaultValues: {
87
87
  companyName: '',
@@ -129,7 +129,7 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
129
129
  toast.custom((toastId) => (
130
130
  <Toast variant="success" message={translate('common.preferences.savedSuccess')} toastId={toastId} />
131
131
  ));
132
- onClose();
132
+ completeSave();
133
133
  if (data.language !== currentLocale) {
134
134
  setLocaleCookie(data.language, whitelabel?.domain);
135
135
  router.refresh();
@@ -142,6 +142,7 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
142
142
  toastId={toastId}
143
143
  />
144
144
  ));
145
+ dismissUnsavedChanges();
145
146
  } finally {
146
147
  setIsSaving(false);
147
148
  }
@@ -174,8 +175,15 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
174
175
  const handleCancelGlobal = () => {
175
176
  setConfirmGlobalOpen(false);
176
177
  setPendingSubmit(null);
178
+ dismissUnsavedChanges();
177
179
  };
178
180
 
181
+ useEffect(() => {
182
+ if (!isDirty) return;
183
+ setDirtyForm({ submit: handleSubmit(onSubmit), discard: () => reset() });
184
+ return () => setDirtyForm(null);
185
+ });
186
+
179
187
  return (
180
188
  <>
181
189
  <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col h-full">
@@ -254,20 +262,8 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
254
262
  </FormSection>
255
263
  </div>
256
264
 
257
- <div className="fixed bottom-0 left-0 right-0 lg:absolute flex items-center h-20 px-4 lg:px-8 border-t border-gray-200 justify-between bg-white z-10">
258
- <Button
259
- variant="secondary"
260
- className="h-10!"
261
- type="button"
262
- disabled={isSaving}
263
- onClick={() => {
264
- reset();
265
- onClose();
266
- }}
267
- >
268
- {translate('common.actions.cancel')}
269
- </Button>
270
- <Button className="h-10!" type="submit" disabled={isSaving}>
265
+ <div className="fixed bottom-0 left-0 right-0 lg:absolute flex items-center h-20 px-4 lg:px-8 border-t border-gray-200 justify-end bg-white z-10">
266
+ <Button className="h-10!" type="submit" disabled={!isDirty || isSaving}>
271
267
  {isSaving ? translate('common.actions.saving') : translate('common.actions.saveChanges')}
272
268
  </Button>
273
269
  </div>
@@ -1,8 +1,9 @@
1
1
  'use client';
2
2
 
3
- import { IconCircleCheckFilled, IconInfoCircle } from '@tabler/icons-react';
3
+ import { IconInfoCircle } from '@tabler/icons-react';
4
4
  import { useTranslations } from 'next-intl';
5
5
  import { Dialog, DialogContent, DialogTitle } from '../../../ui/overlay/Dialog';
6
+ import { SuccessConfettiIcon } from '../../../ui/data-display/SuccessConfettiIcon';
6
7
  import { useCurrencyFormatter } from '../../../../modules/accounts/hooks/use-currency-formatter.hook';
7
8
  import { useIsDefaultWhitelabel } from '../../../../providers/whitelabel.provider';
8
9
  import { cn } from '../../../../infra/utils/clsx';
@@ -27,7 +28,7 @@ export function PaymentConfirmationDialog() {
27
28
  return (
28
29
  <Dialog open={!!confirmation} onOpenChange={(nextOpen) => !nextOpen && close()}>
29
30
  <DialogContent className="flex flex-col p-4 lg:p-6 gap-4 items-center max-w-[calc(100%-32px)]! h-auto! rounded-lg border top-[50%]! left-[50%]! right-auto! bottom-auto! translate-x-[-50%]! translate-y-[-50%]! lg:max-w-[386px]!">
30
- <IconCircleCheckFilled size={56} className="text-green-500" />
31
+ <SuccessConfettiIcon />
31
32
 
32
33
  <div className="flex flex-col gap-2 text-center">
33
34
  <DialogTitle className="paragraph-medium-semibold text-zinc-950">
@@ -0,0 +1,33 @@
1
+ export function SuccessConfettiIcon({ className }: { className?: string }) {
2
+ return (
3
+ <svg
4
+ width="149"
5
+ height="83"
6
+ viewBox="0 0 149 83"
7
+ fill="none"
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ className={className}
10
+ aria-hidden
11
+ >
12
+ <path opacity="0.4" d="M18.6348 28.4102C18.6348 30.574 19.9096 30.8716 21.7838 31.1393" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
13
+ <path opacity="0.4" d="M109.117 41.4266C110.106 41.3745 110.639 40.9023 110.797 39.957" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
14
+ <path opacity="0.4" d="M64.6035 75.1963C62.2234 77.2378 61.7986 79.4524 63.2302 82.1283" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
15
+ <path opacity="0.4" 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"/>
16
+ <path opacity="0.4" 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"/>
17
+ <path opacity="0.4" 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"/>
18
+ <path d="M112.314 25.2715L113.514 24.7026" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
19
+ <path d="M51.492 49.2344C51.0065 49.3838 50.6337 49.7823 50.2324 50.0741" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
20
+ <path opacity="0.4" d="M77.8867 9.72656C77.4011 9.87596 77.3223 10.0019 77.3223 10.0019" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
21
+ <path opacity="0.4" d="M10.7246 56.0059C10.239 56.1553 10.1602 56.2812 10.1602 56.2812" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
22
+ <path opacity="0.4" d="M28.3302 80.1108C28.6726 79.7356 28.6766 79.587 28.6766 79.587" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
23
+ <path opacity="0.4" d="M128.043 49.0421C127.77 48.6138 127.627 48.5713 127.627 48.5713" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
24
+ <path opacity="0.4" d="M135.461 29.4915C134.972 29.6314 134.891 29.7558 134.891 29.7558" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
25
+ <path opacity="0.4" d="M52.3396 22.1222C52.0664 21.6939 51.924 21.6514 51.924 21.6514" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
26
+ <path d="M45.9383 40.1115L45.1508 39.1744" stroke="#12B76A" strokeWidth="1.12879" strokeLinecap="round"/>
27
+ <path opacity="0.8" 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"/>
28
+ <path 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"/>
29
+ <path 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"/>
30
+ <path d="M79.9009 38.541L73.1554 45.2865L69.1035 41.2384" stroke="#12B76A" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
31
+ </svg>
32
+ );
33
+ }
@@ -5,4 +5,5 @@ export enum AccountHubFlow {
5
5
  RECEIPT = 'receipt',
6
6
  CREATE_PROJECT = 'create-project',
7
7
  ADD_USER = 'add-user',
8
+ CONFIRMATION = 'confirmation',
8
9
  }
@@ -59,6 +59,11 @@ const messages = {
59
59
  },
60
60
 
61
61
  account: {
62
+ unsavedChanges: {
63
+ title: 'Leave without saving?',
64
+ description: 'You have unsaved changes. Do you want to save before leaving?',
65
+ discard: 'Leave without saving',
66
+ },
62
67
  notificationTypes: {
63
68
  projectUpdates: 'Project updates',
64
69
  securityAlerts: 'Security alerts',
@@ -59,6 +59,11 @@ const messages = {
59
59
  },
60
60
 
61
61
  account: {
62
+ unsavedChanges: {
63
+ title: '¿Salir sin guardar?',
64
+ description: 'Tienes cambios sin guardar. ¿Deseas guardar antes de salir?',
65
+ discard: 'Salir sin guardar',
66
+ },
62
67
  notificationTypes: {
63
68
  projectUpdates: 'Actualizaciones de proyectos',
64
69
  securityAlerts: 'Alertas de seguridad',
@@ -68,6 +68,11 @@ const messages = {
68
68
 
69
69
  // Conta — modais e seções. `<b>` = trecho em negrito (rich text); `{count}` = interpolação.
70
70
  account: {
71
+ unsavedChanges: {
72
+ title: 'Sair sem salvar?',
73
+ description: 'Você fez alterações que ainda não foram salvas. Deseja salvar antes de sair?',
74
+ discard: 'Sair sem salvar',
75
+ },
71
76
  notificationTypes: {
72
77
  projectUpdates: 'Atualizações de projetos',
73
78
  securityAlerts: 'Alertas de segurança',
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";
@@ -40,7 +40,7 @@ export function createAuthMiddleware(options?: CreateAuthMiddlewareOptions): Mid
40
40
  ? new URL('/login', accountsUrl)
41
41
  : new URL('/login', request.url);
42
42
 
43
- if (pathname !== '/') {
43
+ if (pathname !== '/' || request.nextUrl.search) {
44
44
  // URL absoluta da página de origem — o login vive em outro domínio (accounts),
45
45
  // então só o pathname faria o redirect cair no host do accounts.
46
46
  const proto =
@@ -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
  }
@@ -0,0 +1,52 @@
1
+ 'use client';
2
+
3
+ import { create } from 'zustand';
4
+
5
+ interface DirtyAccountForm {
6
+ submit: () => void;
7
+ discard: () => void;
8
+ }
9
+
10
+ interface AccountUnsavedChangesState {
11
+ dirtyForm: DirtyAccountForm | null;
12
+ pendingAction: (() => void) | null;
13
+
14
+ setDirtyForm: (form: DirtyAccountForm | null) => void;
15
+ guard: (action: () => void) => void;
16
+ save: () => void;
17
+ completeSave: () => void;
18
+ discard: () => void;
19
+ dismiss: () => void;
20
+ }
21
+
22
+ export const useAccountUnsavedChanges = create<AccountUnsavedChangesState>((set, get) => ({
23
+ dirtyForm: null,
24
+ pendingAction: null,
25
+
26
+ setDirtyForm: (dirtyForm) => set({ dirtyForm }),
27
+
28
+ guard: (action) => {
29
+ if (get().dirtyForm) {
30
+ set({ pendingAction: action });
31
+ return;
32
+ }
33
+ action();
34
+ },
35
+
36
+ save: () => get().dirtyForm?.submit(),
37
+
38
+ completeSave: () => {
39
+ const { pendingAction } = get();
40
+ set({ pendingAction: null });
41
+ pendingAction?.();
42
+ },
43
+
44
+ discard: () => {
45
+ const { dirtyForm, pendingAction } = get();
46
+ dirtyForm?.discard();
47
+ set({ dirtyForm: null, pendingAction: null });
48
+ pendingAction?.();
49
+ },
50
+
51
+ dismiss: () => set({ pendingAction: null }),
52
+ }));