// Dependencies import { welcomeSteps } from './shared.mjs' import { validateEmail, validateTld, getSearchParam } from '@freesewing/utils' // Context import { LoadingStatusContext } from '@freesewing/react/context/LoadingStatus' // Hooks import React, { useState, useContext, useEffect } from 'react' import { useAccount } from '@freesewing/react/hooks/useAccount' import { useBackend } from '@freesewing/react/hooks/useBackend' // Components import { Link as WebLink } from '@freesewing/react/components/Link' import { SaveIcon } from '@freesewing/react/components/Icon' import { EmailInput } from '@freesewing/react/components/Input' import { Popout } from '@freesewing/react/components/Popout' import { Spinner } from '@freesewing/react/components/Spinner' /* * Component for the account/bio page * * @params {object} props - All React props * @params {bool} props.welcome - Set to true to use this component on the welcome page * @params {function} props.Link - A framework specific Link component for client-side routing */ export const Email = ({ welcome = false, Link = false }) => { if (!Link) Link = WebLink // Hooks const { account, setAccount } = useAccount() const backend = useBackend() const { setLoadingStatus } = useContext(LoadingStatusContext) // State const [email, setEmail] = useState(account.email) const [changed, setChanged] = useState(false) // Helper method to update account const save = async () => { setLoadingStatus([true, 'Updating email address']) const [status, body] = await backend.updateAccount({ email }) if (status === 200 && body.result === 'success') { setAccount(body.account) setChanged(true) setLoadingStatus([true, 'Email change initiated', true, true]) } else setLoadingStatus([true, 'Something went wrong. Please report this', true, true]) } // Is email valid? const valid = (validateEmail(email) && validateTld(email)) || false return (
We have sent an E-mail to your new address to confirm this change. Please click the link in that message to finalize this change.
> )}
This error is unexpected. Please report this.
// If we do not (yet) have the data, show a loader if (!id || !check) return ( <>One moment please
}