Skip to content

Commit

Permalink
logout deleted user automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahladdie committed Sep 27, 2024
1 parent a40c76c commit 66d79ae
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 29 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,6 @@
"lint-staged": {
"*.{js,ts,tsx}": "eslint --fix",
"*.{js,ts,html,css,md}": "prettier --write \"./**/*.{js,ts,jsx,tsx,json}\""
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
2 changes: 1 addition & 1 deletion src/components/ManagerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function ManagerCard() {
grade,
teamname: team.name,
coordinator: team?.cohort?.coordinator?.profile
? team.cohort?.coordinator.profile.name
? team.cohort?.coordinator?.profile?.name
: team?.cohort?.coordinator?.email,
ttl: team?.ttl?.profile ? team.ttl.profile.name : team?.ttl?.email,
phase: team?.cohort?.phase?.name,
Expand Down
54 changes: 28 additions & 26 deletions src/components/teamDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ function TeamDetails() {
cohort: team?.cohort?.name,
teamname: team.name,
coordinator: team?.cohort?.coordinator?.profile
? team.cohort?.coordinator.profile.name
? team?.cohort?.coordinator?.profile?.name
: team?.cohort?.coordinator?.email,
ttl: team?.ttl?.profile ? team.ttl.profile.name : team?.ttl?.email,
ttl: team?.ttl?.profile ? team?.ttl?.profile?.name : team?.ttl?.email,
Qty,
Qnty,
skills,
Expand Down Expand Up @@ -228,12 +228,12 @@ function TeamDetails() {
<h1 className="font-bold text-xl">{teamname}</h1>
<div className="border-r-2 h-6 border-black" />
<h1 className="font-extrabold text-xl">
{selectedTeam.cohort}
{selectedTeam?.cohort}
</h1>
</div>
<div className="relative dark:text-black">
<p>Coordinator: {selectedTeam?.coordinator}</p>
<p>TTL: {selectedTeam.ttl}</p>
<p>TTL: {selectedTeam?.ttl}</p>
</div>
</div>

Expand Down Expand Up @@ -285,12 +285,12 @@ function TeamDetails() {
<div className="flex flex-row lg:flex-row ">
<div className="w-[90px]">
<CircularProgressbar
value={(selectedTeam.Qty / 2) * 100}
text={`${selectedTeam.Qty.toFixed(1)}`}
className={getRatingColorClass(selectedTeam.Qty)}
value={(selectedTeam?.Qty / 2) * 100}
text={`${selectedTeam?.Qty.toFixed(1)}`}
className={getRatingColorClass(selectedTeam?.Qty)}
styles={{
path: {
stroke: getColor(selectedTeam.Qty),
stroke: getColor(selectedTeam?.Qty),
transition: 'stroke-dashoffset 0.5s ease 0s',
},
trail: {
Expand All @@ -310,10 +310,11 @@ function TeamDetails() {
<ul className="list-disc">
<li>Quality</li>
</ul>
<span style={{ color: getColor(selectedTeam.Qty) }}>
{selectedTeam.Qty >= 1.5 && selectedTeam.Qty <= 2
<span style={{ color: getColor(selectedTeam?.Qty) }}>
{selectedTeam?.Qty >= 1.5 && selectedTeam?.Qty <= 2
? 'Good'
: selectedTeam.Qty >= 1 && selectedTeam.Qty < 1.5
: selectedTeam?.Qty >= 1 &&
selectedTeam?.Qty < 1.5
? 'Improve'
: 'Poor'}
</span>
Expand All @@ -322,11 +323,11 @@ function TeamDetails() {
<div className=" flex flex-row lg:flex-row ">
<div className="w-[90px] ">
<CircularProgressbar
value={(selectedTeam.Qnty / 2) * 100}
text={`${selectedTeam.Qnty.toFixed(1)}`}
value={(selectedTeam?.Qnty / 2) * 100}
text={`${selectedTeam?.Qnty.toFixed(1)}`}
styles={{
path: {
stroke: getColor(selectedTeam.Qnty),
stroke: getColor(selectedTeam?.Qnty),
transition: 'stroke-dashoffset 0.5s ease 0s',
},
trail: {
Expand All @@ -346,11 +347,12 @@ function TeamDetails() {
<ul className="list-disc ">
<li>Quantity</li>
</ul>
<span style={{ color: getColor(selectedTeam.Qnty) }}>
{selectedTeam.Qnty >= 1.5 && selectedTeam.Qnty <= 2
<span style={{ color: getColor(selectedTeam?.Qnty) }}>
{selectedTeam?.Qnty >= 1.5 &&
selectedTeam?.Qnty <= 2
? 'Good'
: selectedTeam.Qnty >= 1 &&
selectedTeam.Qnty < 1.5
: selectedTeam?.Qnty >= 1 &&
selectedTeam?.Qnty < 1.5
? 'Improve'
: 'Poor'}
</span>
Expand All @@ -360,11 +362,11 @@ function TeamDetails() {
<div className=" w-full flex flex-row">
<div className="w-[90px] ">
<CircularProgressbar
value={(selectedTeam.skills / 2) * 100}
text={`${selectedTeam.skills.toFixed(1)}`}
value={(selectedTeam?.skills / 2) * 100}
text={`${selectedTeam?.skills.toFixed(1)}`}
styles={{
path: {
stroke: getColor(selectedTeam.skills),
stroke: getColor(selectedTeam?.skills),
transition: 'stroke-dashoffset 0.5s ease 0s',
},
trail: {
Expand All @@ -384,12 +386,12 @@ function TeamDetails() {
<ul className="list-disc ">
<li>Professionalism</li>
</ul>
<span style={{ color: getColor(selectedTeam.skills) }}>
{selectedTeam.skills >= 1.5 &&
selectedTeam.skills <= 2
<span style={{ color: getColor(selectedTeam?.skills) }}>
{selectedTeam?.skills >= 1.5 &&
selectedTeam?.skills <= 2
? 'Good'
: selectedTeam.skills >= 1 &&
selectedTeam.skills < 1.5
: selectedTeam?.skills >= 1 &&
selectedTeam?.skills < 1.5
? 'Improve'
: 'Poor'}
</span>
Expand Down
17 changes: 17 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,26 @@ import UserProvider from './hook/useAuth';
import App from './App';
import ThemeProvider from './hook/ThemeProvider';

const specificMessagesToLogout = [
'User not authenticated',
'User account does not exist or has been deleted',
'User with this token no longer exist!!',
];
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path, extensions }) => {
if (
specificMessagesToLogout.some((errorMessage) =>
message.includes(errorMessage),
)
) {
const encodedMessage = encodeURIComponent(message); // Encode the message
window.location.href = `/users/login?redirect_message=${encodedMessage}`;
localStorage.removeItem('auth');
localStorage.removeItem('auth_token');
toast.error(message);
}

if (extensions?.code === 'JWT_EXPIRED') {
window.location.pathname = '/users/login';
localStorage.removeItem('auth');
Expand Down
16 changes: 15 additions & 1 deletion src/pages/Organization/AdminLogin.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable */
'use client';
import { useApolloClient, useMutation } from '@apollo/client';
import React, { useContext, useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { FaRegEnvelope, FaRegEye } from 'react-icons/fa';
Expand Down Expand Up @@ -45,6 +46,19 @@ function AdminLogin() {
const [LoginUser] = useMutation(LOGIN_MUTATION);
const client = useApolloClient();
const [searchParams] = useSearchParams();
// Function to get the redirect_message from the URL and toast it
const showRedirectMessage = () => {
const redirectMessage = searchParams.get('redirect_message');
console.log(redirectMessage);
if (redirectMessage) {
toast.error(redirectMessage);
}
};

// Call showRedirectMessage when the component mounts
useEffect(() => {
showRedirectMessage();
}, [searchParams]);

const onSubmit = async (userInput: any) => {
userInput.orgToken = orgToken;
Expand Down

0 comments on commit 66d79ae

Please sign in to comment.