Skip to content

Commit

Permalink
client/notifications: Fix crash when selecting profile's email
Browse files Browse the repository at this point in the history
Removed some unused imports as well
  • Loading branch information
sashko9807 committed Jan 4, 2024
1 parent ae3f223 commit b34adf1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { useState } from 'react'
import React from 'react'
import Image from 'next/image'
import { useTranslation } from 'next-i18next'
import ChevronRightIcon from '@mui/icons-material/ChevronRight'
import { Box, Grid } from '@mui/material'
import { Box } from '@mui/material'
import { routes } from 'common/routes'

import { Heading, InfoText, OutlinedButton } from '../../IndexPage.styled'
import { Root } from './TeamMembersSection.styled'
import { SectionGridWrapper } from '../PlatformStatisticsSection/PlatformStatisticsSection.styled'

export default function TeamMembersSection() {
const { t } = useTranslation('index')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const validationSchema: yup.SchemaOf<SubscribeToNotificationsInput> = yup

export default function RenderCampaignSubscribeModal({ campaign, setOpen }: ModalProps) {
const { t } = useTranslation()
const { status } = useSession()
const { status, data } = useSession()
const [loading, setLoading] = useState(false)
const [isSuccess, setIsSuccess] = useState(false)
const [isGuest, setIsGuest] = useState(false)
Expand All @@ -75,13 +75,10 @@ export default function RenderCampaignSubscribeModal({ campaign, setOpen }: Moda
>({
mutationFn: useSubscribeToCampaign(campaign.id),
onError: (error) => {
console.log(error.message)

handleError(error)
},
onSuccess: () => {
AlertStore.show(t('common:alerts.message-sent'), 'success')

setIsSuccess(true)
},
})
Expand Down Expand Up @@ -137,10 +134,11 @@ export default function RenderCampaignSubscribeModal({ campaign, setOpen }: Moda
}

const sendOnProfileEmail = (status: string) => {
const userData = data?.user
if (status !== 'authenticated') {
router.push(routes.login)
} else {
onSubmit({ email: email || '', consent: consent || true })
onSubmit({ email: userData?.email || '', consent: consent || true })
handleClose()
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/client/notifications/GeneralSubscribeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const validationSchema: yup.SchemaOf<SubscribeToNotificationsInput> = yup

export default function RenderSubscribeModal({ setOpen }: ModalProps) {
const { t } = useTranslation()
const { status } = useSession()
const { status, data } = useSession()

const [loading, setLoading] = useState(false)
const [isSuccess, setIsSuccess] = useState(false)
Expand Down Expand Up @@ -139,10 +139,11 @@ export default function RenderSubscribeModal({ setOpen }: ModalProps) {
}

const sendOnProfileEmail = (status: string) => {
const userData = data?.user
if (status !== 'authenticated') {
router.push(routes.login)
} else {
onSubmit({ email: email || '' })
onSubmit({ email: userData?.email || '' })
handleClose()
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/components/client/notifications/SubscriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,26 @@ export default function SubscriptionPage(data: Props) {
}, [])

const handleError = (e: AxiosError<ApiError>) => {
const error = e.response?.data?.message
AlertStore.show(error ? error : t('common:alerts.error'), 'error')
setLoading(false)
setIsSuccess(false)
}

const handleSuccess = () => {
AlertStore.show(t('common:alerts.message-sent'), 'success')
setIsSuccess(true)
setLoading(false)
}

const mutation = useMutation<
AxiosResponse<SubscribePublicEmailResponse>,
AxiosError<ApiError>,
SubscribePublicEmailInput
>({
mutationFn: useSubscribePublicEmail(),
onError: (error) => handleError(error),
onSuccess: () => {
AlertStore.show(t('common:alerts.message-sent'), 'success')
setIsSuccess(true)
setLoading(false)
},
onSuccess: () => handleSuccess,
})

async function callSubscribeApiRoute(values: {
Expand Down

0 comments on commit b34adf1

Please sign in to comment.