Add ettempts in contests
This commit is contained in:
@@ -3,12 +3,12 @@ import { Account } from '../../../assets/icons/auth';
|
||||
import { PrimaryButton } from '../../../components/button/PrimaryButton';
|
||||
import { ReverseButton } from '../../../components/button/ReverseButton';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { toastSuccess, toastWarning } from '../../../lib/toastNotification';
|
||||
import { toastWarning } from '../../../lib/toastNotification';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useAppDispatch, useAppSelector } from '../../../redux/hooks';
|
||||
import { addOrUpdateContestMember } from '../../../redux/slices/contests';
|
||||
|
||||
export type Role = "None" | "Participant" | "Organizer";
|
||||
export type Role = 'None' | 'Participant' | 'Organizer';
|
||||
|
||||
export interface ContestItemProps {
|
||||
id: number;
|
||||
@@ -67,31 +67,29 @@ const ContestItem: React.FC<ContestItemProps> = ({
|
||||
|
||||
const waitTime = new Date(startAt).getTime() - now.getTime();
|
||||
|
||||
const [myRole, setMyRole] = useState<Role>("None");
|
||||
const [myRole, setMyRole] = useState<Role>('None');
|
||||
|
||||
const userId = useAppSelector((state) => state.auth.id);
|
||||
const {contests: contestsRegistered} = useAppSelector((state) => state.contests.fetchParticipating);
|
||||
const {contests: contestsMy} = useAppSelector((state) => state.contests.fetchMyContests);
|
||||
|
||||
const { contests: contestsRegistered } = useAppSelector(
|
||||
(state) => state.contests.fetchParticipating,
|
||||
);
|
||||
const { contests: contestsMy } = useAppSelector(
|
||||
(state) => state.contests.fetchMyContests,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!contestsRegistered || contestsRegistered.length === 0) {
|
||||
setMyRole("None");
|
||||
setMyRole('None');
|
||||
return;
|
||||
}
|
||||
|
||||
const reg = contestsRegistered.find(c => c.id === id);
|
||||
const my = contestsMy.find(c => c.id === id);
|
||||
|
||||
if (my)
|
||||
setMyRole("Organizer");
|
||||
else if (reg)
|
||||
setMyRole("Participant");
|
||||
else
|
||||
setMyRole("None");
|
||||
}, [contestsRegistered])
|
||||
|
||||
const reg = contestsRegistered.find((c) => c.id === id);
|
||||
const my = contestsMy.find((c) => c.id === id);
|
||||
|
||||
if (my) setMyRole('Organizer');
|
||||
else if (reg) setMyRole('Participant');
|
||||
else setMyRole('None');
|
||||
}, [contestsRegistered]);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -104,9 +102,9 @@ const ContestItem: React.FC<ContestItemProps> = ({
|
||||
: ' bg-liquid-background',
|
||||
)}
|
||||
onClick={() => {
|
||||
if (myRole == 'None'){
|
||||
toastWarning("Зарегистрируйтесь на контест");
|
||||
return;
|
||||
if (myRole == 'None') {
|
||||
toastWarning('Зарегистрируйтесь на контест');
|
||||
return;
|
||||
}
|
||||
navigate(`/contest/${id}`);
|
||||
}}
|
||||
@@ -133,15 +131,30 @@ const ContestItem: React.FC<ContestItemProps> = ({
|
||||
{myRole == 'None' ? (
|
||||
<>
|
||||
{' '}
|
||||
<PrimaryButton onClick={() => {
|
||||
dispatch(addOrUpdateContestMember({contestId: id, member: {userId: Number(userId), role:"Participant"}}))
|
||||
}} text="Регистрация" />
|
||||
<PrimaryButton
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
addOrUpdateContestMember({
|
||||
contestId: id,
|
||||
member: {
|
||||
userId: Number(userId),
|
||||
role: 'Participant',
|
||||
},
|
||||
}),
|
||||
);
|
||||
}}
|
||||
text="Регистрация"
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{' '}
|
||||
<ReverseButton onClick={() => {
|
||||
navigate(`/contest/${id}`);}} text="Войти" />
|
||||
<ReverseButton
|
||||
onClick={() => {
|
||||
navigate(`/contest/${id}`);
|
||||
}}
|
||||
text="Войти"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,6 @@ import { cn } from '../../../lib/cn';
|
||||
import { ChevroneDown } from '../../../assets/icons/groups';
|
||||
import ContestItem from './ContestItem';
|
||||
import { Contest } from '../../../redux/slices/contests';
|
||||
import { useAppSelector } from '../../../redux/hooks';
|
||||
|
||||
interface ContestsBlockProps {
|
||||
contests: Contest[];
|
||||
@@ -58,8 +57,12 @@ const ContestsBlock: FC<ContestsBlockProps> = ({
|
||||
name={v.name}
|
||||
startAt={v.startsAt ?? new Date().toString()}
|
||||
duration={
|
||||
new Date(v.endsAt ?? new Date().toString()).getTime() -
|
||||
new Date(v.startsAt ?? new Date().toString()).getTime()
|
||||
new Date(
|
||||
v.endsAt ?? new Date().toString(),
|
||||
).getTime() -
|
||||
new Date(
|
||||
v.startsAt ?? new Date().toString(),
|
||||
).getTime()
|
||||
}
|
||||
members={v.members?.length ?? 0}
|
||||
type={i % 2 ? 'second' : 'first'}
|
||||
|
||||
Reference in New Issue
Block a user