mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
Отрефакторил бэк, исправил ошибки (#138)
* fixed paths to match refactored backend * fixed some paths according to new backend * fixed auth urls for new endpoints * fixed urls * fixed error handling * fixes * fixed error handling on user form * fixed error handling on oauth * using fallback: true on node pages * type button for comment attach buttons * fixed return types of social delete * changed the way we upload user avatars
This commit is contained in:
parent
1745cc636d
commit
080d59858c
42 changed files with 544 additions and 420 deletions
|
@ -2,7 +2,12 @@ import { useCallback, useMemo } from 'react';
|
|||
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { apiAttachSocial, apiDropSocial, apiGetSocials, apiLoginWithSocial } from '~/api/auth';
|
||||
import {
|
||||
apiAttachSocial,
|
||||
apiDropSocial,
|
||||
apiGetSocials,
|
||||
apiLoginWithSocial,
|
||||
} from '~/api/auth';
|
||||
import { API } from '~/constants/api';
|
||||
import { Dialog } from '~/constants/modal';
|
||||
import { useAuth } from '~/hooks/auth/useAuth';
|
||||
|
@ -15,13 +20,14 @@ export const useOAuth = () => {
|
|||
const { isUser, setToken } = useAuth();
|
||||
const { showModal, hideModal } = useModal();
|
||||
|
||||
const { data, isValidating: isLoading, mutate } = useSWR(
|
||||
isUser ? API.USER.GET_SOCIALS : null,
|
||||
async () => {
|
||||
const result = await apiGetSocials();
|
||||
return result.accounts;
|
||||
}
|
||||
);
|
||||
const {
|
||||
data,
|
||||
isValidating: isLoading,
|
||||
mutate,
|
||||
} = useSWR(isUser ? API.USER.GET_SOCIALS : null, async () => {
|
||||
const result = await apiGetSocials();
|
||||
return result.accounts;
|
||||
});
|
||||
|
||||
const openOauthWindow = useCallback((provider: OAuthProvider) => {
|
||||
window.open(API.USER.OAUTH_WINDOW(provider), '', 'width=600,height=400');
|
||||
|
@ -37,10 +43,9 @@ export const useOAuth = () => {
|
|||
setToken(result.token);
|
||||
hideModal();
|
||||
} catch (error) {
|
||||
const needsRegister: string | undefined = path(
|
||||
['response', 'data', 'needs_register'],
|
||||
error
|
||||
);
|
||||
console.log(path(['response'], error));
|
||||
|
||||
const needsRegister = path(['response', 'status'], error) === 428;
|
||||
|
||||
if (needsRegister && token) {
|
||||
showModal(Dialog.LoginSocialRegister, { token });
|
||||
|
@ -50,7 +55,7 @@ export const useOAuth = () => {
|
|||
showErrorToast(error);
|
||||
}
|
||||
},
|
||||
[showModal, hideModal, setToken]
|
||||
[showModal, hideModal, setToken],
|
||||
);
|
||||
|
||||
const loginWithSocial = useCallback(
|
||||
|
@ -62,7 +67,7 @@ export const useOAuth = () => {
|
|||
setToken(token);
|
||||
hideModal();
|
||||
},
|
||||
[setToken, hideModal]
|
||||
[setToken, hideModal],
|
||||
);
|
||||
|
||||
const attachAccount = useCallback(
|
||||
|
@ -76,7 +81,7 @@ export const useOAuth = () => {
|
|||
showErrorToast(error);
|
||||
}
|
||||
},
|
||||
[mutate]
|
||||
[mutate],
|
||||
);
|
||||
|
||||
const dropAccount = useCallback(
|
||||
|
@ -88,7 +93,7 @@ export const useOAuth = () => {
|
|||
showErrorToast(error);
|
||||
}
|
||||
},
|
||||
[mutate]
|
||||
[mutate],
|
||||
);
|
||||
|
||||
const accounts = useMemo(() => data || [], [data]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue