@@ -4,6 +4,9 @@ import { getFirestore, doc, getDoc, getDocs } from "firebase/firestore";
4
4
import { collection , addDoc } from "firebase/firestore" ;
5
5
import { ToastContainer , toast } from "react-toastify" ;
6
6
import "react-toastify/dist/ReactToastify.css" ;
7
+ import { TiEdit } from "react-icons/ti" ;
8
+
9
+ import { FiDelete } from "react-icons/fi" ;
7
10
8
11
const Tasks = ( ) => {
9
12
const [ userData , setUserData ] = useState ( null ) ;
@@ -28,6 +31,20 @@ const Tasks = () => {
28
31
setUserRole ( userData . role ) ;
29
32
setUserFormType ( userData . role + "forms" ) ;
30
33
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 ) ;
31
48
} else {
32
49
console . log ( "No such document!" ) ;
33
50
}
@@ -39,38 +56,8 @@ const Tasks = () => {
39
56
fetchUserData ( ) ;
40
57
} , [ ] ) ;
41
58
42
- console . log ( userFormType ) ;
43
-
44
59
///fethch all forms from tthis user from the userFormType collection
45
60
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
-
74
61
console . log ( userForms [ 0 ] ) ;
75
62
76
63
return (
@@ -85,8 +72,8 @@ const Tasks = () => {
85
72
< div className = "place-items-start align-top items-center" >
86
73
< SideBar />
87
74
</ 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 >
90
77
</ div >
91
78
</ div >
92
79
< div className = "flex flex-col gap-5" >
@@ -103,7 +90,67 @@ const Tasks = () => {
103
90
</ p >
104
91
</ div >
105
92
{ /* 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 >
107
154
</ div >
108
155
</ div >
109
156
</ div >
0 commit comments