Reviewed-on: #433 Co-authored-by: miteruzo <miteruzo@naver.com>
このコミットはプルリクエスト #433 でマージされました。
このコミットが含まれているのは:
@@ -63,7 +63,7 @@ describe ('DeerjikistDetailPage', () => {
|
||||
await waitFor (() => {
|
||||
expect (api.apiPut).toHaveBeenCalledWith (
|
||||
'/tags/7/deerjikists',
|
||||
[{ platform: null, code: 'abc' }],
|
||||
[{ platform: null, code: 'abc' }], { locale: 'ja' },
|
||||
)
|
||||
})
|
||||
expect (await screen.findByText ('プラットフォームを入力してください.')).toBeInTheDocument ()
|
||||
|
||||
@@ -2,11 +2,14 @@ import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useParams } from 'react-router-dom'
|
||||
|
||||
import { useLocale } from '@/lib/useLocale'
|
||||
import { useUITranslation } from '@/lib/useUITranslation'
|
||||
import TagLink from '@/components/TagLink'
|
||||
import FieldError from '@/components/common/FieldError'
|
||||
import FormField from '@/components/common/FormField'
|
||||
import PageTitle from '@/components/common/PageTitle'
|
||||
import MainArea from '@/components/layout/MainArea'
|
||||
import PageHead from '@/components/common/PageHead'
|
||||
import { toast } from '@/components/ui/use-toast'
|
||||
import { PLATFORM_NAMES, PLATFORMS } from '@/consts'
|
||||
import { apiPut } from '@/lib/api'
|
||||
@@ -24,18 +27,20 @@ type DeerjikistFormField =
|
||||
|
||||
|
||||
const DeerjikistDetailPage: FC = () => {
|
||||
const { message, label } = useUITranslation ('shared')
|
||||
const locale = useLocale ()
|
||||
const { id } = useParams ()
|
||||
const tagId = String (id ?? '')
|
||||
const tagKey = tagsKeys.deerjikists (tagId)
|
||||
const tagKey = tagsKeys.deerjikists (tagId, locale)
|
||||
|
||||
const { data: qData, isLoading: loading } =
|
||||
useQuery ({ queryKey: tagKey, queryFn: () => fetchDeerjikistsByTag (tagId) })
|
||||
useQuery ({ queryKey: tagKey, queryFn: () => fetchDeerjikistsByTag (tagId, locale) })
|
||||
const tag = qData?.tag
|
||||
const deerjikists = useMemo (() => qData?.deerjikists ?? [], [qData])
|
||||
|
||||
const [data, setData] =
|
||||
useState<(Omit<Deerjikist, 'platform'> & { platform: Platform | null })[]> ([])
|
||||
const [disabled, setDisabled] = useState (true)
|
||||
useState<(Omit<Deerjikist, 'platform'> & { platform: Platform | null })[]> (deerjikists)
|
||||
const [disabled, setDisabled] = useState (tag == null)
|
||||
const { baseErrors, fieldErrors, clearValidationErrors, applyValidationError } =
|
||||
useValidationErrors<DeerjikistFormField> ()
|
||||
|
||||
@@ -49,15 +54,16 @@ const DeerjikistDetailPage: FC = () => {
|
||||
{
|
||||
setDisabled (true)
|
||||
|
||||
setData (await apiPut<Deerjikist[]> (`/tags/${ id }/deerjikists`, data))
|
||||
setData (await apiPut<Deerjikist[]> (`/tags/${ id }/deerjikists`, data, { locale }))
|
||||
qc.invalidateQueries ({ queryKey: tagsKeys.root })
|
||||
|
||||
toast ({ description: '更新しました.' })
|
||||
toast ({ description: label ('messages.updated') })
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
applyValidationError (e)
|
||||
toast ({ title: '更新失敗', description: '入力内容を確認してください.' })
|
||||
toast ({ title: label ('messages.updateFailed'),
|
||||
description: label ('messages.checkInputContent') })
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -78,7 +84,8 @@ const DeerjikistDetailPage: FC = () => {
|
||||
|
||||
return (
|
||||
<MainArea>
|
||||
{(loading || !(tag)) ? 'Loading...' : (
|
||||
<PageHead title={tag?.name ?? message ('common:categories.deerjikist')}/>
|
||||
{(loading || !(tag)) ? label ('common:loading') : (
|
||||
<div className="max-w-xl">
|
||||
<PageTitle>
|
||||
<TagLink tag={tag} withWiki={false} withCount={false}/>
|
||||
@@ -104,7 +111,7 @@ const DeerjikistDetailPage: FC = () => {
|
||||
|
||||
{/* プラットフォーム */}
|
||||
<FormField
|
||||
label="プラットフォーム"
|
||||
label={label ('labels.platform')}
|
||||
messages={fieldErrors[`deerjikists${ i }Platform`]}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<select
|
||||
@@ -129,7 +136,7 @@ const DeerjikistDetailPage: FC = () => {
|
||||
|
||||
{/* コード */}
|
||||
<FormField
|
||||
label="コード"
|
||||
label={label ('labels.code')}
|
||||
messages={fieldErrors[`deerjikists${ i }Code`]}>
|
||||
{({ describedBy, invalid }) => (
|
||||
<input
|
||||
@@ -164,7 +171,7 @@ const DeerjikistDetailPage: FC = () => {
|
||||
(disabled
|
||||
? 'text-gray-300 bg-gray-500'
|
||||
: 'text-white bg-blue-500'))}>
|
||||
更新
|
||||
{label ('actions.update')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする