1
- import React from 'react'
2
- import SideBar from '../../Components/Sidebar/SideBar'
1
+ import React , { useEffect , useState } from "react" ;
2
+ import SideBar from "../../Components/Sidebar/SideBar" ;
3
+ import { getFirestore , doc , getDoc , getDocs } from "firebase/firestore" ;
4
+ import { collection , addDoc } from "firebase/firestore" ;
5
+ import { ToastContainer , toast } from "react-toastify" ;
6
+ import "react-toastify/dist/ReactToastify.css" ;
7
+ import { TiEdit } from "react-icons/ti" ;
3
8
9
+ import { FiDelete } from "react-icons/fi" ;
10
+
11
+ const Tasks = ( ) => {
12
+ const [ userData , setUserData ] = useState ( null ) ;
13
+ const [ userRole , setUserRole ] = useState ( null ) ;
14
+ const [ userid , setUserId ] = useState ( null ) ;
15
+ const [ userFormType , setUserFormType ] = useState ( null ) ;
16
+ const [ userEmail , setUserEmail ] = useState ( null ) ;
17
+ const [ userForms , setUserForms ] = useState ( [ ] ) ;
18
+ useEffect ( ( ) => {
19
+ const fetchUserData = async ( ) => {
20
+ try {
21
+ const userId = localStorage . getItem ( "userId" ) ;
22
+ setUserId ( userId ) ;
23
+ console . log ( userId ) ;
24
+ const db = getFirestore ( ) ;
25
+ const userDataRef = doc ( db , "users" , userId ) ;
26
+
27
+ const userDataSnapshot = await getDoc ( userDataRef ) ;
28
+ if ( userDataSnapshot . exists ( ) ) {
29
+ const userData = userDataSnapshot . data ( ) ;
30
+ setUserData ( userData ) ;
31
+ setUserRole ( userData . role ) ;
32
+ setUserFormType ( userData . role + "forms" ) ;
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 ) ;
48
+ } else {
49
+ console . log ( "No such document!" ) ;
50
+ }
51
+ } catch ( error ) {
52
+ console . error ( "Error fetching user data:" , error ) ;
53
+ }
54
+ } ;
55
+
56
+ fetchUserData ( ) ;
57
+ } , [ ] ) ;
58
+
59
+ ///fethch all forms from tthis user from the userFormType collection
60
+
61
+ console . log ( userForms [ 0 ] ) ;
4
62
5
- const Favorites = ( ) => {
6
63
return (
7
64
< div className = "flex flex-row ml-10 mt-10" >
8
65
< div className = "" >
9
- < div className = "place-items-start align-top items-center" >
10
- < SideBar />
11
- </ div >
12
- < div className = " text-black w-64 h-full p-4" >
13
-
14
- </ div >
66
+ < div className = " text-black w-64 h-full p-4" > </ div >
15
67
</ div >
16
68
17
69
< div >
18
- < h1 > Favorites</ h1 >
70
+ < div className = "flex flex-col gap-10" >
71
+ < div >
72
+ < div className = "place-items-start align-top items-center" >
73
+ < SideBar />
74
+ </ div >
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 >
77
+ </ div >
78
+ </ div >
79
+ < div className = "flex flex-col gap-5" >
80
+ < div className = "flex flex-col gap-2" >
81
+ < h2 className = "text-2xl font-semibold text-yellow-500 " >
82
+ Here Are Some Forms Favourited By You
83
+ </ h2 >
84
+ < p className = "text-gray-500 " >
85
+ Apply for leave by filling in the form below and submitting it
86
+ to your department head. You will be notified of the status of
87
+ your application. And also, you can apply for a loan by filling
88
+ in the form below and submitting it to your department head. You
89
+ will be notified of the status of your application.
90
+ </ p >
91
+ </ div >
92
+ { /* cards */ }
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
+ Remove Form Favourites < TiEdit />
146
+ </ button >
147
+ </ div >
148
+ </ div >
149
+ </ section >
150
+ </ div >
151
+ ) ) }
152
+ </ div >
153
+ </ div >
154
+ </ div >
155
+ </ div >
19
156
</ div >
20
157
</ div >
21
-
22
- )
23
- }
158
+ ) ;
159
+ } ;
24
160
25
- export default Favorites
161
+ export default Tasks ;
0 commit comments