// Hooks import { useState } from 'react' import { useTranslation } from 'next-i18next' import { useBackend } from 'site/hooks/useBackend.mjs' import { useToast } from 'site/hooks/useToast.mjs' // Components import Link from 'next/link' import { Popout } from 'shared/components/popout.mjs' import { BackToAccountButton } from './shared.mjs' import { SaveSettingsButton } from 'site/components/buttons/save-settings-button.mjs' import { GdprProfileDetails, GdprMeasurementsDetails, ns as gdprNs, } from 'site/components/gdpr/details.mjs' export const ns = [...gdprNs, 'account', 'toast'] const Checkbox = ({ value, setter, label, children = null }) => (
setter(value ? false : true)} >
setter(value ? false : true)} /> {label}
{children}
) export const ConsentSettings = ({ app, title = false }) => { const backend = useBackend(app) const toast = useToast() const { t } = useTranslation(ns) const [profile, setProfile] = useState(app.account?.consent > 0) const [measurements, setMeasurements] = useState(app.account?.consent > 1) const [openData, setOpenData] = useState(app.account?.consent > 2) const update = async () => { let newConsent = 0 if (profile) newConsent = 1 if (profile && measurements) newConsent = 2 if (profile && measurements && openData) newConsent = 3 if (newConsent !== app.account.consent) { app.startLoading() const result = await backend.updateAccount({ consent: newConsent }) if (result === true) toast.for.settingsSaved() else toast.for.backendError() app.stopLoading() } } const removeAccount = async () => { app.startLoading() const result = await backend.removeAccount() if (result === true) toast.for.settingsSaved() else toast.for.backendError() app.setToken(null) app.setAccount({ username: false }) app.stopLoading() } const partA = ( <>
{t('profileQuestion')}
{profile ? ( ) : ( <> {t('profileWarning')} )} ) const partB = ( <>
{t('setQuestion')}
{measurements ? ( ) : ( )} {measurements ? ( ) : null} {measurements && !openData ? {t('openDataInfo')} : null} {!measurements && {t('noConsentNoPatterns')}} ) return ( <> {title ?

{t('privacyMatters')}

: null}

{t('compliant')}

{t('consentWhyAnswer')}

{partA} {profile && partB} {profile && measurements ? ( ) : null} {profile && !measurements ? ( ) : null} {!profile ? ( ) : null}

FreeSewing Privacy Notice

) }