Skip to content

Commit 5da4f13

Browse files
committed
add new data form
1 parent af0a2c9 commit 5da4f13

File tree

1 file changed

+80
-33
lines changed

1 file changed

+80
-33
lines changed

frontend/src/pages/Private/Tasks.js

+80-33
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { getFirestore, doc, getDoc, getDocs } from "firebase/firestore";
44
import { collection, addDoc } from "firebase/firestore";
55
import { ToastContainer, toast } from "react-toastify";
66
import "react-toastify/dist/ReactToastify.css";
7+
import { TiEdit } from "react-icons/ti";
8+
9+
import { FiDelete } from "react-icons/fi";
710

811
const Tasks = () => {
912
const [userData, setUserData] = useState(null);
@@ -28,6 +31,20 @@ const Tasks = () => {
2831
setUserRole(userData.role);
2932
setUserFormType(userData.role + "forms");
3033
setUserEmail(userData.email);
34+
35+
// Fetch user forms from a separate collection
36+
const userFormsCollectionRef = collection(
37+
db,
38+
"users",
39+
userId,
40+
"forms"
41+
);
42+
const userFormsSnapshot = await getDocs(userFormsCollectionRef);
43+
const userFormsData = userFormsSnapshot.docs.map((doc) => doc.data());
44+
setUserForms(userFormsData);
45+
46+
console.log("User Data:", userData);
47+
console.log("User Forms:", userFormsData);
3148
} else {
3249
console.log("No such document!");
3350
}
@@ -39,38 +56,8 @@ const Tasks = () => {
3956
fetchUserData();
4057
}, []);
4158

42-
console.log(userFormType);
43-
4459
///fethch all forms from tthis user from the userFormType collection
4560

46-
useEffect(() => {
47-
const fetchUserForms = async () => {
48-
try {
49-
const db = getFirestore();
50-
const userFormsRef = collection(db, userFormType);
51-
const userFormsSnapshot = await getDocs(userFormsRef);
52-
53-
userFormsSnapshot.forEach((doc) => {
54-
const userFormData = doc.data();
55-
56-
//fetch all the forms for the user with the email
57-
if (userEmail === userFormData.userData.email) {
58-
console.log(userFormData);
59-
//insert the form data into the userForms state
60-
setUserForms((prev) => [...prev, userFormData]);
61-
}
62-
});
63-
64-
setUserForms(userFormsSnapshot);
65-
} catch (error) {
66-
console.error("Error fetching user forms:", error);
67-
}
68-
};
69-
if (userFormType) {
70-
fetchUserForms();
71-
}
72-
}, [userFormType]);
73-
7461
console.log(userForms[0]);
7562

7663
return (
@@ -85,8 +72,8 @@ const Tasks = () => {
8572
<div className="place-items-start align-top items-center">
8673
<SideBar />
8774
</div>
88-
<div className="bg-yellow-100 text-yellow-800 w-36 font-medium px-2.5 py-0.5 rounded-full text-md">
89-
{userRole} Account
75+
<div className="bg-yellow-100 text-yellow-800 w-40 flex gap-2 font-medium px-4 py-0.5 rounded-full text-md">
76+
{userRole} <span>Account</span>
9077
</div>
9178
</div>
9279
<div className="flex flex-col gap-5">
@@ -103,7 +90,67 @@ const Tasks = () => {
10390
</p>
10491
</div>
10592
{/* cards */}
106-
<div className=" mt-5 grid grid-cols-3 gap-5"></div>
93+
<div className="flex flex-col gap-5">
94+
<div className=" w-[1200px]">
95+
{userForms.map((formData, index) => (
96+
<div
97+
key={index}
98+
className="bg-white p-4 rounded-lg shadow-md flex flex-row justify-between gap-3 mt-5 hover:bg-slate-100 cursor-pointer transition duration-300 ease-in-out transform hover:-translate-y-1 hover:scale-101"
99+
>
100+
<div>
101+
<h3 className="text-lg font-semibold text-blue-700 ">
102+
Form Information {formData.formType}
103+
</h3>
104+
105+
<div className=" flex gap-10 mt-3 ">
106+
<p className=" bg-yellow-100 text-yellow-800 font-medium px-4 py-0.5 rounded-full text-md">
107+
{formData.userData.firstName}{" "}
108+
{formData.userData.lastName}
109+
</p>
110+
<p className=" bg-yellow-100 text-yellow-800 font-medium px-4 py-0.5 rounded-full text-md">
111+
{formData.userData.email}{" "}
112+
</p>
113+
<p className=" bg-yellow-100 text-yellow-800 font-medium px-4 py-0.5 rounded-full text-md">
114+
{formData.userData.department}{" "}
115+
</p>
116+
</div>
117+
<div className=" mt-5">
118+
<p className="pb-3 ">
119+
<h2 className=" mb-3">applications form</h2>
120+
{formData.selectedOption.map((option, index) => (
121+
<span
122+
className=" bg-blue-100 text-blue-800 font-medium px-4 py-0.5 rounded-full text-md"
123+
key={index}
124+
>
125+
{option}
126+
</span>
127+
))}
128+
</p>
129+
<hr />
130+
<p className="mt-3">
131+
Number Of Applicaions : {formData.numberOfApplication}{" "}
132+
</p>
133+
<p className=" mt-3 ">
134+
Number Of Applicaions : {formData.numberOfSections}{" "}
135+
</p>
136+
</div>
137+
</div>
138+
<section>
139+
<div className="flex flex-row justify-between items-center">
140+
<div className="flex gap-2">
141+
<button className="bg-red-100 text-red-800 flex items-center gap-4 font-medium px-4 py-2 rounded-full text-md">
142+
Delete <FiDelete />
143+
</button>
144+
<button className="bg-blue-100 text-blue-800 flex items-center gap-4 font-medium px-4 py-2 rounded-full text-md">
145+
Edit <TiEdit />
146+
</button>
147+
</div>
148+
</div>
149+
</section>
150+
</div>
151+
))}
152+
</div>
153+
</div>
107154
</div>
108155
</div>
109156
</div>

0 commit comments

Comments
 (0)