import { useState } from 'react'; import { Flex, PinInput, Title, Text, Stack, LoadingOverlay } from '@mantine/core'; import useConsumeCode from '../hooks/use-consume-code'; import { useSearch } from '@tanstack/react-router'; import { Trans, useLingui } from '@lingui/react/macro'; const CodePrompt = () => { const { number } = useSearch({ from: '/login' }); const { t } = useLingui(); const [isWrong, setIsWrong] = useState(false); const [code, setCode] = useState(''); const handleWrongCode = () => setIsWrong(true); const { mutate: consumeCode, isPending } = useConsumeCode(handleWrongCode); const handleChange = (value: string) => { if (value.length === 0) return; if (isWrong) setIsWrong(false); setCode(value); if (value.length === 6) { consumeCode(value); } } return ( <Trans>Enter Verification Code</Trans> A code was sent to +1 ({number?.slice(0, 3)}) {number?.slice(3, 6)}-{number?.slice(6)} {isWrong && Incorrect code} ) }; export default CodePrompt;