// Context import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs' // Hooks import { useState, useContext } from 'react' import { useBackend } from 'shared/hooks/use-backend.mjs' import { useTranslation } from 'next-i18next' import { useAccount } from 'shared/hooks/use-account.mjs' import { useRouter } from 'next/router' // Components import Link from 'next/link' import { Robot } from 'shared/components/robot/index.mjs' import { StringInput, PasswordInput } from 'shared/components/inputs.mjs' import { FreeSewingAnimation } from 'shared/components/animations/freesewing.mjs' import { DynamicMdx } from 'shared/components/mdx/dynamic.mjs' // Translation namespaces used on this page export const ns = ['signup', 'errros', 'account'] const DarkLink = ({ href, txt }) => ( {txt} ) export const Migrate = () => { const backend = useBackend() const { t, i18n } = useTranslation(ns) const { loading, setLoadingStatus } = useContext(LoadingStatusContext) const { setAccount, setSeenUser, setToken } = useAccount() const router = useRouter() const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [result, setResult] = useState(false) const migrate = async () => { setLoadingStatus([true, 'migrateV2Account']) const result = await backend.migrate({ username, password }) if (result.success) { setLoadingStatus([true, 'nailedIt', true, true]) setAccount(result.data.account) setToken(result.data.token) setSeenUser(result.data.account.username) setLoadingStatus([ true, t('signup:welcomeMigrateName', { name: result.data.account.username }), true, true, ]) setResult('success') router.push('/account') } else { let msg = t('signup:authenticationFailed') if (result.response?.response?.data?.error === 'userExists') { setResult('exists') msg = t('signup:v3UserAlreadyExists') } else setResult('failed') setLoadingStatus([true, msg, true, false]) } } if (result === 'success') return ( <> ) if (result === 'exists') return ( <>

{t('signup:v3UserAlreadyExists')}

{t('signIn')}
{t('contact')}
) if (result === 'failed') return ( <>

{t('signup:noWorkie')}

{t('signUpHere')}
{t('contact')}
) return ( <>

{t('signup:migrateV2')}

{t('migrateV2Desc')}

val.length > 1} docs={} /> val.length > 1} docs={} />

{t('dontHaveAV2Account')}

) }