Skip to content

Commit

Permalink
Merge pull request #763 from ita-social-projects/#762EnhanceAutoappro…
Browse files Browse the repository at this point in the history
…veDelayComponentOnAdminPage

#762 [FE] Enhance AutoapproveDelay component  on Admin page
  • Loading branch information
YanZhylavy authored Sep 4, 2024
2 parents ec94b0d + ad5e40f commit e0aec70
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ 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((e) => {
if (!e.response || e.response.status !== 401) {
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 +23,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 +34,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 e0aec70

Please sign in to comment.