feat(studio): assign robot author subtopics
This commit is contained in:
@@ -2,10 +2,10 @@ import { useEffect } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { z } from 'zod'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import type { StudioRobotAuthor } from '@/api/types'
|
||||
import { updateRobotAuthor } from '@/api/modules/studio'
|
||||
import { fetchSubtopics, updateRobotAuthor } from '@/api/modules/studio'
|
||||
import { handleApiError } from '@/lib/errors'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Label } from '@/components/ui/label'
|
||||
@@ -47,6 +47,7 @@ const jsonObject = z.string().refine(
|
||||
const schema = z.object({
|
||||
persona: z.string(),
|
||||
status: z.enum(STATUSES),
|
||||
subtopic_id: z.string(),
|
||||
article_style: jsonObject,
|
||||
image_style: jsonObject,
|
||||
publishing_rules: jsonObject,
|
||||
@@ -74,6 +75,7 @@ export function RobotAuthorEditSheet({ author, onOpenChange }: RobotAuthorEditSh
|
||||
defaultValues: {
|
||||
persona: '',
|
||||
status: 'pending',
|
||||
subtopic_id: '',
|
||||
article_style: '',
|
||||
image_style: '',
|
||||
publishing_rules: '',
|
||||
@@ -85,18 +87,26 @@ export function RobotAuthorEditSheet({ author, onOpenChange }: RobotAuthorEditSh
|
||||
form.reset({
|
||||
persona: author.persona ?? '',
|
||||
status: author.status,
|
||||
subtopic_id: author.subtopic_id ?? '',
|
||||
article_style: asText(author.article_style),
|
||||
image_style: asText(author.image_style),
|
||||
publishing_rules: asText(author.publishing_rules),
|
||||
})
|
||||
}, [author, form])
|
||||
|
||||
const subtopics = useQuery({
|
||||
queryKey: ['studio-subtopics', 'author-editor', author?.category_id],
|
||||
queryFn: () => fetchSubtopics({ category_id: author!.category_id, status: 'active', page_size: 100 }),
|
||||
enabled: author !== null,
|
||||
})
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: (values: FormValues) => {
|
||||
if (!author) throw new Error('no author')
|
||||
return updateRobotAuthor(author.id, {
|
||||
persona: values.persona.trim() || null,
|
||||
status: values.status,
|
||||
subtopic_id: values.subtopic_id || null,
|
||||
article_style: parseObject(values.article_style),
|
||||
image_style: parseObject(values.image_style),
|
||||
publishing_rules: parseObject(values.publishing_rules),
|
||||
@@ -142,6 +152,21 @@ export function RobotAuthorEditSheet({ author, onOpenChange }: RobotAuthorEditSh
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field label="子话题">
|
||||
<Select
|
||||
value={form.watch('subtopic_id') || '__none'}
|
||||
onValueChange={(value) => form.setValue('subtopic_id', value === '__none' ? '' : value)}
|
||||
>
|
||||
<SelectTrigger><SelectValue placeholder="未分配" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__none">未分配</SelectItem>
|
||||
{subtopics.data?.data.map((subtopic) => (
|
||||
<SelectItem key={subtopic.id} value={subtopic.id}>{subtopic.title}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field label="人设" error={form.formState.errors.persona?.message}>
|
||||
<Textarea rows={3} {...form.register('persona')} placeholder="务实的家电维修师傅…" />
|
||||
</Field>
|
||||
|
||||
Reference in New Issue
Block a user