Fix workspace prefill and remove user allowImpersonation Boolean

This commit is contained in:
Charles Bochet
2023-11-24 00:07:15 +01:00
parent 5038c36df4
commit 2d0f63219f
12 changed files with 21 additions and 76 deletions

View File

@ -160,6 +160,7 @@ export enum FieldMetadataType {
FullName = 'FULL_NAME', FullName = 'FULL_NAME',
Link = 'LINK', Link = 'LINK',
Number = 'NUMBER', Number = 'NUMBER',
Numeric = 'NUMERIC',
Phone = 'PHONE', Phone = 'PHONE',
Probability = 'PROBABILITY', Probability = 'PROBABILITY',
Relation = 'RELATION', Relation = 'RELATION',
@ -445,7 +446,6 @@ export type UserEdge = {
export type UserWorkspaceMember = { export type UserWorkspaceMember = {
__typename?: 'UserWorkspaceMember'; __typename?: 'UserWorkspaceMember';
allowImpersonation: Scalars['Boolean']['output'];
avatarUrl?: Maybe<Scalars['String']['output']>; avatarUrl?: Maybe<Scalars['String']['output']>;
colorScheme: Scalars['String']['output']; colorScheme: Scalars['String']['output'];
id: Scalars['ID']['output']; id: Scalars['ID']['output'];

View File

@ -126,6 +126,7 @@ export enum FieldMetadataType {
FullName = 'FULL_NAME', FullName = 'FULL_NAME',
Link = 'LINK', Link = 'LINK',
Number = 'NUMBER', Number = 'NUMBER',
Numeric = 'NUMERIC',
Phone = 'PHONE', Phone = 'PHONE',
Probability = 'PROBABILITY', Probability = 'PROBABILITY',
Relation = 'RELATION', Relation = 'RELATION',
@ -439,7 +440,6 @@ export type UserExists = {
export type UserWorkspaceMember = { export type UserWorkspaceMember = {
__typename?: 'UserWorkspaceMember'; __typename?: 'UserWorkspaceMember';
allowImpersonation: Scalars['Boolean'];
avatarUrl?: Maybe<Scalars['String']>; avatarUrl?: Maybe<Scalars['String']>;
colorScheme: Scalars['String']; colorScheme: Scalars['String'];
id: Scalars['ID']; id: Scalars['ID'];
@ -609,7 +609,7 @@ export type ImpersonateMutationVariables = Exact<{
}>; }>;
export type ImpersonateMutation = { __typename?: 'Mutation', impersonate: { __typename?: 'Verify', user: { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember: { __typename?: 'UserWorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, allowImpersonation: boolean, name: { __typename?: 'UserWorkspaceMemberName', firstName: string, lastName: string } }, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean } }, tokens: { __typename?: 'AuthTokenPair', accessToken: { __typename?: 'AuthToken', token: string, expiresAt: string }, refreshToken: { __typename?: 'AuthToken', token: string, expiresAt: string } } } }; export type ImpersonateMutation = { __typename?: 'Mutation', impersonate: { __typename?: 'Verify', user: { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember: { __typename?: 'UserWorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, name: { __typename?: 'UserWorkspaceMemberName', firstName: string, lastName: string } }, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean } }, tokens: { __typename?: 'AuthTokenPair', accessToken: { __typename?: 'AuthToken', token: string, expiresAt: string }, refreshToken: { __typename?: 'AuthToken', token: string, expiresAt: string } } } };
export type RenewTokenMutationVariables = Exact<{ export type RenewTokenMutationVariables = Exact<{
refreshToken: Scalars['String']; refreshToken: Scalars['String'];
@ -632,7 +632,7 @@ export type VerifyMutationVariables = Exact<{
}>; }>;
export type VerifyMutation = { __typename?: 'Mutation', verify: { __typename?: 'Verify', user: { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember: { __typename?: 'UserWorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, allowImpersonation: boolean, name: { __typename?: 'UserWorkspaceMemberName', firstName: string, lastName: string } }, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean } }, tokens: { __typename?: 'AuthTokenPair', accessToken: { __typename?: 'AuthToken', token: string, expiresAt: string }, refreshToken: { __typename?: 'AuthToken', token: string, expiresAt: string } } } }; export type VerifyMutation = { __typename?: 'Mutation', verify: { __typename?: 'Verify', user: { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember: { __typename?: 'UserWorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, name: { __typename?: 'UserWorkspaceMemberName', firstName: string, lastName: string } }, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean } }, tokens: { __typename?: 'AuthTokenPair', accessToken: { __typename?: 'AuthToken', token: string, expiresAt: string }, refreshToken: { __typename?: 'AuthToken', token: string, expiresAt: string } } } };
export type CheckUserExistsQueryVariables = Exact<{ export type CheckUserExistsQueryVariables = Exact<{
email: Scalars['String']; email: Scalars['String'];
@ -654,7 +654,7 @@ export type UploadImageMutationVariables = Exact<{
export type UploadImageMutation = { __typename?: 'Mutation', uploadImage: string }; export type UploadImageMutation = { __typename?: 'Mutation', uploadImage: string };
export type UserQueryFragmentFragment = { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember: { __typename?: 'UserWorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, allowImpersonation: boolean, name: { __typename?: 'UserWorkspaceMemberName', firstName: string, lastName: string } }, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean } }; export type UserQueryFragmentFragment = { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember: { __typename?: 'UserWorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, name: { __typename?: 'UserWorkspaceMemberName', firstName: string, lastName: string } }, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean } };
export type DeleteUserAccountMutationVariables = Exact<{ [key: string]: never; }>; export type DeleteUserAccountMutationVariables = Exact<{ [key: string]: never; }>;
@ -671,7 +671,7 @@ export type UploadProfilePictureMutation = { __typename?: 'Mutation', uploadProf
export type GetCurrentUserQueryVariables = Exact<{ [key: string]: never; }>; export type GetCurrentUserQueryVariables = Exact<{ [key: string]: never; }>;
export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember: { __typename?: 'UserWorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, allowImpersonation: boolean, name: { __typename?: 'UserWorkspaceMemberName', firstName: string, lastName: string } }, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean } } }; export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember: { __typename?: 'UserWorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, name: { __typename?: 'UserWorkspaceMemberName', firstName: string, lastName: string } }, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean } } };
export type DeleteCurrentWorkspaceMutationVariables = Exact<{ [key: string]: never; }>; export type DeleteCurrentWorkspaceMutationVariables = Exact<{ [key: string]: never; }>;
@ -732,7 +732,6 @@ export const UserQueryFragmentFragmentDoc = gql`
colorScheme colorScheme
avatarUrl avatarUrl
locale locale
allowImpersonation
} }
defaultWorkspace { defaultWorkspace {
id id
@ -1197,7 +1196,6 @@ export const GetCurrentUserDocument = gql`
colorScheme colorScheme
avatarUrl avatarUrl
locale locale
allowImpersonation
} }
defaultWorkspace { defaultWorkspace {
id id

View File

@ -1,5 +1,6 @@
import { useTheme } from '@emotion/react'; import { useTheme } from '@emotion/react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { isNonEmptyString } from '@sniptt/guards';
import { ActivityTargetChips } from '@/activities/components/ActivityTargetChips'; import { ActivityTargetChips } from '@/activities/components/ActivityTargetChips';
import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer'; import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer';
@ -71,7 +72,8 @@ export const TaskRow = ({
const theme = useTheme(); const theme = useTheme();
const openActivityRightDrawer = useOpenActivityRightDrawer(); const openActivityRightDrawer = useOpenActivityRightDrawer();
const body = JSON.parse(task.body ?? '{}')[0]?.content[0]?.text; const body = JSON.parse(isNonEmptyString(task.body) ? task.body : '{}')[0]
?.content[0]?.text;
const { completeTask } = useCompleteTask(task); const { completeTask } = useCompleteTask(task);
const activityTargetIds = const activityTargetIds =

View File

@ -1,5 +1,6 @@
import { Tooltip } from 'react-tooltip'; import { Tooltip } from 'react-tooltip';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { isNonEmptyString } from '@sniptt/guards';
import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer'; import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer';
import { useCompleteTask } from '@/activities/tasks/hooks/useCompleteTask'; import { useCompleteTask } from '@/activities/tasks/hooks/useCompleteTask';
@ -136,7 +137,9 @@ type TimelineActivityProps = {
export const TimelineActivity = ({ activity }: TimelineActivityProps) => { export const TimelineActivity = ({ activity }: TimelineActivityProps) => {
const beautifiedCreatedAt = beautifyPastDateRelativeToNow(activity.createdAt); const beautifiedCreatedAt = beautifyPastDateRelativeToNow(activity.createdAt);
const exactCreatedAt = beautifyExactDateTime(activity.createdAt); const exactCreatedAt = beautifyExactDateTime(activity.createdAt);
const body = JSON.parse(activity.body ?? '{}')[0]?.content[0]?.text; const body = JSON.parse(
isNonEmptyString(activity.body) ? activity.body : '{}',
)[0]?.content[0]?.text;
const openActivityRightDrawer = useOpenActivityRightDrawer(); const openActivityRightDrawer = useOpenActivityRightDrawer();
const { completeTask } = useCompleteTask(activity); const { completeTask } = useCompleteTask(activity);

View File

@ -33,6 +33,11 @@ export const settingsFieldMetadataTypes: Record<
defaultValue: defaultValue:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum magna enim, dapibus non enim in, lacinia faucibus nunc. Sed interdum ante sed felis facilisis, eget ultricies neque molestie. Mauris auctor, justo eu volutpat cursus, libero erat tempus nulla, non sodales lorem lacus a est.', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum magna enim, dapibus non enim in, lacinia faucibus nunc. Sed interdum ante sed felis facilisis, eget ultricies neque molestie. Mauris auctor, justo eu volutpat cursus, libero erat tempus nulla, non sodales lorem lacus a est.',
}, },
[FieldMetadataType.Numeric]: {
label: 'Numeric',
Icon: IconNumbers,
defaultValue: 2000,
},
[FieldMetadataType.Number]: { [FieldMetadataType.Number]: {
label: 'Number', label: 'Number',
Icon: IconNumbers, Icon: IconNumbers,

View File

@ -1,51 +0,0 @@
import { useRecoilState } from 'recoil';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { Toggle } from '@/ui/input/components/Toggle';
export const ToggleField = () => {
const { enqueueSnackBar } = useSnackBar();
const [currentWorkspaceMember, setCurrentWorkspaceMember] = useRecoilState(
currentWorkspaceMemberState,
);
const { updateOneObject, objectNotFoundInMetadata } =
useUpdateOneObjectRecord({
objectNameSingular: 'workspaceMember',
});
const handleChange = async (value: boolean) => {
try {
if (!updateOneObject || objectNotFoundInMetadata) {
throw new Error('Object not found in metadata');
}
if (!currentWorkspaceMember?.id) {
throw new Error('User is not logged in');
}
await updateOneObject({
idToUpdate: currentWorkspaceMember?.id,
input: {
allowImpersonation: value,
},
});
setCurrentWorkspaceMember({
...currentWorkspaceMember,
allowImpersonation: value,
});
} catch (err: any) {
enqueueSnackBar(err?.message, {
variant: 'error',
});
}
};
return (
<Toggle
value={currentWorkspaceMember?.allowImpersonation}
onChange={handleChange}
/>
);
};

View File

@ -17,7 +17,6 @@ export const USER_QUERY_FRAGMENT = gql`
colorScheme colorScheme
avatarUrl avatarUrl
locale locale
allowImpersonation
} }
defaultWorkspace { defaultWorkspace {
id id

View File

@ -18,7 +18,6 @@ export const GET_CURRENT_USER = gql`
colorScheme colorScheme
avatarUrl avatarUrl
locale locale
allowImpersonation
} }
defaultWorkspace { defaultWorkspace {
id id

View File

@ -9,5 +9,4 @@ export type WorkspaceMember = {
avatarUrl?: string | null; avatarUrl?: string | null;
locale: string; locale: string;
colorScheme?: ColorScheme; colorScheme?: ColorScheme;
allowImpersonation: boolean;
}; };

View File

@ -8,7 +8,7 @@ type MockedUser = Pick<
User, User,
'id' | 'email' | 'firstName' | 'lastName' | 'canImpersonate' | '__typename' 'id' | 'email' | 'firstName' | 'lastName' | 'canImpersonate' | '__typename'
> & { > & {
workspaceMember: Pick<WorkspaceMember, 'id' | 'allowImpersonation'> & { workspaceMember: Pick<WorkspaceMember, 'id'> & {
workspace: Pick< workspace: Pick<
Workspace, Workspace,
'id' | 'displayName' | 'domainName' | 'inviteHash' | 'logo' | '__typename' 'id' | 'displayName' | 'domainName' | 'inviteHash' | 'logo' | '__typename'
@ -36,7 +36,6 @@ export const mockedUsersData: Array<MockedUser> = [
canImpersonate: false, canImpersonate: false,
workspaceMember: { workspaceMember: {
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
allowImpersonation: true,
workspace: { workspace: {
__typename: 'Workspace', __typename: 'Workspace',
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
@ -61,7 +60,6 @@ export const mockedUsersData: Array<MockedUser> = [
canImpersonate: false, canImpersonate: false,
workspaceMember: { workspaceMember: {
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
allowImpersonation: true,
workspace: { workspace: {
__typename: 'Workspace', __typename: 'Workspace',
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
@ -89,7 +87,6 @@ export const mockedOnboardingUsersData: Array<MockedUser> = [
canImpersonate: false, canImpersonate: false,
workspaceMember: { workspaceMember: {
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
allowImpersonation: true,
workspace: { workspace: {
__typename: 'Workspace', __typename: 'Workspace',
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
@ -114,7 +111,6 @@ export const mockedOnboardingUsersData: Array<MockedUser> = [
canImpersonate: false, canImpersonate: false,
workspaceMember: { workspaceMember: {
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
allowImpersonation: true,
workspace: { workspace: {
__typename: 'Workspace', __typename: 'Workspace',
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',

View File

@ -27,7 +27,4 @@ export class UserWorkspaceMember {
@Field({ nullable: false }) @Field({ nullable: false })
locale: string; locale: string;
@Field({ nullable: false })
allowImpersonation: boolean;
} }

View File

@ -40,8 +40,6 @@ export class UserService extends TypeOrmQueryService<User> {
userWorkspaceMember.id = workspaceMembers[0].id; userWorkspaceMember.id = workspaceMembers[0].id;
userWorkspaceMember.colorScheme = workspaceMembers[0].colorScheme; userWorkspaceMember.colorScheme = workspaceMembers[0].colorScheme;
userWorkspaceMember.locale = workspaceMembers[0].locale; userWorkspaceMember.locale = workspaceMembers[0].locale;
userWorkspaceMember.allowImpersonation =
workspaceMembers[0].allowImpersonation;
userWorkspaceMember.avatarUrl = workspaceMembers[0].avatarUrl; userWorkspaceMember.avatarUrl = workspaceMembers[0].avatarUrl;
userWorkspaceMember.name = { userWorkspaceMember.name = {
firstName: workspaceMembers[0].nameFirstName, firstName: workspaceMembers[0].nameFirstName,
@ -63,10 +61,10 @@ export class UserService extends TypeOrmQueryService<User> {
await workspaceDataSource?.query( await workspaceDataSource?.query(
`INSERT INTO ${dataSourceMetadata.schema}."workspaceMember" `INSERT INTO ${dataSourceMetadata.schema}."workspaceMember"
("nameFirstName", "nameLastName", "colorScheme", "userId", "allowImpersonation", "avatarUrl") ("nameFirstName", "nameLastName", "colorScheme", "userId", "avatarUrl")
VALUES ('${user.firstName}', '${user.lastName}', 'Light', '${ VALUES ('${user.firstName}', '${user.lastName}', 'Light', '${
user.id user.id
}', true, '${avatarUrl ?? ''}')`, }', '${avatarUrl ?? ''}')`,
); );
} }