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:
parent
e994176bff
commit
47eee7d166
10 changed files with 112 additions and 26 deletions
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue