-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
review(front): refacto url-manager #8861
Conversation
Renamed `lastAuthenticateWorkspaceState` to `workspaceDomainState` for clearer context and consistency across modules. Updated imports, variable references, and renamed related files. This change improves code readability by aligning state names with their purpose.
Replaced workspaceDomainState with lastAuthenticateWorkspaceDomainState to consolidate domain management logic. Updated all references to use the new hook for improved clarity and consistency. Adjusted import paths for domain configuration state to a more consistent naming convention.
Removed unused `useRecoilValue` and `domainConfigurationState` imports to streamline the code. Introduced `isMultiWorkspaceEnabledState` management in useAuth, aligning with clientConfig changes. Also added a zod schema for structured cookie attribute validation in recoil-effects.
Refactored the validation logic for custom cookie attributes by adding a helper function, `isCustomCookiesAttributesValue`, to improve code readability and maintainability. This refactor removes redundant parsing logic and ensures correct type checking, streamlining the existing recoil effect utility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR refactors the URL management system by introducing a new domain-manager module that replaces the centralized url-manager with more focused, specialized hooks for handling workspace and domain-related functionality.
- Added new
domain-manager
module with specialized hooks likeuseBuildWorkspaceUrl
,useDefaultDomain
, anduseDomainBackToWorkspace
for better separation of concerns - Replaced
urlManagerState
withdomainConfigurationState
for managing domain configuration across the application - Introduced
lastAuthenticateWorkspaceDomainState
with cookie persistence for tracking authenticated workspace domains - Added Zod validation schema for cookie attributes in
recoil-effects.ts
to improve type safety - Simplified workspace navigation by replacing
redirectToWorkspace
withbackToWorkspace
function in sign-in and workspace creation flows
22 file(s) reviewed, 24 comment(s)
Edit PR Review Bot Settings | Greptile
packages/twenty-front/src/modules/client-config/components/ClientConfigProviderEffect.tsx
Outdated
Show resolved
Hide resolved
onPage?: string, | ||
searchParams?: Record<string, string>, | ||
) => { | ||
const url = new URL(window.location.href); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Using window.location.href as base URL could cause issues if current URL is malformed. Consider using a default base URL as fallback.
if (isDefined(subdomain) && subdomain.length !== 0) { | ||
url.hostname = `${subdomain}.${domainConfiguration.frontDomain}`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Missing validation for domainConfiguration.frontDomain - could throw if undefined. Add check before string interpolation.
const defaultDomain = isMultiWorkspaceEnabled | ||
? `${domainConfiguration.defaultSubdomain}.${domainConfiguration.frontDomain}` | ||
: domainConfiguration.frontDomain; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Missing validation for domainConfiguration.defaultSubdomain - could be undefined in multi-workspace mode causing invalid domain string
if (isDefined(errors) || !isDefined(data?.switchWorkspace.subdomain)) { | ||
return redirectToHome(); | ||
return backToDefaultSubdomain(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding error details to the snackbar when redirecting to default subdomain due to errors
workspacePublicData.subdomain !== workspaceSubdomain() | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: workspaceSubdomain() is called in render and dependency array but result isn't cached - could cause unnecessary re-renders
const isMultiWorkspaceEnabled = useRecoilValue(isMultiWorkspaceEnabledState); | ||
|
||
const signInUpForm = useMemo(() => { | ||
if (isTwentyHomePage && isMultiWorkspaceEnabled) { | ||
if (loading) return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: returning null during loading could cause a flash of no content - consider showing a loading state instead
Reorganize imports in useSignInUpForm.ts for better readability and fix indentation in workspace-invitation.service.ts for code consistency. These changes enhance code maintainability without altering functionality.
packages/twenty-front/src/modules/domain-manager/hooks/useWorkspaceSubdomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useWorkspaceSubdomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useWorkspaceSubdomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useDefaultDomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useDefaultDomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useBuildWorkspaceUrl.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useBuildWorkspaceUrl.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useDomainBackToDefaultSubdomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useDomainBackToWorkspace.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useLastAuthenticateWorkspaceDomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useLastAuthenticateWorkspaceDomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useLastAuthenticateWorkspaceDomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/hooks/useLastAuthenticateWorkspaceDomain.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/states/lastAuthenticateWorkspaceDomainState.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/domain-manager/states/lastAuthenticateWorkspaceDomainState.ts
Outdated
Show resolved
Hide resolved
11e296d
to
1509e45
Compare
640c1dd
to
4e15b72
Compare
# Conflicts: # packages/twenty-front/vite.config.ts
…nager # Conflicts: # packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpGlobalScopeForm.tsx # packages/twenty-front/src/pages/auth/SignInUp.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks @AMoreaux for your contribution! |
Replace #8855