fix billingCheckoutSession query param + enable redirect on workspace… (#11509)
… during onboarding fixes : https://github.com/twentyhq/core-team-issues/issues/668
This commit is contained in:
@ -0,0 +1,32 @@
|
||||
import { animateModalState } from '@/auth/states/animateModalState';
|
||||
import { billingCheckoutSessionState } from '@/auth/states/billingCheckoutSessionState';
|
||||
import { BILLING_CHECKOUT_SESSION_DEFAULT_VALUE } from '@/billing/constants/BillingCheckoutSessionDefaultValue';
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
|
||||
export const useBuildSearchParamsFromUrlSyncedStates = () => {
|
||||
const buildSearchParamsFromUrlSyncedStates = useRecoilCallback(
|
||||
({ snapshot }) =>
|
||||
async () => {
|
||||
const animateModal = snapshot.getLoadable(animateModalState).getValue();
|
||||
const billingCheckoutSession = snapshot
|
||||
.getLoadable(billingCheckoutSessionState)
|
||||
.getValue();
|
||||
|
||||
const output = {
|
||||
...(billingCheckoutSession !== BILLING_CHECKOUT_SESSION_DEFAULT_VALUE
|
||||
? {
|
||||
billingCheckoutSession: JSON.stringify(billingCheckoutSession),
|
||||
}
|
||||
: {}),
|
||||
...(animateModal === false ? { animateModal: 'false' } : {}),
|
||||
};
|
||||
|
||||
return output;
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return {
|
||||
buildSearchParamsFromUrlSyncedStates,
|
||||
};
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { lastAuthenticatedWorkspaceDomainState } from '@/domain-manager/states/lastAuthenticatedWorkspaceDomainState';
|
||||
import { domainConfigurationState } from '@/domain-manager/states/domainConfigurationState';
|
||||
import { lastAuthenticatedWorkspaceDomainState } from '@/domain-manager/states/lastAuthenticatedWorkspaceDomainState';
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
|
||||
export const useLastAuthenticatedWorkspaceDomain = () => {
|
||||
const domainConfiguration = useRecoilValue(domainConfigurationState);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWorkspaceEnabledState';
|
||||
import { useBuildSearchParamsFromUrlSyncedStates } from '@/domain-manager/hooks/useBuildSearchParamsFromUrlSyncedStates';
|
||||
import { useBuildWorkspaceUrl } from '@/domain-manager/hooks/useBuildWorkspaceUrl';
|
||||
import { useRedirect } from '@/domain-manager/hooks/useRedirect';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
@ -8,14 +9,23 @@ export const useRedirectToWorkspaceDomain = () => {
|
||||
const { buildWorkspaceUrl } = useBuildWorkspaceUrl();
|
||||
const { redirect } = useRedirect();
|
||||
|
||||
const redirectToWorkspaceDomain = (
|
||||
const { buildSearchParamsFromUrlSyncedStates } =
|
||||
useBuildSearchParamsFromUrlSyncedStates();
|
||||
|
||||
const redirectToWorkspaceDomain = async (
|
||||
baseUrl: string,
|
||||
pathname?: string,
|
||||
searchParams?: Record<string, string | boolean>,
|
||||
target?: string,
|
||||
) => {
|
||||
if (!isMultiWorkspaceEnabled) return;
|
||||
redirect(buildWorkspaceUrl(baseUrl, pathname, searchParams), target);
|
||||
redirect(
|
||||
buildWorkspaceUrl(baseUrl, pathname, {
|
||||
...searchParams,
|
||||
...(await buildSearchParamsFromUrlSyncedStates()),
|
||||
}),
|
||||
target,
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user