From 6ad30b1e742e07956135516367b3482d15a4b6e3 Mon Sep 17 00:00:00 2001 From: PradeepKumarRebbavarapu Date: Fri, 12 Jan 2024 01:15:52 +0530 Subject: [PATCH] added key prop --- src/app/(routes)/admin/jobs/[jobId]/error.tsx | 15 --- src/app/(routes)/admin/jobs/[jobId]/page.tsx | 27 +++++- src/app/(routes)/admin/jobs/error.tsx | 15 --- src/app/(routes)/admin/students/error.tsx | 15 --- src/app/(routes)/admin/students/page.tsx | 2 +- .../Students/StudentsTable/StudentTable.tsx | 28 ++---- src/components/jobs/AddEventDialog.tsx | 95 +++++++++++++++++++ src/components/jobs/EventCard.tsx | 94 ++++++++++++++++++ src/components/jobs/JobDeleteModal.tsx | 90 ++++++++++++++++++ src/helpers/api.ts | 30 +++++- 10 files changed, 337 insertions(+), 74 deletions(-) delete mode 100644 src/app/(routes)/admin/jobs/[jobId]/error.tsx delete mode 100644 src/app/(routes)/admin/jobs/error.tsx delete mode 100644 src/app/(routes)/admin/students/error.tsx create mode 100644 src/components/jobs/AddEventDialog.tsx create mode 100644 src/components/jobs/EventCard.tsx create mode 100644 src/components/jobs/JobDeleteModal.tsx diff --git a/src/app/(routes)/admin/jobs/[jobId]/error.tsx b/src/app/(routes)/admin/jobs/[jobId]/error.tsx deleted file mode 100644 index 9631c501..00000000 --- a/src/app/(routes)/admin/jobs/[jobId]/error.tsx +++ /dev/null @@ -1,15 +0,0 @@ -"use client"; - -import React, { Component } from "react"; - -class Error extends Component { - render() { - return ( -
- Something went wrong! -
- ); - } -} - -export default Error; diff --git a/src/app/(routes)/admin/jobs/[jobId]/page.tsx b/src/app/(routes)/admin/jobs/[jobId]/page.tsx index 795d4d3c..1ea7d77d 100644 --- a/src/app/(routes)/admin/jobs/[jobId]/page.tsx +++ b/src/app/(routes)/admin/jobs/[jobId]/page.tsx @@ -1,8 +1,10 @@ import { Separator } from "@/components/ui/separator"; import { Jobs } from "../../../../../dummyData/job"; -import { fetchEachJob } from "@/helpers/api"; +import { fetchEachJob, fetchJobEvents } from "@/helpers/api"; import { cookies } from "next/headers"; import { Button } from "@/components/ui/button"; +import EventCard from "@/components/jobs/EventCard"; +import { AddEventDialog } from "@/components/jobs/AddEventDialog"; interface Props { params: { @@ -15,6 +17,8 @@ const EachJobPage = async ({ params }: Props) => { cookies()?.get("accessToken")?.value, params.jobId, ); + + const AllEvents = await fetchJobEvents(cookies()?.get("accessToken")?.value, params.jobId) return (
@@ -66,15 +70,28 @@ const EachJobPage = async ({ params }: Props) => {
  • have relevant skills and interests
  • +
    +

    Our Events

    +
    + {AllEvents?.event?.map((ele: any, index: number) => { + return ( +
    + +
    + ) + })} +
    +
    - - -
    + + + +
    - + ); diff --git a/src/app/(routes)/admin/jobs/error.tsx b/src/app/(routes)/admin/jobs/error.tsx deleted file mode 100644 index 9631c501..00000000 --- a/src/app/(routes)/admin/jobs/error.tsx +++ /dev/null @@ -1,15 +0,0 @@ -"use client"; - -import React, { Component } from "react"; - -class Error extends Component { - render() { - return ( -
    - Something went wrong! -
    - ); - } -} - -export default Error; diff --git a/src/app/(routes)/admin/students/error.tsx b/src/app/(routes)/admin/students/error.tsx deleted file mode 100644 index 9631c501..00000000 --- a/src/app/(routes)/admin/students/error.tsx +++ /dev/null @@ -1,15 +0,0 @@ -"use client"; - -import React, { Component } from "react"; - -class Error extends Component { - render() { - return ( -
    - Something went wrong! -
    - ); - } -} - -export default Error; diff --git a/src/app/(routes)/admin/students/page.tsx b/src/app/(routes)/admin/students/page.tsx index 4a6fff95..bb57034e 100644 --- a/src/app/(routes)/admin/students/page.tsx +++ b/src/app/(routes)/admin/students/page.tsx @@ -10,7 +10,7 @@ const StudentPage = async () => {

    Students

    - +
    ); diff --git a/src/components/Students/StudentsTable/StudentTable.tsx b/src/components/Students/StudentsTable/StudentTable.tsx index afc93437..f5f0e6c1 100644 --- a/src/components/Students/StudentsTable/StudentTable.tsx +++ b/src/components/Students/StudentsTable/StudentTable.tsx @@ -51,7 +51,7 @@ interface Student { totalPenalty: number; createdAt: string; updatedAt: string; - member: { + user: { id: string; email: string; name: string; @@ -114,14 +114,14 @@ export const columns: ColumnDef[] = [ enableHiding: false, }, { - accessorKey: "name", + accessorKey: "user.name", header: "Name", - cell: ({ row }) =>
    {row.getValue("name")}
    , + cell: ({ row }) =>
    {row.original.user.name}
    , }, { accessorKey: "rollNo", header: "Roll Number", - cell: ({ row }) =>
    {row.getValue("rollNo")}
    , + cell: ({ row }) =>
    {row.getValue('rollNo')}
    , }, { accessorKey: "category", @@ -129,9 +129,9 @@ export const columns: ColumnDef[] = [ cell: ({ row }) =>
    {row.getValue("category")}
    , }, { - accessorKey: "member.email", + accessorKey: "user.email", header: "Email", - cell: ({ row }) =>
    {row.original.member.email}
    , + cell: ({ row }) =>
    {row.original.user.email}
    , }, { accessorKey: "gender", @@ -139,19 +139,9 @@ export const columns: ColumnDef[] = [ cell: ({ row }) =>
    {row.getValue("gender")}
    , }, { - accessorKey: "branch", - header: "Branch", - cell: ({ row }) =>
    {row.getValue("branch")}
    , - }, - { - accessorKey: "graduationYear", - header: "Graduation Year", - cell: ({ row }) =>
    {row.getValue("graduationYear")}
    , - }, - { - accessorKey: "currentCPI", - header: "Current CPI", - cell: ({ row }) =>
    {row.getValue("currentCPI")}
    , + accessorKey: "contact", + header: "Contact", + cell: ({ row }) =>
    {row.original.user.contact}
    , }, { id: "actions", diff --git a/src/components/jobs/AddEventDialog.tsx b/src/components/jobs/AddEventDialog.tsx new file mode 100644 index 00000000..c69a8b3f --- /dev/null +++ b/src/components/jobs/AddEventDialog.tsx @@ -0,0 +1,95 @@ +'use client' +import { Button } from "@/components/ui/button" +import Cookies from "js-cookie" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" +import axios from "axios" +import { useState } from "react" +import submit from "../action" + + +interface Props{ + jobId : String +} + +export function AddEventDialog({jobId}:Props) { + const [type,settype] = useState(null); + const [round,setround] = useState(null); + const [date,setdate] = useState(null); + const [loading,setloading] = useState(false); + return ( +
    + + + + + + + Add An Event + +
    +
    + + { + settype(e?.target?.value) + }} + className="col-span-3 text-black" + /> +
    +
    + + { + setround(e?.target?.value) + }} + /> +
    +
    + + { + setdate(e?.target?.value) + }} + className="col-span-3 text-black" + /> +
    +
    + + + +
    +
    +
    + ) +} diff --git a/src/components/jobs/EventCard.tsx b/src/components/jobs/EventCard.tsx new file mode 100644 index 00000000..d69ed52a --- /dev/null +++ b/src/components/jobs/EventCard.tsx @@ -0,0 +1,94 @@ +'use client' +import { MdDelete } from "react-icons/md"; +import { JobDeleteModal } from "./JobDeleteModal"; +export default function EventCard({ ele ,jobId}: any) { + var date = ele.startDateTime; + date = date.substring(0, 10).split('-') + date = date[1] + '-' + date[2] + '-' + date[0] + return ( +
    +
    +

    {ele?.type} +

    +

    Round Number : {ele?.roundNumber}

    + +
    + {date} +
    + +
    + +
    + +
    + +
    + ) +} diff --git a/src/components/jobs/JobDeleteModal.tsx b/src/components/jobs/JobDeleteModal.tsx new file mode 100644 index 00000000..960d5e94 --- /dev/null +++ b/src/components/jobs/JobDeleteModal.tsx @@ -0,0 +1,90 @@ +'use client' +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import submit from "../action" +import Cookies from "js-cookie" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" +import { useState } from "react" +import { MdDelete } from "react-icons/md"; +import axios from "axios" +import toast from "react-hot-toast" +interface Props { + jobId: string, + eventId: string, +} + +export function JobDeleteModal({ jobId, eventId }: Props) { + const [answer, setanswer] = useState(null) + const [loading,setloading] = useState(false) + const [open,setopen] = useState(false) + return ( + + +
    { + setopen(true) + }}>
    +
    + + + Delete Event + + type in Delete to confirm the delete + + +
    +
    + + { + if (e.target.value != "Delete") { + e.target.classList.add("!ring-red-600"); + e.target.classList.remove("!ring-green-600"); + } else { + e.target.classList.remove("!ring-red-600"); + e.target.classList.add("!ring-green-600"); + } + setanswer(e.target.value); + }} + id="name" + + className="col-span-3 text-black !w-full" + /> +
    + +
    + + + +
    +
    + ) +} diff --git a/src/helpers/api.ts b/src/helpers/api.ts index 26a43a78..97d1bcea 100644 --- a/src/helpers/api.ts +++ b/src/helpers/api.ts @@ -91,10 +91,13 @@ export const fetchStudentData = async (accessToken: string | undefined) => { redirect(); return; } - // const res = await fetch('') - // const json = res.json() - // return json - return StudentsData; + const res = await fetch('http://tpc.iiti.ac.in/api/v1/students',{ + headers:{ + Authorization:`Bearer ${accessToken}` + } + }) + const json = res.json() + return json }; export const fetchCompanyRecruiters = async ( @@ -147,4 +150,23 @@ export const fetchEachJob = async (accessToken:string | undefined,jobId:String | const json = res.json(); return json; +} + +export const fetchJobEvents = async (accessToken : string | undefined,jobId : String | undefined) =>{ + if(!accessToken || accessToken===undefined){ + redirect(); + return ; + } + const res = await fetch(`http://tpc.iiti.ac.in/api/v1/jobs/${jobId}/events`,{ + next: { + tags: ["AllEvents"], + }, + headers:{ + Authorization : `Bearer ${accessToken}` + }, + + }) + + const json = res.json() + return json } \ No newline at end of file