Skip to content

Commit 9f2f78a

Browse files
committed
logout deleted user automatically
1 parent 57c1c9c commit 9f2f78a

File tree

5 files changed

+94
-61
lines changed

5 files changed

+94
-61
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,6 @@
178178
"lint-staged": {
179179
"*.{js,ts,tsx}": "eslint --fix",
180180
"*.{js,ts,html,css,md}": "prettier --write \"./**/*.{js,ts,jsx,tsx,json}\""
181-
}
181+
},
182+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
182183
}

src/components/ManagerCard.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ function ManagerCard() {
144144
grade,
145145
teamname: team.name,
146146
coordinator: team?.cohort?.coordinator?.profile
147-
? team.cohort.coordinator.profile.name
148-
: team?.cohort.coordinator?.email,
147+
? team.cohort?.coordinator?.profile?.name
148+
: team?.cohort?.coordinator?.email,
149149
ttl: team?.ttl?.profile ? team.ttl.profile.name : team?.ttl?.email,
150-
phase: team.cohort.phase.name,
150+
phase: team?.cohort?.phase?.name,
151151
week:
152152
calculateWeeks(team.startingPhase) > 0
153153
? calculateWeeks(team.startingPhase)
@@ -161,9 +161,7 @@ function ManagerCard() {
161161
});
162162

163163
return (
164-
<div
165-
className="font-serif px-4 md:px-0 pb-20 w-full dark:bg-dark-frame-bg dark:text-black h-full flex overflow-x-auto "
166-
>
164+
<div className="font-serif px-4 md:px-0 pb-20 w-full dark:bg-dark-frame-bg dark:text-black h-full flex overflow-x-auto ">
167165
{loading ? (
168166
<div className="flex items-center justify-center w-full h-full">
169167
<div className="spinner" />
@@ -172,7 +170,7 @@ function ManagerCard() {
172170
<div className="pl-10 flex">
173171
{teamData &&
174172
teamData.map((teamProps: any, index: number) => (
175-
<Link key={index} to={`/team/${(teamProps.teamname)}`}>
173+
<Link key={index} to={`/team/${teamProps.teamname}`}>
176174
<Card {...teamProps} />
177175
</Link>
178176
))}

src/components/teamDetails.tsx

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ function TeamDetails() {
7878
cohort: team?.cohort?.name,
7979
teamname: team.name,
8080
coordinator: team?.cohort?.coordinator?.profile
81-
? team.cohort.coordinator.profile.name
82-
: team?.cohort.coordinator?.email,
83-
ttl: team?.ttl?.profile ? team.ttl.profile.name : team?.ttl?.email,
81+
? team?.cohort?.coordinator?.profile?.name
82+
: team?.cohort?.coordinator?.email,
83+
ttl: team?.ttl?.profile ? team?.ttl?.profile?.name : team?.ttl?.email,
8484
Qty,
8585
Qnty,
8686
skills,
@@ -90,8 +90,8 @@ function TeamDetails() {
9090

9191
const selectedTeam = teamData
9292
? teamData.find(
93-
(team: { teamname: string | null }) => team.teamname === teamname,
94-
)
93+
(team: { teamname: string | null }) => team.teamname === teamname,
94+
)
9595
: null;
9696
function getColor(rating: number) {
9797
if (rating >= 1.5 && rating <= 2) {
@@ -228,12 +228,12 @@ function TeamDetails() {
228228
<h1 className="font-bold text-xl">{teamname}</h1>
229229
<div className="border-r-2 h-6 border-black" />
230230
<h1 className="font-extrabold text-xl">
231-
{selectedTeam.cohort}
231+
{selectedTeam?.cohort}
232232
</h1>
233233
</div>
234234
<div className="relative dark:text-black">
235-
<p>Coordinator: {selectedTeam.coordinator}</p>
236-
<p>TTL: {selectedTeam.ttl}</p>
235+
<p>Coordinator: {selectedTeam?.coordinator}</p>
236+
<p>TTL: {selectedTeam?.ttl}</p>
237237
</div>
238238
</div>
239239

@@ -285,12 +285,12 @@ function TeamDetails() {
285285
<div className="flex flex-row lg:flex-row ">
286286
<div className="w-[90px]">
287287
<CircularProgressbar
288-
value={(selectedTeam.Qty / 2) * 100}
289-
text={`${selectedTeam.Qty.toFixed(1)}`}
290-
className={getRatingColorClass(selectedTeam.Qty)}
288+
value={(selectedTeam?.Qty / 2) * 100}
289+
text={`${selectedTeam?.Qty.toFixed(1)}`}
290+
className={getRatingColorClass(selectedTeam?.Qty)}
291291
styles={{
292292
path: {
293-
stroke: getColor(selectedTeam.Qty),
293+
stroke: getColor(selectedTeam?.Qty),
294294
transition: 'stroke-dashoffset 0.5s ease 0s',
295295
},
296296
trail: {
@@ -310,23 +310,24 @@ function TeamDetails() {
310310
<ul className="list-disc">
311311
<li>Quality</li>
312312
</ul>
313-
<span style={{ color: getColor(selectedTeam.Qty) }}>
314-
{selectedTeam.Qty >= 1.5 && selectedTeam.Qty <= 2
313+
<span style={{ color: getColor(selectedTeam?.Qty) }}>
314+
{selectedTeam?.Qty >= 1.5 && selectedTeam?.Qty <= 2
315315
? 'Good'
316-
: selectedTeam.Qty >= 1 && selectedTeam.Qty < 1.5
317-
? 'Improve'
318-
: 'Poor'}
316+
: selectedTeam?.Qty >= 1 &&
317+
selectedTeam?.Qty < 1.5
318+
? 'Improve'
319+
: 'Poor'}
319320
</span>
320321
</div>
321322
</div>
322323
<div className=" flex flex-row lg:flex-row ">
323324
<div className="w-[90px] ">
324325
<CircularProgressbar
325-
value={(selectedTeam.Qnty / 2) * 100}
326-
text={`${selectedTeam.Qnty.toFixed(1)}`}
326+
value={(selectedTeam?.Qnty / 2) * 100}
327+
text={`${selectedTeam?.Qnty.toFixed(1)}`}
327328
styles={{
328329
path: {
329-
stroke: getColor(selectedTeam.Qnty),
330+
stroke: getColor(selectedTeam?.Qnty),
330331
transition: 'stroke-dashoffset 0.5s ease 0s',
331332
},
332333
trail: {
@@ -346,25 +347,26 @@ function TeamDetails() {
346347
<ul className="list-disc ">
347348
<li>Quantity</li>
348349
</ul>
349-
<span style={{ color: getColor(selectedTeam.Qnty) }}>
350-
{selectedTeam.Qnty >= 1.5 && selectedTeam.Qnty <= 2
350+
<span style={{ color: getColor(selectedTeam?.Qnty) }}>
351+
{selectedTeam?.Qnty >= 1.5 &&
352+
selectedTeam?.Qnty <= 2
351353
? 'Good'
352-
: selectedTeam.Qnty >= 1 &&
353-
selectedTeam.Qnty < 1.5
354-
? 'Improve'
355-
: 'Poor'}
354+
: selectedTeam?.Qnty >= 1 &&
355+
selectedTeam?.Qnty < 1.5
356+
? 'Improve'
357+
: 'Poor'}
356358
</span>
357359
</div>
358360
</div>
359361
</div>
360362
<div className=" w-full flex flex-row">
361363
<div className="w-[90px] ">
362364
<CircularProgressbar
363-
value={(selectedTeam.skills / 2) * 100}
364-
text={`${selectedTeam.skills.toFixed(1)}`}
365+
value={(selectedTeam?.skills / 2) * 100}
366+
text={`${selectedTeam?.skills.toFixed(1)}`}
365367
styles={{
366368
path: {
367-
stroke: getColor(selectedTeam.skills),
369+
stroke: getColor(selectedTeam?.skills),
368370
transition: 'stroke-dashoffset 0.5s ease 0s',
369371
},
370372
trail: {
@@ -384,14 +386,14 @@ function TeamDetails() {
384386
<ul className="list-disc ">
385387
<li>Professionalism</li>
386388
</ul>
387-
<span style={{ color: getColor(selectedTeam.skills) }}>
388-
{selectedTeam.skills >= 1.5 &&
389-
selectedTeam.skills <= 2
389+
<span style={{ color: getColor(selectedTeam?.skills) }}>
390+
{selectedTeam?.skills >= 1.5 &&
391+
selectedTeam?.skills <= 2
390392
? 'Good'
391-
: selectedTeam.skills >= 1 &&
392-
selectedTeam.skills < 1.5
393-
? 'Improve'
394-
: 'Poor'}
393+
: selectedTeam?.skills >= 1 &&
394+
selectedTeam?.skills < 1.5
395+
? 'Improve'
396+
: 'Poor'}
395397
</span>
396398
</div>
397399
</div>

src/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,26 @@ import UserProvider from './hook/useAuth';
2323
import App from './App';
2424
import ThemeProvider from './hook/ThemeProvider';
2525

26+
const specificMessagesToLogout = [
27+
'User not authenticated',
28+
'User account does not exist or has been deleted',
29+
'User with this token no longer exist!!',
30+
];
2631
const errorLink = onError(({ graphQLErrors, networkError }) => {
2732
if (graphQLErrors) {
2833
graphQLErrors.forEach(({ message, locations, path, extensions }) => {
34+
if (
35+
specificMessagesToLogout.some((errorMessage) =>
36+
message.includes(errorMessage),
37+
)
38+
) {
39+
const encodedMessage = encodeURIComponent(message); // Encode the message
40+
window.location.href = `/users/login?redirect_message=${encodedMessage}`;
41+
localStorage.removeItem('auth');
42+
localStorage.removeItem('auth_token');
43+
toast.error(message);
44+
}
45+
2946
if (extensions?.code === 'JWT_EXPIRED') {
3047
window.location.pathname = '/users/login';
3148
localStorage.removeItem('auth');

src/pages/Organization/AdminLogin.tsx

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable */
2+
'use client';
23
import { useApolloClient, useMutation } from '@apollo/client';
3-
import React, { useContext, useState } from 'react';
4+
import React, { useContext, useEffect, useState } from 'react';
45
import { useForm } from 'react-hook-form';
56
import { useTranslation } from 'react-i18next';
67
import { FaRegEnvelope, FaRegEye } from 'react-icons/fa';
@@ -45,6 +46,19 @@ function AdminLogin() {
4546
const [LoginUser] = useMutation(LOGIN_MUTATION);
4647
const client = useApolloClient();
4748
const [searchParams] = useSearchParams();
49+
// Function to get the redirect_message from the URL and toast it
50+
const showRedirectMessage = () => {
51+
const redirectMessage = searchParams.get('redirect_message');
52+
console.log(redirectMessage);
53+
if (redirectMessage) {
54+
toast.error(redirectMessage);
55+
}
56+
};
57+
58+
// Call showRedirectMessage when the component mounts
59+
useEffect(() => {
60+
showRedirectMessage();
61+
}, [searchParams]);
4862

4963
const onSubmit = async (userInput: any) => {
5064
userInput.orgToken = orgToken;
@@ -76,26 +90,28 @@ function AdminLogin() {
7690
redirect
7791
? navigate(`${redirect}`)
7892
: data.loginUser.user.role === 'superAdmin'
79-
? navigate(`/organizations`)
80-
: data.loginUser.user.role === 'admin'
81-
? navigate(`/trainees`)
82-
: data.loginUser.user.role === 'coordinator'
83-
? navigate(`/trainees`)
84-
: data.loginUser.user.role === 'manager'
85-
? navigate(`/dashboard`)
86-
: data.loginUser.user.role === 'ttl'
87-
? navigate('/ttl-trainees')
88-
: navigate('/performance');
93+
? navigate(`/organizations`)
94+
: data.loginUser.user.role === 'admin'
95+
? navigate(`/trainees`)
96+
: data.loginUser.user.role === 'coordinator'
97+
? navigate(`/trainees`)
98+
: data.loginUser.user.role === 'manager'
99+
? navigate(`/dashboard`)
100+
: data.loginUser.user.role === 'ttl'
101+
? navigate('/ttl-trainees')
102+
: navigate('/performance');
89103
} else {
90104
navigate('/dashboard');
91105
}
92106
},
93107
onError: (err) => {
94108
/* istanbul ignore next */
95109
if (err.networkError)
96-
toast.error('There was a problem contacting the server')
110+
toast.error('There was a problem contacting the server');
97111
else if (err.message.toLowerCase() !== 'invalid credential') {
98-
const translateError = t('Please wait to be added to a program or cohort')
112+
const translateError = t(
113+
'Please wait to be added to a program or cohort',
114+
);
99115
toast.error(translateError);
100116
} else {
101117
/* istanbul ignore next */
@@ -178,7 +194,7 @@ function AdminLogin() {
178194
{t('Welcome to')}{' '}
179195
{orgName
180196
? orgName.charAt(0).toUpperCase() +
181-
orgName.slice(1).toLowerCase()
197+
orgName.slice(1).toLowerCase()
182198
: ''}
183199
</h2>
184200
<div className="border-[1px] w-10 bg-primary border-primary inline-block mb-2" />
@@ -202,7 +218,7 @@ function AdminLogin() {
202218
data-testid="loginForm"
203219
>
204220
{errors.password &&
205-
errors.password.message === t('Invalid credentials') ? (
221+
errors.password.message === t('Invalid credentials') ? (
206222
<div className=" bg-red-400 rounded-md w-full text-center p-4 my-4">
207223
<small className="text-white">
208224
{errors.password.message}
@@ -250,14 +266,13 @@ function AdminLogin() {
250266
</div>
251267
<div className="pl-4 mb-1 text-left">
252268
{errors.password &&
253-
errors.password.message !== t('Invalid credentials') ? (
269+
errors.password.message !== t('Invalid credentials') ? (
254270
<small className="text-red-600">
255271
{errors.password.message}
256272
</small>
257273
) : (
258274
''
259275
)}
260-
261276
</div>
262277
<div className="flex w-full flex-col sm:flex-row justify-between items-center rounded mb-5 mt-5">
263278
<div className="w-50%">

0 commit comments

Comments
 (0)