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

telegram: add button to boris

This commit is contained in:
Fedor Katurov 2023-04-08 19:31:05 +06:00
parent b0d9e8f8ba
commit 176f823315
4 changed files with 92 additions and 34 deletions

View file

@ -1,18 +1,21 @@
import { useCallback, useState } from 'react';
import { useCallback, useMemo, useState } from 'react';
import { TelegramUser } from '@v9v/ts-react-telegram-login';
import { Dialog } from '~/constants/modal';
import { showErrorToast } from '~/utils/errors/showToast';
import { useNotifications } from '~/utils/providers/NotificationProvider';
import { apiAttachTelegram } from '../../api/auth/index';
import { useModal } from '../modal/useModal';
import { useOAuth } from './useOAuth';
export const useTelegramAccount = () => {
const [loading, setLoading] = useState(false);
const { refresh } = useOAuth();
const { refresh, accounts } = useOAuth();
const { refresh: refreshNotificationSettings } = useNotifications();
const { showModal } = useModal();
const attach = useCallback(
async (data: TelegramUser, callback?: () => void) => {
@ -30,5 +33,12 @@ export const useTelegramAccount = () => {
[],
);
return { attach, loading };
const connect = useCallback(() => showModal(Dialog.TelegramAttach, {}), []);
const connected = useMemo(
() => accounts.some((it) => it.provider === 'telegram'),
[accounts],
);
return { attach, loading, connected, connect };
};