import { ChallengePrompt, ChallengeValidation, MobileDeviceInterface, 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' import Button from '../Button/Button' import { WebApplication } from '@/Application/Application' import { InputValue } from './InputValue' type Props = { application: WebApplication prompt: ChallengePrompt values: ChallengeModalValues index: number onValueChange: (value: InputValue['value'], prompt: ChallengePrompt) => void isInvalid: boolean } const ChallengeModalPrompt: FunctionComponent = ({ application, prompt, values, index, onValueChange, isInvalid, }) => { const inputRef = useRef(null) const biometricsButtonRef = useRef(null) useEffect(() => { const isNotFirstPrompt = index !== 0 if (isNotFirstPrompt) { return } if (prompt.validation === ChallengeValidation.Biometric) { biometricsButtonRef.current?.click() } else { inputRef.current?.focus() } }, [index, prompt.validation]) 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.validation === ChallengeValidation.Biometric ? (
) : prompt.secureTextEntry ? ( onValueChange(value, prompt)} /> ) : ( onValueChange(value, prompt)} /> )} {isInvalid &&
Invalid authentication, please try again.
}
) } export default ChallengeModalPrompt