From 3e329d5bb30795cf45aa4b66d3a0d39c2d3cf810 Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Sat, 17 Aug 2024 12:03:30 +0200 Subject: [PATCH] [~] Added toast exclusion list for API calls. Removed FetchLogsRequest calls interface (duplicate of base ServerRequest) --- src/service/api.tsx | 62 ++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/service/api.tsx b/src/service/api.tsx index f9e4487..056d8e5 100644 --- a/src/service/api.tsx +++ b/src/service/api.tsx @@ -36,10 +36,6 @@ interface CommandRequest extends BaseRequest { name: string; } -interface FetchLogsRequest extends BaseRequest { - name: string; -} - enum serviiRequest { setSubdomain = 'SetSubdomain', fetchServers = 'FetchServers', @@ -54,6 +50,12 @@ enum serviiRequest { fetchLogs = 'FetchLogs', } + +const nonToastableCalls: string[] = [ + serviiRequest.fetchServers, + serviiRequest.fetchLogs, + ]; + class serviiApi { constructor() {} @@ -75,28 +77,30 @@ class serviiApi { return { return_code: status, message: json }; } - let toastType: 'success' | 'error' | 'info'; - let toastColor: string; + if (!nonToastableCalls.includes(endpoint)) { - if (status >= 200 && status < 300) { - toastType = 'success'; - } else if (status >= 400 && status < 600) { - toastType = 'error'; - } else { - toastType = 'info'; - } + let toastType: 'success' | 'error' | 'info'; - toast[toastType](json.message, { - position: "top-right", - autoClose: 3500, - hideProgressBar: false, - closeOnClick: true, - pauseOnHover: true, - draggable: true, - progress: undefined, - theme: "light", - transition: Bounce, - }); + if (status >= 200 && status < 300) { + toastType = 'success'; + } else if (status >= 400 && status < 600) { + toastType = 'error'; + } else { + toastType = 'info'; + } + + toast[toastType](json.message, { + position: "top-right", + autoClose: 3500, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "light", + transition: Bounce, + }); + } return { return_code: status, message: json.message }; } @@ -119,6 +123,11 @@ class serviiApi { return this.call(serviiRequest.fetchServers, payload); } + public static async fetchLogs(name: string): Promise { + const payload: ServerRequest = { token: this.token(), name: name }; + return this.call(serviiRequest.fetchLogs, payload); + } + public static async accountCreate(): Promise { const payload: BaseRequest = { token: this.token() }; return this.call(serviiRequest.accountCreate, payload); @@ -162,11 +171,6 @@ class serviiApi { const payload: CommandRequest = { token: this.token(), command: command, name: name }; return this.call(serviiRequest.command, payload); } - - public static async fetchLogs(name: string): Promise { - const payload: FetchLogsRequest = { token: this.token(), name: name }; - return this.call(serviiRequest.fetchLogs, payload); - } } export default serviiApi;