diff --git a/apps/web/src/services/ops-flow/components/PackageForm.vue b/apps/web/src/services/ops-flow/components/PackageForm.vue index 4b4de7999e..82a42bc3d6 100644 --- a/apps/web/src/services/ops-flow/components/PackageForm.vue +++ b/apps/web/src/services/ops-flow/components/PackageForm.vue @@ -10,7 +10,7 @@ import { } from '@cloudforet/mirinae'; import type { SelectDropdownMenuItem } from '@cloudforet/mirinae/src/controls/dropdown/select-dropdown/type'; -import { getParticle } from '@/translations'; +import { getParticle, i18n as _i18n } from '@/translations'; import { showSuccessMessage } from '@/lib/helper/notice-alert-helper'; @@ -38,6 +38,8 @@ const { setSelectedWorkspaces, setInitialWorkspaces, applyPackageToWorkspaces, + addedWorkspaceItems, + removedWorkspaceItems, } = useWorkspaceField(); const workspaceType = ref<'unset'|'specific'>('unset'); const handleSelectUnsetWorkspace = () => { @@ -57,6 +59,8 @@ const { setSelectedCategoryItems, setInitialCategoriesByPackageId, applyPackageToCategories, + addedCategoryItems, + removedCategoryItems, } = useCategoryField(); /* form */ @@ -75,9 +79,22 @@ const { workspaces: workspaceValidator, }, { name(value: string) { - if (!value.trim().length) return 'Name is required'; - if (value.length > 50) return 'Name should be less than 50 characters'; - if (packageStore.getters.packages.some((p) => p.package_id !== taskManagementPageState.targetPackageId && p.name === value)) return 'Name already exists'; + if (!value.trim().length) { + return _i18n.t('OPSFLOW.VALIDATION.REQUIRED', { + topic: _i18n.t('OPSFLOW.NAME'), + particle: getParticle(_i18n.t('OPSFLOW.NAME') as string, 'topic'), + }); + } + if (value.length > 50) { + return _i18n.t('OPSFLOW.VALIDATION.LENGTH_MAX', { + topic: _i18n.t('OPSFLOW.NAME'), + particle: getParticle(_i18n.t('OPSFLOW.NAME') as string, 'topic'), + length: 50, + }); + } + if (packageStore.getters.packages.some((p) => p.package_id !== taskManagementPageState.targetPackageId && p.name === value)) { + return _i18n.t('OPSFLOW.VALIDATION.DUPLICATED', { field: _i18n.t('OPSFLOW.NAME') }); + } return true; }, }); @@ -93,8 +110,23 @@ const handleCancelOrClose = () => { const handleClosed = () => { taskManagementPageStore.resetTargetPackageId(); }; -const handleConfirm = async () => { - if (!isAllValid.value) return; +const handleFormConfirm = () => { + if (addedWorkspaceItems.value.length || removedWorkspaceItems.value.length + || addedCategoryItems.value.length || removedCategoryItems.value.length) { + visibleUpdateConfirmModal.value = true; + } else { + handleUpdateConfirm(); + } +}; +const handleUpdateCancel = () => { + visibleUpdateConfirmModal.value = false; +}; +const handleUpdateConfirm = async () => { + visibleUpdateConfirmModal.value = false; + + if (!isAllValid.value) { + ErrorHandler.handleError(new Error('Invalid form')); + } loading.value = true; if (taskManagementPageState.targetPackageId) { try { @@ -117,9 +149,9 @@ const handleConfirm = async () => { if (errorMessages.length) { throw new Error(errorMessages.join('\n')); } - showSuccessMessage('Successfully updated the package', ''); + showSuccessMessage(_i18n.t('OPSFLOW.ALT_S_EDIT_TARGET', { target: _i18n.t('OPSFLOW.PACKAGE') }), ''); } catch (e) { - ErrorHandler.handleRequestError(e, 'Failed to update package'); + ErrorHandler.handleRequestError(e, _i18n.t('OPSFLOW.ALT_E_EDIT_TARGET', { target: _i18n.t('OPSFLOW.PACKAGE') })); } } else { try { @@ -142,9 +174,9 @@ const handleConfirm = async () => { if (errorMessages.length) { throw new Error(errorMessages.join('\n')); } - showSuccessMessage('Successfully added the package', ''); + showSuccessMessage(_i18n.t('OPSFLOW.ALT_S_ADD_TARGET', { target: _i18n.t('OPSFLOW.PACKAGE') }), ''); } catch (e) { - ErrorHandler.handleRequestError(e, 'Failed to create package'); + ErrorHandler.handleRequestError(e, _i18n.t('OPSFLOW.ALT_E_ADD_TARGET', { target: _i18n.t('OPSFLOW.PACKAGE') })); } } taskManagementPageStore.closePackageForm(); @@ -291,14 +323,23 @@ watch([() => taskManagementPageState.visiblePackageForm, () => taskManagementPag {{ $t('COMMON.BUTTONS.CONFIRM') }} - + diff --git a/apps/web/src/services/ops-flow/components/PackageUpdateConfirmModal.vue b/apps/web/src/services/ops-flow/components/PackageUpdateConfirmModal.vue index b9156375b9..98daf58f8f 100644 --- a/apps/web/src/services/ops-flow/components/PackageUpdateConfirmModal.vue +++ b/apps/web/src/services/ops-flow/components/PackageUpdateConfirmModal.vue @@ -1,69 +1,157 @@