fix(#3100): user mailings page pr fixes

keep-around/9d11a525a1ee745f785976389c40d7a0601133e1
Rakov Roman 3 years ago
parent 77784a4a5a
commit 3fafdca9a8
  1. 2
      src/features/App/AuthenticatedApp.tsx
  2. 10
      src/features/AuthStore/hooks/useAuth.tsx
  3. 170
      src/pages/Mailings/index.tsx

@ -63,7 +63,7 @@ export const AuthenticatedApp = () => {
{/* в Switch как прямой children
можно рендерить только Route или Redirect */}
<Switch>
<Route path={`${PAGES.mailings}`}>
<Route path={PAGES.mailings}>
<Mailings />
</Route>
<Route path={PAGES.useraccount}>

@ -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(() => {

@ -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 = (
<ContentWrapper>
<Title>
<T9n t='you_are_now_unsubscribed' />
</Title>
<br />
<Text>
<T9n t='you_have_been_removed_from_the_inSports_newsletter' />
</Text>
<ButtonsBlock>
<SolidButton onClick={() => onUnsubscribe(false)}>
<T9n t='resubscribe' />
</SolidButton>
<ScLink to={PAGES.home}>
<OutlineButton>
<T9n t='go_to_the_main_page' />
</OutlineButton>
</ScLink>
</ButtonsBlock>
</ContentWrapper>
)
} else {
content = (
<ContentWrapper>
<Title><T9n t='unsubscribe' /></Title>
<br />
<Text>
<T9n t='click_unsubscribe_to_stop_receiving_inSports_emails_to' />
<Email>{' '}{userInfo?.email}</Email>
</Text>
<ButtonsBlock>
<ScLink to={PAGES.home}>
<SolidButton>
<T9n t='cancel' />
</SolidButton>
</ScLink>
<OutlineButton onClick={() => onUnsubscribe(true)}>
<T9n t='unsubscribe' />
</OutlineButton>
</ButtonsBlock>
</ContentWrapper>
)
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 = (
<ContentWrapper>
<Title><T9n t='resubscription_successful' /></Title>
<br />
<Text>
<T9n t='you_have_been_resubscribed_to_inSports_newsletter' />
</Text>
<ButtonsBlock>
<ScLink to={PAGES.home}>
<SolidButton>
<T9n t='go_to_the_main_page' />
</SolidButton>
</ScLink>
</ButtonsBlock>
</ContentWrapper>
)
const getContent = () => {
switch (true) {
case userInfo.is_unsubscribed:
return (
<ContentWrapper>
<Title>
<T9n t='you_are_now_unsubscribed' />
</Title>
<br />
<Text>
<T9n t='you_have_been_removed_from_the_inSports_newsletter' />
</Text>
<ButtonsBlock>
<SolidButton onClick={() => onUnsubscribe(false)}>
<T9n t='resubscribe' />
</SolidButton>
<ScLink to={PAGES.home}>
<OutlineButton>
<T9n t='go_to_the_main_page' />
</OutlineButton>
</ScLink>
</ButtonsBlock>
</ContentWrapper>
)
case isReSubscribed:
return (
<ContentWrapper>
<Title><T9n t='resubscription_successful' /></Title>
<br />
<Text>
<T9n t='you_have_been_resubscribed_to_inSports_newsletter' />
</Text>
<ButtonsBlock>
<ScLink to={PAGES.home}>
<SolidButton>
<T9n t='go_to_the_main_page' />
</SolidButton>
</ScLink>
</ButtonsBlock>
</ContentWrapper>
)
default:
return (
<ContentWrapper>
<Title><T9n t='unsubscribe' /></Title>
<br />
<Text>
<T9n t='click_unsubscribe_to_stop_receiving_inSports_emails_to' />
<Email>{' '}{userInfo?.email}</Email>
</Text>
<ButtonsBlock>
<ScLink to={PAGES.home}>
<SolidButton>
<T9n t='cancel' />
</SolidButton>
</ScLink>
<OutlineButton onClick={() => onUnsubscribe(true)}>
<T9n t='unsubscribe' />
</OutlineButton>
</ButtonsBlock>
</ContentWrapper>
)
}
}
return (
@ -147,7 +129,7 @@ const Mailings = () => {
</Link>
</HeaderWrapper>
<Body>
{content}
{getContent()}
</Body>
<Footer>
<FooterLogo />

Loading…
Cancel
Save