// __SDEFILE__ - This file is a dependency for the stand-alone environment // Dependencies import { useState, useContext } from 'react' import { useTranslation } from 'next-i18next' // Context import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs' // Hooks import { useAccount } from 'shared/hooks/use-account.mjs' import { useBackend } from 'shared/hooks/use-backend.mjs' // Components import { BackToAccountButton, Icons, welcomeSteps } from './shared.mjs' import { ContinueButton } from 'shared/components/buttons/continue-button.mjs' import { ListInput } from 'shared/components/inputs.mjs' import { ControlScore } from 'shared/components/control/score.mjs' import { DynamicMdx } from 'shared/components/mdx/dynamic.mjs' export const ns = ['account', 'status'] /** state handlers for any input that changes the control setting */ export const useControlState = () => { // Hooks const { account, setAccount, token } = useAccount() const backend = useBackend() const { setLoadingStatus } = useContext(LoadingStatusContext) // State const [selection, setSelection] = useState(account.control) // Method to update the control setting const update = async (control) => { if (control !== selection) { if (token) { setLoadingStatus([true, 'processingUpdate']) const result = await backend.updateAccount({ control }) if (result.success) { setSelection(control) setAccount(result.data.account) setLoadingStatus([true, 'settingsSaved', true, true]) } else setLoadingStatus([true, 'backendError', true, true]) } //fallback for guest users else { setAccount({ ...account, control }) setSelection(control) } } } return { selection, update } } export const ControlSettings = ({ welcome = false, noBack = false }) => { const { t, i18n } = useTranslation(ns) const { selection, update } = useControlState() // Helper to get the link to the next onboarding step const nextHref = welcome ? welcomeSteps[selection].length > 1 ? '/welcome/' + welcomeSteps[selection][1] : '/docs/about/guide' : false return (