Files
twenty_crm/packages/twenty-front/src/modules/auth/sign-in-up/hooks/useNavigateAfterSignInUp.ts
martmull 8f6200be7d 41 update subscription when workspace member changes 2 (#4252)
* Add loader and disabling on checkout button

* Add Stripe Subscription Item id to subscriptionItem entity

* Handle create and delete workspace members

* Update billing webhook

* Make stripe attribute private

* Fixing webhook error

* Clean migration

* Cancel subscription when deleting workspace

* Fix test

* Add freetrial

* Update navigate after signup

* Add automatic tax collection
2024-03-01 17:29:28 +01:00

45 lines
1.3 KiB
TypeScript

import { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { CurrentWorkspace } from '@/auth/states/currentWorkspaceState.ts';
import { billingState } from '@/client-config/states/billingState.ts';
import { AppPath } from '@/types/AppPath.ts';
import { WorkspaceMember } from '~/generated/graphql.tsx';
export const useNavigateAfterSignInUp = () => {
const navigate = useNavigate();
const billing = useRecoilValue(billingState);
const navigateAfterSignInUp = useCallback(
(
currentWorkspace: CurrentWorkspace,
currentWorkspaceMember: WorkspaceMember | null,
) => {
if (
billing?.isBillingEnabled &&
!['active', 'trialing'].includes(currentWorkspace.subscriptionStatus)
) {
navigate(AppPath.PlanRequired);
return;
}
if (currentWorkspace.activationStatus !== 'active') {
navigate(AppPath.CreateWorkspace);
return;
}
if (
!currentWorkspaceMember?.name.firstName ||
!currentWorkspaceMember?.name.lastName
) {
navigate(AppPath.CreateProfile);
return;
}
navigate(AppPath.Index);
},
[billing, navigate],
);
return { navigateAfterSignInUp };
};