// Dependencies import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { nsMerge, getSearchParam } from 'shared/utils.mjs' // Hooks import { useEffect, useState, useContext } from 'react' import { useTranslation } from 'next-i18next' import { useBackend } from 'shared/hooks/use-backend.mjs' // Context import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs' // Components import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs' import { Popout } from 'shared/components/popout/index.mjs' import { PageLink } from 'shared/components/link.mjs' import { Hodl } from 'shared/components/hodl/index.mjs' // Translation namespaces used on this page const namespaces = nsMerge(pageNs, 'newsletter') /* * Each page MUST be wrapped in the PageWrapper component. * You also MUST spread props.page into this wrapper component * when path and locale come from static props (as here) * or set them manually. */ const NewsletterPage = ({ page }) => { const { t } = useTranslation(namespaces) const { setLoadingStatus } = useContext(LoadingStatusContext) const backend = useBackend() const [confirmed, setConfirmed] = useState(false) const [id, setId] = useState() const [ehash, setEhash] = useState() useEffect(() => { const newId = getSearchParam('id') const newEhash = getSearchParam('check') if (newId !== id) setId(newId) if (newEhash !== ehash) setEhash(newEhash) }, [id, ehash]) const handler = async () => { setLoadingStatus([true, 'status:contactingBackend']) await backend.confirmNewsletterSubscribe({ id, ehash }) setLoadingStatus([true, 'status:settingsSaved', true, true]) setConfirmed(true) } if (!id || !ehash) return ( {JSON.stringify({ id, ehash })} ) return ( {confirmed ? ( <> {t('newsletter:newsletter')} {t('newsletter:thanksDone')} {t('newsletter:subscribePs')} > ) : ( <> {t('newsletter:newsletter')}: {t('newsletter:subscribe')} {t('newsletter:subscribeConfirm')} {t('newsletter:subscribeLead')} {t('newsletter:confirm')} {t('newsletter:whatsWithTheClicks')} {t('newsletter:whyLead')} {t('newsletter:faqLead')}:{' '} > )} ) } export default NewsletterPage export async function getStaticProps({ locale }) { return { props: { ...(await serverSideTranslations(locale, namespaces)), page: { locale, path: ['newsletter', 'subscribe'], }, }, } }
{JSON.stringify({ id, ehash })}
{t('newsletter:thanksDone')}
{t('newsletter:subscribePs')}
{t('newsletter:subscribeLead')}
{t('newsletter:whyLead')}
{t('newsletter:faqLead')}:{' '}