6a1b28bc12
## What & why A single, consistent **workspace-creation step** for both multi-workspace and single-workspace self-host — collecting **name + logo** (and the **subdomain** in multi-workspace) — which **removes the duplicate name/logo prompt** that previously reappeared on the workspace subdomain (reported after #21641). ## Changes **One creation form for both modes** - With 0 workspaces, both multi-workspace and single-workspace route to the shared `SignInUpWorkspaceCreationForm`; `SignInUp` renders it for the `WorkspaceCreation` step regardless of domain/scope. - The subdomain field shows only in multi-workspace; single-workspace keeps its fixed address. **Logo on the creation step** - New scoped `uploadNewWorkspaceLogo(workspaceId, file)` mutation: the creator sets a logo on their just-created `PENDING_CREATION` workspace via the workspace-agnostic token (membership enforced — only the creator is a member at that point), reusing `uploadWorkspacePicture`. Upload size is capped via `settings.storage.maxFileSize` (also applied to the existing logo / profile-picture uploads). - The picked file is held locally (object-URL preview, revoked on unmount) and uploaded right after creation (non-fatal on failure). **Onboarding step → pure activation loader** - The old "Create your workspace" form (name + logo) is removed. The onboarding step now activates the pending workspace on mount and shows the loader, with a **Retry** action on failure. ## Testing - typecheck (front + server) ✅; oxlint + oxfmt clean on changed files ✅ - Unit tests: `auth.resolver.spec`, `useWorkspaceSubdomainField`, `SignInUpWorkspaceCreationForm` (multi + single-workspace), `useAuth` ✅ - Metadata GraphQL + `twenty-client-sdk` schema regenerated. Follow-up to #21641. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Xw37hR5seiCyWnppG9z4op --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
195 lines
6.3 KiB
TypeScript
195 lines
6.3 KiB
TypeScript
import { verifyEmailRedirectPathState } from '@/app/states/verifyEmailRedirectPathState';
|
|
import { ONBOARDING_PATHS } from '@/auth/constants/OnboardingPaths';
|
|
import { ONGOING_USER_CREATION_PATHS } from '@/auth/constants/OngoingUserCreationPaths';
|
|
import { useHasAccessTokenPair } from '@/auth/hooks/useHasAccessTokenPair';
|
|
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
|
import { returnToPathState } from '@/auth/states/returnToPathState';
|
|
import { calendarBookingPageIdState } from '@/client-config/states/calendarBookingPageIdState';
|
|
import { useIsCurrentLocationOnAWorkspace } from '@/domain-manager/hooks/useIsCurrentLocationOnAWorkspace';
|
|
import { useDefaultHomePagePath } from '@/navigation/hooks/useDefaultHomePagePath';
|
|
import { objectMetadataItemsSelector } from '@/object-metadata/states/objectMetadataItemsSelector';
|
|
import { useOnboardingStatus } from '@/onboarding/hooks/useOnboardingStatus';
|
|
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
|
import { useIsWorkspaceActivationStatusEqualsTo } from '@/workspace/hooks/useIsWorkspaceActivationStatusEqualsTo';
|
|
import { isValidReturnToPath } from '@/auth/utils/isValidReturnToPath';
|
|
import { useQuery } from '@apollo/client/react';
|
|
import { isNonEmptyString } from '@sniptt/guards';
|
|
import { useLocation, useParams } from 'react-router-dom';
|
|
import { AppPath, SettingsPath } from 'twenty-shared/types';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
|
|
import {
|
|
FindOnePageLayoutTypeDocument,
|
|
OnboardingStatus,
|
|
PageLayoutType,
|
|
} from '~/generated-metadata/graphql';
|
|
import { isMatchingLocation } from '~/utils/isMatchingLocation';
|
|
|
|
const readReturnToPathFromUrlSearchParams = (): string | null => {
|
|
const value = new URLSearchParams(window.location.search).get('returnToPath');
|
|
|
|
return value && isValidReturnToPath(value) ? value : null;
|
|
};
|
|
|
|
export const usePageChangeEffectNavigateLocation = () => {
|
|
const hasAccessTokenPair = useHasAccessTokenPair();
|
|
const currentWorkspace = useAtomStateValue(currentWorkspaceState);
|
|
const { isOnAWorkspace } = useIsCurrentLocationOnAWorkspace();
|
|
const onboardingStatus = useOnboardingStatus();
|
|
const isWorkspaceSuspended = useIsWorkspaceActivationStatusEqualsTo(
|
|
WorkspaceActivationStatus.SUSPENDED,
|
|
);
|
|
const { defaultHomePagePath } = useDefaultHomePagePath();
|
|
const location = useLocation();
|
|
const calendarBookingPageId = useAtomStateValue(calendarBookingPageIdState);
|
|
|
|
const someMatchingLocationOf = (appPaths: AppPath[]): boolean =>
|
|
appPaths.some((appPath) => isMatchingLocation(location, appPath));
|
|
|
|
const params = useParams();
|
|
|
|
const objectNamePlural = params.objectNamePlural ?? '';
|
|
const objectMetadataItems = useAtomStateValue(objectMetadataItemsSelector);
|
|
const objectMetadataItem = objectMetadataItems?.find(
|
|
(objectMetadataItem) => objectMetadataItem.namePlural === objectNamePlural,
|
|
);
|
|
|
|
const pageLayoutId = params.pageLayoutId;
|
|
const isOnPageLayoutPage = isMatchingLocation(
|
|
location,
|
|
AppPath.PageLayoutPage,
|
|
);
|
|
|
|
const { data: pageLayoutData, loading: isPageLayoutLoading } = useQuery(
|
|
FindOnePageLayoutTypeDocument,
|
|
{
|
|
variables: { id: pageLayoutId ?? '' },
|
|
skip: !isOnPageLayoutPage || !isDefined(pageLayoutId),
|
|
},
|
|
);
|
|
const verifyEmailRedirectPath = useAtomStateValue(
|
|
verifyEmailRedirectPathState,
|
|
);
|
|
|
|
const returnToPath = useAtomStateValue(returnToPathState);
|
|
const resolvedReturnToPath = isNonEmptyString(returnToPath)
|
|
? returnToPath
|
|
: readReturnToPathFromUrlSearchParams();
|
|
|
|
if (
|
|
(!hasAccessTokenPair || !isOnAWorkspace || !isDefined(currentWorkspace)) &&
|
|
!someMatchingLocationOf([
|
|
...ONGOING_USER_CREATION_PATHS,
|
|
AppPath.ResetPassword,
|
|
])
|
|
) {
|
|
return AppPath.SignInUp;
|
|
}
|
|
|
|
if (
|
|
onboardingStatus === OnboardingStatus.PLAN_REQUIRED &&
|
|
!someMatchingLocationOf([
|
|
AppPath.PlanRequired,
|
|
AppPath.PlanRequiredSuccess,
|
|
AppPath.BookCall,
|
|
AppPath.BookCallDecision,
|
|
])
|
|
) {
|
|
if (
|
|
isMatchingLocation(location, AppPath.VerifyEmail) &&
|
|
isDefined(verifyEmailRedirectPath)
|
|
) {
|
|
return verifyEmailRedirectPath;
|
|
}
|
|
return AppPath.PlanRequired;
|
|
}
|
|
|
|
if (isWorkspaceSuspended) {
|
|
if (!isMatchingLocation(location, AppPath.SettingsCatchAll)) {
|
|
return `${AppPath.SettingsCatchAll.replace('/*', '')}/${
|
|
SettingsPath.Billing
|
|
}`;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (
|
|
onboardingStatus === OnboardingStatus.WORKSPACE_ACTIVATION &&
|
|
!someMatchingLocationOf([
|
|
AppPath.WorkspaceActivation,
|
|
AppPath.BookCallDecision,
|
|
AppPath.BookCall,
|
|
])
|
|
) {
|
|
return AppPath.WorkspaceActivation;
|
|
}
|
|
|
|
if (
|
|
onboardingStatus === OnboardingStatus.PROFILE_CREATION &&
|
|
!isMatchingLocation(location, AppPath.CreateProfile)
|
|
) {
|
|
return AppPath.CreateProfile;
|
|
}
|
|
|
|
if (
|
|
onboardingStatus === OnboardingStatus.SYNC_EMAIL &&
|
|
!isMatchingLocation(location, AppPath.SyncEmails)
|
|
) {
|
|
return AppPath.SyncEmails;
|
|
}
|
|
|
|
if (
|
|
onboardingStatus === OnboardingStatus.INVITE_TEAM &&
|
|
!isMatchingLocation(location, AppPath.InviteTeam)
|
|
) {
|
|
return AppPath.InviteTeam;
|
|
}
|
|
|
|
if (
|
|
onboardingStatus === OnboardingStatus.BOOK_ONBOARDING &&
|
|
!someMatchingLocationOf([AppPath.BookCallDecision, AppPath.BookCall])
|
|
) {
|
|
if (!isDefined(calendarBookingPageId)) {
|
|
return defaultHomePagePath;
|
|
}
|
|
return AppPath.BookCallDecision;
|
|
}
|
|
|
|
if (
|
|
onboardingStatus === OnboardingStatus.COMPLETED &&
|
|
someMatchingLocationOf([
|
|
...ONBOARDING_PATHS,
|
|
...ONGOING_USER_CREATION_PATHS,
|
|
]) &&
|
|
!isMatchingLocation(location, AppPath.ResetPassword) &&
|
|
hasAccessTokenPair &&
|
|
isOnAWorkspace
|
|
) {
|
|
return resolvedReturnToPath ?? defaultHomePagePath;
|
|
}
|
|
|
|
if (isMatchingLocation(location, AppPath.Index) && hasAccessTokenPair) {
|
|
return resolvedReturnToPath ?? defaultHomePagePath;
|
|
}
|
|
|
|
if (
|
|
isMatchingLocation(location, AppPath.RecordIndexPage) &&
|
|
!isDefined(objectMetadataItem)
|
|
) {
|
|
return AppPath.NotFound;
|
|
}
|
|
|
|
if (
|
|
isOnPageLayoutPage &&
|
|
isDefined(pageLayoutId) &&
|
|
!isPageLayoutLoading &&
|
|
(!isDefined(pageLayoutData?.getPageLayout) ||
|
|
pageLayoutData.getPageLayout.type !== PageLayoutType.STANDALONE_PAGE)
|
|
) {
|
|
return AppPath.NotFound;
|
|
}
|
|
|
|
return;
|
|
};
|