このコミットが含まれているのは:
@@ -3,7 +3,9 @@ import type { FC } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Helmet } from 'react-helmet-async'
|
||||
|
||||
import FieldError from '@/components/common/FieldError'
|
||||
import Form from '@/components/common/Form'
|
||||
import FormField from '@/components/common/FormField'
|
||||
import Label from '@/components/common/Label'
|
||||
import PageTitle from '@/components/common/PageTitle'
|
||||
import MainArea from '@/components/layout/MainArea'
|
||||
@@ -13,22 +15,30 @@ import { Button } from '@/components/ui/button'
|
||||
import { toast } from '@/components/ui/use-toast'
|
||||
import { SITE_TITLE } from '@/config'
|
||||
import { apiPut } from '@/lib/api'
|
||||
import { inputClass } from '@/lib/utils'
|
||||
import { useValidationErrors } from '@/lib/useValidationErrors'
|
||||
|
||||
import type { User } from '@/types'
|
||||
|
||||
type Props = { user: User | null
|
||||
setUser: React.Dispatch<React.SetStateAction<User | null>> }
|
||||
|
||||
type UserFormField = 'name'
|
||||
|
||||
|
||||
const SettingPage: FC<Props> = ({ user, setUser }) => {
|
||||
const [name, setName] = useState ('')
|
||||
const [userCodeVsbl, setUserCodeVsbl] = useState (false)
|
||||
const [inheritVsbl, setInheritVsbl] = useState (false)
|
||||
const { baseErrors, fieldErrors, clearValidationErrors, applyValidationError } =
|
||||
useValidationErrors<UserFormField> ()
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(user))
|
||||
return
|
||||
|
||||
clearValidationErrors ()
|
||||
|
||||
const formData = new FormData
|
||||
formData.append ('name', name)
|
||||
|
||||
@@ -40,8 +50,9 @@ const SettingPage: FC<Props> = ({ user, setUser }) => {
|
||||
setUser (user => ({ ...user, ...data }))
|
||||
toast ({ title: '設定を更新しました.' })
|
||||
}
|
||||
catch
|
||||
catch (e)
|
||||
{
|
||||
applyValidationError (e)
|
||||
toast ({ title: 'しっぱい……' })
|
||||
}
|
||||
}
|
||||
@@ -65,11 +76,16 @@ const SettingPage: FC<Props> = ({ user, setUser }) => {
|
||||
|
||||
{user ? (
|
||||
<>
|
||||
<FieldError messages={baseErrors}/>
|
||||
|
||||
{/* 名前 */}
|
||||
<div>
|
||||
<Label>表示名</Label>
|
||||
<FormField label="表示名" messages={fieldErrors.name}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<>
|
||||
<input type="text"
|
||||
className="w-full border rounded p-2"
|
||||
aria-describedby={describedBy}
|
||||
aria-invalid={invalid}
|
||||
className={inputClass (invalid)}
|
||||
value={name}
|
||||
placeholder="名もなきニジラー"
|
||||
onChange={ev => setName (ev.target.value)}/>
|
||||
@@ -77,7 +93,8 @@ const SettingPage: FC<Props> = ({ user, setUser }) => {
|
||||
<p className="mt-1 text-sm text-red-500">
|
||||
名前が未設定のアカウントは 30 日間アクセスしないと削除されます!!!!
|
||||
</p>)}
|
||||
</div>
|
||||
</>)}
|
||||
</FormField>
|
||||
|
||||
{/* 送信 */}
|
||||
<Button onClick={handleSubmit}
|
||||
|
||||
新しい課題から参照
ユーザをブロックする