Skip to content

Commit fc6309c

Browse files
committed
#172 Export CSV for trainee details
1 parent d048945 commit fc6309c

File tree

2 files changed

+96
-5
lines changed

2 files changed

+96
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"pusher": "^5.2.0",
126126
"pusher-js": "^8.4.0-rc2",
127127
"quill": "^2.0.2",
128+
"react-csv": "^2.2.2",
128129
"react-datepicker": "^4.8.0",
129130
"react-hook-form": "^7.45.4",
130131
"react-hot-toast": "^2.4.1",

src/components/TraineeDetail/decisionSection.tsx

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import { DownloadPdf } from "../../utils/DownloadPdf";
3+
import { TiExportOutline } from "react-icons/ti";
4+
import { AiFillCaretDown } from "react-icons/ai";
5+
import { CSVLink } from "react-csv"; // Import CSVLink
6+
import { Link } from "lucide-react";
37

48
interface TraineeDetails {
59
interview_decision: string;
@@ -8,6 +12,19 @@ interface TraineeDetails {
812
lastName: string;
913
firstName: string;
1014
};
15+
gender: string;
16+
Address: string;
17+
phone: string;
18+
field_of_study: string;
19+
education_level: string;
20+
province: string;
21+
district: string;
22+
sector: string;
23+
isEmployed: boolean;
24+
haveLaptop: boolean;
25+
isStudent: boolean;
26+
Hackerrank_score: any;
27+
english_score: any;
1128
}
1229

1330
interface DecisionButtonProps {
@@ -46,8 +63,65 @@ const DecisionButton: React.FC<DecisionButtonProps> = ({ decision }) => {
4663
);
4764
};
4865

66+
67+
const createCSVData = (traineeDetails: TraineeDetails) => {
68+
const { interview_decision, trainee_id, gender, Address, phone, field_of_study, education_level, province, district, sector, isEmployed, haveLaptop, isStudent, Hackerrank_score, english_score } = traineeDetails;
69+
const { email, firstName, lastName } = trainee_id;
70+
71+
72+
console.log(phone)
73+
return [
74+
[
75+
"First Name",
76+
"Last Name",
77+
"Email",
78+
"Gender",
79+
"Address",
80+
"Phone",
81+
"Field of Study",
82+
"Education Level",
83+
"Province",
84+
"District",
85+
"Sector",
86+
"Is Employed",
87+
"Have Laptop",
88+
"Is Student",
89+
"Hackerrank Score",
90+
"English Score",
91+
"Interview Decision",
92+
],
93+
[
94+
firstName,
95+
lastName,
96+
email,
97+
gender,
98+
Address,
99+
phone,
100+
field_of_study,
101+
education_level,
102+
province,
103+
district,
104+
sector,
105+
isEmployed ? "Yes" : "No",
106+
haveLaptop ? "Yes" : "No",
107+
isStudent ? "Yes" : "No",
108+
Hackerrank_score ?? "N/A",
109+
english_score ?? "N/A",
110+
interview_decision ?? "N/A",
111+
],
112+
];
113+
};
114+
115+
49116
const DecisionSection: React.FC<{ traineeDetails: TraineeDetails }> = ({ traineeDetails }) => {
50117
const { interview_decision, trainee_id } = traineeDetails;
118+
const [open, setOpen] = useState<boolean>(false);
119+
120+
const handleDropDown = (state: boolean) => {
121+
setOpen(!state);
122+
};
123+
124+
const csvData = createCSVData(traineeDetails);
51125

52126
return (
53127
<div className="w-full py-7 flex flex-col mx-16 bg-slate-200 rounded-xl shadow-md overflow-hidden md:max-w-2xl lg:flex lg:max-w-3xl dark:bg-[#192432] dark:text-white">
@@ -57,10 +131,26 @@ const DecisionSection: React.FC<{ traineeDetails: TraineeDetails }> = ({ trainee
57131
<div className="h-16 flex pl-6 items-center gap-5">
58132
<DecisionButton decision={interview_decision} />
59133
<button
60-
onClick={() => DownloadPdf()}
61-
className="btn-Aprov h-11 bg-blue-700 hover:bg-blue-600 dark:hover:bg-blue-600 text-white font-bold py-2 px-2 rounded dark:bg-blue-700"
134+
onClick={(e) => handleDropDown(open)}
135+
className="bg-[#56C870] hover:bg-[#1f544cef] text-white font-bold py-2 px-4 rounded mr-16"
62136
>
63-
Download PDF
137+
<TiExportOutline className="float-left m-1" />
138+
Export
139+
<AiFillCaretDown className="float-right m-1" />
140+
{open && (
141+
<ul className="bg-[#1F2A37] font-light text-sm text-white m-1 flex flex-col">
142+
<button className="border-solid border-black border-b-2 " onClick={() => DownloadPdf()}>
143+
Export to PDF
144+
</button>
145+
<CSVLink
146+
data={csvData}
147+
filename={"trainee-info.csv"}
148+
className="border-solid border-black border-b-2 p-2"
149+
>
150+
Export to CSV
151+
</CSVLink>
152+
</ul>
153+
)}
64154
</button>
65155
<button className="btn-Aprov h-11 bg-blue-500 hover:bg-blue-600 dark:hover:bg-blue-600 text-white font-bold py-2 px-8 rounded dark:bg-blue-500">
66156
<a
@@ -76,4 +166,4 @@ const DecisionSection: React.FC<{ traineeDetails: TraineeDetails }> = ({ trainee
76166
);
77167
};
78168

79-
export default DecisionSection;
169+
export default DecisionSection;

0 commit comments

Comments
 (0)