From c761f337b1da8f018d5b8c280413dc433ff0eeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9=20=D0=9B=D0=B0?= =?UTF-8?q?=D0=B2=D1=88=D0=BE=D0=BD=D0=BE=D0=BA?= <114582703+valavshonok@users.noreply.github.com> Date: Wed, 10 Dec 2025 02:37:16 +0300 Subject: [PATCH] group drop down list --- src/pages/ContestEditor.tsx | 84 ++++++++++++++++++------- src/views/home/contests/ModalCreate.tsx | 74 +++++++++++++++++----- 2 files changed, 122 insertions(+), 36 deletions(-) diff --git a/src/pages/ContestEditor.tsx b/src/pages/ContestEditor.tsx index 527eba1..03bfd7e 100644 --- a/src/pages/ContestEditor.tsx +++ b/src/pages/ContestEditor.tsx @@ -21,6 +21,7 @@ import { import { NumberInput } from '../components/input/NumberInput'; import { cn } from '../lib/cn'; import DateInput from '../components/input/DateInput'; +import { fetchMyGroups } from '../redux/slices/groups'; interface Mission { id: number; @@ -92,7 +93,7 @@ const ContestEditor = () => { missionIds: [], articleIds: [], }); - + const myname = useAppSelector((state) => state.auth.username); const [missions, setMissions] = useState([]); const statusDelete = useAppSelector( @@ -106,6 +107,16 @@ const ContestEditor = () => { (state) => state.contests.fetchContestById, ); + const myGroups = useAppSelector( + (state) => state.groups.fetchMyGroups.groups, + ).filter((group) => + group.members.some( + (member) => + member.username === myname && + member.role.includes('Administrator'), + ), + ); + function toLocalInputValue(utcString: string) { const d = new Date(utcString); @@ -193,6 +204,7 @@ const ContestEditor = () => { useEffect(() => { if (refactor && contestByIdstatus == 'successful' && contestById) { + dispatch(fetchMyGroups()); setContest({ ...contestById, // groupIds: contestById.groups.map(group => group.groupId), @@ -205,8 +217,6 @@ const ContestEditor = () => { } }, [contestById]); - console.log(contest); - const visibilityDefaultState = visibilityItems.find( (i) => contest && i.value === contest.visibility, @@ -217,6 +227,17 @@ const ContestEditor = () => { (i) => contest && i.value === contest.scheduleType, ) ?? scheduleTypeItems[0]; + const groupItems = myGroups.map((v) => { + return { + value: '' + v.id, + text: v.name, + }; + }); + const groupIdDefaultState = + myGroups.find((g) => g.id == contest?.groupId) ?? + myGroups[0] ?? + undefined; + return (
navigate(back || '/home/contests')} /> @@ -287,29 +308,50 @@ const ContestEditor = () => {
-
-
- - handleChange( - 'groupId', - Number(v), - ) - } - /> + {groupIdDefaultState ? ( +
+
+ + + { + handleChange( + 'groupId', + Number(v), + ); + }} + weight="w-full" + /> +
-
+ ) : ( +
+
+ У вас нет группы вкоторой вы + являетесь Администратором! +
+
+ )}
{/* Даты */} diff --git a/src/views/home/contests/ModalCreate.tsx b/src/views/home/contests/ModalCreate.tsx index aa2d212..21ea94e 100644 --- a/src/views/home/contests/ModalCreate.tsx +++ b/src/views/home/contests/ModalCreate.tsx @@ -17,6 +17,7 @@ import { } from '../../../components/input/DropDownList'; import DateInput from '../../../components/input/DateInput'; import { cn } from '../../../lib/cn'; +import { fetchMyGroups } from '../../../redux/slices/groups'; function toUtc(localDateTime?: string): string { if (!localDateTime) return ''; @@ -80,6 +81,16 @@ const ModalCreateContest: FC = ({ const contest = useAppSelector( (state) => state.contests.createContest.contest, ); + const myname = useAppSelector((state) => state.auth.username); + const myGroups = useAppSelector( + (state) => state.groups.fetchMyGroups.groups, + ).filter((group) => + group.members.some( + (member) => + member.username === myname && + member.role.includes('Administrator'), + ), + ); useEffect(() => { if (status === 'successful') { @@ -92,6 +103,12 @@ const ModalCreateContest: FC = ({ } }, [status]); + useEffect(() => { + if (active) { + dispatch(fetchMyGroups()); + } + }, [active]); + const handleChange = (key: keyof CreateContestBody, value: any) => { setForm((prev) => ({ ...prev, [key]: value })); }; @@ -105,7 +122,16 @@ const ModalCreateContest: FC = ({ }), ); }; + const groupItems = myGroups.map((v) => { + return { + value: '' + v.id, + text: v.name, + }; + }); + const groupIdDefaultState = + myGroups.find((g) => g.id == form?.groupId) ?? myGroups[0] ?? undefined; + console.log(groupItems, myGroups, groupIdDefaultState); return ( = ({
-
-
- - handleChange('groupId', Number(v)) - } - /> + {groupIdDefaultState ? ( +
+
+ + + { + handleChange('groupId', Number(v)); + }} + weight="w-full" + /> +
-
+ ) : ( +
+
+ У вас нет группы вкоторой вы являетесь + Администратором! +
+
+ )}
{/* Даты */}