mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-22 22:07:10 +00:00
feat: access to competition is blocked if it is ended
This commit is contained in:
@@ -13,7 +13,13 @@ import { useUserStore } from "@/shared/stores/user";
|
||||
|
||||
const Header = () => {
|
||||
const user = useUserStore((state) => state.user);
|
||||
const clearUser = useUserStore((state) => state.clearUser);
|
||||
const [isProfileOpen, setIsProfileOpen] = useState(false);
|
||||
|
||||
const handleLogout = () => {
|
||||
clearUser();
|
||||
setIsProfileOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<header className="bg-card sticky top-0 z-30 flex h-[72px] w-full items-center justify-center px-4 sm:px-6">
|
||||
@@ -69,9 +75,7 @@ const Header = () => {
|
||||
<ProfileOption
|
||||
icon={<LogOut size={18} />}
|
||||
label="Выйти"
|
||||
onClick={() => {
|
||||
setIsProfileOpen(false);
|
||||
}}
|
||||
onClick={handleLogout}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useParams, Link, useNavigate } from "react-router-dom";
|
||||
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 { useQuery, useMutation } from "@tanstack/react-query";
|
||||
import { getCompetition, startCompetition } from "@/shared/api/competitions";
|
||||
@@ -39,6 +39,7 @@ const CompetitionPage = () => {
|
||||
console.error("Failed to start competition:", error);
|
||||
}
|
||||
});
|
||||
|
||||
const formatDate = (date?: Date | string) => {
|
||||
if (!date) return "";
|
||||
|
||||
@@ -56,6 +57,20 @@ const CompetitionPage = () => {
|
||||
const handleStart = () => {
|
||||
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) {
|
||||
return <Loading />;
|
||||
@@ -66,6 +81,7 @@ const CompetitionPage = () => {
|
||||
}
|
||||
|
||||
const competition = competitionQuery.data;
|
||||
const competitionEnded = isCompetitionEnded();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
@@ -103,6 +119,12 @@ const CompetitionPage = () => {
|
||||
</>
|
||||
)}
|
||||
</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>
|
||||
|
||||
<h1 className="text-[34px] leading-11 font-semibold text-balance">
|
||||
@@ -133,13 +155,24 @@ const CompetitionPage = () => {
|
||||
</div>
|
||||
|
||||
<div className="w-full *:w-full md:w-96">
|
||||
<Button
|
||||
size={"lg"}
|
||||
onClick={handleStart}
|
||||
disabled={startMutation.isPending}
|
||||
>
|
||||
{startMutation.isPending ? "Загрузка..." : "Приступить к выполнению"}
|
||||
</Button>
|
||||
{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
|
||||
size={"lg"}
|
||||
onClick={handleStart}
|
||||
disabled={startMutation.isPending}
|
||||
>
|
||||
{startMutation.isPending ? "Загрузка..." : "Приступить к выполнению"}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ interface UserState {
|
||||
loading: boolean;
|
||||
|
||||
fetchUser: () => Promise<void>;
|
||||
clearUser: () => void;
|
||||
}
|
||||
|
||||
const useUserStore = create<UserState>((set) => ({
|
||||
@@ -18,6 +19,10 @@ const useUserStore = create<UserState>((set) => ({
|
||||
const user = await getCurrentUser();
|
||||
set({ user, loading: false });
|
||||
},
|
||||
|
||||
clearUser: () => {
|
||||
set({ user: null });
|
||||
},
|
||||
}));
|
||||
|
||||
export { useUserStore };
|
||||
export { useUserStore };
|
||||
Reference in New Issue
Block a user