3959 create a activationstatus in coreworkspace and use it in front to redirect properly (#3989)

* Add computed field to workspace entity

* Add activationStatus to front requests

* Update Selector

* Use activation status

* Stop using selector for mock values

* Remove isCurrentWorkspaceActiveSelector

* Use activation status

* Fix typo

* Use activation status

* Create hook for sign in up navigate

* Update hook to handle profile creation

* Use varaible

* Use more readable boolean function
This commit is contained in:
martmull
2024-02-16 16:00:39 +01:00
committed by GitHub
parent 03a1d3aa75
commit 0ee512a983
26 changed files with 165 additions and 105 deletions

View File

@ -0,0 +1,44 @@
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 &&
currentWorkspace.subscriptionStatus !== 'active'
) {
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 };
};