From b9e1fd3422251423f14c5fbc94e8ee606621ab49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E6=B9=9B?= <0x1304570@gmail.com> Date: Fri, 26 Jan 2024 18:31:06 +1300 Subject: [PATCH] feat: support hide custom type toast in operator (#6879) --- config-ui/src/utils/operator.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/config-ui/src/utils/operator.ts b/config-ui/src/utils/operator.ts index 1f570bb0239..e14263b4f27 100644 --- a/config-ui/src/utils/operator.ts +++ b/config-ui/src/utils/operator.ts @@ -23,6 +23,8 @@ export type OperateConfig = { formatMessage?: () => string; formatReason?: (err: unknown) => string; hideToast?: boolean; + hideSuccessToast?: boolean; + hideErrorToast?: boolean; }; /** @@ -32,6 +34,9 @@ export type OperateConfig = { * @param config.setOperating -> Control the status of the request * @param config.formatMessage -> Show the message for the success * @param config.formatReason -> Show the reason for the failure + * @param config.hideToast -> Hide all the toast + * @param config.hideSuccessToast -> Hide the success toast + * @param config.hideErrorToast -> Hide the error toast * @returns */ export const operator = async (request: () => Promise, config?: OperateConfig): Promise<[boolean, any?]> => { @@ -41,14 +46,14 @@ export const operator = async (request: () => Promise, config?: OperateCon setOperating?.(true); const res = await request(); const content = formatMessage?.() ?? 'Operation successfully completed'; - if (!config?.hideToast) { + if (!config?.hideToast || !config?.hideSuccessToast) { message.success(content); } return [true, res]; } catch (err) { console.error('Operation failed.', err); const reason = formatReason?.(err) ?? (err as any).response?.data?.message ?? 'Operation failed.'; - if (!config?.hideToast) { + if (!config?.hideToast || !config?.hideErrorToast) { message.error(reason); }