diff --git a/src/components/filters/DropDownList.tsx b/src/components/filters/DropDownList.tsx index ba4b5fc..eacb43e 100644 --- a/src/components/filters/DropDownList.tsx +++ b/src/components/filters/DropDownList.tsx @@ -32,8 +32,6 @@ export const DropDownList: React.FC = ({ ); const [active, setActive] = React.useState(false); - React.useEffect(() => onChange(value.value), [value]); - const ref = React.useRef(null); useClickOutside(ref, () => { @@ -63,7 +61,7 @@ export const DropDownList: React.FC = ({ @@ -78,7 +76,7 @@ export const DropDownList: React.FC = ({ : 'grid-rows-[0fr] opacity-0', )} > -
+
= ({ )} onClick={() => { setValue(v); + onChange(v.value); setActive(false); }} > diff --git a/src/components/input/DateInput.tsx b/src/components/input/DateInput.tsx index 9d3473e..4428b3b 100644 --- a/src/components/input/DateInput.tsx +++ b/src/components/input/DateInput.tsx @@ -18,7 +18,7 @@ const DateInput: React.FC = ({ }) => { return (
-
); diff --git a/src/pages/ContestEditor.tsx b/src/pages/ContestEditor.tsx index e1537c2..6dba45a 100644 --- a/src/pages/ContestEditor.tsx +++ b/src/pages/ContestEditor.tsx @@ -10,11 +10,17 @@ import { setContestStatus, updateContest, } from '../redux/slices/contests'; -import DateRangeInput from '../components/input/DateRangeInput'; import { useQuery } from '../hooks/useQuery'; import { Navigate, useNavigate } from 'react-router-dom'; import { fetchMissionById } from '../redux/slices/missions'; import { ReverseButton } from '../components/button/ReverseButton'; +import { + DropDownList, + DropDownListItem, +} from '../components/filters/DropDownList'; +import { NumberInput } from '../components/input/NumberInput'; +import { cn } from '../lib/cn'; +import DateInput from '../components/input/DateInput'; interface Mission { id: number; @@ -52,6 +58,17 @@ const ContestEditor = () => { return local.toISOString().slice(0, 16); }; + const visibilityItems: DropDownListItem[] = [ + { value: 'Public', text: 'Публичный' }, + { value: 'GroupPrivate', text: 'Для группы' }, + ]; + + const scheduleTypeItems: DropDownListItem[] = [ + { value: 'AlwaysOpen', text: 'Всегда открыт' }, + { value: 'FixedWindow', text: 'Фиксированое окно' }, + { value: 'RollingWindow', text: 'Скользящее окно' }, + ]; + const [contest, setContest] = useState({ name: '', description: '', @@ -78,6 +95,18 @@ const ContestEditor = () => { const { contest: contestById, status: contestByIdstatus } = useAppSelector( (state) => state.contests.fetchContestById, ); + + function toLocalInputValue(utcString: string) { + const d = new Date(utcString); + + const pad = (n: number) => n.toString().padStart(2, '0'); + + return ( + `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}` + + `T${pad(d.getHours())}:${pad(d.getMinutes())}` + ); + } + useEffect(() => { if (status === 'successful') { } @@ -154,13 +183,23 @@ const ContestEditor = () => { articleIds: contestById.articles?.map( (article) => article.articleId, ), - visibility: 'Public', - scheduleType: 'AlwaysOpen', }); setMissions(contestById.missions ?? []); } }, [contestById]); + console.log(contest); + + const visibilityDefaultState = + visibilityItems.find( + (i) => contest && i.value === contest.visibility, + ) ?? visibilityItems[0]; + + const scheduleTypeDefaultState = + scheduleTypeItems.find( + (i) => contest && i.value === contest.scheduleType, + ) ?? scheduleTypeItems[0]; + return (
navigate(back || '/home/contests')} /> @@ -201,73 +240,113 @@ const ContestEditor = () => {
- + + { + handleChange('scheduleType', v); + }} + weight="w-full" + />
- + { + handleChange('visibility', v); + }} + defaultState={visibilityDefaultState} + weight="w-full" + />
- {/* Даты начала и конца */} -
- +
+
+
+ + handleChange( + 'groupId', + Number(v), + ) + } + /> +
+
+
+ + {/* Даты */} +
+
+
+ + handleChange('startsAt', v) + } + /> + + + handleChange('endsAt', v) + } + /> +
+
{/* Продолжительность и лимиты */}
- handleChange( 'attemptDurationMinutes', @@ -275,35 +354,19 @@ const ContestEditor = () => { ) } /> - handleChange('maxAttempts', Number(v)) } />
- {/* Разрешить раннее завершение */} -
- - handleChange( - 'allowEarlyFinish', - e.target.checked, - ) - } - /> - -
- {/* Кнопки */}
= ({ }} weight="w-full" /> - - {/* */}
@@ -180,33 +160,9 @@ const ModalCreateContest: FC = ({ }} weight="w-full" /> - {/* */}
- {/* Даты начала и конца */} - {/*
- -
*/} -