From dd359e08a74fdba2a86928c25585c45a59b87390 Mon Sep 17 00:00:00 2001 From: Yan Zhylavy Date: Wed, 4 Sep 2024 16:24:32 +0300 Subject: [PATCH] Correct error on toast, add error handling for get request, change variable declaration to const --- .../adminPage/auto-approve-delay/AutoApproveDelay.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FrontEnd/src/components/adminPage/auto-approve-delay/AutoApproveDelay.jsx b/FrontEnd/src/components/adminPage/auto-approve-delay/AutoApproveDelay.jsx index 8d75e882d..adfb8abee 100644 --- a/FrontEnd/src/components/adminPage/auto-approve-delay/AutoApproveDelay.jsx +++ b/FrontEnd/src/components/adminPage/auto-approve-delay/AutoApproveDelay.jsx @@ -6,7 +6,7 @@ import axios from 'axios'; import css from './AutoApproveDelay.module.css'; const AutoApproveDelay = () => { - const fetcher = url => axios.get(url).then(res => res.data); + const fetcher = url => axios.get(url).then(res => res.data).catch(() => toast.error('Помилка зв`язку із сервером.')); const url = `${process.env.REACT_APP_BASE_API_URL}/api/admin/automoderation/`; const { data, mutate } = useSWR(url, fetcher); const [delay, setDelay] = useState(null); @@ -19,7 +19,7 @@ const AutoApproveDelay = () => { }, [data]); const handleInputChange = (e) => { - let value = Number(e.target.value); + const value = Number(e.target.value); setError(null); setDelay(value); if (!(1 <= value && value <= 48) || !Number.isInteger(value)) { @@ -30,7 +30,7 @@ const AutoApproveDelay = () => { const handleSubmit = () => { !error && axios.put(`${process.env.REACT_APP_BASE_API_URL}/api/admin/automoderation/`, { 'auto_moderation_hours': delay }) .then(() => { toast.success('Зміни успішно застосовано.'); mutate({ ...data, auto_moderation_hours: delay }); }) - .catch((e) => toast.error(e.message)); + .catch(() => toast.error('Не вдалося зберегти зміни, сталася помилка')); }; return (