本地Mock自定义店铺自动记忆沉淀为下拉可选项
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { PlusOutlined } from '@ant-design/icons'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { App, AutoComplete, Button, Card, Form, Input, InputNumber, Select, Switch } from 'antd'
|
||||
import { useState } from 'react'
|
||||
|
||||
import { createAdminMockWorkOrder } from '@/services/admin'
|
||||
import { createAdminMockWorkOrder, fetchAdminMockCustomShops } from '@/services/admin'
|
||||
import { fetchAdminKuaishouIndustryShops } from '@/services/admin/kuaishou-industry'
|
||||
import type { WorkOrderStatistics } from '@/types/worker-platform'
|
||||
import { buildMockWorkOrderShopOptions } from '@/utils/mock-work-order'
|
||||
@@ -58,13 +58,24 @@ export function WorkOrderStatisticsBar({ statistics }: { statistics?: WorkOrderS
|
||||
|
||||
export function MockWorkOrderForm({ onCreated }: { onCreated: () => Promise<void> }) {
|
||||
const { message } = App.useApp()
|
||||
const queryClient = useQueryClient()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [form] = Form.useForm()
|
||||
const shopsQuery = useQuery({
|
||||
queryKey: ['admin-kuaishou-industry-shops', 'mock-work-order'],
|
||||
queryFn: fetchAdminKuaishouIndustryShops,
|
||||
})
|
||||
const shopOptions = buildMockWorkOrderShopOptions(shopsQuery.data?.data.shops || [])
|
||||
const customShopsQuery = useQuery({
|
||||
queryKey: ['admin-mock-custom-shops'],
|
||||
queryFn: fetchAdminMockCustomShops,
|
||||
})
|
||||
const shopOptions = [
|
||||
...buildMockWorkOrderShopOptions(shopsQuery.data?.data.shops || []),
|
||||
...(customShopsQuery.data?.data.items || []).map((name) => ({
|
||||
value: name,
|
||||
label: `${name}(自定义)`,
|
||||
})),
|
||||
]
|
||||
|
||||
async function submit(values: {
|
||||
platformOrderId: string
|
||||
@@ -83,6 +94,8 @@ export function MockWorkOrderForm({ onCreated }: { onCreated: () => Promise<void
|
||||
})
|
||||
message.success('Mock 工单已生成')
|
||||
form.resetFields()
|
||||
// 自定义店铺由后端记忆,刷新后即可在下拉中选到。
|
||||
await queryClient.invalidateQueries({ queryKey: ['admin-mock-custom-shops'] })
|
||||
await onCreated()
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '生成失败')
|
||||
|
||||
Reference in New Issue
Block a user