| } | } | ||||
| if (!response) { | if (!response) { | ||||
| notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) | |||||
| notify({ type: 'error', message: t('datasetPipeline.creation.errorTip') }) | |||||
| isCreatingRef.current = false | isCreatingRef.current = false | ||||
| return | return | ||||
| } | } | ||||
| notify({ | notify({ | ||||
| type: status === DSLImportStatus.COMPLETED ? 'success' : 'warning', | type: status === DSLImportStatus.COMPLETED ? 'success' : 'warning', | ||||
| message: t(status === DSLImportStatus.COMPLETED ? 'app.newApp.appCreated' : 'app.newApp.caution'), | |||||
| message: t(status === DSLImportStatus.COMPLETED ? 'datasetPipeline.creation.successTip' : 'datasetPipeline.creation.caution'), | |||||
| children: status === DSLImportStatus.COMPLETED_WITH_WARNINGS && t('app.newApp.appCreateDSLWarning'), | children: status === DSLImportStatus.COMPLETED_WITH_WARNINGS && t('app.newApp.appCreateDSLWarning'), | ||||
| }) | }) | ||||
| if (pipeline_id) | if (pipeline_id) | ||||
| isCreatingRef.current = false | isCreatingRef.current = false | ||||
| } | } | ||||
| else { | else { | ||||
| notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) | |||||
| notify({ type: 'error', message: t('datasetPipeline.creation.errorTip') }) | |||||
| isCreatingRef.current = false | isCreatingRef.current = false | ||||
| } | } | ||||
| } | } | ||||
| const response = await importDSLConfirm(importId) | const response = await importDSLConfirm(importId) | ||||
| if (!response) { | if (!response) { | ||||
| notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) | |||||
| notify({ type: 'error', message: t('datasetPipeline.creation.errorTip') }) | |||||
| return | return | ||||
| } | } | ||||
| notify({ | notify({ | ||||
| type: 'success', | type: 'success', | ||||
| message: t('app.newApp.appCreated'), | |||||
| message: t('datasetPipeline.creation.successTip'), | |||||
| }) | }) | ||||
| if (pipeline_id) | if (pipeline_id) | ||||
| await handleCheckPluginDependencies(pipeline_id, true) | await handleCheckPluginDependencies(pipeline_id, true) | ||||
| push(`datasets/${dataset_id}/pipeline`) | push(`datasets/${dataset_id}/pipeline`) | ||||
| } | } | ||||
| else if (status === DSLImportStatus.FAILED) { | else if (status === DSLImportStatus.FAILED) { | ||||
| notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) | |||||
| notify({ type: 'error', message: t('datasetPipeline.creation.errorTip') }) | |||||
| } | } | ||||
| } | } | ||||
| import type { CreateFormData } from '@/models/pipeline' | import type { CreateFormData } from '@/models/pipeline' | ||||
| import Modal from '@/app/components/base/modal' | import Modal from '@/app/components/base/modal' | ||||
| import { useRouter } from 'next/navigation' | import { useRouter } from 'next/navigation' | ||||
| import Toast from '@/app/components/base/toast' | |||||
| import { useTranslation } from 'react-i18next' | |||||
| import { useResetDatasetList } from '@/service/knowledge/use-dataset' | |||||
| type CreateFromScratchModalProps = { | type CreateFromScratchModalProps = { | ||||
| show: boolean | show: boolean | ||||
| show, | show, | ||||
| onClose, | onClose, | ||||
| }: CreateFromScratchModalProps) => { | }: CreateFromScratchModalProps) => { | ||||
| const { t } = useTranslation() | |||||
| const { push } = useRouter() | const { push } = useRouter() | ||||
| const [memberList, setMemberList] = useState<Member[]>([]) | const [memberList, setMemberList] = useState<Member[]>([]) | ||||
| const { data: members } = useMembers() | const { data: members } = useMembers() | ||||
| }, [members]) | }, [members]) | ||||
| const { mutateAsync: createEmptyDataset } = useCreatePipelineDataset() | const { mutateAsync: createEmptyDataset } = useCreatePipelineDataset() | ||||
| const resetDatasetList = useResetDatasetList() | |||||
| const handleCreate = useCallback(async (payload: CreateFormData) => { | const handleCreate = useCallback(async (payload: CreateFormData) => { | ||||
| const { name, appIcon, description, permission, selectedMemberIDs } = payload | const { name, appIcon, description, permission, selectedMemberIDs } = payload | ||||
| request.partial_member_list = selectedMemberList | request.partial_member_list = selectedMemberList | ||||
| } | } | ||||
| await createEmptyDataset(request, { | await createEmptyDataset(request, { | ||||
| onSettled: (data) => { | |||||
| onSuccess: (data) => { | |||||
| if (data) { | if (data) { | ||||
| const { id } = data | const { id } = data | ||||
| Toast.notify({ | |||||
| type: 'success', | |||||
| message: t('datasetPipeline.creation.successTip'), | |||||
| }) | |||||
| resetDatasetList() | |||||
| push(`/datasets/${id}/pipeline`) | push(`/datasets/${id}/pipeline`) | ||||
| } | } | ||||
| }, | |||||
| onError: () => { | |||||
| Toast.notify({ | |||||
| type: 'error', | |||||
| message: t('datasetPipeline.creation.errorTip'), | |||||
| }) | |||||
| }, | |||||
| onSettled: () => { | |||||
| onClose?.() | onClose?.() | ||||
| }, | }, | ||||
| }) | }) | ||||
| }, [createEmptyDataset, memberList, onClose, push]) | |||||
| }, [createEmptyDataset, memberList, onClose, push, resetDatasetList, t]) | |||||
| return ( | return ( | ||||
| <Modal | <Modal | 
| onSuccess: async (newDataset) => { | onSuccess: async (newDataset) => { | ||||
| Toast.notify({ | Toast.notify({ | ||||
| type: 'success', | type: 'success', | ||||
| message: t('app.newApp.appCreated'), | |||||
| message: t('datasetPipeline.creation.successTip'), | |||||
| }) | }) | ||||
| resetDatasetList() | resetDatasetList() | ||||
| if (newDataset.pipeline_id) | if (newDataset.pipeline_id) |