import React, { FC, memo, useEffect, useRef, useState, } from '../../../../lib/teact/teact'; import { withGlobal } from '../../../../global'; import { ApiSticker } from '../../../../api/types'; import { SettingsScreens } from '../../../../types'; import { IS_SINGLE_COLUMN_LAYOUT, IS_TOUCH_ENV } from '../../../../util/environment'; import { selectAnimatedEmoji } from '../../../../global/selectors'; import useFlag from '../../../../hooks/useFlag'; import useLang from '../../../../hooks/useLang'; import useHistoryBack from '../../../../hooks/useHistoryBack'; import Button from '../../../ui/Button'; import Modal from '../../../ui/Modal'; import AnimatedEmoji from '../../../common/AnimatedEmoji'; import InputText from '../../../ui/InputText'; import renderText from '../../../common/helpers/renderText'; type OwnProps = { icon: 'hint' | 'email'; type?: 'text' | 'email'; isLoading?: boolean; error?: string; placeholder: string; shouldConfirm?: boolean; clearError?: NoneToVoidFunction; onSubmit: (value?: string) => void; isActive?: boolean; onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; screen: SettingsScreens; }; type StateProps = { animatedEmoji: ApiSticker; }; const FOCUS_DELAY_TIMEOUT_MS = IS_SINGLE_COLUMN_LAYOUT ? 550 : 400; const SettingsTwoFaSkippableForm: FC = ({ animatedEmoji, type = 'text', isLoading, error, placeholder, shouldConfirm, clearError, onSubmit, isActive, onScreenSelect, onReset, screen, }) => { // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); const [value, setValue] = useState(''); const [isConfirmShown, markIsConfirmShown, unmarkIsConfirmShown] = useFlag(false); useEffect(() => { if (!IS_TOUCH_ENV) { setTimeout(() => { inputRef.current!.focus(); }, FOCUS_DELAY_TIMEOUT_MS); } }, []); const handleInputChange = (e: React.ChangeEvent) => { if (error && clearError) { clearError(); } setValue(e.target.value); }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!inputRef.current) { return; } onSubmit(value); }; const handleSkip = () => { onSubmit(); }; const handleSkipConfirm = () => { unmarkIsConfirmShown(); onSubmit(); }; const lang = useLang(); useHistoryBack(isActive, onReset, onScreenSelect, screen); return (
{value ? ( ) : ( )} {shouldConfirm && ( {renderText(lang('YourEmailSkipWarningText'), ['br', 'simple_markdown'])}
)}
); }; export default memo(withGlobal((global, { icon }) => { return { animatedEmoji: selectAnimatedEmoji(global, icon === 'email' ? '💌' : '💡'), }; })(SettingsTwoFaSkippableForm));