V2 onboarding (#2543)
* fix cannot query avatarUrl * create workspace working * fix bugs related to refetch queries * onboarding working * updated dependency array * improve error handling * update types, remove as any, remove console logs * small fix
This commit is contained in:
@ -1,9 +1,7 @@
|
||||
import { getOperationName } from '@apollo/client/utilities';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
||||
import { ImageInput } from '@/ui/input/components/ImageInput';
|
||||
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
|
||||
import { getImageAbsoluteURIOrBase64 } from '@/users/utils/getProfilePictureAbsoluteURI';
|
||||
import {
|
||||
useRemoveWorkspaceLogoMutation,
|
||||
@ -13,23 +11,41 @@ import {
|
||||
export const WorkspaceLogoUploader = () => {
|
||||
const [uploadLogo] = useUploadWorkspaceLogoMutation();
|
||||
const [removeLogo] = useRemoveWorkspaceLogoMutation();
|
||||
const currentWorkspace = useRecoilValue(currentWorkspaceState);
|
||||
const [currentWorkspace, setCurrentWorkspace] = useRecoilState(
|
||||
currentWorkspaceState,
|
||||
);
|
||||
|
||||
const onUpload = async (file: File) => {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
if (!currentWorkspace?.id) {
|
||||
throw new Error('Workspace id not found');
|
||||
}
|
||||
await uploadLogo({
|
||||
variables: {
|
||||
file,
|
||||
},
|
||||
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],
|
||||
onCompleted: (data) => {
|
||||
setCurrentWorkspace({
|
||||
...currentWorkspace,
|
||||
logo: data.uploadWorkspaceLogo,
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const onRemove = async () => {
|
||||
if (!currentWorkspace?.id) {
|
||||
throw new Error('Workspace id not found');
|
||||
}
|
||||
await removeLogo({
|
||||
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],
|
||||
onCompleted: () => {
|
||||
setCurrentWorkspace({
|
||||
...currentWorkspace,
|
||||
logo: null,
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user