|
6 | 6 | import React, { useState, useEffect } from 'react';
|
7 | 7 | import { useQuery } from '@apollo/client';
|
8 | 8 | import { GET_LOGIN_ACTIVITIES } from '../queries/manageStudent.queries';
|
| 9 | +import LoginActivitiesSkeleton from '../Skeletons/loginActivities.skeleton'; |
9 | 10 |
|
10 | 11 | interface LoginActivitiesData {
|
11 | 12 | loginActivities: LoginActivity[];
|
@@ -99,78 +100,88 @@ const LoginActivitiesTable: React.FC = () => {
|
99 | 100 | const displayActivities = loginActivities.slice(startIndex, endIndex);
|
100 | 101 | console.log('displayActivities', displayActivities);
|
101 | 102 |
|
102 |
| - if (loading && page === 1) { |
103 |
| - return <div>Loading login activities...</div>; |
104 |
| - } |
105 |
| - |
106 |
| - /* istanbul ignore next */ |
107 |
| - if (error) { |
108 |
| - return <div>Error retrieving login activities.</div>; |
109 |
| - } |
110 |
| - |
111 |
| - /* istanbul ignore next */ |
112 |
| - if (displayActivities.length === 0) { |
113 |
| - return <div>No login activities yet.</div>; |
114 |
| - } |
115 |
| - |
116 | 103 | /* istanbul ignore next */
|
117 | 104 | return (
|
118 | 105 | <div className="flex flex-col items-center mt-4 font-serif">
|
119 |
| - <table className="w-full border border-gray-300"> |
120 |
| - <thead className="bg-[#163274a3] text-white"> |
121 |
| - <tr> |
122 |
| - <th className="py-2 px-4 border">Date</th> |
123 |
| - <th className="py-2 px-4 border">Country Name</th> |
124 |
| - <th className="py-2 px-4 border">City</th> |
125 |
| - <th className="py-2 px-4 border">State</th> |
126 |
| - <th className="py-2 px-4 border">IPv4</th> |
127 |
| - <th className="py-2 px-4 border">Attempt</th> |
128 |
| - </tr> |
129 |
| - </thead> |
130 |
| - <tbody> |
131 |
| - {displayActivities.map((activity, index) => ( |
132 |
| - <tr |
133 |
| - key={`${activity.date || index}-${activity.IPv4 || index}`} |
134 |
| - className="transition-colors duration-200" |
135 |
| - > |
136 |
| - <td className="py-2 px-4 border"> |
137 |
| - {new Date(Number(activity.date)).toLocaleString()} |
138 |
| - </td> |
139 |
| - <td className="py-2 px-4 border"> |
140 |
| - {activity.country_name || 'N/A'} |
141 |
| - </td> |
142 |
| - <td className="py-2 px-4 border">{activity.city || 'N/A'}</td> |
143 |
| - <td className="py-2 px-4 border">{activity.state || 'N/A'}</td> |
144 |
| - <td className="py-2 px-4 border">{activity.IPv4 || 'N/A'}</td> |
145 |
| - <td className="py-2 px-4 border"> |
146 |
| - {activity.failed > 0 ? 'Failed' : 'Success'} |
147 |
| - </td> |
148 |
| - </tr> |
149 |
| - ))} |
150 |
| - </tbody> |
151 |
| - </table> |
152 |
| - |
153 |
| - <div className="flex justify-center mb-20 mt-4"> |
154 |
| - <span className="mr-2 text-gray-600"> |
155 |
| - Page {page} of {totalPages} |
156 |
| - </span> |
157 |
| - {page > 1 && ( |
158 |
| - <button |
159 |
| - className="px-4 py-2 mr-2 font-bold text-white bg-gray-500 rounded" |
160 |
| - onClick={handleGoBack} |
161 |
| - > |
162 |
| - Previous |
163 |
| - </button> |
164 |
| - )} |
165 |
| - {page < totalPages && ( |
166 |
| - <button |
167 |
| - className="px-4 py-2 font-bold text-white bg-blue-500 rounded hover:bg-blue-700" |
168 |
| - onClick={handleLoadMore} |
169 |
| - > |
170 |
| - Next |
171 |
| - </button> |
172 |
| - )} |
173 |
| - </div> |
| 106 | + <h1 className="text-3xl font-bold font-lexend pb-3">Login Activities</h1> |
| 107 | + |
| 108 | + {/* eslint-disable-next-line no-nested-ternary */} |
| 109 | + {loading && page === 1 ? ( |
| 110 | + <div className="my-2 items-center"> |
| 111 | + <LoginActivitiesSkeleton /> |
| 112 | + </div> |
| 113 | + ) : /* eslint-disable-next-line no-nested-ternary */ |
| 114 | + error ? ( |
| 115 | + <div>Error retrieving login activities.</div> |
| 116 | + ) : displayActivities.length === 0 ? ( |
| 117 | + <div>No login activities yet.</div> |
| 118 | + ) : ( |
| 119 | + <> |
| 120 | + <div className="w-full overflow-x-auto"> |
| 121 | + <table className="w-full border border-gray-300 min-w-[800px]"> |
| 122 | + <thead className="bg-[#163274a3] text-white"> |
| 123 | + <tr> |
| 124 | + <th className="py-2 px-4 border">Date</th> |
| 125 | + <th className="py-2 px-4 border">Country Name</th> |
| 126 | + <th className="py-2 px-4 border">City</th> |
| 127 | + <th className="py-2 px-4 border">State</th> |
| 128 | + <th className="py-2 px-4 border">IPv4</th> |
| 129 | + <th className="py-2 px-4 border">Attempt</th> |
| 130 | + </tr> |
| 131 | + </thead> |
| 132 | + <tbody> |
| 133 | + {displayActivities.map((activity, index) => ( |
| 134 | + <tr |
| 135 | + key={`${activity.date || index}-${activity.IPv4 || index}`} |
| 136 | + className="transition-colors duration-200" |
| 137 | + > |
| 138 | + <td className="py-2 px-4 border"> |
| 139 | + {new Date(Number(activity.date)).toLocaleString()} |
| 140 | + </td> |
| 141 | + <td className="py-2 px-4 border"> |
| 142 | + {activity.country_name || 'N/A'} |
| 143 | + </td> |
| 144 | + <td className="py-2 px-4 border"> |
| 145 | + {activity.city || 'N/A'} |
| 146 | + </td> |
| 147 | + <td className="py-2 px-4 border"> |
| 148 | + {activity.state || 'N/A'} |
| 149 | + </td> |
| 150 | + <td className="py-2 px-4 border"> |
| 151 | + {activity.IPv4 || 'N/A'} |
| 152 | + </td> |
| 153 | + <td className="py-2 px-4 border"> |
| 154 | + {activity.failed > 0 ? 'Failed' : 'Success'} |
| 155 | + </td> |
| 156 | + </tr> |
| 157 | + ))} |
| 158 | + </tbody> |
| 159 | + </table> |
| 160 | + </div> |
| 161 | + |
| 162 | + <div className="flex justify-center mb-20 mt-4"> |
| 163 | + <span className="mr-2 text-gray-600"> |
| 164 | + Page {page} of {totalPages} |
| 165 | + </span> |
| 166 | + {page > 1 && ( |
| 167 | + <button |
| 168 | + className="px-4 py-2 mr-2 font-bold text-white bg-gray-500 rounded" |
| 169 | + onClick={handleGoBack} |
| 170 | + > |
| 171 | + Previous |
| 172 | + </button> |
| 173 | + )} |
| 174 | + {page < totalPages && ( |
| 175 | + <button |
| 176 | + className="px-4 py-2 font-bold text-white bg-blue-500 rounded hover:bg-blue-700" |
| 177 | + onClick={handleLoadMore} |
| 178 | + > |
| 179 | + Next |
| 180 | + </button> |
| 181 | + )} |
| 182 | + </div> |
| 183 | + </> |
| 184 | + )} |
174 | 185 | </div>
|
175 | 186 | );
|
176 | 187 | };
|
|
0 commit comments