From 952c69762897badee5709176b0a10aadd7330174 Mon Sep 17 00:00:00 2001 From: Gabriel-mdv Date: Fri, 1 Dec 2023 11:09:15 +0200 Subject: [PATCH] fixing errors that appear in the console log --- src/ProtectedRoute.tsx | 10 +- src/components/Organizations.tsx | 201 ++++++----- src/index.tsx | 1 + src/pages/AdminTraineeDashboard.tsx | 533 ++++++++++++++-------------- src/pages/Home.tsx | 1 + src/pages/Organization/Orglogin.tsx | 8 +- src/utils/validateOrgToken.tsx | 9 +- 7 files changed, 392 insertions(+), 371 deletions(-) diff --git a/src/ProtectedRoute.tsx b/src/ProtectedRoute.tsx index 56f9baf23..643507ca5 100644 --- a/src/ProtectedRoute.tsx +++ b/src/ProtectedRoute.tsx @@ -8,12 +8,12 @@ interface SomeType { } // eslint-disable-next-line react/prop-types export default function ProtectedRoutes(obj: SomeType) { - /* istanbul ignore if */ - if (window.location.pathname === '/users/login') { - /* istanbul ignore next */ - checkOrgTokenExpiration(); - } const { user } = useContext(UserContext); + /* istanbul ignore if */ + // if (window.location.pathname === '/users/login') { + /* istanbul ignore next */ + checkOrgTokenExpiration(); + // } if (!user?.auth) { return obj.children; } diff --git a/src/components/Organizations.tsx b/src/components/Organizations.tsx index f536eec47..3c688c69c 100644 --- a/src/components/Organizations.tsx +++ b/src/components/Organizations.tsx @@ -8,10 +8,11 @@ import CreateOrganizationModal, { import { gql, useMutation, useQuery } from '@apollo/client'; import useDocumentTitle from '../hook/useDocumentTitle'; import Button from './Buttons'; +import Tooltip from '@mui/material/Tooltip'; import { toast } from 'react-toastify'; import { Icon } from '@iconify/react'; -import DataTable from '../components/DataTable' +import DataTable from '../components/DataTable'; export interface Admin { id: string; @@ -66,84 +67,90 @@ export const RegisterNewOrganization = gql` `; function ActionButtons({ - getData, - setData, - removeInviteModel, - removeDeleteModel, - approveModel, - rejectModel, - ...props - }: any) { - const checkStatus = getData?.getOrganizations[props.row.index].status - return ( -
- {checkStatus == 'active' ? ( - <> -
{ - setData(getData?.getOrganizations[props.row.index]); - console.log(getData?.getOrganizations[props.row.index]) - removeInviteModel(); - }} - > - -
-
{ - setData(getData?.getOrganizations[props.row.index]); - removeDeleteModel(); - }} - > - -
- - ) : ( - <> -
{ - setData(getData?.getOrganizations[props.row.index]); - approveModel(); - }} - > - -
-
{ - setData(getData?.getOrganizations[props.row.index]); - rejectModel(); - }} - > - -
- - )} -
- ); - } + getData, + setData, + removeInviteModel, + removeDeleteModel, + approveModel, + rejectModel, + ...props +}: any) { + const checkStatus = getData?.getOrganizations[props.row.index].status; + return ( +
+ {checkStatus == 'active' ? ( + <> +
{ + setData(getData?.getOrganizations[props.row.index]); + console.log(getData?.getOrganizations[props.row.index]); + removeInviteModel(); + }} + > + + + +
+
{ + setData(getData?.getOrganizations[props.row.index]); + removeDeleteModel(); + }} + > + +
+ + ) : ( + <> +
{ + setData(getData?.getOrganizations[props.row.index]); + approveModel(); + }} + > + + + +
+
{ + setData(getData?.getOrganizations[props.row.index]); + rejectModel(); + }} + > + + + +
+ + )} +
+ ); +} const Organizations = () => { useDocumentTitle('Organizations'); @@ -174,8 +181,8 @@ const Organizations = () => { id: '', name: '', admin: { - id:'', - email:'' + id: '', + email: '', }, description: '', }); @@ -287,12 +294,14 @@ const Organizations = () => { }, ]; - const organizationData = getData?.getOrganizations.map(({ name, description, admin, status }) => ({ - name, - adminEmail: admin?.email, - description, - status, - })); + const organizationData = getData?.getOrganizations.map( + ({ name, description, admin, status }) => ({ + name, + adminEmail: admin?.email, + description, + status, + }), + ); return ( <> @@ -321,7 +330,9 @@ const Organizations = () => {

- {t('Are you sure you want to permanently delete this organization?')} + {t( + 'Are you sure you want to permanently delete this organization?', + )}

@@ -358,13 +369,13 @@ const Organizations = () => {
{/* =========================== End:: delete Session Model =============================== */} - {/* =========================== Start:: SendInviteModel =============================== */} + {/* =========================== Start:: SendInviteModel =============================== */} -
+

@@ -489,7 +500,7 @@ const Organizations = () => {

{t('Reject New Organization Request')} -

+


diff --git a/src/index.tsx b/src/index.tsx index c9ca158d5..120b208d4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,6 +18,7 @@ import { toast, ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import UserProvider from './hook/useAuth'; import { WebSocketLink } from '@apollo/client/link/ws'; +import { GraphQLWsLink } from '@apollo/client/link/subscriptions'; import { t } from 'i18next'; import { getMainDefinition } from '@apollo/client/utilities'; import App from './App'; diff --git a/src/pages/AdminTraineeDashboard.tsx b/src/pages/AdminTraineeDashboard.tsx index 5cdcd9373..8301ef267 100644 --- a/src/pages/AdminTraineeDashboard.tsx +++ b/src/pages/AdminTraineeDashboard.tsx @@ -639,181 +639,208 @@ function AdminTraineeDashboard() { fullWidth > - -
-
- Logo -
+ {/* */} +
+
+ Logo +
-

- {traineeDetails && traineeDetails.profile - ? traineeDetails.profile.name +

+ {traineeDetails && traineeDetails.profile + ? traineeDetails.profile.name + : 'Un availabe'} +

+ +
+ {' '} +

+ EMAIL{' '} +

+

+ + {' '} + {traineeDetails && traineeDetails.profile + ? traineeDetails.email + : 'Un availabe'} + +

+
+
+ {' '} +

+ START DATE +

+

+ {traineeDetails && traineeDetails.team + ? traineeDetails.team.cohort.startDate.split('T')[0] : 'Un availabe'} - +

+
+
+ {' '} +

+ PROGRAM{' '} +

+

+ + {' '} + {traineeDetails && traineeDetails.team + ? traineeDetails.team.cohort.program.name + : 'Un availabe'} + +

+
-
- {' '} -

- EMAIL{' '} -

-

- - {' '} - {traineeDetails && traineeDetails.profile - ? traineeDetails.email - : 'Un availabe'} - -

-
-
- {' '} -

- START DATE -

-

+

+ {' '} +

+ PHASE{' '} +

+

+ {traineeDetails && traineeDetails.team - ? traineeDetails.team.cohort.startDate.split('T')[0] + ? traineeDetails.team.cohort.phase.name : 'Un availabe'} -

-
-
- {' '} -

- PROGRAM{' '} -

-

- - {' '} - {traineeDetails && traineeDetails.team - ? traineeDetails.team.cohort.program.name - : 'Un availabe'} - -

-
+
+

+
-
- {' '} -

- PHASE{' '} -

-

- - {traineeDetails && traineeDetails.team - ? traineeDetails.team.cohort.phase.name - : 'Un availabe'} - -

-
+
+ {' '} +

+ COHORT{' '} +

+

+ + {' '} + {traineeDetails && traineeDetails.team + ? traineeDetails.team.cohort.name + : 'Un availabe'} + +

+
+
+ {' '} +

+ MANAGER{' '} +

+

+ + {' '} + {traineeDetails && traineeDetails.team + ? traineeDetails.team.cohort.program?.manager?.profile + .name + : 'Un availabe'} + +

+
-
- {' '} -

- COHORT{' '} -

-

- - {' '} - {traineeDetails && traineeDetails.team - ? traineeDetails.team.cohort.name - : 'Un availabe'} - -

-
-
- {' '} -

- MANAGER{' '} -

-

- - {' '} - {traineeDetails && traineeDetails.team - ? traineeDetails.team.cohort.program.manager.profile - .name - : 'Un availabe'} - -

-
+ {/* show coordinator */} +
+ {' '} +

+ COORDINATOR{' '} +

+

+ + {' '} + {traineeDetails && traineeDetails.cohort + ? traineeDetails.cohort.coordinator.profile.name + : 'Un availabe'} + +

+
- {/* show coordinator */} + {/* Show resume URL for admins and managers */} + {user && (user.role === 'admin' || user.role === 'coordinator') && (
- {' '}

- COORDINATOR{' '} + RESUME

- - {' '} - {traineeDetails && traineeDetails.cohort - ? traineeDetails.cohort.coordinator.profile.name - : 'Un availabe'} - + {traineeDetails?.profile?.resume ? ( + + View Resume + + ) : ( + 'Unavailable' + )}

- - {/* Show resume URL for admins and managers */} - {user && - (user.role === 'admin' || user.role === 'coordinator') && ( -
-

- RESUME -

-

- {traineeDetails?.profile?.resume ? ( - - View Resume - + )} + +

+ {isLoaded ? ( +
+ Loading gitHub statistics... + +
+
+ ) : ( +
+
+ + {gitHubStatistics?.totalCommits} total commits + +
+
+
+ {traineeDetails?.profile && + traineeDetails?.profile?.githubUsername ? ( + ) : ( - 'Unavailable' + <> )} -

-
- )} - -
- {isLoaded ? ( -

-

- Loading gitHub statistics... - -
-
-

- ) : ( -
-
- - {gitHubStatistics?.totalCommits} total commits - -
-
-
- {traineeDetails?.profile && - traineeDetails?.profile?.githubUsername ? ( - - ) : ( - <> - )} -
- )} -
- - +
+ )}
- + + +
+ {/* */}
@@ -1327,11 +1324,19 @@ function AdminTraineeDashboard() { data-testid="saveButton" style="w-[30%] md:w-1/4 text-sm font-sans" onClick={() => { - if (Object.values(email)[1] && Object.values(selectedOption)[1] && Object.values(selectedTeamOption)[1]) { + if ( + Object.values(email)[1] && + Object.values(selectedOption)[1] && + Object.values(selectedTeamOption)[1] + ) { setButtonLoading(true); addMemberToTeam(); - } else if (!Object.values(email)[1] || !Object.values(selectedOption)[1] || !Object.values(selectedTeamOption)[1]) { - toast.error(t("Enter all the required information")); + } else if ( + !Object.values(email)[1] || + !Object.values(selectedOption)[1] || + !Object.values(selectedTeamOption)[1] + ) { + toast.error(t('Enter all the required information')); } }} loading={buttonLoading} diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 9c2e5569a..3a803619e 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -19,6 +19,7 @@ function LandingPage() {

diff --git a/src/pages/Organization/Orglogin.tsx b/src/pages/Organization/Orglogin.tsx index cfe0fa303..190b2f296 100644 --- a/src/pages/Organization/Orglogin.tsx +++ b/src/pages/Organization/Orglogin.tsx @@ -187,10 +187,10 @@ function Orglogin() {

{t('Looking to register an organization instead?')} - - - {t('Register a new organization')} - + + {/* */} + {t('Register a new organization')} + {/* */}
diff --git a/src/utils/validateOrgToken.tsx b/src/utils/validateOrgToken.tsx index ff46f9fc3..6e9d27821 100644 --- a/src/utils/validateOrgToken.tsx +++ b/src/utils/validateOrgToken.tsx @@ -9,16 +9,18 @@ import React, { useContext } from 'react'; import { Navigate } from 'react-router'; import { UserContext } from '../hook/useAuth'; -const checkOrgTokenExpiration = async () => { +const checkOrgTokenExpiration = (): boolean | undefined => { const { t } = useTranslation(); const { logout } = useContext(UserContext); const token = window.localStorage.getItem('orgToken'); const orgName = window.localStorage.getItem('orgName'); let expiration: any = ''; - token ? (expiration = await jwt_decode(token)) : (expiration = null); + token ? (expiration = jwt_decode(token)) : (expiration = null); - if (expiration !== null && expiration.exp * 1000 < Date.now()) { + if (window.location.pathname !== '/users/login') { + return undefined; + } else if (expiration !== null && expiration.exp * 1000 < Date.now()) { localStorage.removeItem('orgToken'); localStorage.removeItem('orgName'); toast.error( @@ -31,6 +33,7 @@ const checkOrgTokenExpiration = async () => { window.location.pathname = '/login/org'; return false; } else if (!orgName) { + // const { logout } = useContext(UserContext); window.location.pathname = '/login/org'; return false; } else if (expiration !== null && expiration.exp * 1000 > Date.now()) {