This commit is contained in:
Виталий Лавшонок
2025-12-09 16:24:40 +03:00
parent 46e27616b2
commit 4391114dc3
5 changed files with 114 additions and 127 deletions

View File

@@ -1,38 +1,35 @@
// DateInput.tsx
import React from 'react';
interface DateInputProps {
label?: string;
value?: string;
defaultValue?: string;
onChange: (value: string) => void;
className?: string;
label?: string;
value?: string;
defaultValue?: string;
onChange: (value: string) => void;
className?: string;
}
const DateInput: React.FC<DateInputProps> = ({
label = 'Дата',
value,
defaultValue,
onChange,
className = '',
label = 'Дата',
value,
defaultValue,
onChange,
className = '',
}) => {
return (
<div className={`flex flex-col gap-1 ${className}`}>
<label className="block text-sm font-medium text-gray-700">
{label}
</label>
<input
type="datetime-local"
value={value}
defaultValue={defaultValue}
onChange={(e) => onChange(e.target.value)}
className="mt-1 block w-full rounded-md border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
/>
</div>
);
return (
<div className={`flex flex-col gap-1 ${className}`}>
<label className="block text-sm font-medium text-gray-700">
{label}
</label>
<input
type="datetime-local"
value={value}
defaultValue={defaultValue}
onChange={(e) => onChange(e.target.value)}
className="mt-1 block w-full rounded-md border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
/>
</div>
);
};
export default DateInput;

View File

@@ -43,16 +43,14 @@ const ContestEditor = () => {
const [missionIdInput, setMissionIdInput] = useState<string>('');
const now = new Date();
const plus60 = new Date(now.getTime() + 60 * 60 * 1000);
const toLocal = (d: Date) => {
const off = d.getTimezoneOffset();
const local = new Date(d.getTime() - off * 60000);
return local.toISOString().slice(0, 16);
};
const now = new Date();
const plus60 = new Date(now.getTime() + 60 * 60 * 1000);
const toLocal = (d: Date) => {
const off = d.getTimezoneOffset();
const local = new Date(d.getTime() - off * 60000);
return local.toISOString().slice(0, 16);
};
const [contest, setContest] = useState<CreateContestBody>({
name: '',

View File

@@ -2,7 +2,10 @@ import { useEffect } from 'react';
import { useAppDispatch, useAppSelector } from '../../../redux/hooks';
import { setMenuActivePage } from '../../../redux/slices/store';
import { Navigate, Route, Routes, useParams } from 'react-router-dom';
import { fetchContestById, fetchMyAttemptsInContest } from '../../../redux/slices/contests';
import {
fetchContestById,
fetchMyAttemptsInContest,
} from '../../../redux/slices/contests';
import ContestMissions from './Missions';
import Submissions from './Submissions';

View File

@@ -1,7 +1,4 @@
import {
FilterDropDown,
FilterItem,
} from '../../../components/filters/Filter';
import { FilterDropDown, FilterItem } from '../../../components/filters/Filter';
import { SorterDropDown } from '../../../components/filters/Sorter';
import { SearchInput } from '../../../components/input/SearchInput';

View File

@@ -9,10 +9,12 @@ import {
setContestStatus,
} from '../../../redux/slices/contests';
import { CreateContestBody } from '../../../redux/slices/contests';
import DateRangeInput from '../../../components/input/DateRangeInput';
import { useNavigate } from 'react-router-dom';
import { NumberInput } from '../../../components/input/NumberInput';
import { DropDownList, DropDownListItem } from '../../../components/filters/DropDownList';
import {
DropDownList,
DropDownListItem,
} from '../../../components/filters/DropDownList';
import DateInput from '../../../components/input/DateInput';
import { cn } from '../../../lib/cn';
@@ -42,25 +44,24 @@ const ModalCreateContest: FC<ModalCreateContestProps> = ({
);
const visibilityItems: DropDownListItem[] = [
{ value: "Public", text: "Публичный"},
{ value: "GroupPrivate", text: "Для группы"},
]
{ value: 'Public', text: 'Публичный' },
{ value: 'GroupPrivate', text: 'Для группы' },
];
const scheduleTypeItems: DropDownListItem[] = [
{value: "AlwaysOpen", text: "Всегда открыт"},
{value: "FixedWindow", text: "Фиксированое окно"},
{value: "RollingWindow", text: "Скользящее окно"},
]
{ value: 'AlwaysOpen', text: 'Всегда открыт' },
{ value: 'FixedWindow', text: 'Фиксированое окно' },
{ value: 'RollingWindow', text: 'Скользящее окно' },
];
const now = new Date();
const plus60 = new Date(now.getTime() + 60 * 60 * 1000);
const plus60 = new Date(now.getTime() + 60 * 60 * 1000);
const toLocal = (d: Date) => {
const off = d.getTimezoneOffset();
const local = new Date(d.getTime() - off * 60000);
return local.toISOString().slice(0, 16);
};
const toLocal = (d: Date) => {
const off = d.getTimezoneOffset();
const local = new Date(d.getTime() - off * 60000);
return local.toISOString().slice(0, 16);
};
const [form, setForm] = useState<CreateContestBody>({
name: '',
@@ -105,7 +106,6 @@ return local.toISOString().slice(0, 16);
);
};
return (
<Modal
className="bg-liquid-background border-liquid-lighter border-[2px] p-[25px] rounded-[20px] text-liquid-white"
@@ -136,24 +136,19 @@ return local.toISOString().slice(0, 16);
onChange={(v) => handleChange('description', v)}
/>
<div className="grid grid-cols-2 gap-[10px] mt-[10px]">
<div>
<label className="block text-sm mb-1">
Тип контеста
</label>
<DropDownList
items={scheduleTypeItems}
onChange={(v) => {
handleChange("scheduleType", v);
}}
weight='w-full'
/>
items={scheduleTypeItems}
onChange={(v) => {
handleChange('scheduleType', v);
}}
weight="w-full"
/>
{/* <select
className="w-full p-2 rounded-md bg-liquid-darker border border-liquid-lighter"
@@ -178,13 +173,13 @@ return local.toISOString().slice(0, 16);
<div>
<label className="block text-sm mb-1">Видимость</label>
<DropDownList
items={visibilityItems}
onChange={(v) => {
handleChange("visibility", v);
}}
weight='w-full'
/>
<DropDownList
items={visibilityItems}
onChange={(v) => {
handleChange('visibility', v);
}}
weight="w-full"
/>
{/* <select
className="w-full p-2 rounded-md bg-liquid-darker border border-liquid-lighter"
value={form.visibility}
@@ -212,60 +207,59 @@ return local.toISOString().slice(0, 16);
/>
</div> */}
<div
className={cn(
' grid grid-flow-row grid-rows-[0fr] opacity-0 transition-all duration-200',
form.visibility == "GroupPrivate" && 'grid-rows-[1fr] opacity-100',
)}
>
<div className="overflow-hidden">
<div className='grid grid-cols-2 gap-[10px] mt-[10px]'>
<NumberInput
defaultState={form.groupId??1}
name="groupId"
label="Id группы"
placeholder="Например: 3"
minValue={1}
maxValue={1000000000000000}
onChange={(v) => handleChange('groupId', Number(v))}
/>
</div></div>
<div
className={cn(
' grid grid-flow-row grid-rows-[0fr] opacity-0 transition-all duration-200',
form.visibility == 'GroupPrivate' &&
'grid-rows-[1fr] opacity-100',
)}
>
<div className="overflow-hidden">
<div className="grid grid-cols-2 gap-[10px] mt-[10px]">
<NumberInput
defaultState={form.groupId ?? 1}
name="groupId"
label="Id группы"
placeholder="Например: 3"
minValue={1}
maxValue={1000000000000000}
onChange={(v) =>
handleChange('groupId', Number(v))
}
/>
</div>
</div>
</div>
{/* Даты */}
<div
className={cn(
' grid grid-flow-row grid-rows-[0fr] opacity-0 transition-all duration-200',
form.scheduleType != "AlwaysOpen" && 'grid-rows-[1fr] opacity-100',
)}
>
<div className="overflow-hidden">
<div className="grid grid-cols-2 gap-[10px] mt-[10px]">
<DateInput
label="Дата начала"
value={form.startsAt}
onChange={(v) => handleChange('startsAt', v)}
/>
<DateInput
label="Дата окончания"
value={form.endsAt}
onChange={(v) => handleChange('endsAt', v)}
/>
</div>
</div>
{/* Даты */}
<div
className={cn(
' grid grid-flow-row grid-rows-[0fr] opacity-0 transition-all duration-200',
form.scheduleType != 'AlwaysOpen' &&
'grid-rows-[1fr] opacity-100',
)}
>
<div className="overflow-hidden">
<div className="grid grid-cols-2 gap-[10px] mt-[10px]">
<DateInput
label="Дата начала"
value={form.startsAt}
onChange={(v) => handleChange('startsAt', v)}
/>
<DateInput
label="Дата окончания"
value={form.endsAt}
onChange={(v) => handleChange('endsAt', v)}
/>
</div>
</div>
</div>
{/* Продолжительность и лимиты */}
<div className="grid grid-cols-2 gap-[10px] mt-[10px]">
<NumberInput
defaultState={form.attemptDurationMinutes}
defaultState={form.attemptDurationMinutes}
name="attemptDurationMinutes"
label="Длительность попытки (мин)"
placeholder="Например: 60"
@@ -276,7 +270,7 @@ onChange={(v) => handleChange('endsAt', v)}
}
/>
<NumberInput
defaultState={form.maxAttempts}
defaultState={form.maxAttempts}
name="maxAttempts"
label="Макс. попыток"
placeholder="Например: 3"
@@ -286,8 +280,6 @@ onChange={(v) => handleChange('endsAt', v)}
/>
</div>
{/* Разрешить раннее завершение */}
{/* <div className="flex items-center gap-[10px] mt-[15px]">
<input