mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
removed profile redux items
This commit is contained in:
parent
5b28313afd
commit
3c0571816c
55 changed files with 488 additions and 710 deletions
30
src/hooks/profile/usePatchProfile.ts
Normal file
30
src/hooks/profile/usePatchProfile.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { useUploader } from '~/hooks/data/useUploader';
|
||||
import { UploadSubject, UploadTarget } from '~/constants/uploads';
|
||||
import { useCallback } from 'react';
|
||||
import { showErrorToast } from '~/utils/errors/showToast';
|
||||
import { IUser } from '~/redux/auth/types';
|
||||
import { apiUpdateUser } from '~/redux/auth/api';
|
||||
|
||||
export const usePatchProfile = (updateUserData: (user: Partial<IUser>) => void) => {
|
||||
const { uploadFile } = useUploader(UploadSubject.Avatar, UploadTarget.Profiles);
|
||||
|
||||
const updateProfile = useCallback(async (user: Partial<IUser>) => {
|
||||
const result = await apiUpdateUser({ user });
|
||||
await updateUserData(result.user);
|
||||
return result.user;
|
||||
}, []);
|
||||
|
||||
const updatePhoto = useCallback(
|
||||
async (file: File) => {
|
||||
try {
|
||||
const photo = await uploadFile(file);
|
||||
await updateProfile({ photo });
|
||||
} catch (error) {
|
||||
showErrorToast(error);
|
||||
}
|
||||
},
|
||||
[updateUserData, uploadFile, updateProfile]
|
||||
);
|
||||
|
||||
return { updatePhoto, updateProfile };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue