2472 v2 settings workspace module (#2532)
* update findOneWorkspaceMember * profile picture upload is working * first name and last name working * support almost working * remove picture working * removed unused code * remove console logs and fix allowImpersonation in FIND_ONE_WORKSPACE_MEMBER_V2 * use useUpdateOneObjectRecord
This commit is contained in:
@ -33,16 +33,12 @@ export const useMapFieldMetadataToGraphQLQuery = () => {
|
|||||||
fieldType === 'RELATION' &&
|
fieldType === 'RELATION' &&
|
||||||
field.toRelationMetadata?.relationType === 'ONE_TO_MANY'
|
field.toRelationMetadata?.relationType === 'ONE_TO_MANY'
|
||||||
) {
|
) {
|
||||||
console.log({ objectMetadataItems, field });
|
|
||||||
|
|
||||||
const relationMetadataItem = objectMetadataItems.find(
|
const relationMetadataItem = objectMetadataItems.find(
|
||||||
(objectMetadataItem) =>
|
(objectMetadataItem) =>
|
||||||
objectMetadataItem.id ===
|
objectMetadataItem.id ===
|
||||||
(field.toRelationMetadata as any)?.fromObjectMetadata?.id,
|
(field.toRelationMetadata as any)?.fromObjectMetadata?.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log({ relationMetadataItem });
|
|
||||||
|
|
||||||
return `${field.name}
|
return `${field.name}
|
||||||
{
|
{
|
||||||
id
|
id
|
||||||
|
|||||||
@ -8,6 +8,10 @@ export const FIND_ONE_WORKSPACE_MEMBER_V2 = gql`
|
|||||||
id
|
id
|
||||||
firstName
|
firstName
|
||||||
lastName
|
lastName
|
||||||
|
colorScheme
|
||||||
|
avatarUrl
|
||||||
|
locale
|
||||||
|
allowImpersonation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,6 @@ export const useUpdateOneObjectRecord = ({
|
|||||||
objectNameSingular,
|
objectNameSingular,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('update one object');
|
|
||||||
|
|
||||||
// TODO: type this with a minimal type at least with Record<string, any>
|
// TODO: type this with a minimal type at least with Record<string, any>
|
||||||
const [mutate] = useMutation(updateOneMutation);
|
const [mutate] = useMutation(updateOneMutation);
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,12 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { getOperationName } from '@apollo/client/utilities';
|
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import debounce from 'lodash.debounce';
|
import debounce from 'lodash.debounce';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { currentUserState } from '@/auth/states/currentUserState';
|
import { currentUserState } from '@/auth/states/currentUserState';
|
||||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||||
|
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
|
||||||
import { TextInput } from '@/ui/input/components/TextInput';
|
import { TextInput } from '@/ui/input/components/TextInput';
|
||||||
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
|
|
||||||
import { useUpdateUserMutation } from '~/generated/graphql';
|
|
||||||
import { logError } from '~/utils/logError';
|
import { logError } from '~/utils/logError';
|
||||||
|
|
||||||
const StyledComboInputContainer = styled.div`
|
const StyledComboInputContainer = styled.div`
|
||||||
@ -31,7 +29,9 @@ export const NameFields = ({
|
|||||||
onLastNameUpdate,
|
onLastNameUpdate,
|
||||||
}: NameFieldsProps) => {
|
}: NameFieldsProps) => {
|
||||||
const currentUser = useRecoilValue(currentUserState);
|
const currentUser = useRecoilValue(currentUserState);
|
||||||
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
|
const [currentWorkspaceMember, setCurrentWorkspaceMember] = useRecoilState(
|
||||||
|
currentWorkspaceMemberState,
|
||||||
|
);
|
||||||
|
|
||||||
const [firstName, setFirstName] = useState(
|
const [firstName, setFirstName] = useState(
|
||||||
currentWorkspaceMember?.firstName ?? '',
|
currentWorkspaceMember?.firstName ?? '',
|
||||||
@ -40,7 +40,10 @@ export const NameFields = ({
|
|||||||
currentWorkspaceMember?.lastName ?? '',
|
currentWorkspaceMember?.lastName ?? '',
|
||||||
);
|
);
|
||||||
|
|
||||||
const [updateUser] = useUpdateUserMutation();
|
const { updateOneObject, objectNotFoundInMetadata } =
|
||||||
|
useUpdateOneObjectRecord({
|
||||||
|
objectNameSingular: 'workspaceMemberV2',
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: Enhance this with react-web-hook-form (https://www.react-hook-form.com)
|
// TODO: Enhance this with react-web-hook-form (https://www.react-hook-form.com)
|
||||||
const debouncedUpdate = debounce(async () => {
|
const debouncedUpdate = debounce(async () => {
|
||||||
@ -52,22 +55,20 @@ export const NameFields = ({
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (autoSave) {
|
if (autoSave) {
|
||||||
const { data, errors } = await updateUser({
|
if (!updateOneObject || objectNotFoundInMetadata) {
|
||||||
variables: {
|
return;
|
||||||
where: {
|
}
|
||||||
id: currentUser?.id,
|
await updateOneObject({
|
||||||
},
|
idToUpdate: currentWorkspaceMember?.id ?? '',
|
||||||
data: {
|
input: {
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (errors || !data?.updateUser) {
|
setCurrentWorkspaceMember(
|
||||||
throw errors;
|
(current) => ({ ...current, firstName, lastName } as any),
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError(error);
|
logError(error);
|
||||||
|
|||||||
@ -1,28 +1,31 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { getOperationName } from '@apollo/client/utilities';
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { currentUserState } from '@/auth/states/currentUserState';
|
|
||||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||||
|
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
|
||||||
import { ImageInput } from '@/ui/input/components/ImageInput';
|
import { ImageInput } from '@/ui/input/components/ImageInput';
|
||||||
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
|
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
|
||||||
import { getImageAbsoluteURIOrBase64 } from '@/users/utils/getProfilePictureAbsoluteURI';
|
import { getImageAbsoluteURIOrBase64 } from '@/users/utils/getProfilePictureAbsoluteURI';
|
||||||
import {
|
import { useUploadProfilePictureMutation } from '~/generated/graphql';
|
||||||
useRemoveProfilePictureMutation,
|
|
||||||
useUploadProfilePictureMutation,
|
|
||||||
} from '~/generated/graphql';
|
|
||||||
|
|
||||||
export const ProfilePictureUploader = () => {
|
export const ProfilePictureUploader = () => {
|
||||||
const [uploadPicture, { loading: isUploading }] =
|
const [uploadPicture, { loading: isUploading }] =
|
||||||
useUploadProfilePictureMutation();
|
useUploadProfilePictureMutation();
|
||||||
const [removePicture] = useRemoveProfilePictureMutation();
|
|
||||||
const [currentUser] = useRecoilState(currentUserState);
|
const [currentWorkspaceMember, setCurrentWorkspaceMember] = useRecoilState(
|
||||||
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
|
currentWorkspaceMemberState,
|
||||||
|
);
|
||||||
|
|
||||||
const [uploadController, setUploadController] =
|
const [uploadController, setUploadController] =
|
||||||
useState<AbortController | null>(null);
|
useState<AbortController | null>(null);
|
||||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const { updateOneObject, objectNotFoundInMetadata } =
|
||||||
|
useUpdateOneObjectRecord({
|
||||||
|
objectNameSingular: 'workspaceMemberV2',
|
||||||
|
});
|
||||||
|
|
||||||
const handleUpload = async (file: File) => {
|
const handleUpload = async (file: File) => {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return;
|
return;
|
||||||
@ -46,6 +49,26 @@ export const ProfilePictureUploader = () => {
|
|||||||
|
|
||||||
setUploadController(null);
|
setUploadController(null);
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
|
|
||||||
|
const avatarUrl = result?.data?.uploadProfilePicture;
|
||||||
|
|
||||||
|
if (!avatarUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!updateOneObject || objectNotFoundInMetadata) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await updateOneObject({
|
||||||
|
idToUpdate: currentWorkspaceMember?.id ?? '',
|
||||||
|
input: {
|
||||||
|
avatarUrl,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
setCurrentWorkspaceMember(
|
||||||
|
(current) => ({ ...current, avatarUrl } as any),
|
||||||
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setErrorMessage('An error occured while uploading the picture.');
|
setErrorMessage('An error occured while uploading the picture.');
|
||||||
@ -60,14 +83,19 @@ export const ProfilePictureUploader = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleRemove = async () => {
|
const handleRemove = async () => {
|
||||||
await removePicture({
|
if (!updateOneObject || objectNotFoundInMetadata) {
|
||||||
variables: {
|
return;
|
||||||
where: {
|
}
|
||||||
id: currentUser?.id,
|
await updateOneObject({
|
||||||
},
|
idToUpdate: currentWorkspaceMember?.id ?? '',
|
||||||
|
input: {
|
||||||
|
avatarUrl: null,
|
||||||
},
|
},
|
||||||
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setCurrentWorkspaceMember(
|
||||||
|
(current) => ({ ...current, avatarUrl: null } as any),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -1,28 +1,40 @@
|
|||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||||
|
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
|
||||||
import { useSnackBar } from '@/ui/feedback/snack-bar/hooks/useSnackBar';
|
import { useSnackBar } from '@/ui/feedback/snack-bar/hooks/useSnackBar';
|
||||||
import { Toggle } from '@/ui/input/components/Toggle';
|
import { Toggle } from '@/ui/input/components/Toggle';
|
||||||
import { useUpdateAllowImpersonationMutation } from '~/generated/graphql';
|
|
||||||
|
|
||||||
export const ToggleField = () => {
|
export const ToggleField = () => {
|
||||||
const { enqueueSnackBar } = useSnackBar();
|
const { enqueueSnackBar } = useSnackBar();
|
||||||
|
|
||||||
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
|
const [currentWorkspaceMember, setCurrentWorkspaceMember] = useRecoilState(
|
||||||
|
currentWorkspaceMemberState,
|
||||||
|
);
|
||||||
|
|
||||||
const [updateAllowImpersonation] = useUpdateAllowImpersonationMutation();
|
const { updateOneObject, objectNotFoundInMetadata } =
|
||||||
|
useUpdateOneObjectRecord({
|
||||||
|
objectNameSingular: 'workspaceMemberV2',
|
||||||
|
});
|
||||||
|
|
||||||
const handleChange = async (value: boolean) => {
|
const handleChange = async (value: boolean) => {
|
||||||
try {
|
try {
|
||||||
const { data, errors } = await updateAllowImpersonation({
|
if (!updateOneObject || objectNotFoundInMetadata) {
|
||||||
variables: {
|
return;
|
||||||
|
}
|
||||||
|
await updateOneObject({
|
||||||
|
idToUpdate: currentWorkspaceMember?.id ?? '',
|
||||||
|
input: {
|
||||||
allowImpersonation: value,
|
allowImpersonation: value,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
setCurrentWorkspaceMember(
|
||||||
if (errors || !data?.allowImpersonation) {
|
(current) =>
|
||||||
throw new Error('Error while updating user');
|
({
|
||||||
}
|
...current,
|
||||||
|
allowImpersonation: value,
|
||||||
|
} as any),
|
||||||
|
);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
enqueueSnackBar(err?.message, {
|
enqueueSnackBar(err?.message, {
|
||||||
variant: 'error',
|
variant: 'error',
|
||||||
|
|||||||
@ -6,11 +6,6 @@ import { useRelationField } from '../../hooks/useRelationField';
|
|||||||
export const RelationFieldDisplay = () => {
|
export const RelationFieldDisplay = () => {
|
||||||
const { fieldValue, fieldDefinition } = useRelationField();
|
const { fieldValue, fieldDefinition } = useRelationField();
|
||||||
|
|
||||||
console.log({
|
|
||||||
fieldDefinition,
|
|
||||||
fieldValue,
|
|
||||||
});
|
|
||||||
|
|
||||||
const entityChipProps = getEntityChipFromFieldMetadata(
|
const entityChipProps = getEntityChipFromFieldMetadata(
|
||||||
fieldDefinition,
|
fieldDefinition,
|
||||||
fieldValue,
|
fieldValue,
|
||||||
|
|||||||
@ -18,11 +18,6 @@ export const getEntityChipFromFieldMetadata = (
|
|||||||
entityId: fieldValue?.id,
|
entityId: fieldValue?.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log({
|
|
||||||
fieldName,
|
|
||||||
fieldValue,
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: use every
|
// TODO: use every
|
||||||
if (fieldName === 'accountOwner' && fieldValue) {
|
if (fieldName === 'accountOwner' && fieldValue) {
|
||||||
chipValue.name = fieldValue.firstName + ' ' + fieldValue.lastName;
|
chipValue.name = fieldValue.firstName + ' ' + fieldValue.lastName;
|
||||||
|
|||||||
@ -22,11 +22,6 @@ export const useRelationField = () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log({
|
|
||||||
fieldDefinition,
|
|
||||||
fieldValue,
|
|
||||||
});
|
|
||||||
|
|
||||||
const fieldInitialValue = useFieldInitialValue();
|
const fieldInitialValue = useFieldInitialValue();
|
||||||
|
|
||||||
const initialSearchValue = fieldInitialValue?.isEmpty
|
const initialSearchValue = fieldInitialValue?.isEmpty
|
||||||
|
|||||||
Reference in New Issue
Block a user