mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36: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>
|
</div>
|
||||||
|
|
||||||
<div className={styles.account__name}>
|
<div className={styles.account__name}>{it.name || it.id}</div>
|
||||||
{it.name || it.id} - {it.id} - {it.provider}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={styles.account__drop}>
|
<div className={styles.account__drop}>
|
||||||
<Icon
|
<Icon
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { useCallback, useState } from 'react';
|
||||||
import { TelegramUser } from '@v9v/ts-react-telegram-login';
|
import { TelegramUser } from '@v9v/ts-react-telegram-login';
|
||||||
|
|
||||||
import { showErrorToast } from '~/utils/errors/showToast';
|
import { showErrorToast } from '~/utils/errors/showToast';
|
||||||
|
import { useNotifications } from '~/utils/providers/NotificationProvider';
|
||||||
|
|
||||||
import { apiAttachTelegram } from '../../api/auth/index';
|
import { apiAttachTelegram } from '../../api/auth/index';
|
||||||
|
|
||||||
|
@ -11,13 +12,14 @@ import { useOAuth } from './useOAuth';
|
||||||
export const useTelegramAccount = () => {
|
export const useTelegramAccount = () => {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const { refresh } = useOAuth();
|
const { refresh } = useOAuth();
|
||||||
|
const { refresh: refreshNotificationSettings } = useNotifications();
|
||||||
|
|
||||||
const attach = useCallback(
|
const attach = useCallback(
|
||||||
async (data: TelegramUser, callback?: () => void) => {
|
async (data: TelegramUser, callback?: () => void) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
await apiAttachTelegram(data);
|
await apiAttachTelegram(data);
|
||||||
await refresh();
|
await Promise.all([refresh(), refreshNotificationSettings()]);
|
||||||
callback?.();
|
callback?.();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showErrorToast(error);
|
showErrorToast(error);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useCallback } from 'react';
|
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';
|
import { useAuth } from '../auth/useAuth';
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ export const useNotificationSettings = () => {
|
||||||
lastDate,
|
lastDate,
|
||||||
isLoading: isLoadingSettings,
|
isLoading: isLoadingSettings,
|
||||||
update,
|
update,
|
||||||
|
refresh,
|
||||||
} = useNotificationSettingsRequest();
|
} = useNotificationSettingsRequest();
|
||||||
|
|
||||||
const enabled =
|
const enabled =
|
||||||
|
@ -45,5 +46,6 @@ export const useNotificationSettings = () => {
|
||||||
indicatorEnabled,
|
indicatorEnabled,
|
||||||
available: isUser,
|
available: isUser,
|
||||||
markAsRead,
|
markAsRead,
|
||||||
|
refresh,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,6 +63,8 @@ export const useNotificationSettingsRequest = () => {
|
||||||
[data, mutate],
|
[data, mutate],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const refresh = useCallback(() => mutate(), [mutate]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
|
@ -75,6 +77,7 @@ export const useNotificationSettingsRequest = () => {
|
||||||
? parseISO(data?.last_date)
|
? parseISO(data?.last_date)
|
||||||
: undefined,
|
: undefined,
|
||||||
enabled: !!data?.enabled && (data.flow || data.comments),
|
enabled: !!data?.enabled && (data.flow || data.comments),
|
||||||
|
refresh,
|
||||||
update,
|
update,
|
||||||
updateError,
|
updateError,
|
||||||
isUpdating,
|
isUpdating,
|
||||||
|
|
|
@ -12,6 +12,7 @@ const defaultValue = {
|
||||||
hasNew: false,
|
hasNew: false,
|
||||||
indicatorEnabled: false,
|
indicatorEnabled: false,
|
||||||
markAsRead: () => {},
|
markAsRead: () => {},
|
||||||
|
refresh: () => Promise.resolve() as Promise<unknown>,
|
||||||
};
|
};
|
||||||
|
|
||||||
const NotificationContext = createContext(defaultValue);
|
const NotificationContext = createContext(defaultValue);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue