Skip to content

Commit

Permalink
Merge pull request #50 from Princekumarofficial/faculty-view
Browse files Browse the repository at this point in the history
Faculty view
  • Loading branch information
AryanGKulkarni authored Jun 16, 2024
2 parents fb894c7 + bf9cd44 commit 415cd80
Show file tree
Hide file tree
Showing 15 changed files with 1,284 additions and 141 deletions.
21 changes: 21 additions & 0 deletions public/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions public/profile-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions public/tick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/app/(routes)/faculty/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Link from "next/link";

interface Props {
children: React.ReactNode;
}

const FacultyLayout = ({ children }: Props) => {
return <div>{children}</div>;
};

export default FacultyLayout;
82 changes: 82 additions & 0 deletions src/app/(routes)/faculty/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"use client";
import { fetchApprovals, updateApproval } from "@/helpers/faculty/api";
import Cookies from "js-cookie";
import TableComponent from "@/components/TableComponent/TableComponent";
import generateColumns from "@/components/TableComponent/ColumnMapping";
import { useState, useEffect } from "react";
import loadingImg from "@/components/Faculty/loadingSpinner.svg";

const dto = [
{
status: "string",
remarks: "string",
faculty: {
department: "string",
user: {
email: "string",
name: "string",
contact: "string",
},
},
salary: {
salaryPeriod: "string",
totalCTC: "number",
job: {
role: "string",
joiningDate: "string",
season: {
year: "string",
type: "string",
},
company: {
name: "string",
},
},
},
},
];

const dynamicColumns = generateColumns(dto);

const FacultyPage = () => {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);

useEffect(() => {
const fetchData = async () => {
try {
const jsonData = await fetchApprovals(
Cookies.get("accessToken"),
undefined
);
setData(jsonData);
} catch (error) {
console.error("Error fetching data:", error);
} finally {
setLoading(false);
}
};

fetchData();
}, []);
return (
<div className="md:m-12 m-2">
<h1 className="text-center font-bold text-3xl my-5 py-5">Approvals</h1>
<div>
{loading && (
<img src={loadingImg.src} alt="" className="mx-auto my-auto" />
)}
{data && (
<TableComponent
data={data}
columns={dynamicColumns}
dto={dto}
isFeedbackForm={true}
/>
)}
</div>
</div>
);
};

export default FacultyPage;
31 changes: 31 additions & 0 deletions src/app/(routes)/faculty/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use client";

import React, { useEffect, useState } from "react";
import FacultyProfile from "@/components/Faculty/Profile";
import { fetchProfile } from "@/helpers/faculty/api";
import Cookies from "js-cookie";
import loadingImg from "@/components/Faculty/loadingSpinner.svg";
import { ProfileFC } from "@/helpers/faculty/api";

const Profile = ({ params }: { params: { facultyId: string } }) => {
const [data, setData] = useState<ProfileFC>();
const [loading, setLoading] = useState(true);

useEffect(() => {
const profileData = async () => {
const jsonData = await fetchProfile(Cookies.get("accessToken"));
setData(jsonData);
setLoading(false);
};
profileData();
}, []);

return (
<div className="h-screen grid justify-center items-center">
{loading && <img src={loadingImg.src} />}
{data && <FacultyProfile profile={data} />}
</div>
);
};

export default Profile;
164 changes: 164 additions & 0 deletions src/components/Faculty/FeedbackFrom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import {
Dialog,
DialogOverlay,
DialogContent,
DialogTrigger,
DialogClose,
DialogHeader,
DialogTitle,
DialogDescription,
} from "../ui/dialog";
import TextArea from "antd/es/input/TextArea";
import { Button } from "@/components/ui/button";
import { useState, useEffect } from "react";
import { updateApproval } from "@/helpers//faculty/api";
import Cookies from "js-cookie";
import tick from "@/../public/tick.svg";
import cross from "@/../public/cross.svg";

interface ButtonProps {
children?: React.ReactNode;
rows?: any[];
remarks?: string;
finalButton: boolean;
}

const UpdateApprovalPATCH = (rows: any[], remarks: string, status: string) => {
var allAppArray: any[] = [];
for (var i = 0; i < rows.length; i++) {
allAppArray.push({ id: rows[i].id, remarks, status });
}
updateApproval(Cookies.get("accessToken"), allAppArray);
window.location.reload();
};

const AcceptButton: React.FC<ButtonProps> = ({
rows = [],
children,
remarks = "",
finalButton,
}) => {
return (
<Button
variant={"default"}
className="bg-sky-600 mx-4 hover:bg-blue-600"
onClick={() => {
if (finalButton) {
UpdateApprovalPATCH(rows, remarks, "APPROVED");
}
}}
>
Approve
<img src={tick.src} />
</Button>
);
};

const RejectButton: React.FC<ButtonProps> = ({
rows = [],
children,
remarks = "",
finalButton,
}) => {
return (
<Button
variant={"destructive"}
className="bg-red-500 hover:bg-red-400"
onClick={() => {
if (finalButton) {
UpdateApprovalPATCH(rows, remarks, "REJECTED");
}
}}
>
Reject
<img src={cross.src} alt="" />
</Button>
);
};

interface Props {
checkedRows: any[]; // Define the prop type as an array of any type
}

const FeedbackForm: React.FC<Props> = ({ checkedRows }) => {
const [isClient, setIsClient] = useState(false);

useEffect(() => {
setIsClient(true);
}, []);

const [feedbackText, setFeedbackText] = useState("");

return (
<>
<h4 className="font-semibold text-base my-3">Write Feedback</h4>
<TextArea
placeholder="Write Your Feedback Here"
name="feedback"
rows={4}
className="mb-3 w-full"
id="feedback"
value={feedbackText}
onChange={(e) => setFeedbackText(e.target.value)}
/>
<div className="flex flex-row">
<Dialog>
<DialogTrigger asChild>
<div>
{isClient ? (
<AcceptButton finalButton={false} />
) : (
<div>none</div>
)}
</div>
</DialogTrigger>
<DialogContent className="text-black">
Are you sure to Accept the Request?
<DialogClose asChild>
<div>
{isClient ? (
<AcceptButton
rows={checkedRows}
remarks={feedbackText}
finalButton
/>
) : (
<div>none</div>
)}
</div>
</DialogClose>
</DialogContent>
</Dialog>
<Dialog>
<DialogTrigger asChild>
<div>
{isClient ? (
<RejectButton finalButton={false} />
) : (
<div>none</div>
)}
</div>
</DialogTrigger>
<DialogContent className="text-black">
Are you sure to Reject the Request?
<DialogClose asChild>
<div>
{isClient ? (
<RejectButton
rows={checkedRows}
remarks={feedbackText}
finalButton
/>
) : (
<div>none</div>
)}
</div>
</DialogClose>
</DialogContent>
</Dialog>
</div>
</>
);
};

export default FeedbackForm;
Loading

0 comments on commit 415cd80

Please sign in to comment.