@greatapps/common 1.1.790 → 1.1.792
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 +36 -0
- package/dist/components/account/AccountHubLinkHandler.mjs.map +1 -0
- package/dist/components/account/AccountModalLayout.mjs +137 -0
- package/dist/components/account/AccountModalLayout.mjs.map +1 -0
- package/dist/components/account/AccountModals.mjs +10 -3
- package/dist/components/account/AccountModals.mjs.map +1 -1
- package/dist/components/account/AccountUnsavedChangesDialog.mjs +34 -0
- package/dist/components/account/AccountUnsavedChangesDialog.mjs.map +1 -0
- package/dist/components/account/DeleteAccountModal.mjs +1 -1
- package/dist/components/account/DeleteAccountModal.mjs.map +1 -1
- package/dist/components/account/IsntPossibleDeleteAccountModal.mjs +8 -1
- package/dist/components/account/IsntPossibleDeleteAccountModal.mjs.map +1 -1
- package/dist/components/account/MyAccountModal.mjs +173 -0
- package/dist/components/account/MyAccountModal.mjs.map +1 -0
- package/dist/components/account/TwoFactorAuthModal.mjs +1 -1
- package/dist/components/account/TwoFactorAuthModal.mjs.map +1 -1
- package/dist/components/account/hooks/useAccountHubActions.mjs +85 -0
- package/dist/components/account/hooks/useAccountHubActions.mjs.map +1 -0
- package/dist/components/account/hooks/useAddCardWithPaymentSwitch.mjs +44 -0
- package/dist/components/account/hooks/useAddCardWithPaymentSwitch.mjs.map +1 -0
- package/dist/components/account/hooks/useAffiliatesActions.mjs +69 -0
- package/dist/components/account/hooks/useAffiliatesActions.mjs.map +1 -0
- package/dist/components/account/hooks/useMyAccountModal.mjs +27 -0
- package/dist/components/account/hooks/useMyAccountModal.mjs.map +1 -0
- package/dist/components/account/hooks/useProjectsActions.mjs +40 -0
- package/dist/components/account/hooks/useProjectsActions.mjs.map +1 -0
- package/dist/components/account/hooks/useSubscriptionActions.mjs +87 -0
- package/dist/components/account/hooks/useSubscriptionActions.mjs.map +1 -0
- package/dist/components/account/hooks/useTeamActions.mjs +31 -0
- package/dist/components/account/hooks/useTeamActions.mjs.map +1 -0
- package/dist/components/account/sections/AffiliatesSection.mjs +313 -0
- package/dist/components/account/sections/AffiliatesSection.mjs.map +1 -0
- package/dist/components/account/sections/ChangePasswordSection.mjs +5 -5
- package/dist/components/account/sections/ChangePasswordSection.mjs.map +1 -1
- package/dist/components/account/sections/MyProfileSection.mjs +212 -164
- package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
- package/dist/components/account/sections/PreferencesSection.mjs +74 -68
- package/dist/components/account/sections/PreferencesSection.mjs.map +1 -1
- package/dist/components/account/sections/ProjectsSection.mjs +77 -0
- package/dist/components/account/sections/ProjectsSection.mjs.map +1 -0
- package/dist/components/account/sections/SecuritySection.mjs +55 -36
- package/dist/components/account/sections/SecuritySection.mjs.map +1 -1
- package/dist/components/account/sections/SubscriptionSection.mjs +29 -0
- package/dist/components/account/sections/SubscriptionSection.mjs.map +1 -0
- package/dist/components/account/sections/TeamSection.mjs +119 -0
- package/dist/components/account/sections/TeamSection.mjs.map +1 -0
- package/dist/components/account/sections/TokenSection.mjs +41 -43
- package/dist/components/account/sections/TokenSection.mjs.map +1 -1
- package/dist/components/account/sections/affiliates/AffiliateCommissionCard.mjs +73 -0
- package/dist/components/account/sections/affiliates/AffiliateCommissionCard.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/AffiliateFlows.mjs +20 -0
- package/dist/components/account/sections/affiliates/AffiliateFlows.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/AffiliateLeadsSheet.mjs +99 -0
- package/dist/components/account/sections/affiliates/AffiliateLeadsSheet.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/AffiliateStatsCard.mjs +31 -0
- package/dist/components/account/sections/affiliates/AffiliateStatsCard.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/AffiliateStepCard.mjs +15 -0
- package/dist/components/account/sections/affiliates/AffiliateStepCard.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/AffiliateTransactionsList.mjs +108 -0
- package/dist/components/account/sections/affiliates/AffiliateTransactionsList.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/NoReceivingAccountModal.mjs +49 -0
- package/dist/components/account/sections/affiliates/NoReceivingAccountModal.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/ReceivingAccountModal.mjs +182 -0
- package/dist/components/account/sections/affiliates/ReceivingAccountModal.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/RequestWithdrawalSheet.mjs +476 -0
- package/dist/components/account/sections/affiliates/RequestWithdrawalSheet.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/ViewAttachmentModal.mjs +34 -0
- package/dist/components/account/sections/affiliates/ViewAttachmentModal.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/reports/AffiliatesIndicatorsChart.mjs +27 -0
- package/dist/components/account/sections/affiliates/reports/AffiliatesIndicatorsChart.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/reports/AffiliatesReportsTab.mjs +30 -0
- package/dist/components/account/sections/affiliates/reports/AffiliatesReportsTab.mjs.map +1 -0
- package/dist/components/account/sections/affiliates/reports/useAffiliatesIndicatorsChart.mjs +120 -0
- package/dist/components/account/sections/affiliates/reports/useAffiliatesIndicatorsChart.mjs.map +1 -0
- package/dist/components/account/sections/projects/DeleteProjectModal.mjs +205 -0
- package/dist/components/account/sections/projects/DeleteProjectModal.mjs.map +1 -0
- package/dist/components/account/sections/projects/ProjectFlows.mjs +16 -0
- package/dist/components/account/sections/projects/ProjectFlows.mjs.map +1 -0
- package/dist/components/account/sections/projects/ProjectMembersStack.mjs +53 -0
- package/dist/components/account/sections/projects/ProjectMembersStack.mjs.map +1 -0
- package/dist/components/account/sections/projects/ProjectRow.mjs +85 -0
- package/dist/components/account/sections/projects/ProjectRow.mjs.map +1 -0
- package/dist/components/account/sections/projects/ProjectSheet.mjs +499 -0
- package/dist/components/account/sections/projects/ProjectSheet.mjs.map +1 -0
- package/dist/components/account/sections/projects/ProjectsDisabledModal.mjs +55 -0
- package/dist/components/account/sections/projects/ProjectsDisabledModal.mjs.map +1 -0
- package/dist/components/account/sections/projects/project-form.schema.mjs +28 -0
- package/dist/components/account/sections/projects/project-form.schema.mjs.map +1 -0
- package/dist/components/account/sections/shared/ConnectListRow.mjs +45 -0
- package/dist/components/account/sections/shared/ConnectListRow.mjs.map +1 -0
- package/dist/components/account/sections/shared/DateFilterPopover.mjs +51 -0
- package/dist/components/account/sections/shared/DateFilterPopover.mjs.map +1 -0
- package/dist/components/account/sections/shared/EntityAvatar.mjs +41 -0
- package/dist/components/account/sections/shared/EntityAvatar.mjs.map +1 -0
- package/dist/components/account/sections/shared/FilterPopover.mjs +62 -0
- package/dist/components/account/sections/shared/FilterPopover.mjs.map +1 -0
- package/dist/components/account/sections/shared/FormSection.mjs +14 -0
- package/dist/components/account/sections/shared/FormSection.mjs.map +1 -0
- package/dist/components/account/sections/shared/IconBox.mjs +18 -0
- package/dist/components/account/sections/shared/IconBox.mjs.map +1 -0
- package/dist/components/account/sections/shared/InfiniteScrollList.mjs +36 -0
- package/dist/components/account/sections/shared/InfiniteScrollList.mjs.map +1 -0
- package/dist/components/account/sections/shared/ListPagination.mjs +69 -0
- package/dist/components/account/sections/shared/ListPagination.mjs.map +1 -0
- package/dist/components/account/sections/shared/RowActionsMenu.mjs +52 -0
- package/dist/components/account/sections/shared/RowActionsMenu.mjs.map +1 -0
- package/dist/components/account/sections/shared/SectionLoadError.mjs +20 -0
- package/dist/components/account/sections/shared/SectionLoadError.mjs.map +1 -0
- package/dist/components/account/sections/shared/StatusBadge.mjs +26 -0
- package/dist/components/account/sections/shared/StatusBadge.mjs.map +1 -0
- package/dist/components/account/sections/shared/WorkspaceSection.mjs +10 -0
- package/dist/components/account/sections/shared/WorkspaceSection.mjs.map +1 -0
- package/dist/components/account/sections/subscription/AiCreditsUsage.mjs +106 -0
- package/dist/components/account/sections/subscription/AiCreditsUsage.mjs.map +1 -0
- package/dist/components/account/sections/subscription/BillingAddressSheet.mjs +407 -0
- package/dist/components/account/sections/subscription/BillingAddressSheet.mjs.map +1 -0
- package/dist/components/account/sections/subscription/BoletoDetailsDialog.mjs +73 -0
- package/dist/components/account/sections/subscription/BoletoDetailsDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/BoletoGeneratedDialog.mjs +22 -0
- package/dist/components/account/sections/subscription/BoletoGeneratedDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/CancelPlanDialog.mjs +161 -0
- package/dist/components/account/sections/subscription/CancelPlanDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/ChargeRow.mjs +127 -0
- package/dist/components/account/sections/subscription/ChargeRow.mjs.map +1 -0
- package/dist/components/account/sections/subscription/ChargeStatusBadge.mjs +27 -0
- package/dist/components/account/sections/subscription/ChargeStatusBadge.mjs.map +1 -0
- package/dist/components/account/sections/subscription/ChargesList.mjs +88 -0
- package/dist/components/account/sections/subscription/ChargesList.mjs.map +1 -0
- package/dist/components/account/sections/subscription/ManageCardsSheet.mjs +49 -0
- package/dist/components/account/sections/subscription/ManageCardsSheet.mjs.map +1 -0
- package/dist/components/account/sections/subscription/OverdueReceiptOpener.mjs +26 -0
- package/dist/components/account/sections/subscription/OverdueReceiptOpener.mjs.map +1 -0
- package/dist/components/account/sections/subscription/PayChargeDialog.mjs +222 -0
- package/dist/components/account/sections/subscription/PayChargeDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/PaymentConfirmationDialog.mjs +61 -0
- package/dist/components/account/sections/subscription/PaymentConfirmationDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/PaymentMethodsCard.mjs +72 -0
- package/dist/components/account/sections/subscription/PaymentMethodsCard.mjs.map +1 -0
- package/dist/components/account/sections/subscription/PendingChangeDialog.mjs +117 -0
- package/dist/components/account/sections/subscription/PendingChangeDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/PixDetailsDialog.mjs +165 -0
- package/dist/components/account/sections/subscription/PixDetailsDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/PixPaymentDialog.mjs +155 -0
- package/dist/components/account/sections/subscription/PixPaymentDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/PlanDetailsSheet.mjs +253 -0
- package/dist/components/account/sections/subscription/PlanDetailsSheet.mjs.map +1 -0
- package/dist/components/account/sections/subscription/ReceiptDetailsSheet.mjs +237 -0
- package/dist/components/account/sections/subscription/ReceiptDetailsSheet.mjs.map +1 -0
- package/dist/components/account/sections/subscription/SubscriptionFlows.mjs +40 -0
- package/dist/components/account/sections/subscription/SubscriptionFlows.mjs.map +1 -0
- package/dist/components/account/sections/subscription/SubscriptionPlanCard.mjs +303 -0
- package/dist/components/account/sections/subscription/SubscriptionPlanCard.mjs.map +1 -0
- package/dist/components/account/sections/subscription/UsageReportSheet.mjs +163 -0
- package/dist/components/account/sections/subscription/UsageReportSheet.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/ChangePlanSheet.mjs +75 -0
- package/dist/components/account/sections/subscription/change-plan/ChangePlanSheet.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/components/AbTestDetailsDialog.mjs +55 -0
- package/dist/components/account/sections/subscription/change-plan/components/AbTestDetailsDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/components/AddonsBlock.mjs +188 -0
- package/dist/components/account/sections/subscription/change-plan/components/AddonsBlock.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/components/AlternativeBucketsSection.mjs +66 -0
- package/dist/components/account/sections/subscription/change-plan/components/AlternativeBucketsSection.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/components/CouponBlock.mjs +42 -0
- package/dist/components/account/sections/subscription/change-plan/components/CouponBlock.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/components/CouponDialog.mjs +119 -0
- package/dist/components/account/sections/subscription/change-plan/components/CouponDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/components/PricePreview.mjs +17 -0
- package/dist/components/account/sections/subscription/change-plan/components/PricePreview.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/components/SummaryBlock.mjs +130 -0
- package/dist/components/account/sections/subscription/change-plan/components/SummaryBlock.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/plan-comparison.mjs +38 -0
- package/dist/components/account/sections/subscription/change-plan/plan-comparison.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/steps/PaymentSummaryStep.mjs +127 -0
- package/dist/components/account/sections/subscription/change-plan/steps/PaymentSummaryStep.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/steps/PlanComparisonStep.mjs +111 -0
- package/dist/components/account/sections/subscription/change-plan/steps/PlanComparisonStep.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/steps/PlanViewStep.mjs +69 -0
- package/dist/components/account/sections/subscription/change-plan/steps/PlanViewStep.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/steps/ReactivationConfigStep.mjs +88 -0
- package/dist/components/account/sections/subscription/change-plan/steps/ReactivationConfigStep.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/steps/ReactivationPaymentStep.mjs +115 -0
- package/dist/components/account/sections/subscription/change-plan/steps/ReactivationPaymentStep.mjs.map +1 -0
- package/dist/components/account/sections/subscription/change-plan/useChangePlanState.mjs +918 -0
- package/dist/components/account/sections/subscription/change-plan/useChangePlanState.mjs.map +1 -0
- package/dist/components/account/sections/subscription/downgrade/CannotDowngradeDialog.mjs +216 -0
- package/dist/components/account/sections/subscription/downgrade/CannotDowngradeDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/downgrade/DowngradeReasonDialog.mjs +128 -0
- package/dist/components/account/sections/subscription/downgrade/DowngradeReasonDialog.mjs.map +1 -0
- package/dist/components/account/sections/subscription/plans/PlanCard.mjs +281 -0
- package/dist/components/account/sections/subscription/plans/PlanCard.mjs.map +1 -0
- package/dist/components/account/sections/subscription/plans/PlanCardSkeleton.mjs +53 -0
- package/dist/components/account/sections/subscription/plans/PlanCardSkeleton.mjs.map +1 -0
- package/dist/components/account/sections/subscription/plans/PlansCatalogDialog.mjs +119 -0
- package/dist/components/account/sections/subscription/plans/PlansCatalogDialog.mjs.map +1 -0
- package/dist/components/account/sections/team/DeleteUserModal.mjs +116 -0
- package/dist/components/account/sections/team/DeleteUserModal.mjs.map +1 -0
- package/dist/components/account/sections/team/TeamFlows.mjs +14 -0
- package/dist/components/account/sections/team/TeamFlows.mjs.map +1 -0
- package/dist/components/account/sections/team/TeamMemberRow.mjs +99 -0
- package/dist/components/account/sections/team/TeamMemberRow.mjs.map +1 -0
- package/dist/components/account/sections/team/UserSheet.mjs +570 -0
- package/dist/components/account/sections/team/UserSheet.mjs.map +1 -0
- package/dist/components/account/sections/team/steps/NotificationsStep.mjs +80 -0
- package/dist/components/account/sections/team/steps/NotificationsStep.mjs.map +1 -0
- package/dist/components/account/sections/team/steps/ProjectSelectionStep.mjs +180 -0
- package/dist/components/account/sections/team/steps/ProjectSelectionStep.mjs.map +1 -0
- package/dist/components/account/sections/team/steps/UserInformationStep.mjs +371 -0
- package/dist/components/account/sections/team/steps/UserInformationStep.mjs.map +1 -0
- package/dist/components/account/sections/team/user-form.schema.mjs +37 -0
- package/dist/components/account/sections/team/user-form.schema.mjs.map +1 -0
- package/dist/components/account/types/workspace-actions.type.mjs +1 -0
- package/dist/components/account/types/workspace-actions.type.mjs.map +1 -0
- package/dist/components/layouts/ProfilePopover.mjs +10 -12
- package/dist/components/layouts/ProfilePopover.mjs.map +1 -1
- package/dist/components/layouts/UsersSelectorPopover.mjs +7 -4
- package/dist/components/layouts/UsersSelectorPopover.mjs.map +1 -1
- package/dist/components/modals/AccountDeletionWarningModal.mjs +4 -5
- package/dist/components/modals/AccountDeletionWarningModal.mjs.map +1 -1
- package/dist/components/modals/AccountFrozenModal.mjs +6 -3
- package/dist/components/modals/AccountFrozenModal.mjs.map +1 -1
- package/dist/components/modals/Modals.mjs +3 -3
- package/dist/components/modals/Modals.mjs.map +1 -1
- package/dist/components/modals/PaidPlanRequiredModal.mjs +4 -5
- package/dist/components/modals/PaidPlanRequiredModal.mjs.map +1 -1
- package/dist/components/modals/cards/AddFirstCardWarningModal.mjs +63 -0
- package/dist/components/modals/cards/AddFirstCardWarningModal.mjs.map +1 -0
- package/dist/components/modals/cards/SwitchPaymentToCardModal.mjs +187 -0
- package/dist/components/modals/cards/SwitchPaymentToCardModal.mjs.map +1 -0
- package/dist/components/modals/promo/AiCreditsOfferModal/AiCreditsOfferModal.mjs +5 -4
- package/dist/components/modals/promo/AiCreditsOfferModal/AiCreditsOfferModal.mjs.map +1 -1
- package/dist/components/ui/data-display/CardItem.mjs +9 -1
- package/dist/components/ui/data-display/CardItem.mjs.map +1 -1
- package/dist/components/ui/data-display/PaymentMethodIcons.mjs +50 -0
- package/dist/components/ui/data-display/PaymentMethodIcons.mjs.map +1 -0
- package/dist/components/ui/form/BillingPeriodSelector.mjs +108 -0
- package/dist/components/ui/form/BillingPeriodSelector.mjs.map +1 -0
- package/dist/components/ui/form/PaymentMethodToggle.mjs +82 -0
- package/dist/components/ui/form/PaymentMethodToggle.mjs.map +1 -0
- package/dist/components/ui/form/RadioOptionFieldIcon.mjs +57 -0
- package/dist/components/ui/form/RadioOptionFieldIcon.mjs.map +1 -0
- package/dist/components/ui/form/SegmentedControl.mjs +56 -0
- package/dist/components/ui/form/SegmentedControl.mjs.map +1 -0
- package/dist/components/ui/overlay/Dialog.mjs +21 -4
- package/dist/components/ui/overlay/Dialog.mjs.map +1 -1
- package/dist/components/ui/overlay/Sheet.mjs +26 -8
- package/dist/components/ui/overlay/Sheet.mjs.map +1 -1
- package/dist/components/ui/overlay/layers.mjs +52 -5
- package/dist/components/ui/overlay/layers.mjs.map +1 -1
- package/dist/enums/AccountHubFlow.mjs +13 -0
- package/dist/enums/AccountHubFlow.mjs.map +1 -0
- package/dist/enums/DateFilterPeriod.mjs +22 -0
- package/dist/enums/DateFilterPeriod.mjs.map +1 -0
- package/dist/enums/WorkspaceSectionType.mjs +11 -0
- package/dist/enums/WorkspaceSectionType.mjs.map +1 -0
- package/dist/handlers.mjs +24 -0
- package/dist/handlers.mjs.map +1 -1
- package/dist/hooks/useDebounce.mjs +5 -3
- package/dist/hooks/useDebounce.mjs.map +1 -1
- package/dist/hooks/useUploadProgress.mjs +33 -0
- package/dist/hooks/useUploadProgress.mjs.map +1 -0
- package/dist/i18n/messages/en-us.mjs +868 -3
- package/dist/i18n/messages/en-us.mjs.map +1 -1
- package/dist/i18n/messages/es-es.mjs +868 -3
- package/dist/i18n/messages/es-es.mjs.map +1 -1
- package/dist/i18n/messages/pt-br.mjs +868 -3
- package/dist/i18n/messages/pt-br.mjs.map +1 -1
- package/dist/index.mjs +87 -7
- package/dist/index.mjs.map +1 -1
- package/dist/infra/http/paged.mjs +20 -0
- package/dist/infra/http/paged.mjs.map +1 -0
- package/dist/middleware.mjs +2 -0
- package/dist/middleware.mjs.map +1 -1
- package/dist/middlewares/create-auth-middleware.mjs +2 -4
- package/dist/middlewares/create-auth-middleware.mjs.map +1 -1
- package/dist/middlewares/create-legacy-account-routes-middleware.mjs +44 -0
- package/dist/middlewares/create-legacy-account-routes-middleware.mjs.map +1 -0
- package/dist/middlewares/is-route-equals.mjs +7 -0
- package/dist/middlewares/is-route-equals.mjs.map +1 -0
- package/dist/modules/accounts/actions/account-management.action.mjs +20 -1
- package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -1
- package/dist/modules/accounts/constants/account-hub-link.constants.mjs +9 -0
- package/dist/modules/accounts/constants/account-hub-link.constants.mjs.map +1 -0
- package/dist/modules/accounts/constants/legacy-account-routes.constants.mjs +5 -0
- package/dist/modules/accounts/constants/legacy-account-routes.constants.mjs.map +1 -0
- package/dist/modules/accounts/handlers/list-account-members.handler.mjs +22 -0
- package/dist/modules/accounts/handlers/list-account-members.handler.mjs.map +1 -0
- package/dist/modules/accounts/hooks/add-user-projects.hook.mjs +51 -0
- package/dist/modules/accounts/hooks/add-user-projects.hook.mjs.map +1 -0
- package/dist/modules/accounts/hooks/create-account-user.hook.mjs +20 -0
- package/dist/modules/accounts/hooks/create-account-user.hook.mjs.map +1 -0
- package/dist/modules/accounts/hooks/remove-user-projects.hook.mjs +47 -0
- package/dist/modules/accounts/hooks/remove-user-projects.hook.mjs.map +1 -0
- package/dist/modules/accounts/hooks/use-account-members.hook.mjs +20 -0
- package/dist/modules/accounts/hooks/use-account-members.hook.mjs.map +1 -0
- package/dist/modules/accounts/services/account.service.mjs +59 -0
- package/dist/modules/accounts/services/account.service.mjs.map +1 -1
- package/dist/modules/accounts/types/account-hub-link.type.mjs +1 -0
- package/dist/modules/accounts/types/account-hub-link.type.mjs.map +1 -0
- package/dist/modules/accounts/utils/build-account-hub-url.mjs +16 -0
- package/dist/modules/accounts/utils/build-account-hub-url.mjs.map +1 -0
- package/dist/modules/accounts/utils/is-account-hub-flow.mjs +9 -0
- package/dist/modules/accounts/utils/is-account-hub-flow.mjs.map +1 -0
- package/dist/modules/accounts/utils/is-account-section.mjs +9 -0
- package/dist/modules/accounts/utils/is-account-section.mjs.map +1 -0
- package/dist/modules/accounts/utils/is-my-account-section.mjs +13 -0
- package/dist/modules/accounts/utils/is-my-account-section.mjs.map +1 -0
- package/dist/modules/accounts/utils/map-legacy-account-route.mjs +93 -0
- package/dist/modules/accounts/utils/map-legacy-account-route.mjs.map +1 -0
- package/dist/modules/accounts/utils/parse-account-hub-link.mjs +20 -0
- package/dist/modules/accounts/utils/parse-account-hub-link.mjs.map +1 -0
- package/dist/modules/affiliates/actions/ensure-affiliate.action.mjs +10 -0
- package/dist/modules/affiliates/actions/ensure-affiliate.action.mjs.map +1 -0
- package/dist/modules/affiliates/actions/request-deposit.action.mjs +10 -0
- package/dist/modules/affiliates/actions/request-deposit.action.mjs.map +1 -0
- package/dist/modules/affiliates/actions/update-affiliate.action.mjs +10 -0
- package/dist/modules/affiliates/actions/update-affiliate.action.mjs.map +1 -0
- package/dist/modules/affiliates/constants/affiliate.constants.mjs +11 -0
- package/dist/modules/affiliates/constants/affiliate.constants.mjs.map +1 -0
- package/dist/modules/affiliates/constants/query-keys.constants.mjs +15 -0
- package/dist/modules/affiliates/constants/query-keys.constants.mjs.map +1 -0
- package/dist/modules/affiliates/handlers/affiliate-report-analytics.handler.mjs +16 -0
- package/dist/modules/affiliates/handlers/affiliate-report-analytics.handler.mjs.map +1 -0
- package/dist/modules/affiliates/handlers/affiliate-withdrawal-limits.handler.mjs +12 -0
- package/dist/modules/affiliates/handlers/affiliate-withdrawal-limits.handler.mjs.map +1 -0
- package/dist/modules/affiliates/handlers/current-affiliate.handler.mjs +12 -0
- package/dist/modules/affiliates/handlers/current-affiliate.handler.mjs.map +1 -0
- package/dist/modules/affiliates/handlers/list-affiliate-coupons.handler.mjs +12 -0
- package/dist/modules/affiliates/handlers/list-affiliate-coupons.handler.mjs.map +1 -0
- package/dist/modules/affiliates/handlers/list-affiliate-leads.handler.mjs +22 -0
- package/dist/modules/affiliates/handlers/list-affiliate-leads.handler.mjs.map +1 -0
- package/dist/modules/affiliates/handlers/list-affiliate-transactions.handler.mjs +22 -0
- package/dist/modules/affiliates/handlers/list-affiliate-transactions.handler.mjs.map +1 -0
- package/dist/modules/affiliates/hooks/use-affiliate-coupons.hook.mjs +17 -0
- package/dist/modules/affiliates/hooks/use-affiliate-coupons.hook.mjs.map +1 -0
- package/dist/modules/affiliates/hooks/use-affiliate-leads.hook.mjs +22 -0
- package/dist/modules/affiliates/hooks/use-affiliate-leads.hook.mjs.map +1 -0
- package/dist/modules/affiliates/hooks/use-affiliate-report-analytics.hook.mjs +17 -0
- package/dist/modules/affiliates/hooks/use-affiliate-report-analytics.hook.mjs.map +1 -0
- package/dist/modules/affiliates/hooks/use-affiliate-transactions.hook.mjs +20 -0
- package/dist/modules/affiliates/hooks/use-affiliate-transactions.hook.mjs.map +1 -0
- package/dist/modules/affiliates/hooks/use-current-affiliate.hook.mjs +17 -0
- package/dist/modules/affiliates/hooks/use-current-affiliate.hook.mjs.map +1 -0
- package/dist/modules/affiliates/hooks/use-ensure-affiliate.hook.mjs +23 -0
- package/dist/modules/affiliates/hooks/use-ensure-affiliate.hook.mjs.map +1 -0
- package/dist/modules/affiliates/hooks/use-request-deposit.hook.mjs +28 -0
- package/dist/modules/affiliates/hooks/use-request-deposit.hook.mjs.map +1 -0
- package/dist/modules/affiliates/hooks/use-update-affiliate.hook.mjs +22 -0
- package/dist/modules/affiliates/hooks/use-update-affiliate.hook.mjs.map +1 -0
- package/dist/modules/affiliates/hooks/use-withdrawal-limits.hook.mjs +17 -0
- package/dist/modules/affiliates/hooks/use-withdrawal-limits.hook.mjs.map +1 -0
- package/dist/modules/affiliates/services/affiliates.service.mjs +183 -0
- package/dist/modules/affiliates/services/affiliates.service.mjs.map +1 -0
- package/dist/modules/affiliates/types/affiliate.type.mjs +100 -0
- package/dist/modules/affiliates/types/affiliate.type.mjs.map +1 -0
- package/dist/modules/affiliates/utils/get-affiliate-share-link.mjs +9 -0
- package/dist/modules/affiliates/utils/get-affiliate-share-link.mjs.map +1 -0
- package/dist/modules/charges/actions/get-nota-fiscal.action.mjs +10 -0
- package/dist/modules/charges/actions/get-nota-fiscal.action.mjs.map +1 -0
- package/dist/modules/charges/actions/refresh-pix.action.mjs +10 -0
- package/dist/modules/charges/actions/refresh-pix.action.mjs.map +1 -0
- package/dist/modules/charges/hooks/nota-fiscal.hook.mjs +13 -0
- package/dist/modules/charges/hooks/nota-fiscal.hook.mjs.map +1 -0
- package/dist/modules/charges/hooks/refresh-pix.hook.mjs +13 -0
- package/dist/modules/charges/hooks/refresh-pix.hook.mjs.map +1 -0
- package/dist/modules/charges/services/charges.service.mjs +67 -0
- package/dist/modules/charges/services/charges.service.mjs.map +1 -1
- package/dist/modules/charges/types/nota-fiscal.type.mjs +1 -0
- package/dist/modules/charges/types/nota-fiscal.type.mjs.map +1 -0
- package/dist/modules/charges/types/refresh-pix.type.mjs +1 -0
- package/dist/modules/charges/types/refresh-pix.type.mjs.map +1 -0
- package/dist/modules/charges/utils/get-charge-download-url.mjs +8 -0
- package/dist/modules/charges/utils/get-charge-download-url.mjs.map +1 -0
- package/dist/modules/coupons/constants/query-keys.constants.mjs +5 -0
- package/dist/modules/coupons/constants/query-keys.constants.mjs.map +1 -0
- package/dist/modules/coupons/handlers/find-coupon-by-code.handler.mjs +17 -0
- package/dist/modules/coupons/handlers/find-coupon-by-code.handler.mjs.map +1 -0
- package/dist/modules/coupons/handlers/find-coupon-by-id.handler.mjs +16 -0
- package/dist/modules/coupons/handlers/find-coupon-by-id.handler.mjs.map +1 -0
- package/dist/modules/coupons/hooks/use-coupon-by-code.hook.mjs +15 -0
- package/dist/modules/coupons/hooks/use-coupon-by-code.hook.mjs.map +1 -0
- package/dist/modules/coupons/hooks/use-coupon-by-id.hook.mjs +18 -0
- package/dist/modules/coupons/hooks/use-coupon-by-id.hook.mjs.map +1 -0
- package/dist/modules/coupons/services/coupons.service.mjs +44 -0
- package/dist/modules/coupons/services/coupons.service.mjs.map +1 -0
- package/dist/modules/coupons/types/coupon.type.mjs +61 -0
- package/dist/modules/coupons/types/coupon.type.mjs.map +1 -0
- package/dist/modules/coupons/utils/coupon-restrictions.mjs +60 -0
- package/dist/modules/coupons/utils/coupon-restrictions.mjs.map +1 -0
- package/dist/modules/domains/handlers/count-domains.handler.mjs +12 -0
- package/dist/modules/domains/handlers/count-domains.handler.mjs.map +1 -0
- package/dist/modules/domains/hooks/count-domains.hook.mjs +17 -0
- package/dist/modules/domains/hooks/count-domains.hook.mjs.map +1 -0
- package/dist/modules/domains/services/domains.service.mjs +18 -0
- package/dist/modules/domains/services/domains.service.mjs.map +1 -0
- package/dist/modules/ia-credits/handlers/list-ia-credit-operations.handler.mjs +15 -0
- package/dist/modules/ia-credits/handlers/list-ia-credit-operations.handler.mjs.map +1 -0
- package/dist/modules/ia-credits/hooks/ia-credit-operations.hook.mjs +28 -0
- package/dist/modules/ia-credits/hooks/ia-credit-operations.hook.mjs.map +1 -0
- package/dist/modules/ia-credits/services/ia-credits.service.mjs +23 -2
- package/dist/modules/ia-credits/services/ia-credits.service.mjs.map +1 -1
- package/dist/modules/pages/handlers/count-pages.handler.mjs +4 -2
- package/dist/modules/pages/handlers/count-pages.handler.mjs.map +1 -1
- package/dist/modules/pages/hooks/count-published-pages.hook.mjs +26 -0
- package/dist/modules/pages/hooks/count-published-pages.hook.mjs.map +1 -0
- package/dist/modules/pages/services/pages.service.mjs +3 -2
- package/dist/modules/pages/services/pages.service.mjs.map +1 -1
- package/dist/modules/plans/constants/plan-tooltips.constants.mjs +14 -0
- package/dist/modules/plans/constants/plan-tooltips.constants.mjs.map +1 -0
- package/dist/modules/plans/hooks/use-enriched-plans.hook.mjs +28 -0
- package/dist/modules/plans/hooks/use-enriched-plans.hook.mjs.map +1 -0
- package/dist/modules/plans/hooks/use-ui-plans.hook.mjs +20 -0
- package/dist/modules/plans/hooks/use-ui-plans.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/add-project-users.hook.mjs +25 -0
- package/dist/modules/projects/hooks/add-project-users.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs +3 -6
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs +3 -6
- package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +3 -6
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs +3 -6
- package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/remove-project-users.hook.mjs +25 -0
- package/dist/modules/projects/hooks/remove-project-users.hook.mjs.map +1 -0
- package/dist/modules/projects/services/project-users.service.mjs +5 -0
- package/dist/modules/projects/services/project-users.service.mjs.map +1 -1
- package/dist/modules/projects/types.mjs +3 -2
- package/dist/modules/projects/types.mjs.map +1 -1
- package/dist/modules/subscriptions/actions/cancel-subscription.action.mjs +10 -0
- package/dist/modules/subscriptions/actions/cancel-subscription.action.mjs.map +1 -0
- package/dist/modules/subscriptions/actions/create-subscription.action.mjs +10 -0
- package/dist/modules/subscriptions/actions/create-subscription.action.mjs.map +1 -0
- package/dist/modules/subscriptions/actions/find-pending-pix-status.action.mjs +10 -0
- package/dist/modules/subscriptions/actions/find-pending-pix-status.action.mjs.map +1 -0
- package/dist/modules/subscriptions/actions/find-subscription-by-id.action.mjs +10 -0
- package/dist/modules/subscriptions/actions/find-subscription-by-id.action.mjs.map +1 -0
- package/dist/modules/subscriptions/constants/addons.constants.mjs +35 -0
- package/dist/modules/subscriptions/constants/addons.constants.mjs.map +1 -1
- package/dist/modules/subscriptions/constants/downgrade.constants.mjs +25 -0
- package/dist/modules/subscriptions/constants/downgrade.constants.mjs.map +1 -0
- package/dist/modules/subscriptions/constants/subscription.constants.mjs +2 -0
- package/dist/modules/subscriptions/constants/subscription.constants.mjs.map +1 -1
- package/dist/modules/subscriptions/handlers/pending-pix-status.handler.mjs +15 -0
- package/dist/modules/subscriptions/handlers/pending-pix-status.handler.mjs.map +1 -0
- package/dist/modules/subscriptions/hooks/cancel-subscription.hook.mjs +25 -0
- package/dist/modules/subscriptions/hooks/cancel-subscription.hook.mjs.map +1 -0
- package/dist/modules/subscriptions/hooks/create-subscription.hook.mjs +33 -0
- package/dist/modules/subscriptions/hooks/create-subscription.hook.mjs.map +1 -0
- package/dist/modules/subscriptions/hooks/find-subscription-by-id.hook.mjs +18 -0
- package/dist/modules/subscriptions/hooks/find-subscription-by-id.hook.mjs.map +1 -0
- package/dist/modules/subscriptions/hooks/pending-pix-status.hook.mjs +25 -0
- package/dist/modules/subscriptions/hooks/pending-pix-status.hook.mjs.map +1 -0
- package/dist/modules/subscriptions/services/subscriptions.service.mjs +71 -0
- package/dist/modules/subscriptions/services/subscriptions.service.mjs.map +1 -1
- package/dist/modules/subscriptions/types/cancel-subscription.type.mjs +9 -0
- package/dist/modules/subscriptions/types/cancel-subscription.type.mjs.map +1 -0
- package/dist/modules/subscriptions/types/create-subscription.type.mjs +62 -0
- package/dist/modules/subscriptions/types/create-subscription.type.mjs.map +1 -0
- package/dist/modules/subscriptions/types/pending-pix-status.type.mjs +28 -0
- package/dist/modules/subscriptions/types/pending-pix-status.type.mjs.map +1 -0
- package/dist/modules/subscriptions/types/subscription.type.mjs +9 -1
- package/dist/modules/subscriptions/types/subscription.type.mjs.map +1 -1
- package/dist/modules/subscriptions/utils/addon-buckets.mjs +69 -0
- package/dist/modules/subscriptions/utils/addon-buckets.mjs.map +1 -0
- package/dist/modules/subscriptions/utils/confirm-payment-if-required.mjs +8 -2
- package/dist/modules/subscriptions/utils/confirm-payment-if-required.mjs.map +1 -1
- package/dist/modules/subscriptions/utils/first-period-pricing.mjs +25 -0
- package/dist/modules/subscriptions/utils/first-period-pricing.mjs.map +1 -0
- package/dist/modules/subscriptions/utils/is-api-subscription.mjs +8 -0
- package/dist/modules/subscriptions/utils/is-api-subscription.mjs.map +1 -0
- package/dist/modules/subscriptions/utils/is-boleto-payer.mjs +17 -0
- package/dist/modules/subscriptions/utils/is-boleto-payer.mjs.map +1 -0
- package/dist/modules/subscriptions/utils/is-free-subscription.mjs +8 -0
- package/dist/modules/subscriptions/utils/is-free-subscription.mjs.map +1 -0
- package/dist/modules/subscriptions/utils/periodicity.mjs +55 -1
- package/dist/modules/subscriptions/utils/periodicity.mjs.map +1 -1
- package/dist/modules/subscriptions/utils/resolve-subscription-plan-name.mjs +27 -0
- package/dist/modules/subscriptions/utils/resolve-subscription-plan-name.mjs.map +1 -0
- package/dist/modules/users/hooks/messages.hook.mjs +3 -5
- package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
- package/dist/server.mjs +6 -0
- package/dist/server.mjs.map +1 -1
- package/dist/store/useAccountModals.mjs +9 -2
- package/dist/store/useAccountModals.mjs.map +1 -1
- package/dist/store/useAccountUnsavedChanges.mjs +31 -0
- package/dist/store/useAccountUnsavedChanges.mjs.map +1 -0
- package/dist/store/useAffiliateFlows.mjs +23 -0
- package/dist/store/useAffiliateFlows.mjs.map +1 -0
- package/dist/store/useProjectFlows.mjs +18 -0
- package/dist/store/useProjectFlows.mjs.map +1 -0
- package/dist/store/useSubscriptionFlows.mjs +58 -0
- package/dist/store/useSubscriptionFlows.mjs.map +1 -0
- package/dist/store/useTeamFlows.mjs +15 -0
- package/dist/store/useTeamFlows.mjs.map +1 -0
- package/dist/testing/factories/coupon.factory.mjs +19 -0
- package/dist/testing/factories/coupon.factory.mjs.map +1 -0
- package/dist/testing/factories/index.mjs +6 -0
- package/dist/testing/factories/index.mjs.map +1 -1
- package/dist/testing/factories/project-user.factory.mjs +17 -0
- package/dist/testing/factories/project-user.factory.mjs.map +1 -0
- package/dist/testing/factories/project.factory.mjs +21 -0
- package/dist/testing/factories/project.factory.mjs.map +1 -0
- package/dist/testing/react/providers.mjs +1 -1
- package/dist/testing/react/providers.mjs.map +1 -1
- package/dist/utils/browser/chart-custom-tooltip.mjs +69 -0
- package/dist/utils/browser/chart-custom-tooltip.mjs.map +1 -0
- package/dist/utils/browser/get-css-variable.mjs +9 -0
- package/dist/utils/browser/get-css-variable.mjs.map +1 -0
- package/dist/utils/constants/scrollbar.mjs +5 -0
- package/dist/utils/constants/scrollbar.mjs.map +1 -0
- package/dist/utils/date-filter-period.mjs +34 -0
- package/dist/utils/date-filter-period.mjs.map +1 -0
- package/dist/utils/file/index.mjs +11 -1
- package/dist/utils/file/index.mjs.map +1 -1
- package/dist/utils/format/initials.mjs +8 -0
- package/dist/utils/format/initials.mjs.map +1 -0
- package/dist/utils/format/masks.mjs +32 -1
- package/dist/utils/format/masks.mjs.map +1 -1
- package/dist/utils/qrcode/to-data-url.mjs +12 -0
- package/dist/utils/qrcode/to-data-url.mjs.map +1 -0
- package/dist/utils/validators/account.mjs +1 -7
- package/dist/utils/validators/account.mjs.map +1 -1
- package/package.json +15 -2
- package/src/components/account/AccountHubLinkHandler.tsx +39 -0
- package/src/components/account/AccountModalLayout.tsx +190 -0
- package/src/components/account/AccountModals.tsx +12 -2
- package/src/components/account/AccountUnsavedChangesDialog.tsx +49 -0
- package/src/components/account/DeleteAccountModal.tsx +1 -1
- package/src/components/account/IsntPossibleDeleteAccountModal.tsx +9 -1
- package/src/components/account/MyAccountModal.tsx +222 -0
- package/src/components/account/TwoFactorAuthModal.tsx +1 -1
- package/src/components/account/hooks/useAccountHubActions.ts +95 -0
- package/src/components/account/hooks/useAddCardWithPaymentSwitch.ts +70 -0
- package/src/components/account/hooks/useAffiliatesActions.tsx +78 -0
- package/src/components/account/hooks/useMyAccountModal.ts +40 -0
- package/src/components/account/hooks/useProjectsActions.ts +44 -0
- package/src/components/account/hooks/useSubscriptionActions.ts +99 -0
- package/src/components/account/hooks/useTeamActions.ts +35 -0
- package/src/components/account/sections/AffiliatesSection.tsx +342 -0
- package/src/components/account/sections/ChangePasswordSection.tsx +6 -10
- package/src/components/account/sections/MyProfileSection.tsx +215 -147
- package/src/components/account/sections/PreferencesSection.tsx +71 -71
- package/src/components/account/sections/ProjectsSection.tsx +110 -0
- package/src/components/account/sections/SecuritySection.tsx +72 -62
- package/src/components/account/sections/SubscriptionSection.tsx +36 -0
- package/src/components/account/sections/TeamSection.tsx +161 -0
- package/src/components/account/sections/TokenSection.tsx +4 -8
- package/src/components/account/sections/affiliates/AffiliateCommissionCard.tsx +83 -0
- package/src/components/account/sections/affiliates/AffiliateFlows.tsx +20 -0
- package/src/components/account/sections/affiliates/AffiliateLeadsSheet.tsx +143 -0
- package/src/components/account/sections/affiliates/AffiliateStatsCard.tsx +56 -0
- package/src/components/account/sections/affiliates/AffiliateStepCard.tsx +20 -0
- package/src/components/account/sections/affiliates/AffiliateTransactionsList.tsx +194 -0
- package/src/components/account/sections/affiliates/NoReceivingAccountModal.tsx +63 -0
- package/src/components/account/sections/affiliates/ReceivingAccountModal.tsx +213 -0
- package/src/components/account/sections/affiliates/RequestWithdrawalSheet.tsx +586 -0
- package/src/components/account/sections/affiliates/ViewAttachmentModal.tsx +47 -0
- package/src/components/account/sections/affiliates/reports/AffiliatesIndicatorsChart.tsx +45 -0
- package/src/components/account/sections/affiliates/reports/AffiliatesReportsTab.tsx +44 -0
- package/src/components/account/sections/affiliates/reports/useAffiliatesIndicatorsChart.ts +148 -0
- package/src/components/account/sections/projects/DeleteProjectModal.tsx +246 -0
- package/src/components/account/sections/projects/ProjectFlows.tsx +16 -0
- package/src/components/account/sections/projects/ProjectMembersStack.tsx +75 -0
- package/src/components/account/sections/projects/ProjectRow.tsx +96 -0
- package/src/components/account/sections/projects/ProjectSheet.tsx +603 -0
- package/src/components/account/sections/projects/ProjectsDisabledModal.tsx +69 -0
- package/src/components/account/sections/projects/project-form.schema.ts +30 -0
- package/src/components/account/sections/shared/ConnectListRow.tsx +68 -0
- package/src/components/account/sections/shared/DateFilterPopover.tsx +58 -0
- package/src/components/account/sections/shared/EntityAvatar.tsx +54 -0
- package/src/components/account/sections/shared/FilterPopover.tsx +79 -0
- package/src/components/account/sections/shared/FormSection.tsx +23 -0
- package/src/components/account/sections/shared/IconBox.tsx +21 -0
- package/src/components/account/sections/shared/InfiniteScrollList.tsx +57 -0
- package/src/components/account/sections/shared/ListPagination.tsx +84 -0
- package/src/components/account/sections/shared/RowActionsMenu.tsx +66 -0
- package/src/components/account/sections/shared/SectionLoadError.tsx +27 -0
- package/src/components/account/sections/shared/StatusBadge.tsx +33 -0
- package/src/components/account/sections/shared/WorkspaceSection.tsx +22 -0
- package/src/components/account/sections/subscription/AiCreditsUsage.tsx +152 -0
- package/src/components/account/sections/subscription/BillingAddressSheet.tsx +460 -0
- package/src/components/account/sections/subscription/BoletoDetailsDialog.tsx +104 -0
- package/src/components/account/sections/subscription/BoletoGeneratedDialog.tsx +24 -0
- package/src/components/account/sections/subscription/CancelPlanDialog.tsx +221 -0
- package/src/components/account/sections/subscription/ChargeRow.tsx +161 -0
- package/src/components/account/sections/subscription/ChargeStatusBadge.tsx +29 -0
- package/src/components/account/sections/subscription/ChargesList.tsx +125 -0
- package/src/components/account/sections/subscription/ManageCardsSheet.tsx +93 -0
- package/src/components/account/sections/subscription/OverdueReceiptOpener.tsx +29 -0
- package/src/components/account/sections/subscription/PayChargeDialog.tsx +306 -0
- package/src/components/account/sections/subscription/PaymentConfirmationDialog.tsx +70 -0
- package/src/components/account/sections/subscription/PaymentMethodsCard.tsx +117 -0
- package/src/components/account/sections/subscription/PendingChangeDialog.tsx +168 -0
- package/src/components/account/sections/subscription/PixDetailsDialog.tsx +246 -0
- package/src/components/account/sections/subscription/PixPaymentDialog.tsx +242 -0
- package/src/components/account/sections/subscription/PlanDetailsSheet.tsx +380 -0
- package/src/components/account/sections/subscription/ReceiptDetailsSheet.tsx +318 -0
- package/src/components/account/sections/subscription/SubscriptionFlows.tsx +40 -0
- package/src/components/account/sections/subscription/SubscriptionPlanCard.tsx +433 -0
- package/src/components/account/sections/subscription/UsageReportSheet.tsx +244 -0
- package/src/components/account/sections/subscription/change-plan/ChangePlanSheet.tsx +95 -0
- package/src/components/account/sections/subscription/change-plan/components/AbTestDetailsDialog.tsx +57 -0
- package/src/components/account/sections/subscription/change-plan/components/AddonsBlock.tsx +214 -0
- package/src/components/account/sections/subscription/change-plan/components/AlternativeBucketsSection.tsx +92 -0
- package/src/components/account/sections/subscription/change-plan/components/CouponBlock.tsx +42 -0
- package/src/components/account/sections/subscription/change-plan/components/CouponDialog.tsx +134 -0
- package/src/components/account/sections/subscription/change-plan/components/PricePreview.tsx +28 -0
- package/src/components/account/sections/subscription/change-plan/components/SummaryBlock.tsx +194 -0
- package/src/components/account/sections/subscription/change-plan/plan-comparison.ts +52 -0
- package/src/components/account/sections/subscription/change-plan/steps/PaymentSummaryStep.tsx +161 -0
- package/src/components/account/sections/subscription/change-plan/steps/PlanComparisonStep.tsx +165 -0
- package/src/components/account/sections/subscription/change-plan/steps/PlanViewStep.tsx +89 -0
- package/src/components/account/sections/subscription/change-plan/steps/ReactivationConfigStep.tsx +117 -0
- package/src/components/account/sections/subscription/change-plan/steps/ReactivationPaymentStep.tsx +139 -0
- package/src/components/account/sections/subscription/change-plan/useChangePlanState.tsx +1158 -0
- package/src/components/account/sections/subscription/downgrade/CannotDowngradeDialog.tsx +297 -0
- package/src/components/account/sections/subscription/downgrade/DowngradeReasonDialog.tsx +154 -0
- package/src/components/account/sections/subscription/plans/PlanCard.tsx +417 -0
- package/src/components/account/sections/subscription/plans/PlanCardSkeleton.tsx +70 -0
- package/src/components/account/sections/subscription/plans/PlansCatalogDialog.tsx +156 -0
- package/src/components/account/sections/team/DeleteUserModal.tsx +134 -0
- package/src/components/account/sections/team/TeamFlows.tsx +14 -0
- package/src/components/account/sections/team/TeamMemberRow.tsx +151 -0
- package/src/components/account/sections/team/UserSheet.tsx +688 -0
- package/src/components/account/sections/team/steps/NotificationsStep.tsx +109 -0
- package/src/components/account/sections/team/steps/ProjectSelectionStep.tsx +219 -0
- package/src/components/account/sections/team/steps/UserInformationStep.tsx +423 -0
- package/src/components/account/sections/team/user-form.schema.ts +43 -0
- package/src/components/account/types/workspace-actions.type.ts +56 -0
- package/src/components/layouts/ProfilePopover.tsx +11 -12
- package/src/components/layouts/UsersSelectorPopover.tsx +7 -4
- package/src/components/modals/AccountDeletionWarningModal.tsx +4 -5
- package/src/components/modals/AccountFrozenModal.tsx +6 -3
- package/src/components/modals/Modals.tsx +6 -3
- package/src/components/modals/PaidPlanRequiredModal.tsx +4 -5
- package/src/components/modals/cards/AddFirstCardWarningModal.tsx +72 -0
- package/src/components/modals/cards/SwitchPaymentToCardModal.tsx +232 -0
- package/src/components/modals/promo/AiCreditsOfferModal/AiCreditsOfferModal.tsx +5 -4
- package/src/components/ui/data-display/CardItem.tsx +9 -5
- package/src/components/ui/data-display/PaymentMethodIcons.tsx +43 -0
- package/src/components/ui/form/BillingPeriodSelector.tsx +173 -0
- package/src/components/ui/form/PaymentMethodToggle.tsx +119 -0
- package/src/components/ui/form/RadioOptionFieldIcon.tsx +64 -0
- package/src/components/ui/form/SegmentedControl.tsx +77 -0
- package/src/components/ui/overlay/Dialog.tsx +21 -2
- package/src/components/ui/overlay/Sheet.tsx +26 -5
- package/src/components/ui/overlay/layers.tsx +88 -4
- package/src/enums/AccountHubFlow.ts +8 -0
- package/src/enums/DateFilterPeriod.ts +17 -0
- package/src/enums/WorkspaceSectionType.ts +6 -0
- package/src/handlers.ts +14 -0
- package/src/hooks/useDebounce.ts +5 -3
- package/src/hooks/useUploadProgress.ts +42 -0
- package/src/i18n/messages/en-us.ts +909 -2
- package/src/i18n/messages/es-es.ts +913 -2
- package/src/i18n/messages/pt-br.ts +913 -2
- package/src/index.ts +56 -1
- package/src/infra/http/paged.ts +24 -0
- package/src/middleware.ts +1 -0
- package/src/middlewares/create-auth-middleware.ts +2 -5
- package/src/middlewares/create-legacy-account-routes-middleware.ts +54 -0
- package/src/middlewares/is-route-equals.ts +3 -0
- package/src/modules/accounts/actions/account-management.action.ts +22 -1
- package/src/modules/accounts/constants/account-hub-link.constants.ts +3 -0
- package/src/modules/accounts/constants/legacy-account-routes.constants.ts +1 -0
- package/src/modules/accounts/handlers/list-account-members.handler.ts +23 -0
- package/src/modules/accounts/hooks/add-user-projects.hook.ts +72 -0
- package/src/modules/accounts/hooks/create-account-user.hook.ts +21 -0
- package/src/modules/accounts/hooks/remove-user-projects.hook.ts +68 -0
- package/src/modules/accounts/hooks/use-account-members.hook.ts +31 -0
- package/src/modules/accounts/services/account.service.ts +71 -0
- package/src/modules/accounts/types/account-hub-link.type.ts +13 -0
- package/src/modules/accounts/types.ts +9 -0
- package/src/modules/accounts/utils/build-account-hub-url.ts +14 -0
- package/src/modules/accounts/utils/is-account-hub-flow.ts +7 -0
- package/src/modules/accounts/utils/is-account-section.ts +7 -0
- package/src/modules/accounts/utils/is-my-account-section.ts +12 -0
- package/src/modules/accounts/utils/map-legacy-account-route.ts +108 -0
- package/src/modules/accounts/utils/parse-account-hub-link.ts +21 -0
- package/src/modules/affiliates/actions/ensure-affiliate.action.ts +9 -0
- package/src/modules/affiliates/actions/request-deposit.action.ts +9 -0
- package/src/modules/affiliates/actions/update-affiliate.action.ts +9 -0
- package/src/modules/affiliates/constants/affiliate.constants.ts +11 -0
- package/src/modules/affiliates/constants/query-keys.constants.ts +7 -0
- package/src/modules/affiliates/handlers/affiliate-report-analytics.handler.ts +16 -0
- package/src/modules/affiliates/handlers/affiliate-withdrawal-limits.handler.ts +10 -0
- package/src/modules/affiliates/handlers/current-affiliate.handler.ts +10 -0
- package/src/modules/affiliates/handlers/list-affiliate-coupons.handler.ts +10 -0
- package/src/modules/affiliates/handlers/list-affiliate-leads.handler.ts +23 -0
- package/src/modules/affiliates/handlers/list-affiliate-transactions.handler.ts +23 -0
- package/src/modules/affiliates/hooks/use-affiliate-coupons.hook.ts +19 -0
- package/src/modules/affiliates/hooks/use-affiliate-leads.hook.ts +27 -0
- package/src/modules/affiliates/hooks/use-affiliate-report-analytics.hook.ts +19 -0
- package/src/modules/affiliates/hooks/use-affiliate-transactions.hook.ts +25 -0
- package/src/modules/affiliates/hooks/use-current-affiliate.hook.ts +19 -0
- package/src/modules/affiliates/hooks/use-ensure-affiliate.hook.ts +24 -0
- package/src/modules/affiliates/hooks/use-request-deposit.hook.ts +29 -0
- package/src/modules/affiliates/hooks/use-update-affiliate.hook.ts +24 -0
- package/src/modules/affiliates/hooks/use-withdrawal-limits.hook.ts +20 -0
- package/src/modules/affiliates/services/affiliates.service.ts +240 -0
- package/src/modules/affiliates/types/affiliate.type.ts +180 -0
- package/src/modules/affiliates/utils/get-affiliate-share-link.ts +8 -0
- package/src/modules/charges/actions/get-nota-fiscal.action.ts +8 -0
- package/src/modules/charges/actions/refresh-pix.action.ts +8 -0
- package/src/modules/charges/hooks/nota-fiscal.hook.ts +13 -0
- package/src/modules/charges/hooks/refresh-pix.hook.ts +13 -0
- package/src/modules/charges/services/charges.service.ts +121 -0
- package/src/modules/charges/types/nota-fiscal.type.ts +20 -0
- package/src/modules/charges/types/refresh-pix.type.ts +14 -0
- package/src/modules/charges/utils/get-charge-download-url.ts +10 -0
- package/src/modules/coupons/constants/query-keys.constants.ts +1 -0
- package/src/modules/coupons/handlers/find-coupon-by-code.handler.ts +16 -0
- package/src/modules/coupons/handlers/find-coupon-by-id.handler.ts +15 -0
- package/src/modules/coupons/hooks/use-coupon-by-code.hook.ts +16 -0
- package/src/modules/coupons/hooks/use-coupon-by-id.hook.ts +20 -0
- package/src/modules/coupons/services/coupons.service.ts +54 -0
- package/src/modules/coupons/types/coupon.type.ts +70 -0
- package/src/modules/coupons/utils/coupon-restrictions.ts +112 -0
- package/src/modules/domains/handlers/count-domains.handler.ts +10 -0
- package/src/modules/domains/hooks/count-domains.hook.ts +17 -0
- package/src/modules/domains/services/domains.service.ts +18 -0
- package/src/modules/ia-credits/handlers/list-ia-credit-operations.handler.ts +14 -0
- package/src/modules/ia-credits/hooks/ia-credit-operations.hook.ts +33 -0
- package/src/modules/ia-credits/services/ia-credits.service.ts +32 -1
- package/src/modules/pages/handlers/count-pages.handler.ts +5 -2
- package/src/modules/pages/hooks/count-published-pages.hook.ts +26 -0
- package/src/modules/pages/services/pages.service.ts +3 -2
- package/src/modules/plans/constants/plan-tooltips.constants.ts +16 -0
- package/src/modules/plans/hooks/use-enriched-plans.hook.ts +31 -0
- package/src/modules/plans/hooks/use-ui-plans.hook.ts +22 -0
- package/src/modules/projects/hooks/add-project-users.hook.ts +29 -0
- package/src/modules/projects/hooks/list-all-account-users.hook.ts +3 -6
- package/src/modules/projects/hooks/list-available-users.hook.ts +3 -6
- package/src/modules/projects/hooks/list-infinite-projects.hook.ts +3 -6
- package/src/modules/projects/hooks/list-project-users.hook.ts +3 -6
- package/src/modules/projects/hooks/remove-project-users.hook.ts +29 -0
- package/src/modules/projects/services/project-users.service.ts +135 -130
- package/src/modules/projects/types.ts +89 -88
- package/src/modules/subscriptions/actions/cancel-subscription.action.ts +12 -0
- package/src/modules/subscriptions/actions/create-subscription.action.ts +9 -0
- package/src/modules/subscriptions/actions/find-pending-pix-status.action.ts +8 -0
- package/src/modules/subscriptions/actions/find-subscription-by-id.action.ts +8 -0
- package/src/modules/subscriptions/constants/addons.constants.ts +50 -0
- package/src/modules/subscriptions/constants/downgrade.constants.ts +30 -0
- package/src/modules/subscriptions/constants/subscription.constants.ts +3 -0
- package/src/modules/subscriptions/handlers/pending-pix-status.handler.ts +17 -0
- package/src/modules/subscriptions/hooks/cancel-subscription.hook.ts +28 -0
- package/src/modules/subscriptions/hooks/create-subscription.hook.ts +34 -0
- package/src/modules/subscriptions/hooks/find-subscription-by-id.hook.ts +17 -0
- package/src/modules/subscriptions/hooks/pending-pix-status.hook.ts +30 -0
- package/src/modules/subscriptions/services/subscriptions.service.ts +401 -301
- package/src/modules/subscriptions/types/cancel-subscription.type.ts +8 -0
- package/src/modules/subscriptions/types/create-subscription.type.ts +79 -0
- package/src/modules/subscriptions/types/pending-pix-status.type.ts +33 -0
- package/src/modules/subscriptions/types/subscription.type.ts +157 -147
- package/src/modules/subscriptions/utils/addon-buckets.ts +129 -0
- package/src/modules/subscriptions/utils/confirm-payment-if-required.ts +9 -2
- package/src/modules/subscriptions/utils/first-period-pricing.ts +63 -0
- package/src/modules/subscriptions/utils/is-api-subscription.ts +6 -0
- package/src/modules/subscriptions/utils/is-boleto-payer.ts +21 -0
- package/src/modules/subscriptions/utils/is-free-subscription.ts +6 -0
- package/src/modules/subscriptions/utils/periodicity.ts +101 -0
- package/src/modules/subscriptions/utils/resolve-subscription-plan-name.ts +44 -0
- package/src/modules/users/hooks/messages.hook.ts +3 -5
- package/src/server.ts +102 -99
- package/src/store/useAccountModals.ts +22 -5
- package/src/store/useAccountUnsavedChanges.ts +52 -0
- package/src/store/useAffiliateFlows.ts +46 -0
- package/src/store/useProjectFlows.ts +42 -0
- package/src/store/useSubscriptionFlows.ts +176 -0
- package/src/store/useTeamFlows.ts +34 -0
- package/src/testing/factories/coupon.factory.ts +17 -0
- package/src/testing/factories/index.ts +3 -0
- package/src/testing/factories/project-user.factory.ts +15 -0
- package/src/testing/factories/project.factory.ts +19 -0
- package/src/testing/react/providers.tsx +2 -1
- package/src/utils/browser/chart-custom-tooltip.ts +85 -0
- package/src/utils/browser/get-css-variable.ts +6 -0
- package/src/utils/constants/scrollbar.ts +10 -0
- package/src/utils/date-filter-period.ts +34 -0
- package/src/utils/file/index.ts +13 -0
- package/src/utils/format/initials.ts +10 -0
- package/src/utils/format/masks.ts +41 -0
- package/src/utils/qrcode/to-data-url.ts +23 -0
- package/src/utils/validators/account.ts +0 -8
- package/dist/components/account/ConfigurationsMyAccountModal.mjs +0 -143
- package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +0 -1
- package/dist/components/account/hooks/useConfigurationsModal.mjs +0 -34
- package/dist/components/account/hooks/useConfigurationsModal.mjs.map +0 -1
- package/src/components/account/ConfigurationsMyAccountModal.tsx +0 -179
- package/src/components/account/hooks/useConfigurationsModal.ts +0 -45
|
@@ -0,0 +1,1158 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type ChangeEvent,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { useForm } from 'react-hook-form';
|
|
13
|
+
import { useStripe } from '@stripe/react-stripe-js';
|
|
14
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
15
|
+
import { useTranslations } from 'next-intl';
|
|
16
|
+
import { toast } from 'sonner';
|
|
17
|
+
import z from 'zod';
|
|
18
|
+
import { Toast } from '../../../../ui/feedback/Toast';
|
|
19
|
+
import { useCurrentAccount } from '../../../../../modules/accounts/hooks/current-account.hook';
|
|
20
|
+
import { useCurrencyFormatter } from '../../../../../modules/accounts/hooks/use-currency-formatter.hook';
|
|
21
|
+
import {
|
|
22
|
+
hasCompleteBillingData,
|
|
23
|
+
isBrazilianBillingAccount,
|
|
24
|
+
} from '../../../../../modules/accounts/utils/billing-data';
|
|
25
|
+
import { useCards } from '../../../../../modules/cards/hooks/cards.hook';
|
|
26
|
+
import { useCouponById } from '../../../../../modules/coupons/hooks/use-coupon-by-id.hook';
|
|
27
|
+
import {
|
|
28
|
+
getCouponRestrictions,
|
|
29
|
+
isCouponApplicableToPlan,
|
|
30
|
+
} from '../../../../../modules/coupons/utils/coupon-restrictions';
|
|
31
|
+
import type { CouponStripeData } from '../../../../../modules/coupons/types/coupon.type';
|
|
32
|
+
import { useCountDomains } from '../../../../../modules/domains/hooks/count-domains.hook';
|
|
33
|
+
import { usePlanById } from '../../../../../modules/plans/hooks/use-plan-by-id.hook';
|
|
34
|
+
import {
|
|
35
|
+
ADDON_IDS,
|
|
36
|
+
buildAiCreditOptions,
|
|
37
|
+
canBuyExtraDomains,
|
|
38
|
+
getDomainExtraPrice,
|
|
39
|
+
} from '../../../../../modules/subscriptions/constants/addons.constants';
|
|
40
|
+
import { useCalculateSubscription } from '../../../../../modules/subscriptions/hooks/calculate-subscription.hook';
|
|
41
|
+
import { useCreateSubscription } from '../../../../../modules/subscriptions/hooks/create-subscription.hook';
|
|
42
|
+
import { useCurrentSubscription } from '../../../../../modules/subscriptions/hooks/use-current-subscription.hook';
|
|
43
|
+
import { useUpdateSubscriptionPlan } from '../../../../../modules/subscriptions/hooks/update-subscription-plan.hook';
|
|
44
|
+
import { isPendingPixCreateSubscriptionResponse } from '../../../../../modules/subscriptions/types/create-subscription.type';
|
|
45
|
+
import { confirmPaymentIfRequired, PaymentAuthenticationError } from '../../../../../modules/subscriptions/utils/confirm-payment-if-required';
|
|
46
|
+
import type { BillingPeriod } from '../../../../../modules/subscriptions/types/billing-period.type';
|
|
47
|
+
import type { UpdateSubscriptionPlanRequest } from '../../../../../modules/subscriptions/types/calculate-subscription.type';
|
|
48
|
+
import {
|
|
49
|
+
getAddonBuckets,
|
|
50
|
+
buildDomainPlanExtras,
|
|
51
|
+
buildZeroedOldBuckets,
|
|
52
|
+
type AddonBucket,
|
|
53
|
+
} from '../../../../../modules/subscriptions/utils/addon-buckets';
|
|
54
|
+
import {
|
|
55
|
+
getFirstPeriodPricing,
|
|
56
|
+
type FirstPeriodPricing,
|
|
57
|
+
} from '../../../../../modules/subscriptions/utils/first-period-pricing';
|
|
58
|
+
import { isBoletoAvailable, isBoletoPayer } from '../../../../../modules/subscriptions/utils/is-boleto-payer';
|
|
59
|
+
import {
|
|
60
|
+
billingPeriodToNumeric,
|
|
61
|
+
getBillingPeriodLabel,
|
|
62
|
+
getBillingPeriodMonths,
|
|
63
|
+
getBillingPeriodSuffix,
|
|
64
|
+
getCouponDiscount,
|
|
65
|
+
getDiscount,
|
|
66
|
+
getEffectiveDiscountPercent,
|
|
67
|
+
getPeriodPricingKey,
|
|
68
|
+
getPeriodicityLabel,
|
|
69
|
+
getPriceFromCalculatedData,
|
|
70
|
+
periodicityToBillingPeriod,
|
|
71
|
+
} from '../../../../../modules/subscriptions/utils/periodicity';
|
|
72
|
+
import { resolveSubscriptionPlanName } from '../../../../../modules/subscriptions/utils/resolve-subscription-plan-name';
|
|
73
|
+
import { useWhitelabel } from '../../../../../providers/whitelabel.provider';
|
|
74
|
+
import { useDebouncedEffect } from '../../../../../hooks/useDebouncedEffect';
|
|
75
|
+
import { useSubscriptionFlows } from '../../../../../store/useSubscriptionFlows';
|
|
76
|
+
|
|
77
|
+
/** Mínimo de domínios que qualquer plano inclui. */
|
|
78
|
+
const MIN_DOMAINS = 1;
|
|
79
|
+
|
|
80
|
+
export const changePlanSchema = z.object({
|
|
81
|
+
paymentMethod: z.enum(['card', 'boleto', 'pix']),
|
|
82
|
+
selectedCardId: z.string(),
|
|
83
|
+
selectedReason: z.string(),
|
|
84
|
+
reasonText: z.string(),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export type ChangePlanFormData = z.infer<typeof changePlanSchema>;
|
|
88
|
+
|
|
89
|
+
type ChangePlanState = ReturnType<typeof useChangePlanLogic>;
|
|
90
|
+
|
|
91
|
+
const ChangePlanContext = createContext<ChangePlanState | null>(null);
|
|
92
|
+
|
|
93
|
+
export const ChangePlanProvider = ChangePlanContext.Provider;
|
|
94
|
+
|
|
95
|
+
export function useChangePlan() {
|
|
96
|
+
const context = useContext(ChangePlanContext);
|
|
97
|
+
if (!context) throw new Error('useChangePlan precisa estar dentro de ChangePlanProvider');
|
|
98
|
+
return context;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Delta de pró-rata (centavos) do pix recorrente — resposta passthrough, leitura defensiva. */
|
|
102
|
+
function readProrataValueCents(response: unknown): number | null {
|
|
103
|
+
const value = (response as { prorata_value_cents?: unknown }).prorata_value_cents;
|
|
104
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const paymentMethodToNumeric = (method: 'card' | 'boleto' | 'pix') =>
|
|
108
|
+
method === 'card' ? 1 : method === 'boleto' ? 2 : 3;
|
|
109
|
+
|
|
110
|
+
export function useChangePlanLogic() {
|
|
111
|
+
const translate = useTranslations();
|
|
112
|
+
const { whitelabel } = useWhitelabel();
|
|
113
|
+
const stripe = useStripe();
|
|
114
|
+
const { data: account } = useCurrentAccount();
|
|
115
|
+
const { currency, formatCurrencyNumber } = useCurrencyFormatter();
|
|
116
|
+
const isUsdAccount = currency === 'usd';
|
|
117
|
+
|
|
118
|
+
const changePlan = useSubscriptionFlows((state) => state.changePlan);
|
|
119
|
+
const closeChangePlan = useSubscriptionFlows((state) => state.closeChangePlan);
|
|
120
|
+
const openPlansCatalog = useSubscriptionFlows((state) => state.openPlansCatalog);
|
|
121
|
+
const openPixPayment = useSubscriptionFlows((state) => state.openPixPayment);
|
|
122
|
+
const openBoletoGenerated = useSubscriptionFlows((state) => state.openBoletoGenerated);
|
|
123
|
+
const openBillingAddress = useSubscriptionFlows((state) => state.openBillingAddress);
|
|
124
|
+
const openPaymentConfirmation = useSubscriptionFlows((state) => state.openPaymentConfirmation);
|
|
125
|
+
|
|
126
|
+
const open = !!changePlan;
|
|
127
|
+
const data = changePlan ?? undefined;
|
|
128
|
+
const isReactivation = data?.isReactivation ?? false;
|
|
129
|
+
|
|
130
|
+
const { mutateAsync: updatePlanAsync } = useUpdateSubscriptionPlan();
|
|
131
|
+
const { mutateAsync: createSubscriptionAsync } = useCreateSubscription();
|
|
132
|
+
const { data: cardsData } = useCards();
|
|
133
|
+
|
|
134
|
+
const { data: subscriptionData, isFetched: activeSubscriptionFetched } = useCurrentSubscription();
|
|
135
|
+
const activeSubscription = subscriptionData?.data?.[0];
|
|
136
|
+
const subscriptionCouponId =
|
|
137
|
+
activeSubscription?.id_coupon != null ? Number(activeSubscription.id_coupon) : null;
|
|
138
|
+
const { data: subscriptionCouponData } = useCouponById(
|
|
139
|
+
open && subscriptionCouponId != null ? subscriptionCouponId : null
|
|
140
|
+
);
|
|
141
|
+
const { mutate: calculate, isPending: isCalculatePending, data: calculateData } =
|
|
142
|
+
useCalculateSubscription();
|
|
143
|
+
|
|
144
|
+
const [currentStep, setCurrentStep] = useState(1);
|
|
145
|
+
const [selectedCreditIndex, setSelectedCreditIndex] = useState(0);
|
|
146
|
+
const [bucketEdits, setBucketEdits] = useState<Record<string, number>>({});
|
|
147
|
+
const [abTestEnabled, setAbTestEnabled] = useState(false);
|
|
148
|
+
const [appliedCouponId, setAppliedCouponId] = useState<number | null>(null);
|
|
149
|
+
const [appliedCouponCode, setAppliedCouponCode] = useState<string | null>(null);
|
|
150
|
+
const [appliedCouponStripeData, setAppliedCouponStripeData] = useState<CouponStripeData | null>(null);
|
|
151
|
+
const [activeCardIdAddon, setActiveCardIdAddon] = useState('');
|
|
152
|
+
const [abTestDetailsOpen, setAbTestDetailsOpen] = useState(false);
|
|
153
|
+
const [isCouponDialogOpen, setIsCouponDialogOpen] = useState(false);
|
|
154
|
+
const [isReactivating, setIsReactivating] = useState(false);
|
|
155
|
+
/**
|
|
156
|
+
* Assinatura criada que ficou esperando o 3DS. Enquanto existir, o submit re-autentica ESTA
|
|
157
|
+
* cobrança em vez de criar outra — sem isso, quem erra a autenticação e tenta de novo termina
|
|
158
|
+
* com duas assinaturas.
|
|
159
|
+
*/
|
|
160
|
+
const [pendingAuthSecret, setPendingAuthSecret] = useState<string | null>(null);
|
|
161
|
+
const pendingUpdatePayloadRef = useRef<UpdateSubscriptionPlanRequest | null>(null);
|
|
162
|
+
const hasInitialized = useRef(false);
|
|
163
|
+
|
|
164
|
+
const targetPlan = data?.targetPlan;
|
|
165
|
+
const isDowngrade = data?.isDowngrade ?? false;
|
|
166
|
+
|
|
167
|
+
const { data: currentPlanData } = usePlanById(activeSubscription?.id_plan);
|
|
168
|
+
const currentPlan = currentPlanData?.data;
|
|
169
|
+
const effectivePlan = targetPlan ?? currentPlan;
|
|
170
|
+
const effectivePlanId = targetPlan ? targetPlan.planId : currentPlan?.id;
|
|
171
|
+
|
|
172
|
+
const wlName = whitelabel?.name || '';
|
|
173
|
+
|
|
174
|
+
const subscriptionBillingPeriod =
|
|
175
|
+
periodicityToBillingPeriod(activeSubscription?.periodicity) ?? 'monthly';
|
|
176
|
+
// Reativar pelo card não escolhe período (herda o da assinatura); vindo da vitrine, o período
|
|
177
|
+
// escolhido lá manda — inclusive na contratação, que reusa este mesmo fluxo.
|
|
178
|
+
const requestedBillingPeriod: BillingPeriod = data?.billingPeriod ?? subscriptionBillingPeriod;
|
|
179
|
+
// Só a contratação troca de período aqui dentro: na troca de plano o período já veio decidido
|
|
180
|
+
// pela vitrine, e na gestão de adicionais ele é o da assinatura corrente.
|
|
181
|
+
const [contractingBillingPeriod, setContractingBillingPeriod] = useState<BillingPeriod | null>(null);
|
|
182
|
+
const billingPeriod: BillingPeriod =
|
|
183
|
+
isReactivation && contractingBillingPeriod ? contractingBillingPeriod : requestedBillingPeriod;
|
|
184
|
+
const modalBillingPeriod: BillingPeriod = data?.billingPeriod ?? 'monthly';
|
|
185
|
+
|
|
186
|
+
const subscriptionItems = activeSubscription?.items ?? [];
|
|
187
|
+
const domainItems = subscriptionItems.filter((item) => item.id_addon === ADDON_IDS.DOMAINS);
|
|
188
|
+
const abTestItem = subscriptionItems.find((item) => item.id_addon === ADDON_IDS.AB_TEST);
|
|
189
|
+
const aiItems = subscriptionItems.filter(
|
|
190
|
+
(item) => item.id_addon === ADDON_IDS.AI && (item.value ?? 0) > 0
|
|
191
|
+
);
|
|
192
|
+
const aiItem =
|
|
193
|
+
aiItems.length > 0
|
|
194
|
+
? aiItems.reduce((best, item) => (item.quantity > best.quantity ? item : best))
|
|
195
|
+
: undefined;
|
|
196
|
+
|
|
197
|
+
const planDomainItem = effectivePlan?.items.find(
|
|
198
|
+
(item) => item.id_addon === ADDON_IDS.DOMAINS && item.value == 0
|
|
199
|
+
);
|
|
200
|
+
const planAbTestItem = effectivePlan?.items.find((item) => item.id_addon === ADDON_IDS.AB_TEST);
|
|
201
|
+
const aiCreditOptions = buildAiCreditOptions(effectivePlan?.items ?? []);
|
|
202
|
+
const selectedCredit = aiCreditOptions[selectedCreditIndex] ?? aiCreditOptions[0];
|
|
203
|
+
|
|
204
|
+
const hasDomainsAddon =
|
|
205
|
+
!!effectivePlan?.items.find((item) => item.id_addon === ADDON_IDS.DOMAINS && item.value > 0) &&
|
|
206
|
+
canBuyExtraDomains(effectivePlanId);
|
|
207
|
+
|
|
208
|
+
// A/B incluso no plano (item com value 0) trava o toggle; só o A/B avulso pago é gerenciável.
|
|
209
|
+
const planAbTestIncludedItem = effectivePlan?.items.find(
|
|
210
|
+
(item) => item.id_addon === ADDON_IDS.AB_TEST && (item.value ?? 0) === 0 && (item.quantity ?? 0) > 0
|
|
211
|
+
);
|
|
212
|
+
const abTestIncludedInPlan = !!planAbTestIncludedItem;
|
|
213
|
+
const hasAbTestAddon =
|
|
214
|
+
!abTestIncludedInPlan &&
|
|
215
|
+
!!effectivePlan?.items.find((item) => item.id_addon === ADDON_IDS.AB_TEST && (item.value ?? 0) > 0);
|
|
216
|
+
|
|
217
|
+
const { data: registeredDomains = 0, isSuccess: registeredDomainsLoaded } = useCountDomains({
|
|
218
|
+
enabled: open,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Backend normalizado: `value` de plano e de assinatura é sempre mensal por unidade.
|
|
222
|
+
const planDomainItems = effectivePlan?.items.filter(
|
|
223
|
+
(item) => item.id_addon === ADDON_IDS.DOMAINS && (item.value ?? 0) > 0
|
|
224
|
+
);
|
|
225
|
+
const planDomainPrice =
|
|
226
|
+
planDomainItems?.find((item) => item.base)?.value ??
|
|
227
|
+
planDomainItems?.[0]?.value ??
|
|
228
|
+
getDomainExtraPrice(effectivePlanId);
|
|
229
|
+
const domainPriceMonthly = planDomainPrice;
|
|
230
|
+
|
|
231
|
+
const subscriptionAbTestPrice =
|
|
232
|
+
subscriptionItems.find((item) => item.id_addon === ADDON_IDS.AB_TEST && (item.value ?? 0) > 0)
|
|
233
|
+
?.value ?? 0;
|
|
234
|
+
const abTestPriceMonthly = subscriptionAbTestPrice || (planAbTestItem?.value ?? 0);
|
|
235
|
+
|
|
236
|
+
// A/B incluso nunca é zerado no payload; fora disso segue o toggle.
|
|
237
|
+
const abTestPayloadQuantity = abTestIncludedInPlan
|
|
238
|
+
? (planAbTestIncludedItem?.quantity ?? 1)
|
|
239
|
+
: abTestEnabled
|
|
240
|
+
? 1
|
|
241
|
+
: 0;
|
|
242
|
+
|
|
243
|
+
const subscriptionIncludedDomainsItem = domainItems.find((item) => (item.value ?? 0) === 0);
|
|
244
|
+
const planIncludedDomains = targetPlan
|
|
245
|
+
? (planDomainItem?.quantity ?? MIN_DOMAINS)
|
|
246
|
+
: (subscriptionIncludedDomainsItem?.quantity ?? planDomainItem?.quantity ?? MIN_DOMAINS);
|
|
247
|
+
const currentPlanIncludedDomains =
|
|
248
|
+
effectivePlan?.items?.find((item) => item.id_addon === ADDON_IDS.DOMAINS)?.quantity ?? 0;
|
|
249
|
+
const subscriptionDomainSum = domainItems.reduce((sum, item) => sum + (item.quantity ?? 0), 0);
|
|
250
|
+
const subscriptionExtraDomains = domainItems
|
|
251
|
+
.filter((item) => (item.value ?? 0) > 0)
|
|
252
|
+
.reduce((sum, item) => sum + (item.quantity ?? 0), 0);
|
|
253
|
+
const currentSubscriptionDomains = Math.max(
|
|
254
|
+
subscriptionDomainSum,
|
|
255
|
+
currentPlanIncludedDomains + subscriptionExtraDomains
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
// Reativação e troca de plano colapsam tudo no preço do plano novo.
|
|
259
|
+
const collapseToSingleBucket = isReactivation || !!targetPlan;
|
|
260
|
+
const primaryBucketPrice = planDomainPrice;
|
|
261
|
+
const domainBuckets = getAddonBuckets(
|
|
262
|
+
ADDON_IDS.DOMAINS,
|
|
263
|
+
collapseToSingleBucket ? [] : subscriptionItems,
|
|
264
|
+
primaryBucketPrice,
|
|
265
|
+
bucketEdits
|
|
266
|
+
);
|
|
267
|
+
// Troca de plano precisa zerar explicitamente os itens antigos em outros preços.
|
|
268
|
+
const zeroedOldDomainBuckets = targetPlan
|
|
269
|
+
? buildZeroedOldBuckets(ADDON_IDS.DOMAINS, subscriptionItems, planDomainPrice)
|
|
270
|
+
: [];
|
|
271
|
+
const primaryBucket = domainBuckets.find((bucket) => bucket.isPrimary)!;
|
|
272
|
+
const alternativeBuckets = domainBuckets.filter((bucket) => !bucket.isPrimary && bucket.quantity > 0);
|
|
273
|
+
const hasAlternativeBuckets = domainBuckets.some(
|
|
274
|
+
(bucket) => !bucket.isPrimary && bucket.originalQuantity > 0
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
const totalExtras = domainBuckets.reduce((sum, bucket) => sum + bucket.quantity, 0);
|
|
278
|
+
const totalDomains = planIncludedDomains + totalExtras;
|
|
279
|
+
const domains = planIncludedDomains + primaryBucket.quantity;
|
|
280
|
+
|
|
281
|
+
// Piso: nunca abaixo do incluso no plano nem dos domínios já registrados.
|
|
282
|
+
const minDomains = registeredDomainsLoaded
|
|
283
|
+
? Math.max(planIncludedDomains, registeredDomains)
|
|
284
|
+
: planIncludedDomains;
|
|
285
|
+
const domainsCountLoading = hasDomainsAddon && !registeredDomainsLoaded;
|
|
286
|
+
const isAtMin = totalDomains <= minDomains || primaryBucket.quantity <= 0;
|
|
287
|
+
const extraDomains = totalExtras;
|
|
288
|
+
|
|
289
|
+
const paymentMethodFromSubscription: 'card' | 'boleto' | 'pix' =
|
|
290
|
+
activeSubscription?.payment_method === 2
|
|
291
|
+
? 'boleto'
|
|
292
|
+
: activeSubscription?.payment_method === 3
|
|
293
|
+
? 'pix'
|
|
294
|
+
: 'card';
|
|
295
|
+
|
|
296
|
+
const form = useForm<ChangePlanFormData>({
|
|
297
|
+
resolver: zodResolver(changePlanSchema),
|
|
298
|
+
defaultValues: { paymentMethod: 'card', selectedCardId: '', selectedReason: '', reasonText: '' },
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const { isSubmitting } = form.formState;
|
|
302
|
+
const paymentMethod = form.watch('paymentMethod');
|
|
303
|
+
const selectedCardId = form.watch('selectedCardId');
|
|
304
|
+
|
|
305
|
+
const paymentDefaultAppliedRef = useRef(false);
|
|
306
|
+
useEffect(() => {
|
|
307
|
+
if (!open) {
|
|
308
|
+
paymentDefaultAppliedRef.current = false;
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (paymentDefaultAppliedRef.current || !activeSubscription) return;
|
|
312
|
+
form.setValue('paymentMethod', paymentMethodFromSubscription);
|
|
313
|
+
paymentDefaultAppliedRef.current = true;
|
|
314
|
+
}, [open, activeSubscription, paymentMethodFromSubscription, form]);
|
|
315
|
+
|
|
316
|
+
const couponRestrictions = getCouponRestrictions(appliedCouponStripeData);
|
|
317
|
+
const { allowedPaymentMethod, disabledPaymentMethods } = couponRestrictions;
|
|
318
|
+
const { disabledBillingPeriods, allowedBillingPeriod } = couponRestrictions;
|
|
319
|
+
const { unlocksAllPaymentMethods: couponUnlocksAllMethods } = couponRestrictions;
|
|
320
|
+
|
|
321
|
+
// Assinatura que já é boleto/pix mantém o método enquanto só gerencia adicionais.
|
|
322
|
+
const isCurrentSubscriptionBoleto = isBoletoPayer(activeSubscription?.payment_method);
|
|
323
|
+
const allowBoletoFromCurrentSubscription =
|
|
324
|
+
isCurrentSubscriptionBoleto && !targetPlan && !isReactivation;
|
|
325
|
+
const isCurrentSubscriptionPix = activeSubscription?.payment_method === 3;
|
|
326
|
+
const allowPixFromCurrentSubscription = isCurrentSubscriptionPix && !targetPlan && !isReactivation;
|
|
327
|
+
|
|
328
|
+
const boletoAvailable =
|
|
329
|
+
!isUsdAccount &&
|
|
330
|
+
isBoletoAvailable({
|
|
331
|
+
isBoletoPayer: isCurrentSubscriptionBoleto,
|
|
332
|
+
allowedPaymentMethod,
|
|
333
|
+
unlocksAllPaymentMethods: couponUnlocksAllMethods,
|
|
334
|
+
});
|
|
335
|
+
const pixAvailable = !isUsdAccount;
|
|
336
|
+
|
|
337
|
+
useEffect(() => {
|
|
338
|
+
if (!open) return;
|
|
339
|
+
if (isUsdAccount) {
|
|
340
|
+
if (paymentMethod !== 'card') form.setValue('paymentMethod', 'card');
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (!allowedPaymentMethod) return;
|
|
344
|
+
if (paymentMethod !== allowedPaymentMethod) form.setValue('paymentMethod', allowedPaymentMethod);
|
|
345
|
+
}, [open, isUsdAccount, allowedPaymentMethod, paymentMethod, form]);
|
|
346
|
+
|
|
347
|
+
// Volta para cartão quando o método escolhido deixa de ser permitido no contexto atual.
|
|
348
|
+
useEffect(() => {
|
|
349
|
+
if (!open) return;
|
|
350
|
+
if (billingPeriod === 'annual') return;
|
|
351
|
+
if (paymentMethod !== 'boleto' && paymentMethod !== 'pix') return;
|
|
352
|
+
if (couponUnlocksAllMethods) return;
|
|
353
|
+
if (
|
|
354
|
+
paymentMethod === 'boleto' &&
|
|
355
|
+
(allowedPaymentMethod === 'boleto' || allowBoletoFromCurrentSubscription)
|
|
356
|
+
) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (paymentMethod === 'pix' && (allowedPaymentMethod === 'pix' || allowPixFromCurrentSubscription)) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
form.setValue('paymentMethod', 'card');
|
|
363
|
+
}, [
|
|
364
|
+
open,
|
|
365
|
+
billingPeriod,
|
|
366
|
+
paymentMethod,
|
|
367
|
+
couponUnlocksAllMethods,
|
|
368
|
+
allowedPaymentMethod,
|
|
369
|
+
allowBoletoFromCurrentSubscription,
|
|
370
|
+
allowPixFromCurrentSubscription,
|
|
371
|
+
form,
|
|
372
|
+
]);
|
|
373
|
+
|
|
374
|
+
useEffect(() => {
|
|
375
|
+
if (!open || boletoAvailable || paymentMethod !== 'boleto') return;
|
|
376
|
+
form.setValue('paymentMethod', 'card');
|
|
377
|
+
}, [open, boletoAvailable, paymentMethod, form]);
|
|
378
|
+
|
|
379
|
+
const cards = cardsData?.data ?? [];
|
|
380
|
+
const defaultCardId = (cards.find((card) => card.is_default) ?? cards[0])?.id?.toString() ?? '';
|
|
381
|
+
const resolvedAddonCardId = activeCardIdAddon || defaultCardId;
|
|
382
|
+
|
|
383
|
+
useEffect(() => {
|
|
384
|
+
if (!open || !activeSubscription || !effectivePlan || !registeredDomainsLoaded) return;
|
|
385
|
+
if (hasInitialized.current) return;
|
|
386
|
+
|
|
387
|
+
hasInitialized.current = true;
|
|
388
|
+
|
|
389
|
+
if (hasDomainsAddon) {
|
|
390
|
+
if (collapseToSingleBucket) {
|
|
391
|
+
// Começa com o mínimo de extras que cobre os domínios em uso no plano novo.
|
|
392
|
+
const primaryKey = `${ADDON_IDS.DOMAINS}_${planDomainPrice}`;
|
|
393
|
+
const initialQty = Math.max(0, registeredDomains - planIncludedDomains);
|
|
394
|
+
if (initialQty > 0) setBucketEdits((previous) => ({ ...previous, [primaryKey]: initialQty }));
|
|
395
|
+
} else {
|
|
396
|
+
const initBuckets = getAddonBuckets(ADDON_IDS.DOMAINS, subscriptionItems, domainPriceMonthly, {});
|
|
397
|
+
const initExtras = initBuckets.reduce((sum, bucket) => sum + bucket.quantity, 0);
|
|
398
|
+
const deficit = Math.max(0, minDomains - (planIncludedDomains + initExtras));
|
|
399
|
+
if (deficit > 0) {
|
|
400
|
+
const primary = initBuckets.find((bucket) => bucket.isPrimary)!;
|
|
401
|
+
setBucketEdits((previous) => ({ ...previous, [primary.key]: primary.quantity + deficit }));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Só liga o A/B se o plano efetivo suporta — item remanescente de downgrade não conta.
|
|
407
|
+
setAbTestEnabled(hasAbTestAddon && !!abTestItem);
|
|
408
|
+
|
|
409
|
+
if (aiItem) {
|
|
410
|
+
const aiIndex = aiCreditOptions.findIndex((option) => option.credits === aiItem.quantity);
|
|
411
|
+
if (aiIndex >= 0) setSelectedCreditIndex(aiIndex);
|
|
412
|
+
} else if (data?.selectedCreditIndex != null) {
|
|
413
|
+
setSelectedCreditIndex(data.selectedCreditIndex);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (subscriptionCouponId != null) setAppliedCouponId(subscriptionCouponId);
|
|
417
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
418
|
+
}, [
|
|
419
|
+
open,
|
|
420
|
+
activeSubscription,
|
|
421
|
+
effectivePlan,
|
|
422
|
+
registeredDomainsLoaded,
|
|
423
|
+
hasDomainsAddon,
|
|
424
|
+
minDomains,
|
|
425
|
+
currentSubscriptionDomains,
|
|
426
|
+
data,
|
|
427
|
+
subscriptionCouponId,
|
|
428
|
+
]);
|
|
429
|
+
|
|
430
|
+
// O cupom da assinatura pode chegar depois da inicialização.
|
|
431
|
+
useEffect(() => {
|
|
432
|
+
if (!open) return;
|
|
433
|
+
const coupon = subscriptionCouponData?.data;
|
|
434
|
+
if (!coupon || appliedCouponId !== subscriptionCouponId) return;
|
|
435
|
+
if (coupon.code && !appliedCouponCode) setAppliedCouponCode(coupon.code);
|
|
436
|
+
if (coupon.stripe_data && !appliedCouponStripeData) setAppliedCouponStripeData(coupon.stripe_data);
|
|
437
|
+
}, [
|
|
438
|
+
open,
|
|
439
|
+
subscriptionCouponData,
|
|
440
|
+
subscriptionCouponId,
|
|
441
|
+
appliedCouponId,
|
|
442
|
+
appliedCouponCode,
|
|
443
|
+
appliedCouponStripeData,
|
|
444
|
+
]);
|
|
445
|
+
|
|
446
|
+
// Cartão default: espera a assinatura resolver para sincronizar com o cartão dela.
|
|
447
|
+
const cardDefaultAppliedRef = useRef(false);
|
|
448
|
+
useEffect(() => {
|
|
449
|
+
if (!open) {
|
|
450
|
+
cardDefaultAppliedRef.current = false;
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (cards.length === 0) return;
|
|
454
|
+
|
|
455
|
+
const currentId = form.getValues('selectedCardId');
|
|
456
|
+
const isValid = currentId !== '' && cards.some((card) => card.id.toString() === currentId);
|
|
457
|
+
|
|
458
|
+
if (cardDefaultAppliedRef.current) {
|
|
459
|
+
if (!isValid) {
|
|
460
|
+
const fallbackCard = cards.find((card) => card.is_default) ?? cards[0];
|
|
461
|
+
form.setValue('selectedCardId', fallbackCard.id.toString());
|
|
462
|
+
}
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (!activeSubscriptionFetched) return;
|
|
467
|
+
|
|
468
|
+
const subscriptionCardId =
|
|
469
|
+
activeSubscription?.id_card != null ? String(activeSubscription.id_card) : null;
|
|
470
|
+
const subscriptionCard = subscriptionCardId
|
|
471
|
+
? cards.find((card) => card.id.toString() === subscriptionCardId)
|
|
472
|
+
: undefined;
|
|
473
|
+
const nextCard = subscriptionCard ?? cards.find((card) => card.is_default) ?? cards[0];
|
|
474
|
+
form.setValue('selectedCardId', nextCard.id.toString());
|
|
475
|
+
cardDefaultAppliedRef.current = true;
|
|
476
|
+
}, [cardsData, open, form, cards, activeSubscription, activeSubscriptionFetched]);
|
|
477
|
+
|
|
478
|
+
useEffect(() => {
|
|
479
|
+
if (open) return;
|
|
480
|
+
form.reset();
|
|
481
|
+
setCurrentStep(1);
|
|
482
|
+
setAppliedCouponId(null);
|
|
483
|
+
setAppliedCouponCode(null);
|
|
484
|
+
setAppliedCouponStripeData(null);
|
|
485
|
+
setActiveCardIdAddon('');
|
|
486
|
+
setSelectedCreditIndex(0);
|
|
487
|
+
setBucketEdits({});
|
|
488
|
+
setContractingBillingPeriod(null);
|
|
489
|
+
setPendingAuthSecret(null);
|
|
490
|
+
pendingUpdatePayloadRef.current = null;
|
|
491
|
+
hasInitialized.current = false;
|
|
492
|
+
}, [open, form]);
|
|
493
|
+
|
|
494
|
+
const { isDebouncing } = useDebouncedEffect({
|
|
495
|
+
effect: () => {
|
|
496
|
+
if (!effectivePlan) return;
|
|
497
|
+
|
|
498
|
+
const credit = aiCreditOptions[selectedCreditIndex] ?? aiCreditOptions[0];
|
|
499
|
+
|
|
500
|
+
calculate({
|
|
501
|
+
id_product: 1,
|
|
502
|
+
id_plan: effectivePlanId!,
|
|
503
|
+
periodicity: billingPeriodToNumeric(billingPeriod),
|
|
504
|
+
...(activeSubscription?.id != null && { id_subscription: activeSubscription.id }),
|
|
505
|
+
...(appliedCouponId != null && { id_coupon: appliedCouponId }),
|
|
506
|
+
plan_extras: [
|
|
507
|
+
{ id_addon: ADDON_IDS.AI, quantity: credit.credits },
|
|
508
|
+
// Só os buckets do plano-alvo: o backend não sabe precificar um domínio num preço
|
|
509
|
+
// que não é do plano calculado (ex.: extra legado de R$ 9,90 indo para um plano de
|
|
510
|
+
// R$ 14,90) e recusa a prévia inteira. Zerar os legados é papel do update.
|
|
511
|
+
...buildDomainPlanExtras(domainBuckets),
|
|
512
|
+
{ id_addon: ADDON_IDS.AB_TEST, quantity: abTestPayloadQuantity },
|
|
513
|
+
],
|
|
514
|
+
});
|
|
515
|
+
},
|
|
516
|
+
debouncedDeps: [selectedCreditIndex, bucketEdits, abTestPayloadQuantity],
|
|
517
|
+
immediateDeps: [open, effectivePlan, appliedCouponId, activeSubscription?.items],
|
|
518
|
+
delay: 500,
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
const hasChangedPaymentMethod =
|
|
522
|
+
!!activeSubscription && paymentMethod !== paymentMethodFromSubscription;
|
|
523
|
+
const hasChangedCoupon = appliedCouponId !== subscriptionCouponId;
|
|
524
|
+
const subscriptionCardId =
|
|
525
|
+
activeSubscription?.id_card != null ? String(activeSubscription.id_card) : null;
|
|
526
|
+
const hasChangedCard =
|
|
527
|
+
!!activeSubscription &&
|
|
528
|
+
paymentMethod === 'card' &&
|
|
529
|
+
paymentMethodFromSubscription === 'card' &&
|
|
530
|
+
selectedCardId !== '' &&
|
|
531
|
+
subscriptionCardId !== selectedCardId;
|
|
532
|
+
const hasChanges =
|
|
533
|
+
!!targetPlan ||
|
|
534
|
+
billingPeriod !== subscriptionBillingPeriod ||
|
|
535
|
+
selectedCredit.credits !== (aiItem?.quantity ?? 0) ||
|
|
536
|
+
abTestEnabled !== (hasAbTestAddon && !!abTestItem) ||
|
|
537
|
+
domainBuckets.some((bucket) => bucket.quantity !== bucket.originalQuantity) ||
|
|
538
|
+
hasChangedPaymentMethod ||
|
|
539
|
+
hasChangedCoupon ||
|
|
540
|
+
hasChangedCard;
|
|
541
|
+
|
|
542
|
+
// Boleto e pix emitem nota: sem cadastro fiscal completo o backend recusa a cobrança, então
|
|
543
|
+
// o passo de pagamento manda completar antes de deixar contratar. Só vale com a conta já
|
|
544
|
+
// carregada (senão travaria durante o loading) e brasileira — o formulário pede CPF/CNPJ e
|
|
545
|
+
// CEP, que um cliente de fora não tem como fornecer.
|
|
546
|
+
const requiresBillingData =
|
|
547
|
+
(paymentMethod === 'boleto' || paymentMethod === 'pix') &&
|
|
548
|
+
!!account &&
|
|
549
|
+
isBrazilianBillingAccount(account) &&
|
|
550
|
+
!hasCompleteBillingData(account);
|
|
551
|
+
|
|
552
|
+
const isCalculating = isDebouncing || isCalculatePending;
|
|
553
|
+
const calculatedData = calculateData?.data ?? null;
|
|
554
|
+
|
|
555
|
+
const totalPrice = calculatedData
|
|
556
|
+
? getPriceFromCalculatedData(calculatedData, billingPeriodToNumeric(billingPeriod))
|
|
557
|
+
: null;
|
|
558
|
+
const discountAmount = getDiscount(calculatedData, billingPeriod);
|
|
559
|
+
const couponDiscountAmount = getCouponDiscount(calculatedData, billingPeriod);
|
|
560
|
+
const immediateCharge = calculatedData?.target?.immediate_charge ?? null;
|
|
561
|
+
|
|
562
|
+
// Totais por período para o seletor da contratação: o mesmo calculate já devolve os dois.
|
|
563
|
+
const calculatedPricing = calculatedData
|
|
564
|
+
? { monthly: calculatedData.month, annual: calculatedData.year }
|
|
565
|
+
: null;
|
|
566
|
+
// Percentual EFETIVO por período (periodicidade + cupom, compostos pelo backend).
|
|
567
|
+
const billingDiscounts = {
|
|
568
|
+
monthly: getEffectiveDiscountPercent(calculatedData, 'monthly'),
|
|
569
|
+
annual: getEffectiveDiscountPercent(calculatedData, 'annual'),
|
|
570
|
+
};
|
|
571
|
+
// Split "1º período × depois" por período — null onde o cupom não desconta.
|
|
572
|
+
const firstPeriodPricingByPeriod: {
|
|
573
|
+
monthly: FirstPeriodPricing | null;
|
|
574
|
+
annual: FirstPeriodPricing | null;
|
|
575
|
+
} | null = calculatedData
|
|
576
|
+
? {
|
|
577
|
+
monthly: getFirstPeriodPricing({
|
|
578
|
+
stripeData: appliedCouponStripeData,
|
|
579
|
+
total: calculatedData.month,
|
|
580
|
+
couponDiscount: calculatedData.month_discount_coupom ?? 0,
|
|
581
|
+
}),
|
|
582
|
+
annual: getFirstPeriodPricing({
|
|
583
|
+
stripeData: appliedCouponStripeData,
|
|
584
|
+
total: calculatedData.year,
|
|
585
|
+
couponDiscount: calculatedData.year_discount_coupom ?? 0,
|
|
586
|
+
}),
|
|
587
|
+
}
|
|
588
|
+
: null;
|
|
589
|
+
|
|
590
|
+
const billingLabel = getBillingPeriodLabel(billingPeriod, translate);
|
|
591
|
+
const periodMonths = getBillingPeriodMonths(billingPeriod);
|
|
592
|
+
const periodPricingKey = getPeriodPricingKey(billingPeriod);
|
|
593
|
+
|
|
594
|
+
const currentBillingPeriod = periodicityToBillingPeriod(activeSubscription?.periodicity) ?? 'monthly';
|
|
595
|
+
const currentPeriodLabel = getBillingPeriodSuffix(currentBillingPeriod, translate);
|
|
596
|
+
const periodLabel = getBillingPeriodSuffix(billingPeriod, translate);
|
|
597
|
+
const billingLabelFull = getBillingPeriodLabel(billingPeriod, translate);
|
|
598
|
+
|
|
599
|
+
const handleDecreaseDomains = useCallback(() => {
|
|
600
|
+
if (primaryBucket.quantity <= 0) return;
|
|
601
|
+
if (totalDomains <= minDomains) return;
|
|
602
|
+
setBucketEdits((previous) => ({ ...previous, [primaryBucket.key]: primaryBucket.quantity - 1 }));
|
|
603
|
+
}, [primaryBucket, totalDomains, minDomains]);
|
|
604
|
+
|
|
605
|
+
const handleIncreaseDomains = useCallback(() => {
|
|
606
|
+
setBucketEdits((previous) => ({ ...previous, [primaryBucket.key]: primaryBucket.quantity + 1 }));
|
|
607
|
+
}, [primaryBucket]);
|
|
608
|
+
|
|
609
|
+
const handleDomainsChange = useCallback(
|
|
610
|
+
(event: ChangeEvent<HTMLInputElement>) => {
|
|
611
|
+
const requested = Number.parseInt(event.target.value, 10);
|
|
612
|
+
if (Number.isNaN(requested)) return;
|
|
613
|
+
|
|
614
|
+
// O input mostra o TOTAL (incluso + primary); converte para a quantidade do primary.
|
|
615
|
+
const requestedPrimary = requested - planIncludedDomains;
|
|
616
|
+
const altTotal = domainBuckets
|
|
617
|
+
.filter((bucket) => !bucket.isPrimary)
|
|
618
|
+
.reduce((sum, bucket) => sum + bucket.quantity, 0);
|
|
619
|
+
const minPrimary = Math.max(0, minDomains - planIncludedDomains - altTotal);
|
|
620
|
+
|
|
621
|
+
setBucketEdits((previous) => ({
|
|
622
|
+
...previous,
|
|
623
|
+
[primaryBucket.key]: Math.max(minPrimary, requestedPrimary),
|
|
624
|
+
}));
|
|
625
|
+
},
|
|
626
|
+
[minDomains, planIncludedDomains, primaryBucket, domainBuckets]
|
|
627
|
+
);
|
|
628
|
+
|
|
629
|
+
const handleAlternativeDecrease = useCallback(
|
|
630
|
+
(bucket: AddonBucket) => {
|
|
631
|
+
if (bucket.quantity <= 0) return;
|
|
632
|
+
if (totalDomains - 1 < minDomains) return;
|
|
633
|
+
setBucketEdits((previous) => ({ ...previous, [bucket.key]: bucket.quantity - 1 }));
|
|
634
|
+
},
|
|
635
|
+
[totalDomains, minDomains]
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
const handleAlternativeIncrease = useCallback((bucket: AddonBucket) => {
|
|
639
|
+
if (bucket.quantity >= bucket.originalQuantity) return;
|
|
640
|
+
setBucketEdits((previous) => ({ ...previous, [bucket.key]: bucket.quantity + 1 }));
|
|
641
|
+
}, []);
|
|
642
|
+
|
|
643
|
+
const handleApplyCoupon = useCallback(
|
|
644
|
+
(coupon: { id: number; code: string; stripeData?: CouponStripeData | null }) => {
|
|
645
|
+
const stripeData = coupon.stripeData ?? null;
|
|
646
|
+
|
|
647
|
+
if (!isCouponApplicableToPlan(stripeData, effectivePlanId)) {
|
|
648
|
+
toast.custom((toastId) => (
|
|
649
|
+
<Toast
|
|
650
|
+
variant="error"
|
|
651
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.couponNotValidForPlan', {
|
|
652
|
+
code: coupon.code,
|
|
653
|
+
})}
|
|
654
|
+
toastId={toastId}
|
|
655
|
+
/>
|
|
656
|
+
));
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
const { disabledBillingPeriods: blockedPeriods } = getCouponRestrictions(stripeData);
|
|
661
|
+
if (blockedPeriods.includes(billingPeriod)) {
|
|
662
|
+
toast.custom((toastId) => (
|
|
663
|
+
<Toast
|
|
664
|
+
variant="error"
|
|
665
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.couponNotValidForPeriod', {
|
|
666
|
+
code: coupon.code,
|
|
667
|
+
})}
|
|
668
|
+
toastId={toastId}
|
|
669
|
+
/>
|
|
670
|
+
));
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
setAppliedCouponId(coupon.id);
|
|
675
|
+
setAppliedCouponCode(coupon.code);
|
|
676
|
+
setAppliedCouponStripeData(stripeData);
|
|
677
|
+
},
|
|
678
|
+
[effectivePlanId, billingPeriod, translate]
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
const handleRemoveCoupon = useCallback(() => {
|
|
682
|
+
setAppliedCouponId(null);
|
|
683
|
+
setAppliedCouponCode(null);
|
|
684
|
+
setAppliedCouponStripeData(null);
|
|
685
|
+
}, []);
|
|
686
|
+
|
|
687
|
+
useEffect(() => {
|
|
688
|
+
if (!appliedCouponStripeData || effectivePlanId == null) return;
|
|
689
|
+
if (isCouponApplicableToPlan(appliedCouponStripeData, effectivePlanId)) return;
|
|
690
|
+
|
|
691
|
+
const code = appliedCouponCode;
|
|
692
|
+
handleRemoveCoupon();
|
|
693
|
+
toast.custom((toastId) => (
|
|
694
|
+
<Toast
|
|
695
|
+
variant="warning"
|
|
696
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.couponRemovedInvalidPlan', {
|
|
697
|
+
code: code ?? '',
|
|
698
|
+
})}
|
|
699
|
+
toastId={toastId}
|
|
700
|
+
/>
|
|
701
|
+
));
|
|
702
|
+
}, [effectivePlanId, appliedCouponStripeData, appliedCouponCode, handleRemoveCoupon, translate]);
|
|
703
|
+
|
|
704
|
+
useEffect(() => {
|
|
705
|
+
if (!appliedCouponStripeData) return;
|
|
706
|
+
if (!disabledBillingPeriods.includes(billingPeriod)) return;
|
|
707
|
+
|
|
708
|
+
const code = appliedCouponCode;
|
|
709
|
+
handleRemoveCoupon();
|
|
710
|
+
toast.custom((toastId) => (
|
|
711
|
+
<Toast
|
|
712
|
+
variant="warning"
|
|
713
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.couponRemovedInvalidPeriod', {
|
|
714
|
+
code: code ?? '',
|
|
715
|
+
})}
|
|
716
|
+
toastId={toastId}
|
|
717
|
+
/>
|
|
718
|
+
));
|
|
719
|
+
}, [
|
|
720
|
+
billingPeriod,
|
|
721
|
+
disabledBillingPeriods,
|
|
722
|
+
appliedCouponStripeData,
|
|
723
|
+
appliedCouponCode,
|
|
724
|
+
handleRemoveCoupon,
|
|
725
|
+
translate,
|
|
726
|
+
]);
|
|
727
|
+
|
|
728
|
+
const handleClose = useCallback(() => {
|
|
729
|
+
setCurrentStep(1);
|
|
730
|
+
closeChangePlan();
|
|
731
|
+
}, [closeChangePlan]);
|
|
732
|
+
|
|
733
|
+
const handleBack = useCallback(() => setCurrentStep((previous) => Math.max(1, previous - 1)), []);
|
|
734
|
+
const handleContinue = useCallback(() => setCurrentStep((previous) => previous + 1), []);
|
|
735
|
+
|
|
736
|
+
const handleOpenCouponDialog = useCallback(() => setIsCouponDialogOpen(true), []);
|
|
737
|
+
const handleOpenPlansCatalog = useCallback(() => {
|
|
738
|
+
closeChangePlan();
|
|
739
|
+
openPlansCatalog({ appliedCouponStripeData });
|
|
740
|
+
}, [closeChangePlan, openPlansCatalog, appliedCouponStripeData]);
|
|
741
|
+
|
|
742
|
+
const handleReactivate = useCallback(async () => {
|
|
743
|
+
// Sem plano-alvo é a reativação do mesmo plano; com plano-alvo (veio da vitrine) contrata o
|
|
744
|
+
// escolhido — nos dois casos a assinatura é criada do zero.
|
|
745
|
+
const reactivationPlanId = effectivePlanId ?? activeSubscription?.id_plan;
|
|
746
|
+
if (!reactivationPlanId) return;
|
|
747
|
+
|
|
748
|
+
// Assinatura já criada esperando o 3DS: reautentica ELA em vez de contratar de novo.
|
|
749
|
+
if (pendingAuthSecret) {
|
|
750
|
+
setIsReactivating(true);
|
|
751
|
+
try {
|
|
752
|
+
await confirmPaymentIfRequired(
|
|
753
|
+
stripe,
|
|
754
|
+
{ client_secret: pendingAuthSecret },
|
|
755
|
+
translate('common.payment.authFailed')
|
|
756
|
+
);
|
|
757
|
+
setPendingAuthSecret(null);
|
|
758
|
+
handleClose();
|
|
759
|
+
openPaymentConfirmation({
|
|
760
|
+
planName: targetPlan?.name ?? resolveSubscriptionPlanName(activeSubscription, translate),
|
|
761
|
+
total: totalPrice ?? 0,
|
|
762
|
+
periodLabel: getBillingPeriodSuffix(billingPeriod, translate),
|
|
763
|
+
immediateChargeTotal: null,
|
|
764
|
+
});
|
|
765
|
+
} catch (error) {
|
|
766
|
+
toast.custom((toastId) => (
|
|
767
|
+
<Toast
|
|
768
|
+
variant="error"
|
|
769
|
+
message={
|
|
770
|
+
error instanceof Error ? error.message : translate('common.payment.authFailed')
|
|
771
|
+
}
|
|
772
|
+
toastId={toastId}
|
|
773
|
+
/>
|
|
774
|
+
));
|
|
775
|
+
} finally {
|
|
776
|
+
setIsReactivating(false);
|
|
777
|
+
}
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
setIsReactivating(true);
|
|
782
|
+
try {
|
|
783
|
+
const result = await createSubscriptionAsync({
|
|
784
|
+
id_product: activeSubscription?.id_product ?? 1,
|
|
785
|
+
id_plan: reactivationPlanId,
|
|
786
|
+
type: 'client',
|
|
787
|
+
payment_method: paymentMethodToNumeric(paymentMethod),
|
|
788
|
+
periodicity: billingPeriodToNumeric(billingPeriod),
|
|
789
|
+
...(appliedCouponId != null && { id_coupon: appliedCouponId }),
|
|
790
|
+
...(paymentMethod === 'card' && selectedCardId ? { id_card: selectedCardId } : {}),
|
|
791
|
+
plan_items: [
|
|
792
|
+
{ id_addon: ADDON_IDS.AI, quantity: selectedCredit.credits },
|
|
793
|
+
...buildDomainPlanExtras(domainBuckets),
|
|
794
|
+
{ id_addon: ADDON_IDS.AB_TEST, quantity: abTestPayloadQuantity },
|
|
795
|
+
],
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
const created = Array.isArray(result?.data) ? result.data[0] : result?.data;
|
|
799
|
+
handleClose();
|
|
800
|
+
|
|
801
|
+
if (paymentMethod === 'pix') {
|
|
802
|
+
if (created && isPendingPixCreateSubscriptionResponse(created)) {
|
|
803
|
+
openPixPayment({
|
|
804
|
+
qrCode: created.pix.qr_code ?? null,
|
|
805
|
+
expiresAt: created.pix.expires_at ?? null,
|
|
806
|
+
correlationId: created.pix.correlation_id,
|
|
807
|
+
payNowCents: readProrataValueCents(created),
|
|
808
|
+
});
|
|
809
|
+
} else {
|
|
810
|
+
toast.custom((toastId) => (
|
|
811
|
+
<Toast
|
|
812
|
+
variant="error"
|
|
813
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.pixNotGenerated')}
|
|
814
|
+
toastId={toastId}
|
|
815
|
+
/>
|
|
816
|
+
));
|
|
817
|
+
}
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// Boleto recém-gerado: abre a linha digitável na hora, sem mandar o cliente procurar na
|
|
822
|
+
// lista de cobranças.
|
|
823
|
+
if (paymentMethod === 'boleto') {
|
|
824
|
+
const createdId = (created as { id?: string | number } | undefined)?.id;
|
|
825
|
+
if (createdId != null) {
|
|
826
|
+
openBoletoGenerated({ subscriptionId: createdId });
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
toast.custom((toastId) => (
|
|
832
|
+
<Toast
|
|
833
|
+
variant="success"
|
|
834
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.planReactivated', {
|
|
835
|
+
planName: targetPlan?.name ?? resolveSubscriptionPlanName(activeSubscription, translate),
|
|
836
|
+
})}
|
|
837
|
+
toastId={toastId}
|
|
838
|
+
/>
|
|
839
|
+
));
|
|
840
|
+
} catch (error) {
|
|
841
|
+
// 3DS recusado com a assinatura já criada: guarda o segredo para a próxima tentativa
|
|
842
|
+
// autenticar a mesma cobrança.
|
|
843
|
+
if (error instanceof PaymentAuthenticationError && error.clientSecret) {
|
|
844
|
+
setPendingAuthSecret(error.clientSecret);
|
|
845
|
+
}
|
|
846
|
+
toast.custom((toastId) => (
|
|
847
|
+
<Toast
|
|
848
|
+
variant="error"
|
|
849
|
+
message={
|
|
850
|
+
error instanceof PaymentAuthenticationError
|
|
851
|
+
? error.message
|
|
852
|
+
: translate('common.account.workspace.subscription.changePlan.toasts.reactivateError')
|
|
853
|
+
}
|
|
854
|
+
toastId={toastId}
|
|
855
|
+
/>
|
|
856
|
+
));
|
|
857
|
+
} finally {
|
|
858
|
+
setIsReactivating(false);
|
|
859
|
+
}
|
|
860
|
+
}, [
|
|
861
|
+
activeSubscription,
|
|
862
|
+
effectivePlanId,
|
|
863
|
+
targetPlan,
|
|
864
|
+
billingPeriod,
|
|
865
|
+
appliedCouponId,
|
|
866
|
+
selectedCredit,
|
|
867
|
+
domainBuckets,
|
|
868
|
+
abTestPayloadQuantity,
|
|
869
|
+
paymentMethod,
|
|
870
|
+
selectedCardId,
|
|
871
|
+
handleClose,
|
|
872
|
+
createSubscriptionAsync,
|
|
873
|
+
openPixPayment,
|
|
874
|
+
openBoletoGenerated,
|
|
875
|
+
openPaymentConfirmation,
|
|
876
|
+
pendingAuthSecret,
|
|
877
|
+
stripe,
|
|
878
|
+
totalPrice,
|
|
879
|
+
translate,
|
|
880
|
+
]);
|
|
881
|
+
|
|
882
|
+
const handleSubmit = useCallback(
|
|
883
|
+
async (formData: ChangePlanFormData) => {
|
|
884
|
+
if (pendingAuthSecret && activeSubscription?.date_cancellation) return handleReactivate();
|
|
885
|
+
|
|
886
|
+
const periodicity = billingPeriodToNumeric(billingPeriod ?? 'monthly');
|
|
887
|
+
const periodLbl = getBillingPeriodSuffix(billingPeriod ?? 'monthly', translate);
|
|
888
|
+
|
|
889
|
+
try {
|
|
890
|
+
let createdItem: unknown;
|
|
891
|
+
|
|
892
|
+
if (activeSubscription?.date_cancellation) {
|
|
893
|
+
const result = await createSubscriptionAsync({
|
|
894
|
+
id_product: activeSubscription.id_product,
|
|
895
|
+
id_plan: effectivePlanId!,
|
|
896
|
+
type: 'client',
|
|
897
|
+
payment_method: paymentMethodToNumeric(formData.paymentMethod),
|
|
898
|
+
periodicity,
|
|
899
|
+
...(appliedCouponId != null && { id_coupon: appliedCouponId }),
|
|
900
|
+
...(formData.paymentMethod === 'card' && formData.selectedCardId
|
|
901
|
+
? { id_card: formData.selectedCardId }
|
|
902
|
+
: {}),
|
|
903
|
+
plan_items: [
|
|
904
|
+
{ id_addon: ADDON_IDS.AI, quantity: selectedCredit.credits },
|
|
905
|
+
...buildDomainPlanExtras([...domainBuckets, ...zeroedOldDomainBuckets]),
|
|
906
|
+
{ id_addon: ADDON_IDS.AB_TEST, quantity: abTestPayloadQuantity },
|
|
907
|
+
],
|
|
908
|
+
});
|
|
909
|
+
createdItem = Array.isArray(result?.data) ? result.data[0] : result?.data;
|
|
910
|
+
} else {
|
|
911
|
+
const updateData: UpdateSubscriptionPlanRequest =
|
|
912
|
+
pendingAuthSecret && pendingUpdatePayloadRef.current
|
|
913
|
+
? pendingUpdatePayloadRef.current
|
|
914
|
+
: {
|
|
915
|
+
id_plan: effectivePlanId,
|
|
916
|
+
periodicity,
|
|
917
|
+
enable_charge: true,
|
|
918
|
+
payment_method: paymentMethodToNumeric(formData.paymentMethod),
|
|
919
|
+
...(appliedCouponId != null && { id_coupon: appliedCouponId }),
|
|
920
|
+
...(formData.paymentMethod === 'card' && formData.selectedCardId
|
|
921
|
+
? { id_card: formData.selectedCardId }
|
|
922
|
+
: {}),
|
|
923
|
+
plan_extras: [
|
|
924
|
+
{ id_addon: ADDON_IDS.AI, quantity: selectedCredit.credits },
|
|
925
|
+
...buildDomainPlanExtras([...domainBuckets, ...zeroedOldDomainBuckets]),
|
|
926
|
+
{ id_addon: ADDON_IDS.AB_TEST, quantity: abTestPayloadQuantity },
|
|
927
|
+
],
|
|
928
|
+
};
|
|
929
|
+
pendingUpdatePayloadRef.current = updateData;
|
|
930
|
+
|
|
931
|
+
const result = await updatePlanAsync({
|
|
932
|
+
subscriptionId: activeSubscription!.id,
|
|
933
|
+
data: updateData,
|
|
934
|
+
});
|
|
935
|
+
createdItem = Array.isArray(result?.data) ? result.data[0] : result?.data;
|
|
936
|
+
pendingUpdatePayloadRef.current = null;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
handleClose();
|
|
940
|
+
|
|
941
|
+
// Pix pendente tem precedência: o backend devolve a estrutura quando precisa gerar o QR.
|
|
942
|
+
if (createdItem && isPendingPixCreateSubscriptionResponse(createdItem)) {
|
|
943
|
+
if (formData.paymentMethod !== 'pix') {
|
|
944
|
+
// Pix pendente com cartão/boleto significa que o plano não foi aplicado.
|
|
945
|
+
toast.custom((toastId) => (
|
|
946
|
+
<Toast
|
|
947
|
+
variant="error"
|
|
948
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.updateError')}
|
|
949
|
+
toastId={toastId}
|
|
950
|
+
/>
|
|
951
|
+
));
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
openPixPayment({
|
|
956
|
+
qrCode: createdItem.pix.qr_code ?? null,
|
|
957
|
+
expiresAt: createdItem.pix.expires_at ?? null,
|
|
958
|
+
correlationId: createdItem.pix.correlation_id,
|
|
959
|
+
payNowCents: readProrataValueCents(createdItem),
|
|
960
|
+
});
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// Sem cobrança imediata (downgrade/alteração agendada): só confirma a atualização.
|
|
965
|
+
if ((immediateCharge?.total ?? 0) <= 0) {
|
|
966
|
+
toast.custom((toastId) => (
|
|
967
|
+
<Toast
|
|
968
|
+
variant="success"
|
|
969
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.planUpdated')}
|
|
970
|
+
toastId={toastId}
|
|
971
|
+
/>
|
|
972
|
+
));
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
if (formData.paymentMethod === 'pix') {
|
|
977
|
+
toast.custom((toastId) => (
|
|
978
|
+
<Toast
|
|
979
|
+
variant="error"
|
|
980
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.pixNotGenerated')}
|
|
981
|
+
toastId={toastId}
|
|
982
|
+
/>
|
|
983
|
+
));
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
if (formData.paymentMethod === 'boleto') {
|
|
988
|
+
// O boleto sai na fatura gerada — o cliente abre os dados pela lista de cobranças.
|
|
989
|
+
toast.custom((toastId) => (
|
|
990
|
+
<Toast
|
|
991
|
+
variant="success"
|
|
992
|
+
message={translate('common.account.workspace.subscription.changePlan.toasts.boletoGenerated')}
|
|
993
|
+
toastId={toastId}
|
|
994
|
+
/>
|
|
995
|
+
));
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
openPaymentConfirmation({
|
|
1000
|
+
planName: effectivePlan?.name,
|
|
1001
|
+
total: totalPrice ?? 0,
|
|
1002
|
+
periodLabel: periodLbl,
|
|
1003
|
+
immediateChargeTotal: immediateCharge?.total ?? null,
|
|
1004
|
+
});
|
|
1005
|
+
} catch (error) {
|
|
1006
|
+
if (error instanceof PaymentAuthenticationError && error.clientSecret) {
|
|
1007
|
+
setPendingAuthSecret(error.clientSecret);
|
|
1008
|
+
}
|
|
1009
|
+
const message =
|
|
1010
|
+
error instanceof Error
|
|
1011
|
+
? error.message
|
|
1012
|
+
: translate('common.account.workspace.subscription.changePlan.toasts.updateError');
|
|
1013
|
+
toast.custom((toastId) => <Toast variant="error" message={message} toastId={toastId} />);
|
|
1014
|
+
}
|
|
1015
|
+
},
|
|
1016
|
+
[
|
|
1017
|
+
pendingAuthSecret,
|
|
1018
|
+
handleReactivate,
|
|
1019
|
+
activeSubscription,
|
|
1020
|
+
billingPeriod,
|
|
1021
|
+
createSubscriptionAsync,
|
|
1022
|
+
effectivePlanId,
|
|
1023
|
+
effectivePlan,
|
|
1024
|
+
totalPrice,
|
|
1025
|
+
handleClose,
|
|
1026
|
+
updatePlanAsync,
|
|
1027
|
+
appliedCouponId,
|
|
1028
|
+
selectedCredit,
|
|
1029
|
+
domainBuckets,
|
|
1030
|
+
zeroedOldDomainBuckets,
|
|
1031
|
+
abTestPayloadQuantity,
|
|
1032
|
+
immediateCharge,
|
|
1033
|
+
openPixPayment,
|
|
1034
|
+
openPaymentConfirmation,
|
|
1035
|
+
translate,
|
|
1036
|
+
]
|
|
1037
|
+
);
|
|
1038
|
+
|
|
1039
|
+
return {
|
|
1040
|
+
open,
|
|
1041
|
+
isReactivation,
|
|
1042
|
+
isDowngrade,
|
|
1043
|
+
currentStep,
|
|
1044
|
+
handleBack,
|
|
1045
|
+
handleContinue,
|
|
1046
|
+
handleClose,
|
|
1047
|
+
form,
|
|
1048
|
+
paymentMethod,
|
|
1049
|
+
selectedCardId,
|
|
1050
|
+
isSubmitting,
|
|
1051
|
+
// Base do extrato do resumo: PRÉ-desconto de periodicidade — o extrato desconta periodicidade
|
|
1052
|
+
// e cupom em linhas próprias, então usar o total líquido aqui subtrairia duas vezes.
|
|
1053
|
+
newPlanPrice: targetPlan?.pricingByPeriod
|
|
1054
|
+
? targetPlan.pricingByPeriod.monthly * periodMonths
|
|
1055
|
+
: !isReactivation && currentPlan?.value != null
|
|
1056
|
+
? currentPlan.value * periodMonths
|
|
1057
|
+
: null,
|
|
1058
|
+
// Total líquido do plano-alvo no período, para o card de comparação.
|
|
1059
|
+
newPlanChargedPrice: targetPlan?.pricing
|
|
1060
|
+
? targetPlan.pricing[periodPricingKey].charged
|
|
1061
|
+
: !isReactivation && currentPlan?.pricing
|
|
1062
|
+
? currentPlan.pricing[periodPricingKey].charged
|
|
1063
|
+
: !isReactivation && currentPlan?.value != null
|
|
1064
|
+
? currentPlan.value * periodMonths
|
|
1065
|
+
: null,
|
|
1066
|
+
// Riscado do preview: `list` do MESMO período do charged, nunca a âncora mensal x meses.
|
|
1067
|
+
newPlanListPrice: targetPlan?.pricing
|
|
1068
|
+
? targetPlan.pricing[periodPricingKey].list
|
|
1069
|
+
: !isReactivation && currentPlan?.pricing
|
|
1070
|
+
? currentPlan.pricing[periodPricingKey].list
|
|
1071
|
+
: null,
|
|
1072
|
+
planName: isReactivation ? (targetPlan?.name ?? null) : (effectivePlan?.name ?? null),
|
|
1073
|
+
wlName,
|
|
1074
|
+
cards,
|
|
1075
|
+
resolvedAddonCardId,
|
|
1076
|
+
activeCardIdAddon,
|
|
1077
|
+
setActiveCardIdAddon,
|
|
1078
|
+
selectedCreditIndex,
|
|
1079
|
+
setSelectedCreditIndex,
|
|
1080
|
+
selectedCredit,
|
|
1081
|
+
aiCreditOptions,
|
|
1082
|
+
domains,
|
|
1083
|
+
minDomains,
|
|
1084
|
+
domainsCountLoading,
|
|
1085
|
+
planIncludedDomains,
|
|
1086
|
+
extraDomains,
|
|
1087
|
+
isAtMin,
|
|
1088
|
+
hasDomainsAddon,
|
|
1089
|
+
domainBuckets,
|
|
1090
|
+
primaryBucket,
|
|
1091
|
+
alternativeBuckets,
|
|
1092
|
+
hasAlternativeBuckets,
|
|
1093
|
+
canDecreaseTotal: totalDomains > minDomains,
|
|
1094
|
+
handleAlternativeDecrease,
|
|
1095
|
+
handleAlternativeIncrease,
|
|
1096
|
+
domainPriceMonthly,
|
|
1097
|
+
handleDecreaseDomains,
|
|
1098
|
+
handleIncreaseDomains,
|
|
1099
|
+
handleDomainsChange,
|
|
1100
|
+
abTestEnabled,
|
|
1101
|
+
setAbTestEnabled,
|
|
1102
|
+
hasAbTestAddon,
|
|
1103
|
+
abTestIncludedInPlan,
|
|
1104
|
+
abTestPriceMonthly,
|
|
1105
|
+
handleApplyCoupon,
|
|
1106
|
+
handleRemoveCoupon,
|
|
1107
|
+
handleOpenCouponDialog,
|
|
1108
|
+
isCouponDialogOpen,
|
|
1109
|
+
setIsCouponDialogOpen,
|
|
1110
|
+
handleOpenPlansCatalog,
|
|
1111
|
+
appliedCouponStripeData,
|
|
1112
|
+
disabledBillingPeriods,
|
|
1113
|
+
disabledPaymentMethods,
|
|
1114
|
+
allowedBillingPeriod,
|
|
1115
|
+
allowedPaymentMethod,
|
|
1116
|
+
couponUnlocksAllMethods,
|
|
1117
|
+
allowBoletoFromCurrentSubscription,
|
|
1118
|
+
allowPixFromCurrentSubscription,
|
|
1119
|
+
boletoAvailable,
|
|
1120
|
+
pixAvailable,
|
|
1121
|
+
paymentMethodFromSubscription,
|
|
1122
|
+
hasChangedPaymentMethod,
|
|
1123
|
+
appliedCouponCode,
|
|
1124
|
+
isCalculating,
|
|
1125
|
+
totalPrice,
|
|
1126
|
+
discountAmount,
|
|
1127
|
+
couponDiscountAmount,
|
|
1128
|
+
billingPeriod,
|
|
1129
|
+
modalBillingPeriod,
|
|
1130
|
+
billingLabel,
|
|
1131
|
+
billingLabelFull,
|
|
1132
|
+
periodMonths,
|
|
1133
|
+
periodLabel,
|
|
1134
|
+
currentBillingPeriod,
|
|
1135
|
+
currentPeriodLabel,
|
|
1136
|
+
handleSubmit,
|
|
1137
|
+
handleReactivate,
|
|
1138
|
+
isReactivating,
|
|
1139
|
+
hasPendingAuth: pendingAuthSecret !== null,
|
|
1140
|
+
canReactivate: effectivePlanId != null,
|
|
1141
|
+
requiresBillingData,
|
|
1142
|
+
openBillingAddress,
|
|
1143
|
+
contractingBillingPeriod: billingPeriod,
|
|
1144
|
+
setContractingBillingPeriod,
|
|
1145
|
+
calculatedPricing,
|
|
1146
|
+
billingDiscounts,
|
|
1147
|
+
firstPeriodPricingByPeriod,
|
|
1148
|
+
planPricing: targetPlan?.pricing ?? null,
|
|
1149
|
+
abTestDetailsOpen,
|
|
1150
|
+
setAbTestDetailsOpen,
|
|
1151
|
+
getPeriodicityLabel,
|
|
1152
|
+
targetPlan,
|
|
1153
|
+
immediateCharge,
|
|
1154
|
+
calculatedPlanExtras: calculatedData?.plan_extras ?? [],
|
|
1155
|
+
hasChanges,
|
|
1156
|
+
formatCurrencyNumber,
|
|
1157
|
+
};
|
|
1158
|
+
}
|