missions and filter
This commit is contained in:
@@ -4,7 +4,6 @@ import { PrimaryButton } from '../components/button/PrimaryButton';
|
||||
import { Input } from '../components/input/Input';
|
||||
import { useAppDispatch, useAppSelector } from '../redux/hooks';
|
||||
import {
|
||||
createContest,
|
||||
CreateContestBody,
|
||||
deleteContest,
|
||||
fetchContestById,
|
||||
@@ -17,7 +16,6 @@ import { Navigate, useNavigate } from 'react-router-dom';
|
||||
import { fetchMissionById } from '../redux/slices/missions';
|
||||
import { ReverseButton } from '../components/button/ReverseButton';
|
||||
|
||||
|
||||
interface Mission {
|
||||
id: number;
|
||||
name: string;
|
||||
@@ -27,7 +25,6 @@ interface Mission {
|
||||
* Страница создания / редактирования контеста
|
||||
*/
|
||||
const ContestEditor = () => {
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -36,21 +33,16 @@ const ContestEditor = () => {
|
||||
const contestId = Number(query.get('contestId') ?? undefined);
|
||||
const refactor = !!contestId;
|
||||
|
||||
if (!refactor){
|
||||
return <Navigate to="/home/account/acontest" />
|
||||
if (!refactor) {
|
||||
return <Navigate to="/home/account/acontest" />;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const status = useAppSelector(
|
||||
(state) => state.contests.createContest.status,
|
||||
);
|
||||
|
||||
|
||||
|
||||
const [missionIdInput, setMissionIdInput] = useState<string>('');
|
||||
|
||||
|
||||
const [contest, setContest] = useState<CreateContestBody>({
|
||||
name: '',
|
||||
description: '',
|
||||
@@ -67,9 +59,12 @@ const ContestEditor = () => {
|
||||
|
||||
const [missions, setMissions] = useState<Mission[]>([]);
|
||||
|
||||
|
||||
const statusDelete = useAppSelector((state) => state.contests.deleteContest.status)
|
||||
const statusUpdate = useAppSelector((state) => state.contests.updateContest.status);
|
||||
const statusDelete = useAppSelector(
|
||||
(state) => state.contests.deleteContest.status,
|
||||
);
|
||||
const statusUpdate = useAppSelector(
|
||||
(state) => state.contests.updateContest.status,
|
||||
);
|
||||
|
||||
const { contest: contestById, status: contestByIdstatus } = useAppSelector(
|
||||
(state) => state.contests.fetchContestById,
|
||||
@@ -85,15 +80,13 @@ const ContestEditor = () => {
|
||||
};
|
||||
|
||||
const handleUpdateContest = () => {
|
||||
dispatch(updateContest({...contest, contestId}));
|
||||
dispatch(updateContest({ ...contest, contestId }));
|
||||
};
|
||||
|
||||
|
||||
const handleDeleteContest = () => {
|
||||
dispatch(deleteContest(contestId));
|
||||
};
|
||||
|
||||
|
||||
|
||||
const addMission = () => {
|
||||
const id = Number(missionIdInput.trim());
|
||||
if (!id || contest.missionIds?.includes(id)) return;
|
||||
@@ -121,19 +114,22 @@ const ContestEditor = () => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (statusDelete == "successful"){
|
||||
dispatch(setContestStatus({key: "deleteContest", status: "idle"}))
|
||||
navigate('/home/account/contests')
|
||||
if (statusDelete == 'successful') {
|
||||
dispatch(
|
||||
setContestStatus({ key: 'deleteContest', status: 'idle' }),
|
||||
);
|
||||
navigate('/home/account/contests');
|
||||
}
|
||||
}, [statusDelete])
|
||||
}, [statusDelete]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (statusUpdate == "successful"){
|
||||
dispatch(setContestStatus({key: "updateContest", status: "idle"}))
|
||||
navigate('/home/account/contests')
|
||||
if (statusUpdate == 'successful') {
|
||||
dispatch(
|
||||
setContestStatus({ key: 'updateContest', status: 'idle' }),
|
||||
);
|
||||
navigate('/home/account/contests');
|
||||
}
|
||||
}, [statusUpdate])
|
||||
}, [statusUpdate]);
|
||||
|
||||
useEffect(() => {
|
||||
if (refactor) {
|
||||
@@ -146,8 +142,10 @@ const ContestEditor = () => {
|
||||
setContest({
|
||||
...contestById,
|
||||
// groupIds: contestById.groups.map(group => group.groupId),
|
||||
missionIds: contestById.missions?.map(mission => mission.id),
|
||||
articleIds: contestById.articles?.map(article => article.articleId),
|
||||
missionIds: contestById.missions?.map((mission) => mission.id),
|
||||
articleIds: contestById.articles?.map(
|
||||
(article) => article.articleId,
|
||||
),
|
||||
visibility: 'Public',
|
||||
scheduleType: 'AlwaysOpen',
|
||||
});
|
||||
@@ -300,19 +298,17 @@ const ContestEditor = () => {
|
||||
|
||||
{/* Кнопки */}
|
||||
<div className="flex flex-row w-full items-center justify-end mt-[20px] gap-[20px]">
|
||||
|
||||
<PrimaryButton
|
||||
onClick={handleUpdateContest}
|
||||
text="Сохранить"
|
||||
disabled={status === 'loading'}
|
||||
/>
|
||||
<ReverseButton
|
||||
color="error"
|
||||
onClick={handleDeleteContest}
|
||||
text="Удалить"
|
||||
disabled={statusDelete === 'loading'}
|
||||
/>
|
||||
|
||||
<PrimaryButton
|
||||
onClick={handleUpdateContest}
|
||||
text="Сохранить"
|
||||
disabled={status === 'loading'}
|
||||
/>
|
||||
<ReverseButton
|
||||
color="error"
|
||||
onClick={handleDeleteContest}
|
||||
text="Удалить"
|
||||
disabled={statusDelete === 'loading'}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user