// Dependencies import { useState, useContext, useCallback } from 'react' import { useTranslation } from 'next-i18next' import { useDropzone } from 'react-dropzone' // Context import { LoadingContext } from 'shared/context/loading-context.mjs' // 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 { Icons, welcomeSteps, BackToAccountButton } from './shared.mjs' import { ContinueButton } from 'shared/components/buttons/continue-button.mjs' import { SaveSettingsButton } from 'shared/components/buttons/save-settings-button.mjs' export const ns = ['account', 'toast'] export const ImgSettings = ({ title = false, welcome = false }) => { const { loading, startLoading, stopLoading } = useContext(LoadingContext) const { account, setAccount, token } = useAccount() const backend = useBackend(token) const toast = useToast() const { t } = useTranslation(ns) const [img, setImg] = useState(false) const onDrop = useCallback((acceptedFiles) => { const reader = new FileReader() reader.onload = () => { setImg(reader.result) } acceptedFiles.forEach((file) => reader.readAsDataURL(file)) }, []) const { getRootProps, getInputProps } = useDropzone({ onDrop }) const save = async () => { startLoading() const result = await backend.updateAccount({ img }) if (result.success) { setAccount(result.data.account) toast.for.settingsSaved() } else toast.for.backendError() stopLoading() } const nextHref = '/docs/guide' return (
{title ?

{t('imgTitle')}

: null}
{!welcome || img !== false ? ( img ) : null}

{t('imgDragAndDropImageHere')}

{t('or')}

{welcome ? ( <> {welcomeSteps[account.control].length > 0 ? ( <> 7 / {welcomeSteps[account.control].length} ) : null} ) : ( <> )}
) }