1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

removed profile redux items

This commit is contained in:
Fedor Katurov 2022-01-08 18:01:38 +07:00
parent 5b28313afd
commit 3c0571816c
55 changed files with 488 additions and 710 deletions

View file

@ -1,11 +1,11 @@
import { useModalStore } from '~/store/modal/useModalStore';
import { useCallback } from 'react';
import { Dialog, DIALOG_CONTENT } from '~/constants/modal';
import { IDialogProps } from '~/types/modal';
import { DialogComponentProps } from '~/types/modal';
export type DialogContentProps = {
[K in keyof typeof DIALOG_CONTENT]: typeof DIALOG_CONTENT[K] extends (props: infer U) => any
? U extends IDialogProps
? U extends DialogComponentProps
? keyof Omit<U, 'onRequestClose' | 'children'> extends never
? {}
: Omit<U, 'onRequestClose' | 'children'>

View file

@ -0,0 +1,34 @@
import useSWR from 'swr';
import { API } from '~/constants/api';
import { apiAuthGetUserProfile } from '~/redux/auth/api';
import { EMPTY_USER } from '~/redux/auth/constants';
import { useCallback } from 'react';
import { IUser } from '~/redux/auth/types';
const getKey = (username?: string): string | null => {
return username ? `${API.USER.PROFILE}/${username}` : null;
};
export const useGetProfile = (username?: string) => {
const { data, isValidating, mutate } = useSWR(
getKey(username),
async () => {
const result = await apiAuthGetUserProfile({ username: username || '' });
return result.user;
},
{
refreshInterval: 60000,
}
);
const profile = data || EMPTY_USER;
const update = useCallback(
async (user: Partial<IUser>) => {
await mutate({ ...profile, ...user });
},
[mutate, profile]
);
return { profile, isLoading: !data && isValidating, update };
};

View 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 };
};