Skip to content

Commit

Permalink
Correct error on toast, add error handling for get request, change va…
Browse files Browse the repository at this point in the history
…riable declaration to const
  • Loading branch information
YanZhylavy committed Sep 4, 2024
1 parent ec94b0d commit dd359e0
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand All @@ -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 (
<div className={css['autoapprove-section']}>
Expand Down

0 comments on commit dd359e0

Please sign in to comment.