// Dependencies import { useState, useContext } from 'react' import { useTranslation } from 'next-i18next' // Hooks import { useAccount } from 'shared/hooks/use-account.mjs' import { useBackend } from 'shared/hooks/use-backend.mjs' import { useToast } from 'shared/hooks/use-toast.mjs' // Context import { LoadingContext } from 'shared/context/loading-context.mjs' // Components import { BackToAccountButton, Choice, Icons, welcomeSteps } from './shared.mjs' import { ContinueButton } from 'shared/components/buttons/continue-button.mjs' export const ns = ['account', 'toast'] export const NewsletterSettings = ({ title = false, welcome = false }) => { // Context const { loading, startLoading, stopLoading } = useContext(LoadingContext) // Hooks const { account, setAccount, token } = useAccount() const backend = useBackend(token) const toast = useToast() const { t } = useTranslation(ns) // State const [selection, setSelection] = useState(account?.newsletter ? 'yes' : 'no') // Helper method to update account const update = async (val) => { if (val !== selection) { startLoading() const result = await backend.updateAccount({ newsletter: val === 'yes' ? true : false }) if (result.success) { setAccount(result.data.account) setSelection(val) toast.for.settingsSaved() } else toast.for.backendError() stopLoading() } } // Next step for onboarding const nextHref = welcomeSteps[account?.control].length > 2 ? '/welcome/' + welcomeSteps[account?.control][2] : '/docs/guide' return (