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

telegram: now able to delete it

This commit is contained in:
Fedor Katurov 2023-03-13 18:26:16 +06:00
parent e994176bff
commit 47eee7d166
10 changed files with 112 additions and 26 deletions

View file

@ -43,8 +43,6 @@ export const useOAuth = () => {
setToken(result.token);
hideModal();
} catch (error) {
console.log(path(['response'], error));
const needsRegister = path(['response', 'status'], error) === 428;
if (needsRegister && token) {
@ -97,6 +95,7 @@ export const useOAuth = () => {
);
const accounts = useMemo(() => data || [], [data]);
const refresh = useCallback(() => mutate(), []);
return {
openOauthWindow,
@ -106,5 +105,6 @@ export const useOAuth = () => {
dropAccount,
accounts,
isLoading: !data && isLoading,
refresh,
};
};

View file

@ -21,8 +21,6 @@ export const useOauthEventListeners = () => {
return;
}
console.log('caught event:', type, event.data);
switch (type) {
case EventMessageType.OAuthLogin:
loginWithSocial(path(['data', 'payload', 'token'], event));

View file

@ -1,13 +1,32 @@
import { useCallback } from 'react';
import { useCallback, useState } from 'react';
import { TelegramUser } from '@v9v/ts-react-telegram-login';
import { showErrorToast } from '~/utils/errors/showToast';
import { apiAttachTelegram } from '../../api/auth/index';
export const useTelegramAccount = () => {
const attach = useCallback((data: TelegramUser) => {
apiAttachTelegram(data);
}, []);
import { useOAuth } from './useOAuth';
return { attach };
export const useTelegramAccount = () => {
const [loading, setLoading] = useState(false);
const { refresh } = useOAuth();
const attach = useCallback(
async (data: TelegramUser, callback?: () => void) => {
setLoading(true);
try {
await apiAttachTelegram(data);
await refresh();
callback?.();
} catch (error) {
showErrorToast(error);
} finally {
setLoading(false);
}
},
[],
);
return { attach, loading };
};