diff --git a/.source b/.source index 9957fecaf47..366768dbfbb 160000 --- a/.source +++ b/.source @@ -1 +1 @@ -Subproject commit 9957fecaf47b5f70e01f91be77e4f410f902ceff +Subproject commit 366768dbfbbf8493d361dbe4321816b5d8f1c248 diff --git a/apps/web/src/ee/clerk/providers/EnterpriseAuthProvider.tsx b/apps/web/src/ee/clerk/providers/EnterpriseAuthProvider.tsx index 9a276785769..47feef13653 100644 --- a/apps/web/src/ee/clerk/providers/EnterpriseAuthProvider.tsx +++ b/apps/web/src/ee/clerk/providers/EnterpriseAuthProvider.tsx @@ -9,6 +9,7 @@ import { useNavigate } from 'react-router-dom'; import { useQueryClient } from '@tanstack/react-query'; import { useSegment } from '../../../components/providers/SegmentProvider'; import { ROUTES } from '../../../constants/routes'; +import { useGetDefaultLocale } from '../../translations/hooks/useGetDefaultLocale'; const asyncNoop = async () => {}; @@ -18,6 +19,7 @@ EnterpriseAuthContext.displayName = 'EnterpriseAuthProvider'; export const EnterpriseAuthProvider = ({ children }: { children: React.ReactNode }) => { const { signOut, orgId } = useAuth(); + const { defaultLocale } = useGetDefaultLocale(); const { user: clerkUser, isLoaded: isUserLoaded } = useUser(); const { organization: clerkOrganization, isLoaded: isOrganizationLoaded } = useOrganization(); // TODO @ChmaraX: Can we use setActive from useSession, useSignIn, or useSignUp to avoid loading the list? @@ -106,12 +108,12 @@ export const EnterpriseAuthProvider = ({ children }: { children: React.ReactNode redirectTo({ url: ROUTES.AUTH_SIGNUP_ORGANIZATION_LIST }); } } - }, [navigate, setActive, isOrgListLoaded, clerkUser, orgId, redirectTo]); + }, [setActive, isOrgListLoaded, clerkUser, orgId, redirectTo]); const currentUser = useMemo(() => (clerkUser ? toUserEntity(clerkUser) : undefined), [clerkUser]); const currentOrganization = useMemo( - () => (clerkOrganization ? toOrganizationEntity(clerkOrganization) : undefined), - [clerkOrganization] + () => (clerkOrganization ? toOrganizationEntity(clerkOrganization, defaultLocale) : undefined), + [clerkOrganization, defaultLocale] ); // refetch queries on organization switch @@ -177,7 +179,10 @@ const toUserEntity = (clerkUser: UserResource): IUserEntity => { }; }; -const toOrganizationEntity = (clerkOrganization: OrganizationResource): IOrganizationEntity => { +const toOrganizationEntity = ( + clerkOrganization: OrganizationResource, + defaultLocale: string | undefined +): IOrganizationEntity => { /* * When mapping to IOrganizationEntity, we have 2 cases: * - user exists and has signed in @@ -197,7 +202,7 @@ const toOrganizationEntity = (clerkOrganization: OrganizationResource): IOrganiz name: clerkOrganization.name, createdAt: clerkOrganization.createdAt.toISOString(), updatedAt: clerkOrganization.updatedAt.toISOString(), - defaultLocale: clerkOrganization.publicMetadata.defaultLocale, + defaultLocale: defaultLocale, domain: clerkOrganization.publicMetadata.domain, productUseCases: clerkOrganization.publicMetadata.productUseCases, language: clerkOrganization.publicMetadata.language, diff --git a/apps/web/src/ee/translations/hooks/useGetDefaultLocale.tsx b/apps/web/src/ee/translations/hooks/useGetDefaultLocale.tsx new file mode 100644 index 00000000000..10b2d197641 --- /dev/null +++ b/apps/web/src/ee/translations/hooks/useGetDefaultLocale.tsx @@ -0,0 +1,12 @@ +import { useQuery } from '@tanstack/react-query'; +import { api } from '../../../api'; + +export const useGetDefaultLocale = () => { + const { data } = useQuery<{ defaultLocale: string }>([`translations/defaultLocale`], () => + api.get(`/v1/translations/defaultLocale`) + ); + + return { + defaultLocale: data?.defaultLocale, + }; +};