Skip to content
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

Merged
merged 19 commits into from
Dec 5, 2024
Merged

Conversation

AMoreaux
Copy link
Contributor

@AMoreaux AMoreaux commented Dec 3, 2024

Replace #8855

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.
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 like useBuildWorkspaceUrl, useDefaultDomain, and useDomainBackToWorkspace for better separation of concerns
  • Replaced urlManagerState with domainConfigurationState 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 with backToWorkspace 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/auth/hooks/useAuth.ts Outdated Show resolved Hide resolved
onPage?: string,
searchParams?: Record<string, string>,
) => {
const url = new URL(window.location.href);
Copy link
Contributor

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.

Comment on lines +15 to +17
if (isDefined(subdomain) && subdomain.length !== 0) {
url.hostname = `${subdomain}.${domainConfiguration.frontDomain}`;
}
Copy link
Contributor

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.

Comment on lines 9 to 11
const defaultDomain = isMultiWorkspaceEnabled
? `${domainConfiguration.defaultSubdomain}.${domainConfiguration.frontDomain}`
: domainConfiguration.frontDomain;
Copy link
Contributor

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

Comment on lines 39 to 41
if (isDefined(errors) || !isDefined(data?.switchWorkspace.subdomain)) {
return redirectToHome();
return backToDefaultSubdomain();
}
Copy link
Contributor

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

Comment on lines 28 to 29
workspacePublicData.subdomain !== workspaceSubdomain()
) {
Copy link
Contributor

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;
Copy link
Contributor

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

packages/twenty-front/src/pages/auth/SignInUp.tsx Outdated Show resolved Hide resolved
packages/twenty-front/src/utils/recoil-effects.ts Outdated Show resolved Hide resolved
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.
@AMoreaux AMoreaux force-pushed the review/refacto-url-manager branch from 11e296d to 1509e45 Compare December 5, 2024 09:42
@AMoreaux AMoreaux force-pushed the review/refacto-url-manager branch from 640c1dd to 4e15b72 Compare December 5, 2024 09:58
# 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
Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AMoreaux AMoreaux merged commit 081ecbc into main Dec 5, 2024
19 checks passed
@AMoreaux AMoreaux deleted the review/refacto-url-manager branch December 5, 2024 10:47
Copy link

github-actions bot commented Dec 5, 2024

Thanks @AMoreaux for your contribution!
This marks your 18th PR on the repo. You're top 2% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants