Skip to content

Commit

Permalink
feat: support hide custom type toast in operator (#6879) (#6880)
Browse files Browse the repository at this point in the history
Co-authored-by: 青湛 <[email protected]>
  • Loading branch information
github-actions[bot] and mintsweet authored Jan 26, 2024
1 parent af455b1 commit 987cf40
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions config-ui/src/utils/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type OperateConfig = {
formatMessage?: () => string;
formatReason?: (err: unknown) => string;
hideToast?: boolean;
hideSuccessToast?: boolean;
hideErrorToast?: boolean;
};

/**
Expand All @@ -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 <T>(request: () => Promise<T>, config?: OperateConfig): Promise<[boolean, any?]> => {
Expand All @@ -41,14 +46,14 @@ export const operator = async <T>(request: () => Promise<T>, 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);
}

Expand Down

0 comments on commit 987cf40

Please sign in to comment.