mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
using formik on profile settings
This commit is contained in:
parent
3c0571816c
commit
e8f0ec1f36
5 changed files with 106 additions and 75 deletions
|
@ -2,17 +2,20 @@ 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 { ApiUpdateUserRequest, 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 updateProfile = useCallback(
|
||||
async (user: Partial<ApiUpdateUserRequest['user']>) => {
|
||||
const result = await apiUpdateUser({ user });
|
||||
await updateUserData(result.user);
|
||||
return result.user;
|
||||
},
|
||||
[updateUserData]
|
||||
);
|
||||
|
||||
const updatePhoto = useCallback(
|
||||
async (file: File) => {
|
||||
|
@ -23,7 +26,7 @@ export const usePatchProfile = (updateUserData: (user: Partial<IUser>) => void)
|
|||
showErrorToast(error);
|
||||
}
|
||||
},
|
||||
[updateUserData, uploadFile, updateProfile]
|
||||
[uploadFile, updateProfile]
|
||||
);
|
||||
|
||||
return { updatePhoto, updateProfile };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue