Skip to content

Commit

Permalink
Changes according to suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Princekumarofficial committed Jun 15, 2024
1 parent da35864 commit 40083e0
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 107 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.
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.
16 changes: 6 additions & 10 deletions src/app/(routes)/faculty/[facultyId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
"use client";
import { fetchApprovals, updateApproval } from "@/helpers/api";
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/[email protected] (1).svg";
import loadingImg from "@/components/Faculty/loadingSpinner.svg";

const dto = [
{
// id: "string",
status: "string",
remarks: "string",
faculty: {
// id: "string",
department: "string",
user: {
// id: "string",
email: "string",
name: "string",
contact: "string",
},
},
salary: {
// id: "string",
salaryPeriod: "string",
totalCTC: "number",
job: {
// id: "string",
role: "string",
joiningDate: "string",
season: {
// id: "string",
year: "string",
type: "string",
},
company: {
// id: "string",
name: "string",
},
},
Expand All @@ -52,7 +45,10 @@ const FacultyPage = () => {
useEffect(() => {
const fetchData = async () => {
try {
const jsonData = await fetchApprovals(undefined, undefined);
const jsonData = await fetchApprovals(
Cookies.get("accessToken"),
undefined
);
setData(jsonData);
} catch (error) {
console.error("Error fetching data:", error);
Expand Down
52 changes: 5 additions & 47 deletions src/components/Faculty/FeedbackFrom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import {
import TextArea from "antd/es/input/TextArea";
import { Button } from "@/components/ui/button";
import { useState, useEffect } from "react";
import { updateApproval } from "@/helpers/api";
import { updateApproval } from "@/helpers//faculty/api";
import Cookies from "js-cookie";
import { useRouter } from "next/navigation";
import tick from "@/../public/tick.svg";
import cross from "@/../public/cross.svg";

interface ButtonProps {
children?: React.ReactNode;
Expand Down Expand Up @@ -48,31 +50,7 @@ const AcceptButton: React.FC<ButtonProps> = ({
}}
>
Approve
<svg
xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
width="2rem"
height="2rem"
viewBox="0 0 40 40"
className="ml-2"
>
<path
fill="#8bb7f0"
d="M4.769,37.5c-1.251,0-2.269-1.018-2.269-2.269V4.769C2.5,3.518,3.518,2.5,4.769,2.5h30.462 c1.251,0,2.269,1.018,2.269,2.269v30.462c0,1.251-1.018,2.269-2.269,2.269H4.769z"
></path>
<path
fill="#4e7ab5"
d="M35.231,3C36.206,3,37,3.794,37,4.769v30.462C37,36.206,36.206,37,35.231,37H4.769 C3.794,37,3,36.206,3,35.231V4.769C3,3.794,3.794,3,4.769,3H35.231 M35.231,2H4.769C3.24,2,2,3.24,2,4.769v30.462 C2,36.76,3.24,38,4.769,38h30.462C36.76,38,38,36.76,38,35.231V4.769C38,3.24,36.76,2,35.231,2L35.231,2z"
></path>
<path
fill="none"
stroke="#fff"
strokeMiterlimit="10"
strokeWidth="3"
d="M11 20.053L16.964 26.018 30.385 12.598"
></path>
</svg>
<img src={tick.src} />
</Button>
);
};
Expand All @@ -94,27 +72,7 @@ const RejectButton: React.FC<ButtonProps> = ({
}}
>
Reject
<svg
xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
width="2rem"
height="2rem"
viewBox="0 0 48 48"
>
<path
fill="#f44336"
d="M44,24c0,11.045-8.955,20-20,20S4,35.045,4,24S12.955,4,24,4S44,12.955,44,24z"
></path>
<path
fill="#fff"
d="M29.656,15.516l2.828,2.828l-14.14,14.14l-2.828-2.828L29.656,15.516z"
></path>
<path
fill="#fff"
d="M32.484,29.656l-2.828,2.828l-14.14-14.14l2.828-2.828L32.484,29.656z"
></path>
</svg>
<img src={cross.src} alt="" />
</Button>
);
};
Expand Down
File renamed without changes
5 changes: 0 additions & 5 deletions src/components/TableComponent/TableComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ export default function TableComponent({
<Button
onClick={async () => {
setFilters([]);
// const AllStudents = await fetchStudentData(
// Cookies.get("accessToken"),
// undefined
// );
// setTableData(AllStudents);
}}
className="rounded-md ml-4 md:mx-2 bg-red-500 hover:bg-red-600 text-white"
>
Expand Down
45 changes: 0 additions & 45 deletions src/helpers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const fetchAllJobs = async (
redirect();
return;
}
console.log("filter", filter);
const res = await fetch(filter ? url(`/jobs?${filter}`) : url("/jobs"), {
next: { tags: ["AllJobs"] },
headers: {
Expand All @@ -63,7 +62,6 @@ export const fetchStudentData = async (
redirect();
return;
}
console.log("filter", filter);
const res = await fetch(
filter ? url(`/students?${filter}`) : url("/students"),
{
Expand Down Expand Up @@ -152,46 +150,3 @@ export const fetchJobEvents = async (
const json = await res.json();
return json;
};

export const fetchApprovals = async (
accessToken: string | undefined,
filter: string | undefined
) => {
if (!accessToken || accessToken === undefined) {
redirect();
return;
}
const res = await fetch(
filter ? url(`/faculty-approvals?${filter}`) : url("/faculty-approvals"),
{
next: { tags: ["AllApprovals"] },
cache: "no-store",
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
);
const json = await res.json();
return json;
};

export async function updateApproval(
accessToken: string | undefined,
data: any[]
) {
if (!accessToken || accessToken === undefined) {
redirect();
return;
}
fetch(url("/faculty-approvals"), {
method: "PATCH",
cache: "no-store",
headers: {
"Content-type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify(data),
}).then((response) => {
return response.ok;
});
}
51 changes: 51 additions & 0 deletions src/helpers/faculty/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const redirect = () => {};

const baseUrl = process.env.NEXT_PUBLIC_BACKEND_URL;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

const url = (NextUrl: string) => {
return `${baseUrl}/api/v1${NextUrl}`;
};

export const fetchApprovals = async (
accessToken: string | undefined,
filter: string | undefined
) => {
if (!accessToken || accessToken === undefined) {
redirect();
return;
}
const res = await fetch(
filter ? url(`/faculty-approvals?${filter}`) : url("/faculty-approvals"),
{
next: { tags: ["AllApprovals"] },
cache: "no-store",
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
);
const json = await res.json();
return json;
};

export async function updateApproval(
accessToken: string | undefined,
data: any[]
) {
if (!accessToken || accessToken === undefined) {
redirect();
return;
}
fetch(url("/faculty-approvals"), {
method: "PATCH",
cache: "no-store",
headers: {
"Content-type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify(data),
}).then((response) => {
return response.ok;
});
}

0 comments on commit 40083e0

Please sign in to comment.