Skip to content

Commit 66d79ae

Browse files
committed
logout deleted user automatically
1 parent a40c76c commit 66d79ae

File tree

5 files changed

+63
-29
lines changed

5 files changed

+63
-29
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function ManagerCard() {
144144
grade,
145145
teamname: team.name,
146146
coordinator: team?.cohort?.coordinator?.profile
147-
? team.cohort?.coordinator.profile.name
147+
? team.cohort?.coordinator?.profile?.name
148148
: team?.cohort?.coordinator?.email,
149149
ttl: team?.ttl?.profile ? team.ttl.profile.name : team?.ttl?.email,
150150
phase: team?.cohort?.phase?.name,

src/components/teamDetails.tsx

Lines changed: 28 additions & 26 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
81+
? team?.cohort?.coordinator?.profile?.name
8282
: team?.cohort?.coordinator?.email,
83-
ttl: team?.ttl?.profile ? team.ttl.profile.name : team?.ttl?.email,
83+
ttl: team?.ttl?.profile ? team?.ttl?.profile?.name : team?.ttl?.email,
8484
Qty,
8585
Qnty,
8686
skills,
@@ -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">
235235
<p>Coordinator: {selectedTeam?.coordinator}</p>
236-
<p>TTL: {selectedTeam.ttl}</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,10 +310,11 @@ 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
316+
: selectedTeam?.Qty >= 1 &&
317+
selectedTeam?.Qty < 1.5
317318
? 'Improve'
318319
: 'Poor'}
319320
</span>
@@ -322,11 +323,11 @@ function TeamDetails() {
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,11 +347,12 @@ 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+
: selectedTeam?.Qnty >= 1 &&
355+
selectedTeam?.Qnty < 1.5
354356
? 'Improve'
355357
: 'Poor'}
356358
</span>
@@ -360,11 +362,11 @@ function TeamDetails() {
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,12 +386,12 @@ 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+
: selectedTeam?.skills >= 1 &&
394+
selectedTeam?.skills < 1.5
393395
? 'Improve'
394396
: 'Poor'}
395397
</span>

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: 15 additions & 1 deletion
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;

0 commit comments

Comments
 (0)