From 9fa6bf36115b2cf5b5f083c159d33e09e9349202 Mon Sep 17 00:00:00 2001 From: Jacqueline Tuyisenge Date: Thu, 24 Oct 2024 11:59:20 +0200 Subject: [PATCH] fix(#404): add skeleton loader on login activities table --- src/Skeletons/loginActivities.skeleton.tsx | 49 +++++++ src/components/LoginActivitiesTable.tsx | 149 +++++++++++---------- 2 files changed, 129 insertions(+), 69 deletions(-) create mode 100644 src/Skeletons/loginActivities.skeleton.tsx diff --git a/src/Skeletons/loginActivities.skeleton.tsx b/src/Skeletons/loginActivities.skeleton.tsx new file mode 100644 index 00000000..d500714c --- /dev/null +++ b/src/Skeletons/loginActivities.skeleton.tsx @@ -0,0 +1,49 @@ +import React from 'react'; +import Skeleton from 'react-loading-skeleton'; +import 'react-loading-skeleton/dist/skeleton.css'; + +export default function LoginActivitiesSkeleton() { + // Define an array with unique keys + const skeletonRows = [{ id: 'row-1' }, { id: 'row-2' }, { id: 'row-3' }]; + + return ( +
+ + + + + + + + + + + + + {skeletonRows.map((row) => ( + + + + + + + + + ))} + +
DateCountry NameCityStateIPV4Attempt
+ + + + + + + + + + + +
+
+ ); +} diff --git a/src/components/LoginActivitiesTable.tsx b/src/components/LoginActivitiesTable.tsx index 70554559..e8b571a0 100644 --- a/src/components/LoginActivitiesTable.tsx +++ b/src/components/LoginActivitiesTable.tsx @@ -6,6 +6,7 @@ import React, { useState, useEffect } from 'react'; import { useQuery } from '@apollo/client'; import { GET_LOGIN_ACTIVITIES } from '../queries/manageStudent.queries'; +import LoginActivitiesSkeleton from '../Skeletons/loginActivities.skeleton'; interface LoginActivitiesData { loginActivities: LoginActivity[]; @@ -99,78 +100,88 @@ const LoginActivitiesTable: React.FC = () => { const displayActivities = loginActivities.slice(startIndex, endIndex); console.log('displayActivities', displayActivities); - if (loading && page === 1) { - return
Loading login activities...
; - } - - /* istanbul ignore next */ - if (error) { - return
Error retrieving login activities.
; - } - - /* istanbul ignore next */ - if (displayActivities.length === 0) { - return
No login activities yet.
; - } - /* istanbul ignore next */ return (
- - - - - - - - - - - - - {displayActivities.map((activity, index) => ( - - - - - - - - - ))} - -
DateCountry NameCityStateIPv4Attempt
- {new Date(Number(activity.date)).toLocaleString()} - - {activity.country_name || 'N/A'} - {activity.city || 'N/A'}{activity.state || 'N/A'}{activity.IPv4 || 'N/A'} - {activity.failed > 0 ? 'Failed' : 'Success'} -
- -
- - Page {page} of {totalPages} - - {page > 1 && ( - - )} - {page < totalPages && ( - - )} -
+

Login Activities

+ + {/* eslint-disable-next-line no-nested-ternary */} + {loading && page === 1 ? ( +
+ +
+ ) : /* eslint-disable-next-line no-nested-ternary */ + error ? ( +
Error retrieving login activities.
+ ) : displayActivities.length === 0 ? ( +
No login activities yet.
+ ) : ( + <> +
+ + + + + + + + + + + + + {displayActivities.map((activity, index) => ( + + + + + + + + + ))} + +
DateCountry NameCityStateIPv4Attempt
+ {new Date(Number(activity.date)).toLocaleString()} + + {activity.country_name || 'N/A'} + + {activity.city || 'N/A'} + + {activity.state || 'N/A'} + + {activity.IPv4 || 'N/A'} + + {activity.failed > 0 ? 'Failed' : 'Success'} +
+
+ +
+ + Page {page} of {totalPages} + + {page > 1 && ( + + )} + {page < totalPages && ( + + )} +
+ + )}
); };