diff --git a/apps/web/app/(contest)/contests-dashboard/page.tsx b/apps/web/app/(contest)/contests-dashboard/page.tsx index 7ad7f37..c2b9f73 100644 --- a/apps/web/app/(contest)/contests-dashboard/page.tsx +++ b/apps/web/app/(contest)/contests-dashboard/page.tsx @@ -4,45 +4,15 @@ import SignInFirst from '@/components/SignInFirst' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card' import UserContestTable from '@/components/UserContestTable' +import { IContest, IProblems } from "@repo/common/types" import axios from 'axios' import { useSession } from 'next-auth/react' import Link from 'next/link' import { useEffect, useState } from 'react' -export interface Icontest { - id: string; - title: string; - description: string; - startTime: Date; - hidden: boolean; - endTime: Date; - createdAt: Date; - updatedAt: Date; - leaderboard: boolean; - authorId: string; -} - -export interface IContestProblem { - contestId: string; - problemId: string; -} - -export interface IProblems { - id: string; - title: string; - description: string; - hidden: boolean; - slug: string; - solved: number; - difficulty: string; - contests: IContestProblem[] -} - - - const ContestDashboardPage = () => { const { data, status } = useSession(); - const [contests, setContests] = useState([]); + const [contests, setContests] = useState([]); const [problems, setProblems] = useState([]); const [loading, setLoading] = useState(true); @@ -50,7 +20,7 @@ const ContestDashboardPage = () => { try { const fetchData = async () => { setLoading(true); - const contest: Icontest[] = (await axios.get(`api/contest`)).data; + const contest: IContest[] = (await axios.get(`api/contest`)).data; setContests(contest); const problems: IProblems[] = await (await axios.get(`api/problems`)).data @@ -93,7 +63,7 @@ const ContestDashboardPage = () => {
{contests.length !== 0 ? (
- +
) : ( diff --git a/apps/web/components/Contests.tsx b/apps/web/components/Contests.tsx index 781227e..778970b 100644 --- a/apps/web/components/Contests.tsx +++ b/apps/web/components/Contests.tsx @@ -1,14 +1,14 @@ "use client" import { useEffect, useState } from "react"; import { ContestCard } from "./ContestCard"; -import { Icontest } from "./SelectProblemsTable"; +import { IContest } from "@repo/common/types"; import axios from "axios"; import { toast } from "react-toastify"; import { Loader2 } from "lucide-react"; export function Contests() { - const [upcomingContests, setUpcomingContests] = useState([]); - const [pastContests, setPastContests] = useState([]); + const [upcomingContests, setUpcomingContests] = useState([]); + const [pastContests, setPastContests] = useState([]); const [isLoading, setIsLoading] = useState(false); useEffect(() => { @@ -55,7 +55,7 @@ export function Contests() { ); } -function ShowContest({ upcomingContests, pastContests }: { upcomingContests: Icontest[], pastContests: Icontest[] }) { +function ShowContest({ upcomingContests, pastContests }: { upcomingContests: IContest[], pastContests: IContest[] }) { return (
diff --git a/apps/web/components/CreaatedContest.tsx b/apps/web/components/CreaatedContest.tsx index fd06fe7..f423e06 100644 --- a/apps/web/components/CreaatedContest.tsx +++ b/apps/web/components/CreaatedContest.tsx @@ -1,12 +1,13 @@ -import { Icontest } from "@/app/(contest)/contests-dashboard/page" +import { IContest } from "@repo/common/types" import { Button } from "@/components/ui/button" import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import moment from "moment" import { useRouter } from "next/navigation" import { toast } from "react-toastify" +import { formatDateTime, convertToIST} from "@/lib/time" -export function CreaatedContest({ contest, numberOfProblem }: { contest: Icontest, numberOfProblem: number }) { +export function CreaatedContest({ contest, numberOfProblem }: { contest: IContest, numberOfProblem: number }) { const formattedDateTime = (date: Date) => { return moment(date).utcOffset("+05:30").format('DD / MM / YYYY - hh:mm A'); } diff --git a/apps/web/components/SelectProblemsTable.tsx b/apps/web/components/SelectProblemsTable.tsx index dddb1b3..55de874 100644 --- a/apps/web/components/SelectProblemsTable.tsx +++ b/apps/web/components/SelectProblemsTable.tsx @@ -1,40 +1,11 @@ "use client" import { Button } from "@/components/ui/button" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" +import { IProblems } from "@repo/common/types" import axios from 'axios' import React, { useEffect, useState } from 'react' import { toast } from "react-toastify" - -export interface Icontest { - id: string; - title: string; - description: string; - startTime: Date; - hidden: boolean; - endTime: Date; - createdAt: Date; - updatedAt: Date; - leaderboard: boolean; - authorId: string; -} - -export interface IContestProblem { - contestId: string; - problemId: string; -} - -export interface IProblems { - id: string; - title: string; - description: string; - hidden: boolean; - slug: string; - solved: number; - difficulty: string; - contests: IContestProblem[] -} - export function SelectProblemsTable({ contestId, hight, setNumberOfProblems }: { contestId: string, hight: number, diff --git a/apps/web/components/UserContestTable.tsx b/apps/web/components/UserContestTable.tsx index 1bd2755..0eda728 100644 --- a/apps/web/components/UserContestTable.tsx +++ b/apps/web/components/UserContestTable.tsx @@ -12,41 +12,14 @@ import { import { Input } from "@/components/ui/input" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import useConttestTable from "@/hooks/useUserContestTable" +import { IContest } from "@repo/common/types" import { TrashIcon } from "lucide-react" import Link from 'next/link' import React from 'react' -export interface Icontest { - id: string; - title: string; - description: string; - startTime: Date; - hidden: boolean; - endTime: Date; - createdAt: Date; - updatedAt: Date; - leaderboard: boolean; - authorId: string; -} -export interface IContestProblem { - contestId: string; - problemId: string; -} -export interface IProblems { - id: string; - title: string; - description: string; - hidden: boolean; - slug: string; - solved: number; - difficulty: string; - contests: IContestProblem[] -} - - -export default function UserContestTable({ contests, setContests }: { contests: Icontest[], setContests: React.Dispatch> }) { +export default function UserContestTable({ contests, setContests }: { contests: IContest[], setContests: React.Dispatch> }) { const { convertToIST, diff --git a/apps/web/hooks/useUserContestTable.ts b/apps/web/hooks/useUserContestTable.ts index 588e803..d82f302 100644 --- a/apps/web/hooks/useUserContestTable.ts +++ b/apps/web/hooks/useUserContestTable.ts @@ -1,42 +1,13 @@ +import { IContest } from "@repo/common/types" import axios from "axios" import moment from 'moment' import React, { useState } from 'react' import { toast } from "react-toastify" -export interface Icontest { - id: string; - title: string; - description: string; - startTime: Date; - hidden: boolean; - endTime: Date; - createdAt: Date; - updatedAt: Date; - leaderboard: boolean; - authorId: string; -} - -export interface IContestProblem { - contestId: string; - problemId: string; -} - -export interface IProblems { - id: string; - title: string; - description: string; - hidden: boolean; - slug: string; - solved: number; - difficulty: string; - contests: IContestProblem[] -} - - -export default function useConttestTable({ contests, setContests }: { contests: Icontest[], setContests: React.Dispatch> }) { +export default function useConttestTable({ contests, setContests }: { contests: IContest[], setContests: React.Dispatch> }) { const [editingContestId, setEditingContestId] = useState(null); - const [editingContest, setEditingContest] = useState(null); + const [editingContest, setEditingContest] = useState(null); const [numberOfProblem, setNumberOfProblems] = useState(0) const [deletingContestId, setDeletingContestId] = useState(null) diff --git a/apps/web/hooks/usecreateContest.ts b/apps/web/hooks/usecreateContest.ts index 69fa824..4705029 100644 --- a/apps/web/hooks/usecreateContest.ts +++ b/apps/web/hooks/usecreateContest.ts @@ -1,14 +1,14 @@ -import { Icontest, IProblems } from "@/app/(contest)/contests-dashboard/page" +import { IContest, IProblems } from "@repo/common/types" import axios from "axios" import { useEffect, useState } from "react" import { toast } from "react-toastify" export function useCreateContest() { - const [newContest, setNewContest] = useState() + const [newContest, setNewContest] = useState() const [numberOfProblem, setNumberOfProblems] = useState(0) const [problems, setProblems] = useState([]); const [loading, setLoading] = useState(true); - const [createContest, setCreateContest] = useState() + const [createContest, setCreateContest] = useState() useEffect(() => { try { @@ -34,15 +34,15 @@ export function useCreateContest() { console.log({ name, value, type }); if ((name === 'startTime' || name === 'endTime') && value !== '') { const formattedValue = new Date(value).toISOString(); - setCreateContest((prevState: Icontest | undefined) => ({ + setCreateContest((prevState: IContest | undefined) => ({ ...prevState, [name]: formattedValue - } as Icontest)); + } as IContest)); } else { - setCreateContest((prevState: Icontest | undefined) => ({ + setCreateContest((prevState: IContest | undefined) => ({ ...prevState, [name]: value - } as Icontest)); + } as IContest)); } } diff --git a/packages/common/package.json b/packages/common/package.json index 95dadae..1f146a7 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -2,7 +2,8 @@ "name": "@repo/common", "exports": { "./language": "./language/index.ts", - "./zod": "./zod/index.ts" + "./zod": "./zod/index.ts", + "./types": "./types/index.ts" }, "version": "1.0.0", "description": "", diff --git a/packages/common/types/index.ts b/packages/common/types/index.ts new file mode 100644 index 0000000..3860ab4 --- /dev/null +++ b/packages/common/types/index.ts @@ -0,0 +1,30 @@ +export interface IContest { + id: string; + title: string; + description: string; + startTime: Date; + hidden: boolean; + endTime: Date; + createdAt: Date; + updatedAt: Date; + leaderboard: boolean; + authorId: string; +} + +export interface IContestProblem { + contestId: string; + problemId: string; +} + +export interface IProblems { + id: string; + title: string; + description: string; + hidden: boolean; + slug: string; + solved: number; + difficulty: string; + contests: IContestProblem[] +} + +// Add other shared interfaces here \ No newline at end of file