瀏覽代碼

feat: add debounced enter key submission to install form (#15445) (#15542)

tags/1.1.0
Lam 7 月之前
父節點
當前提交
0bc4da38fc
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 20 行新增6 行删除
  1. 20
    6
      web/app/install/installForm.tsx

+ 20
- 6
web/app/install/installForm.tsx 查看文件

'use client' 'use client'
import React, { useEffect } from 'react'
import React, { useCallback, useEffect } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useDebounceFn } from 'ahooks'


import Link from 'next/link' import Link from 'next/link'
import { useRouter } from 'next/navigation' import { useRouter } from 'next/navigation'
const { const {
register, register,
handleSubmit, handleSubmit,
formState: { errors },
formState: { errors, isSubmitting },
} = useForm<AccountFormValues>({ } = useForm<AccountFormValues>({
resolver: zodResolver(accountFormSchema), resolver: zodResolver(accountFormSchema),
defaultValues: { defaultValues: {
} }


const handleSetting = async () => { const handleSetting = async () => {
if (isSubmitting) return
handleSubmit(onSubmit)() handleSubmit(onSubmit)()
} }


const { run: debouncedHandleKeyDown } = useDebounceFn(
(e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
e.preventDefault()
handleSetting()
}
},
{ wait: 200 },
)

const handleKeyDown = useCallback(debouncedHandleKeyDown, [debouncedHandleKeyDown])

useEffect(() => { useEffect(() => {
fetchSetupStatus().then((res: SetupStatusResponse) => { fetchSetupStatus().then((res: SetupStatusResponse) => {
if (res.step === 'finished') { if (res.step === 'finished') {
</div> </div>
<div className="grow mt-8 sm:mx-auto sm:w-full sm:max-w-md"> <div className="grow mt-8 sm:mx-auto sm:w-full sm:max-w-md">
<div className="bg-white "> <div className="bg-white ">
<form onSubmit={handleSubmit(onSubmit)}>
<form onSubmit={handleSubmit(onSubmit)} onKeyDown={handleKeyDown}>
<div className='mb-5'> <div className='mb-5'>
<label htmlFor="email" className="my-2 flex items-center justify-between text-sm font-medium text-gray-900"> <label htmlFor="email" className="my-2 flex items-center justify-between text-sm font-medium text-gray-900">
{t('login.email')} {t('login.email')}
<input <input
{...register('email')} {...register('email')}
placeholder={t('login.emailPlaceholder') || ''} placeholder={t('login.emailPlaceholder') || ''}
className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder-gray-400 caret-primary-600 sm:text-sm'}
className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder:text-gray-400 caret-primary-600 sm:text-sm'}
/> />
{errors.email && <span className='text-red-400 text-sm'>{t(`${errors.email?.message}`)}</span>} {errors.email && <span className='text-red-400 text-sm'>{t(`${errors.email?.message}`)}</span>}
</div> </div>
<input <input
{...register('name')} {...register('name')}
placeholder={t('login.namePlaceholder') || ''} placeholder={t('login.namePlaceholder') || ''}
className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder-gray-400 caret-primary-600 sm:text-sm pr-10'}
className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder:text-gray-400 caret-primary-600 sm:text-sm pr-10'}
/> />
</div> </div>
{errors.name && <span className='text-red-400 text-sm'>{t(`${errors.name.message}`)}</span>} {errors.name && <span className='text-red-400 text-sm'>{t(`${errors.name.message}`)}</span>}
{...register('password')} {...register('password')}
type={showPassword ? 'text' : 'password'} type={showPassword ? 'text' : 'password'}
placeholder={t('login.passwordPlaceholder') || ''} placeholder={t('login.passwordPlaceholder') || ''}
className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder-gray-400 caret-primary-600 sm:text-sm pr-10'}
className={'appearance-none block w-full rounded-lg pl-[14px] px-3 py-2 border border-gray-200 hover:border-gray-300 hover:shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 placeholder:text-gray-400 caret-primary-600 sm:text-sm pr-10'}
/> />


<div className="absolute inset-y-0 right-0 flex items-center pr-3"> <div className="absolute inset-y-0 right-0 flex items-center pr-3">

Loading…
取消
儲存