import { ChallengePrompt, ChallengeValidation, ProtectionSessionDurations, } from '@standardnotes/snjs' import { FunctionComponent } from 'preact' import { useEffect, useRef } from 'preact/hooks' import { DecoratedInput } from '@/Components/Input/DecoratedInput' import { DecoratedPasswordInput } from '@/Components/Input/DecoratedPasswordInput' import { ChallengeModalValues } from './ChallengeModal' type Props = { prompt: ChallengePrompt values: ChallengeModalValues index: number onValueChange: (value: string | number, prompt: ChallengePrompt) => void isInvalid: boolean } export const ChallengeModalPrompt: FunctionComponent = ({ prompt, values, index, onValueChange, isInvalid, }) => { const inputRef = useRef(null) useEffect(() => { if (index === 0) { inputRef.current?.focus() } }, [index]) useEffect(() => { if (isInvalid) { inputRef.current?.focus() } }, [isInvalid]) return ( <> {prompt.validation === ChallengeValidation.ProtectionSessionDuration ? (
Allow protected access for
{ProtectionSessionDurations.map((option) => { const selected = option.valueInSeconds === values[prompt.id].value return ( ) })}
) : prompt.secureTextEntry ? ( onValueChange(value, prompt)} /> ) : ( onValueChange(value, prompt)} /> )} {isInvalid && (
Invalid authentication, please try again.
)} ) }