// Dependencies import { useState } 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' // Components import { BackToAccountButton, Choice, Icons, welcomeSteps } from './shared.mjs' import { ContinueButton } from 'site/components/buttons/continue-button.mjs' export const ns = ['account', 'toast'] export const NewsletterSettings = ({ app, title = false, welcome = false }) => { const { account, setAccount, token } = useAccount() const backend = useBackend(token) const toast = useToast() const { t } = useTranslation(ns) const [selection, setSelection] = useState(account?.newsletter ? 'yes' : 'no') const update = async (val) => { if (val !== selection) { app.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() app.stopLoading() } } const nextHref = welcomeSteps[account?.control].length > 2 ? '/welcome/' + welcomeSteps[account?.control][2] : '/docs/guide' return ( <> {title ?