1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 05:16: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

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