From e49f69a4e6ca956625eb5847524ecce0bd9ae887 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Mon, 13 Mar 2023 18:48:38 +0600 Subject: [PATCH] telegram: refreshing notification settings on account attachment --- src/containers/profile/ProfileAccounts/index.tsx | 4 +--- src/hooks/auth/useTelegramAccount.ts | 4 +++- src/hooks/notifications/useNotificationSettings.ts | 4 +++- src/hooks/notifications/useNotificationSettingsRequest.ts | 3 +++ src/utils/providers/NotificationProvider.tsx | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/containers/profile/ProfileAccounts/index.tsx b/src/containers/profile/ProfileAccounts/index.tsx index 0c563950..6b953aa8 100644 --- a/src/containers/profile/ProfileAccounts/index.tsx +++ b/src/containers/profile/ProfileAccounts/index.tsx @@ -69,9 +69,7 @@ const ProfileAccounts: FC = () => { -
- {it.name || it.id} - {it.id} - {it.provider} -
+
{it.name || it.id}
{ 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); diff --git a/src/hooks/notifications/useNotificationSettings.ts b/src/hooks/notifications/useNotificationSettings.ts index 4b0c0ac2..f49e1e38 100644 --- a/src/hooks/notifications/useNotificationSettings.ts +++ b/src/hooks/notifications/useNotificationSettings.ts @@ -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, }; }; diff --git a/src/hooks/notifications/useNotificationSettingsRequest.ts b/src/hooks/notifications/useNotificationSettingsRequest.ts index 6e54c08d..6cc5c2a9 100644 --- a/src/hooks/notifications/useNotificationSettingsRequest.ts +++ b/src/hooks/notifications/useNotificationSettingsRequest.ts @@ -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, diff --git a/src/utils/providers/NotificationProvider.tsx b/src/utils/providers/NotificationProvider.tsx index b6d698ec..db4fe8ad 100644 --- a/src/utils/providers/NotificationProvider.tsx +++ b/src/utils/providers/NotificationProvider.tsx @@ -12,6 +12,7 @@ const defaultValue = { hasNew: false, indicatorEnabled: false, markAsRead: () => {}, + refresh: () => Promise.resolve() as Promise, }; const NotificationContext = createContext(defaultValue);