このコミットが含まれているのは:
@@ -10,7 +10,7 @@ import MainArea from '@/components/layout/MainArea'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { toast } from '@/components/ui/use-toast'
|
||||
import { SITE_TITLE } from '@/config'
|
||||
import { apiPost } from '@/lib/api'
|
||||
import { apiPost, isApiError } from '@/lib/api'
|
||||
import { canEditContent } from '@/lib/users'
|
||||
import { inputClass } from '@/lib/utils'
|
||||
import Forbidden from '@/pages/Forbidden'
|
||||
@@ -117,9 +117,13 @@ const PostImportPage: FC<Props> = ({ user }) => {
|
||||
setRows (current => mergeValidatedRows (current, data.rows))
|
||||
setPhase ('preview')
|
||||
}
|
||||
catch
|
||||
catch (error)
|
||||
{
|
||||
toast ({ title: '投稿プレビューに失敗しました' })
|
||||
const message =
|
||||
isApiError<{ message?: string, baseErrors?: string[] }> (error)
|
||||
? error.response?.data?.message ?? error.response?.data?.baseErrors?.[0]
|
||||
: undefined
|
||||
toast ({ title: '投稿プレビューに失敗しました', description: message ?? '入力を確認してください。' })
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -218,14 +222,21 @@ const PostImportPage: FC<Props> = ({ user }) => {
|
||||
}
|
||||
|
||||
const submit = async () => {
|
||||
const targets = rows.filter (row => (row as ImportRow & { importStatus?: string }).importStatus !== 'created')
|
||||
const targets = rows.filter (row => row.importStatus == null || row.importStatus === 'pending')
|
||||
if (targets.length === 0)
|
||||
return
|
||||
setLoading (true)
|
||||
try
|
||||
{
|
||||
const result = await apiPost<{ created: number, skipped: number, failed: number,
|
||||
rows: { sourceRow: number, status: ImportResultStatus, post?: { id: number }, errors?: Record<string, string[]> }[] }> ('/posts/import', { rows: targets, existing })
|
||||
rows: { sourceRow: number, status: ImportResultStatus, post?: { id: number }, errors?: Record<string, string[]> }[] }> ('/posts/import', {
|
||||
rows: targets.map (row => ({ sourceRow: row.sourceRow,
|
||||
url: row.url,
|
||||
attributes: row.attributes,
|
||||
provenance: row.provenance,
|
||||
tagSources: row.tagSources,
|
||||
metadataUrl: row.metadataUrl })),
|
||||
existing })
|
||||
if (result.rows.some (row => !(['created', 'skipped', 'failed'] as string[]).includes (row.status)))
|
||||
throw new Error ('不正な登録結果です。')
|
||||
toast ({ title: `登録完了: ${result.created} 件`,
|
||||
|
||||
新しい課題から参照
ユーザをブロックする