diff --git a/react/src/components/KeypairResourcePolicySettingModal.tsx b/react/src/components/KeypairResourcePolicySettingModal.tsx index 2d875ca53..242a768ac 100644 --- a/react/src/components/KeypairResourcePolicySettingModal.tsx +++ b/react/src/components/KeypairResourcePolicySettingModal.tsx @@ -221,25 +221,25 @@ const KeypairResourcePolicySettingModal: React.FC< props: props as CreateKeyPairResourcePolicyInput, }, onCompleted: (res, errors) => { - if (!res?.create_keypair_resource_policy?.ok || errors) { - if (res.create_keypair_resource_policy?.msg) { - message.error( - painKiller.relieve(res.create_keypair_resource_policy.msg), - ); - } else if (errors && errors.length > 0) { - // if res.create_keypair_resource_policy is null - errors.forEach((error) => - message.error(painKiller.relieve(error.message), 2.5), - ); - } + if ( + !res?.create_keypair_resource_policy?.ok && + res.create_keypair_resource_policy?.msg + ) { + message.error(res.create_keypair_resource_policy.msg); onRequestClose(false); - } else { - message.success(t('resourcePolicy.SuccessfullyCreated')); - onRequestClose(true); + return; } + if (errors && errors.length > 0) { + errors.forEach((error) => message.error(error.message, 2.5)); + onRequestClose(false); + return; + } + + message.success(t('resourcePolicy.SuccessfullyCreated')); + onRequestClose(true); }, onError(err) { - message.error(err.message); + message.error(painKiller.relieve(err?.message)); }, }); } else { @@ -249,25 +249,25 @@ const KeypairResourcePolicySettingModal: React.FC< props: props as ModifyKeyPairResourcePolicyInput, }, onCompleted: (res, errors) => { - if (!res?.modify_keypair_resource_policy?.ok || errors) { - if (res.modify_keypair_resource_policy?.msg) { - message.error( - painKiller.relieve(res.modify_keypair_resource_policy.msg), - ); - } else if (errors && errors.length > 0) { - // if res.create_keypair_resource_policy is null - errors.forEach((error) => - message.error(painKiller.relieve(error.message), 2.5), - ); - } + if ( + !res?.modify_keypair_resource_policy?.ok && + res.modify_keypair_resource_policy?.msg + ) { + message.error(res.modify_keypair_resource_policy.msg); onRequestClose(false); - } else { - message.success(t('resourcePolicy.SuccessfullyCreated')); - onRequestClose(true); + return; } + if (errors && errors.length > 0) { + errors.forEach((error) => message.error(error.message, 2.5)); + onRequestClose(false); + return; + } + + message.success(t('resourcePolicy.SuccessfullyUpdated')); + onRequestClose(true); }, onError(err) { - message.error(err.message); + message.error(painKiller.relieve(err?.message)); }, }); } diff --git a/react/src/components/ProjectResourcePolicySettingModal.tsx b/react/src/components/ProjectResourcePolicySettingModal.tsx index e672027fd..883088e5c 100644 --- a/react/src/components/ProjectResourcePolicySettingModal.tsx +++ b/react/src/components/ProjectResourcePolicySettingModal.tsx @@ -1,6 +1,7 @@ import { GBToBytes, bytesToGB } from '../helper'; import { SIGNED_32BIT_MAX_INT } from '../helper/const-vars'; import { useSuspendedBackendaiClient } from '../hooks'; +import { usePainKiller } from '../hooks/usePainKiller'; import BAIModal, { BAIModalProps } from './BAIModal'; import Flex from './Flex'; import FormItemWithUnlimited from './FormItemWithUnlimited'; @@ -43,6 +44,7 @@ const ProjectResourcePolicySettingModal: React.FC = ({ const { t } = useTranslation(); const { token } = theme.useToken(); const { message } = App.useApp(); + const painKiller = usePainKiller(); const formRef = useRef(null); const baiClient = useSuspendedBackendaiClient(); @@ -157,7 +159,11 @@ const ProjectResourcePolicySettingModal: React.FC = ({ }, onCompleted(res, errors) { if (!res?.create_project_resource_policy?.ok || errors) { - message.error(res?.create_project_resource_policy?.msg); + message.error( + painKiller.relieve( + res?.create_project_resource_policy?.msg as string, + ), + ); onRequestClose(); } else { message.success( @@ -167,7 +173,7 @@ const ProjectResourcePolicySettingModal: React.FC = ({ } }, onError(error) { - message.error(error?.message); + message.error(painKiller.relieve(error?.message)); }, }); } else { @@ -178,7 +184,11 @@ const ProjectResourcePolicySettingModal: React.FC = ({ }, onCompleted(res, errors) { if (!res?.modify_project_resource_policy?.ok || errors) { - message.error(res?.modify_project_resource_policy?.msg); + message.error( + painKiller.relieve( + res?.modify_project_resource_policy?.msg as string, + ), + ); onRequestClose(); } else { message.success( @@ -188,7 +198,7 @@ const ProjectResourcePolicySettingModal: React.FC = ({ } }, onError(error) { - message.error(error?.message); + message.error(painKiller.relieve(error?.message)); }, }); } diff --git a/react/src/components/UserResourcePolicySettingModal.tsx b/react/src/components/UserResourcePolicySettingModal.tsx index a708db60e..fa057e698 100644 --- a/react/src/components/UserResourcePolicySettingModal.tsx +++ b/react/src/components/UserResourcePolicySettingModal.tsx @@ -1,6 +1,7 @@ import { GBToBytes, bytesToGB } from '../helper'; import { SIGNED_32BIT_MAX_INT } from '../helper/const-vars'; import { useSuspendedBackendaiClient } from '../hooks'; +import { usePainKiller } from '../hooks/usePainKiller'; import BAIModal, { BAIModalProps } from './BAIModal'; import Flex from './Flex'; import FormItemWithUnlimited from './FormItemWithUnlimited'; @@ -43,6 +44,8 @@ const UserResourcePolicySettingModal: React.FC = ({ const { t } = useTranslation(); const { token } = theme.useToken(); const { message } = App.useApp(); + const painKiller = usePainKiller(); + const formRef = useRef(null); const baiClient = useSuspendedBackendaiClient(); @@ -166,7 +169,11 @@ const UserResourcePolicySettingModal: React.FC = ({ }, onCompleted(res, errors) { if (!res?.create_user_resource_policy?.ok || errors) { - message.error(res?.create_user_resource_policy?.msg); + message.error( + painKiller.relieve( + res?.create_user_resource_policy?.msg as string, + ), + ); onRequestClose(); } else { message.success( @@ -176,7 +183,7 @@ const UserResourcePolicySettingModal: React.FC = ({ } }, onError(error) { - message.error(error?.message); + message.error(painKiller.relieve(error?.message)); }, }); } else { @@ -187,7 +194,11 @@ const UserResourcePolicySettingModal: React.FC = ({ }, onCompleted(res, errors) { if (!res?.modify_user_resource_policy?.ok || errors) { - message.error(res?.modify_user_resource_policy?.msg); + message.error( + painKiller.relieve( + res?.modify_user_resource_policy?.msg as string, + ), + ); onRequestClose(); } else { message.success( @@ -197,7 +208,7 @@ const UserResourcePolicySettingModal: React.FC = ({ } }, onError(error) { - message.error(error?.message); + message.error(painKiller.relieve(error?.message)); }, }); }