Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#762 [FE] Enhance AutoapproveDelay component on Admin page #763

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading