mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 12:26:40 +07:00
telegram: refreshing notification settings on account attachment
This commit is contained in:
parent
47eee7d166
commit
e49f69a4e6
5 changed files with 11 additions and 5 deletions
|
@ -69,9 +69,7 @@ const ProfileAccounts: FC<ProfileAccountsProps> = () => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.account__name}>
|
||||
{it.name || it.id} - {it.id} - {it.provider}
|
||||
</div>
|
||||
<div className={styles.account__name}>{it.name || it.id}</div>
|
||||
|
||||
<div className={styles.account__drop}>
|
||||
<Icon
|
||||
|
|
|
@ -3,6 +3,7 @@ import { useCallback, useState } from 'react';
|
|||
import { TelegramUser } from '@v9v/ts-react-telegram-login';
|
||||
|
||||
import { showErrorToast } from '~/utils/errors/showToast';
|
||||
import { useNotifications } from '~/utils/providers/NotificationProvider';
|
||||
|
||||
import { apiAttachTelegram } from '../../api/auth/index';
|
||||
|
||||
|
@ -11,13 +12,14 @@ import { useOAuth } from './useOAuth';
|
|||
export const useTelegramAccount = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { refresh } = useOAuth();
|
||||
const { refresh: refreshNotificationSettings } = useNotifications();
|
||||
|
||||
const attach = useCallback(
|
||||
async (data: TelegramUser, callback?: () => void) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await apiAttachTelegram(data);
|
||||
await refresh();
|
||||
await Promise.all([refresh(), refreshNotificationSettings()]);
|
||||
callback?.();
|
||||
} catch (error) {
|
||||
showErrorToast(error);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { useCallback } from 'react';
|
||||
|
||||
import { isAfter, isBefore, isEqual, isValid, parse, parseISO } from 'date-fns';
|
||||
import { isAfter, isEqual } from 'date-fns';
|
||||
|
||||
import { useAuth } from '../auth/useAuth';
|
||||
|
||||
|
@ -17,6 +17,7 @@ export const useNotificationSettings = () => {
|
|||
lastDate,
|
||||
isLoading: isLoadingSettings,
|
||||
update,
|
||||
refresh,
|
||||
} = useNotificationSettingsRequest();
|
||||
|
||||
const enabled =
|
||||
|
@ -45,5 +46,6 @@ export const useNotificationSettings = () => {
|
|||
indicatorEnabled,
|
||||
available: isUser,
|
||||
markAsRead,
|
||||
refresh,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -63,6 +63,8 @@ export const useNotificationSettingsRequest = () => {
|
|||
[data, mutate],
|
||||
);
|
||||
|
||||
const refresh = useCallback(() => mutate(), [mutate]);
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
error,
|
||||
|
@ -75,6 +77,7 @@ export const useNotificationSettingsRequest = () => {
|
|||
? parseISO(data?.last_date)
|
||||
: undefined,
|
||||
enabled: !!data?.enabled && (data.flow || data.comments),
|
||||
refresh,
|
||||
update,
|
||||
updateError,
|
||||
isUpdating,
|
||||
|
|
|
@ -12,6 +12,7 @@ const defaultValue = {
|
|||
hasNew: false,
|
||||
indicatorEnabled: false,
|
||||
markAsRead: () => {},
|
||||
refresh: () => Promise.resolve() as Promise<unknown>,
|
||||
};
|
||||
|
||||
const NotificationContext = createContext(defaultValue);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue