refactor(auth): add workspaces selection (#12098)
This commit is contained in:
@ -8,7 +8,6 @@ import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMembe
|
||||
import { currentWorkspaceMembersState } from '@/auth/states/currentWorkspaceMembersStates';
|
||||
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
||||
import { isCurrentUserLoadedState } from '@/auth/states/isCurrentUserLoadedState';
|
||||
import { workspacesState } from '@/auth/states/workspaces';
|
||||
import { DateFormat } from '@/localization/constants/DateFormat';
|
||||
import { TimeFormat } from '@/localization/constants/TimeFormat';
|
||||
import { dateTimeFormatState } from '@/localization/states/dateTimeFormatState';
|
||||
@ -30,6 +29,7 @@ import { useGetCurrentUserQuery } from '~/generated/graphql';
|
||||
import { dateLocaleState } from '~/localization/states/dateLocaleState';
|
||||
import { dynamicActivate } from '~/utils/i18n/dynamicActivate';
|
||||
import { isMatchingLocation } from '~/utils/isMatchingLocation';
|
||||
import { availableWorkspacesState } from '@/auth/states/availableWorkspacesState';
|
||||
|
||||
export const UserProviderEffect = () => {
|
||||
const location = useLocation();
|
||||
@ -40,7 +40,7 @@ export const UserProviderEffect = () => {
|
||||
const setCurrentUser = useSetRecoilState(currentUserState);
|
||||
const setCurrentWorkspace = useSetRecoilState(currentWorkspaceState);
|
||||
const setCurrentUserWorkspace = useSetRecoilState(currentUserWorkspaceState);
|
||||
const setWorkspaces = useSetRecoilState(workspacesState);
|
||||
const setAvailableWorkspaces = useSetRecoilState(availableWorkspacesState);
|
||||
const setDateTimeFormat = useSetRecoilState(dateTimeFormatState);
|
||||
const isLoggedIn = useIsLogged();
|
||||
|
||||
@ -102,7 +102,7 @@ export const UserProviderEffect = () => {
|
||||
workspaceMember,
|
||||
workspaceMembers,
|
||||
deletedWorkspaceMembers,
|
||||
workspaces: userWorkspaces,
|
||||
availableWorkspaces,
|
||||
} = queryData.currentUser;
|
||||
|
||||
const affectDefaultValuesOnEmptyWorkspaceMemberFields = (
|
||||
@ -153,12 +153,8 @@ export const UserProviderEffect = () => {
|
||||
setCurrentWorkspaceMembersWithDeleted(deletedWorkspaceMembers);
|
||||
}
|
||||
|
||||
if (isDefined(userWorkspaces)) {
|
||||
const workspaces = userWorkspaces
|
||||
.map(({ workspace }) => workspace)
|
||||
.filter(isDefined);
|
||||
|
||||
setWorkspaces(workspaces);
|
||||
if (isDefined(availableWorkspaces)) {
|
||||
setAvailableWorkspaces(availableWorkspaces);
|
||||
}
|
||||
}, [
|
||||
queryLoading,
|
||||
@ -166,9 +162,9 @@ export const UserProviderEffect = () => {
|
||||
setCurrentUser,
|
||||
setCurrentUserWorkspace,
|
||||
setCurrentWorkspaceMembers,
|
||||
setAvailableWorkspaces,
|
||||
setCurrentWorkspace,
|
||||
setCurrentWorkspaceMember,
|
||||
setWorkspaces,
|
||||
setIsCurrentUserLoaded,
|
||||
setDateTimeFormat,
|
||||
setCurrentWorkspaceMembersWithDeleted,
|
||||
|
||||
@ -3,6 +3,7 @@ import { ROLE_FRAGMENT } from '@/settings/roles/graphql/fragments/roleFragment';
|
||||
import { DELETED_WORKSPACE_MEMBER_QUERY_FRAGMENT } from '@/workspace-member/graphql/fragments/deletedWorkspaceMemberQueryFragment';
|
||||
import { WORKSPACE_MEMBER_QUERY_FRAGMENT } from '@/workspace-member/graphql/fragments/workspaceMemberQueryFragment';
|
||||
import { gql } from '@apollo/client';
|
||||
import { AVAILABLE_WORKSPACES_FOR_AUTH_FRAGMENT } from '@/auth/graphql/fragments/authFragments';
|
||||
|
||||
export const USER_QUERY_FRAGMENT = gql`
|
||||
${ROLE_FRAGMENT}
|
||||
@ -48,8 +49,7 @@ export const USER_QUERY_FRAGMENT = gql`
|
||||
customDomain
|
||||
isCustomDomainEnabled
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
...WorkspaceUrlsFragment
|
||||
}
|
||||
featureFlags {
|
||||
key
|
||||
@ -86,22 +86,13 @@ export const USER_QUERY_FRAGMENT = gql`
|
||||
...RoleFragment
|
||||
}
|
||||
}
|
||||
workspaces {
|
||||
workspace {
|
||||
id
|
||||
logo
|
||||
displayName
|
||||
subdomain
|
||||
customDomain
|
||||
workspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
}
|
||||
availableWorkspaces {
|
||||
...AvailableWorkspacesFragment
|
||||
}
|
||||
userVars
|
||||
}
|
||||
|
||||
${AVAILABLE_WORKSPACES_FOR_AUTH_FRAGMENT}
|
||||
${WORKSPACE_MEMBER_QUERY_FRAGMENT}
|
||||
${DELETED_WORKSPACE_MEMBER_QUERY_FRAGMENT}
|
||||
`;
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const WORKSPACE_URLS_FRAGMENT = gql`
|
||||
fragment WorkspaceUrlsFragment on WorkspaceUrls {
|
||||
subdomainUrl
|
||||
customUrl
|
||||
}
|
||||
`;
|
||||
Reference in New Issue
Block a user