mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 02:47:10 +00:00
feat: access to competition is blocked if it is ended
This commit is contained in:
@@ -13,8 +13,14 @@ import { useUserStore } from "@/shared/stores/user";
|
|||||||
|
|
||||||
const Header = () => {
|
const Header = () => {
|
||||||
const user = useUserStore((state) => state.user);
|
const user = useUserStore((state) => state.user);
|
||||||
|
const clearUser = useUserStore((state) => state.clearUser);
|
||||||
const [isProfileOpen, setIsProfileOpen] = useState(false);
|
const [isProfileOpen, setIsProfileOpen] = useState(false);
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
clearUser();
|
||||||
|
setIsProfileOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="bg-card sticky top-0 z-30 flex h-[72px] w-full items-center justify-center px-4 sm:px-6">
|
<header className="bg-card sticky top-0 z-30 flex h-[72px] w-full items-center justify-center px-4 sm:px-6">
|
||||||
<div className="flex w-full max-w-5xl items-center justify-between">
|
<div className="flex w-full max-w-5xl items-center justify-between">
|
||||||
@@ -69,9 +75,7 @@ const Header = () => {
|
|||||||
<ProfileOption
|
<ProfileOption
|
||||||
icon={<LogOut size={18} />}
|
icon={<LogOut size={18} />}
|
||||||
label="Выйти"
|
label="Выйти"
|
||||||
onClick={() => {
|
onClick={handleLogout}
|
||||||
setIsProfileOpen(false);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useParams, Link, useNavigate } from "react-router-dom";
|
import { useParams, Link, useNavigate } from "react-router-dom";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { ArrowLeft, Clock, Trophy, BookOpen } from "lucide-react";
|
import { ArrowLeft, Clock, Trophy, BookOpen, BarChart2 } from "lucide-react";
|
||||||
import ReactMarkdown from "react-markdown";
|
import ReactMarkdown from "react-markdown";
|
||||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||||
import { getCompetition, startCompetition } from "@/shared/api/competitions";
|
import { getCompetition, startCompetition } from "@/shared/api/competitions";
|
||||||
@@ -39,6 +39,7 @@ const CompetitionPage = () => {
|
|||||||
console.error("Failed to start competition:", error);
|
console.error("Failed to start competition:", error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const formatDate = (date?: Date | string) => {
|
const formatDate = (date?: Date | string) => {
|
||||||
if (!date) return "";
|
if (!date) return "";
|
||||||
|
|
||||||
@@ -57,6 +58,20 @@ const CompetitionPage = () => {
|
|||||||
startMutation.mutate();
|
startMutation.mutate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleViewResults = () => {
|
||||||
|
navigate(`/competition/${competitionId}/results`);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if competition has ended
|
||||||
|
const isCompetitionEnded = () => {
|
||||||
|
if (!competitionQuery.data?.end_date) return false;
|
||||||
|
|
||||||
|
const endDate = new Date(competitionQuery.data.end_date);
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
return now > endDate;
|
||||||
|
};
|
||||||
|
|
||||||
if (competitionQuery.isLoading) {
|
if (competitionQuery.isLoading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
@@ -66,6 +81,7 @@ const CompetitionPage = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const competition = competitionQuery.data;
|
const competition = competitionQuery.data;
|
||||||
|
const competitionEnded = isCompetitionEnded();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
@@ -103,6 +119,12 @@ const CompetitionPage = () => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{competitionEnded && competition.type === CompetitionType.COMPETITIVE && (
|
||||||
|
<div className="bg-red-100 text-red-700 px-3 py-1 rounded-full text-sm font-medium">
|
||||||
|
Завершено
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h1 className="text-[34px] leading-11 font-semibold text-balance">
|
<h1 className="text-[34px] leading-11 font-semibold text-balance">
|
||||||
@@ -133,6 +155,16 @@ const CompetitionPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full *:w-full md:w-96">
|
<div className="w-full *:w-full md:w-96">
|
||||||
|
{competitionEnded && competition.type === CompetitionType.COMPETITIVE ? (
|
||||||
|
<Button
|
||||||
|
size={"lg"}
|
||||||
|
onClick={handleViewResults}
|
||||||
|
className="bg-indigo-600 hover:bg-indigo-700"
|
||||||
|
>
|
||||||
|
<BarChart2 size={18} className="mr-2" />
|
||||||
|
Смотреть результаты
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
<Button
|
<Button
|
||||||
size={"lg"}
|
size={"lg"}
|
||||||
onClick={handleStart}
|
onClick={handleStart}
|
||||||
@@ -140,6 +172,7 @@ const CompetitionPage = () => {
|
|||||||
>
|
>
|
||||||
{startMutation.isPending ? "Загрузка..." : "Приступить к выполнению"}
|
{startMutation.isPending ? "Загрузка..." : "Приступить к выполнению"}
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ interface UserState {
|
|||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
|
||||||
fetchUser: () => Promise<void>;
|
fetchUser: () => Promise<void>;
|
||||||
|
clearUser: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useUserStore = create<UserState>((set) => ({
|
const useUserStore = create<UserState>((set) => ({
|
||||||
@@ -18,6 +19,10 @@ const useUserStore = create<UserState>((set) => ({
|
|||||||
const user = await getCurrentUser();
|
const user = await getCurrentUser();
|
||||||
set({ user, loading: false });
|
set({ user, loading: false });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearUser: () => {
|
||||||
|
set({ user: null });
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export { useUserStore };
|
export { useUserStore };
|
||||||
Reference in New Issue
Block a user