import { ChallengePrompt, ChallengeValidation, ProtectionSessionDurations } from '@standardnotes/snjs' import { FunctionComponent, useEffect, useRef } from 'react' import DecoratedInput from '@/Components/Input/DecoratedInput' import DecoratedPasswordInput from '@/Components/Input/DecoratedPasswordInput' import { ChallengeModalValues } from './ChallengeModalValues' type Props = { prompt: ChallengePrompt values: ChallengeModalValues index: number onValueChange: (value: string | number, prompt: ChallengePrompt) => void isInvalid: boolean } 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.
}
) } export default ChallengeModalPrompt