From bb4787f27da1f8cd80f38ac053132f142a4f8271 Mon Sep 17 00:00:00 2001 From: AntoninoP Date: Wed, 17 Jul 2024 13:07:48 +0200 Subject: [PATCH 1/2] toast color now depend on return code --- src/App.jsx | 8 ++++---- src/service/api.tsx | 25 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 8fa45b6..fbe063e 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom'; import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; @@ -38,8 +38,8 @@ const App = () => { } /> { pauseOnFocusLoss draggable pauseOnHover - theme="colored" + theme="light" /> diff --git a/src/service/api.tsx b/src/service/api.tsx index 706d213..1c21977 100644 --- a/src/service/api.tsx +++ b/src/service/api.tsx @@ -1,5 +1,5 @@ import { getAuth } from 'firebase/auth'; -import {Bounce, toast} from "react-toastify"; +import { Bounce, toast } from "react-toastify"; const apiUrl: string = 'https://www.servii.fr/api'; @@ -45,7 +45,7 @@ enum serviiRequest { accountDelete = 'AccountDelete', serverRun = 'ServerRun', serverStop = 'ServerStop', - updateProperty = 'UpdateProperties', + updateProperty = 'UpdateProperties', command = 'Command', } @@ -69,17 +69,30 @@ class serviiApi { } return { return_code: status, message: json }; } - toast.info(json.message, { - position: "top-center", - autoClose: 2500, + + let toastType: 'success' | 'error' | 'info'; + let toastColor: string; + + 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: "colored", + theme: "light", transition: Bounce, }); + return { return_code: status, message: json.message }; } From b8a470afe732027b04f90086d18b7edfb541462c Mon Sep 17 00:00:00 2001 From: AntoninoP Date: Wed, 17 Jul 2024 13:10:40 +0200 Subject: [PATCH 2/2] cleaner code --- src/App.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.jsx b/src/App.jsx index fbe063e..c2c8f18 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom'; import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css';