QLFW-78: сохранять время начала заполнения при повторной отправке
This commit is contained in:
parent
5239f66d21
commit
f9f4fb7c09
@ -2,14 +2,14 @@
|
||||
|
||||
import Link from 'next/link'
|
||||
import { ContactEmailFallback } from './ContactEmailFallback'
|
||||
import { useActionState, useRef, useState } from 'react'
|
||||
import { useActionState, useState } from 'react'
|
||||
import { submitInquiry, type InquiryState } from '@/app/actions/inquiry'
|
||||
import type { Dict, Locale } from '@/i18n'
|
||||
|
||||
/** Форма обращения. dark — на тёмном фоне блока «Сотрудничество». Тексты — из словаря, ошибки по полям. */
|
||||
export function ContactForm({ t, locale, email, dark = false, privacyLink = false }: { t: Dict; locale: Locale; email: string; dark?: boolean; privacyLink?: boolean }) {
|
||||
const [state, action, pending] = useActionState<InquiryState, FormData>(submitInquiry, { status: 'idle' })
|
||||
const openedAt = useRef<HTMLInputElement>(null)
|
||||
const [openedAt, setOpenedAt] = useState<number>()
|
||||
const [values, setValues] = useState({ name: '', email: '', organization: '', message: '', consent: false })
|
||||
const errors = state.status === 'error' ? state.errors : []
|
||||
const f = t.form
|
||||
@ -32,9 +32,9 @@ export function ContactForm({ t, locale, email, dark = false, privacyLink = fals
|
||||
}
|
||||
|
||||
return (
|
||||
<form action={action} noValidate onFocus={() => { if (openedAt.current && !openedAt.current.value) openedAt.current.value = String(Date.now()) }} className="max-w-2xl space-y-6">
|
||||
<form action={action} noValidate onFocus={() => { if (!openedAt) setOpenedAt(Date.now()) }} className="max-w-2xl space-y-6">
|
||||
<input type="hidden" name="locale" value={locale} />
|
||||
<input type="hidden" name="openedAt" ref={openedAt} defaultValue="" />
|
||||
<input type="hidden" name="openedAt" value={openedAt ?? ''} readOnly />
|
||||
{/* Ловушка для роботов: людям не видна. */}
|
||||
<div hidden aria-hidden="true" style={{ display: 'none' }}>
|
||||
<input type="text" name="website" tabIndex={-1} autoComplete="off" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user