diff --git a/src/features/App/AuthenticatedApp.tsx b/src/features/App/AuthenticatedApp.tsx index 338a1a86..d8dc320f 100644 --- a/src/features/App/AuthenticatedApp.tsx +++ b/src/features/App/AuthenticatedApp.tsx @@ -63,7 +63,7 @@ export const AuthenticatedApp = () => { {/* в Switch как прямой children можно рендерить только Route или Redirect */} - + diff --git a/src/features/AuthStore/hooks/useAuth.tsx b/src/features/AuthStore/hooks/useAuth.tsx index cf3d1dea..fa414650 100644 --- a/src/features/AuthStore/hooks/useAuth.tsx +++ b/src/features/AuthStore/hooks/useAuth.tsx @@ -205,11 +205,15 @@ export const useAuth = () => { }, [userManager, storeUser]) const fetchUserInfo = useCallback(async () => { - const userInfoFetched = await getUserInfo() + try { + const userInfoFetched = await getUserInfo() - setUserInfo(userInfoFetched) + setUserInfo(userInfoFetched) - userInfoFetched.language.iso && changeLang(userInfoFetched.language.iso) + userInfoFetched.language.iso && changeLang(userInfoFetched.language.iso) + + // eslint-disable-next-line no-empty + } catch (error) {} }, [changeLang]) useEffect(() => { diff --git a/src/pages/Mailings/index.tsx b/src/pages/Mailings/index.tsx index 16742d39..a84b649d 100644 --- a/src/pages/Mailings/index.tsx +++ b/src/pages/Mailings/index.tsx @@ -35,21 +35,6 @@ const Mailings = () => { if (!userInfo) return null - const { - address_line1, - address_line2, - city, - cityId, - country, - firstname, - is_unsubscribed, - language, - lastname, - phone, - postal_code, - region, - } = { ...userInfo } - const currentYear = format(new Date(), 'Y') const onUnsubscribe = async (isUnsubscribed: boolean) => { @@ -57,86 +42,83 @@ const Mailings = () => { setIsReSubscribed(true) } - await saveUserInfo({ - address_line1, - address_line2, - city, - cityId, - countryId: country?.id!, - firstname, - isUnsubscribed, - language_id: language?.id, - lastname, - phone, - postalCode: postal_code, - region, - }) - await fetchUserInfo() - } - - let content - if (is_unsubscribed) { - content = ( - - - <T9n t='you_are_now_unsubscribed' /> - -
- - - - - onUnsubscribe(false)}> - - - - - - - - -
- ) - } else { - content = ( - - <T9n t='unsubscribe' /> -
- - - {' '}{userInfo?.email} - - - - - - - - onUnsubscribe(true)}> - - - -
- ) + try { + await saveUserInfo({ + ...userInfo, + countryId: userInfo.country?.id!, + isUnsubscribed, + language_id: userInfo.language?.id, + postalCode: userInfo.postal_code, + }) + await fetchUserInfo() + + // eslint-disable-next-line no-empty + } catch (error) {} } - if (isReSubscribed) { - content = ( - - <T9n t='resubscription_successful' /> -
- - - - - - - - - - -
- ) + const getContent = () => { + switch (true) { + case userInfo.is_unsubscribed: + return ( + + + <T9n t='you_are_now_unsubscribed' /> + +
+ + + + + onUnsubscribe(false)}> + + + + + + + + +
+ ) + case isReSubscribed: + return ( + + <T9n t='resubscription_successful' /> +
+ + + + + + + + + + +
+ ) + default: + return ( + + <T9n t='unsubscribe' /> +
+ + + {' '}{userInfo?.email} + + + + + + + + onUnsubscribe(true)}> + + + +
+ ) + } } return ( @@ -147,7 +129,7 @@ const Mailings = () => { - {content} + {getContent()}