Skip to content

Commit

Permalink
fix admin dashboard (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gentille-dev authored and Virgile1k committed Oct 24, 2023
1 parent 3a6b55d commit 2cf115d
Show file tree
Hide file tree
Showing 22 changed files with 5,084 additions and 17,464 deletions.
1 change: 1 addition & 0 deletions atlp-pulse-fn
Submodule atlp-pulse-fn added at db0c6f
21,834 changes: 4,561 additions & 17,273 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"homepage": "https://github.com/atlp-rwanda/atlp-pulse-fn#readme",
"dependencies": {
"@apollo/client": "^3.7.17",
"@apollo/client": "^3.8.5",
"@babel/preset-react": "^7.22.5",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
Expand Down Expand Up @@ -72,7 +72,7 @@
"file-saver": "^2.0.5",
"flowbite-react": "^0.5.0",
"framer-motion": "^6.5.1",
"graphql": "^16.7.1",
"graphql-tag": "^2.12.6",
"i18next": "^21.10.0",
"i18next-browser-languagedetector": "^7.1.0",
"i18next-xhr-backend": "^3.2.2",
Expand All @@ -91,6 +91,7 @@
"react-hook-form": "^7.45.2",
"react-i18next": "^11.18.6",
"react-icons": "^4.10.1",
"react-otp-input": "^3.1.0",
"react-pdf": "^7.3.3",
"react-pdf-js": "^5.1.0",
"react-router": "^6.14.1",
Expand Down Expand Up @@ -146,7 +147,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"faker": "5.5.3",
"file-loader": "^6.2.0",
"graphql": "^16.7.1",
"graphql": "^16.8.1",
"html-webpack-plugin": "^5.5.0",
"husky": "^8.0.1",
"install": "^0.13.0",
Expand Down
21 changes: 21 additions & 0 deletions src/Mutations/Twofactor2fa.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable */
// mutations.ts
import gql from 'graphql-tag';

export const ENABLE_TWO_FACTOR_AUTH = gql`
mutation EnableTwoFactorAuth($email: String!) {
enableTwoFactorAuth(email: $email)
}
`;

export const DISABLE_TWO_FACTOR_AUTH = gql`
mutation DisableTwoFactorAuth($email: String!) {
disableTwoFactorAuth(email: $email)
}
`;

export const VERIFY_ONE_TIME_CODE = gql`
mutation VerifyOneTimeCode($email: String!, $code: String!) {
verifyOneTimeCode(email: $email, code: $code)
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,92 @@ Array [
</div>
</div>
</div>,
<div
className="h-screen w-screen z-20 bg-black bg-opacity-30 backdrop-blur-sm fixed flex items-center justify-center px-4 top-0 left-0 hidden"
>
<div
className="w-full p-4 pb-8 bg-white rounded-lg dark:bg-dark-bg sm:w-3/4 xl:w-4/12"
>
<div
className="flex flex-wrap items-center justify-center w-full card-title"
>
<h3
className="w-11/12 text-sm font-bold text-center dark:text-white"
>
Drop Trainee
</h3>
<hr
className="w-full my-3 border-b bg-primary"
/>
</div>
<div
className="card-body"
>
<form
className="px-8 py-3"
>
<div
className="mb-4"
>
<label
className="block text-sm font-bold text-gray-700 dark:text-white"
htmlFor="reason"
>
Reason
</label>
<input
className="mt-1 px-3 py-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring focus:ring-primary dark:bg-dark-bg dark:text-white"
id="reason"
name="reason"
onChange={[Function]}
type="text"
value=""
/>
</div>
<div
className="mb-4"
>
<label
className="block text-sm font-bold text-gray-700 dark:text-white"
htmlFor="date"
>
Date
</label>
<input
className="mt-1 px-3 py-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring focus:ring-primary dark:bg-dark-bg dark:text-white"
id="date"
name="date"
readOnly={true}
type="text"
value="2023-10-24"
/>
</div>
<div
className="flex justify-between w-full"
>
<button
className="btn info sm w-[30%] md:w-1/4 text-sm font-sans"
data-testid="dropModel"
disabled={false}
onClick={[Function]}
type="button"
>
Cancel
</button>
<button
className="btn primary sm w-[30%] md:w-1/4 text-sm font-sans"
data-testid="dropMemberFromCohort"
disabled={false}
onClick={[Function]}
type="button"
>
Drop Trainee
</button>
</div>
</form>
</div>
</div>
</div>,
<div
className="h-screen w-screen z-20 bg-black bg-opacity-30 backdrop-blur-sm fixed top-0 left-0 flex items-center justify-center px-4 hidden"
>
Expand Down Expand Up @@ -823,7 +909,7 @@ Array [
<h2
className="text-xl font-semibold text-gray-800 dark:text-white "
>
Trainees list
Trainee list
</h2>
<input
className="px-5 py-2 mt-4 font-sans text-xs border border-primary rounded outline-none dark:bg-neutral-600 dark:text-white w-52 md:w-96"
Expand Down Expand Up @@ -944,7 +1030,7 @@ Array [
}
title="Toggle SortBy"
>
View
Status
</th>
<th
className=" thead"
Expand Down Expand Up @@ -1004,7 +1090,7 @@ Array [
className="bg-black text-white rounded-xl px-3"
onClick={[Function]}
>
View
view
</button>
</div>
</td>
Expand All @@ -1013,11 +1099,9 @@ Array [
role="cell"
>
<div
className=" items-center hidden"
className="items-center hidden"
>
<span />
<span />
<span />
</div>
</td>
</tr>
Expand Down
11 changes: 0 additions & 11 deletions src/components/tests/__snapshots__/ProfileCoverpage.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ exports[`<ProfileTabs/> Renders Profile Tabs 1`] = `
className="hidden md:block"
>
Edit
</span>
</span>
<input
Expand Down Expand Up @@ -84,16 +83,6 @@ exports[`<ProfileTabs/> Renders Profile Tabs 1`] = `
strokeLinejoin="round"
/>
</svg>
<span
className=" dark:text-dark-text-fill"
>
<span
className="hidden md:block"
>
Change Picture
</span>
</span>
<input
className="hidden"
data-testid="upload-cover"
Expand Down
56 changes: 10 additions & 46 deletions src/components/tests/__snapshots__/ProfileTabs.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -137,29 +137,11 @@ Object {
</svg>
</div>
<div
class="flex py-4 "
class="flex py-4"
>
<svg
aria-hidden="true"
class="w-6 mr-2 dark:text-dark-text-fill"
fill="none"
stroke="currentColor"
stroke-width="2"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<a
rel="noopener noreferrer"
target="_blank"
>
View Resume
</a>
<p>
No Resume uploaded yet
</p>
</div>
</div>
<div
Expand Down Expand Up @@ -451,7 +433,7 @@ Object {
</div>
</div>
</div>
<div
class="h-screen w-screen z-20 bg-black bg-opacity-30 backdrop-blur-sm absolute flex items-center justify-center px-4 top-0 left-0 bottom-0 hidden"
>
Expand Down Expand Up @@ -781,29 +763,11 @@ Object {
</svg>
</div>
<div
class="flex py-4 "
class="flex py-4"
>
<svg
aria-hidden="true"
class="w-6 mr-2 dark:text-dark-text-fill"
fill="none"
stroke="currentColor"
stroke-width="2"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<a
rel="noopener noreferrer"
target="_blank"
>
View Resume
</a>
<p>
No Resume uploaded yet
</p>
</div>
</div>
<div
Expand Down Expand Up @@ -1095,7 +1059,7 @@ Object {
</div>
</div>
</div>
<div
class="h-screen w-screen z-20 bg-black bg-opacity-30 backdrop-blur-sm absolute flex items-center justify-center px-4 top-0 left-0 bottom-0 hidden"
>
Expand Down
68 changes: 68 additions & 0 deletions src/components/twofactor/ Enable2fa.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable */
import React, { useState } from 'react';
import { useMutation, useQuery } from '@apollo/client';
import { ENABLE_TWO_FACTOR_AUTH } from '../../Mutations/Twofactor2fa';
import { toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import VerifyOneTimeCodeComponent from "../../components/twofactor/Verify2fa";
import { GET_PROFILE } from '../../Mutations/User'; // Import your GET_PROFILE query
import Loader1 from '../../components/loaders/loader2/index'; // Import your loader component

const EnableTwoFactorAuthComponent: React.FC = () => {
const [isTwoFactorEnabled, setIsTwoFactorEnabled] = useState(false);
const [isLoading, setIsLoading] = useState(false);

// Fetch user's profile to get the email
const { loading, error, data } = useQuery(GET_PROFILE);

const [enableTwoFactorAuth] = useMutation(ENABLE_TWO_FACTOR_AUTH);

const handleEnableTwoFactorAuth = async () => {
try {
setIsLoading(true);

// Check if the GET_PROFILE query has loaded
if (loading) {
toast.error('Profile data is loading. Please wait.');
setIsLoading(false);
return;
}
if (error) {
toast.error('Error fetching profile data. Please try again.');
setIsLoading(false);
return;
}

// Extract the email from the profile data
const userProfile = data.getProfile;
const userProfileEmail = userProfile.user.email;

// Send the OTP to the user's email
const response = await enableTwoFactorAuth({
variables: { email: userProfileEmail },
});

console.log(response.data.enableTwoFactorAuth);
toast.success('OTP check email sent! Check your inbox.');
setIsTwoFactorEnabled(true);
} catch (error) {
console.error(error);
toast.error('Error sending OTP check email. Please try again.');
} finally {
setIsLoading(false);
}
};

return (
<div className='border-b border-gray-400 pt-2 pb-1'>
<button onClick={handleEnableTwoFactorAuth} disabled={isLoading}>
{isLoading ? <Loader1 /> : 'Enable 2FA'}
</button>

{isTwoFactorEnabled && <VerifyOneTimeCodeComponent />}
</div>
);
};

export default EnableTwoFactorAuthComponent;

Loading

0 comments on commit 2cf115d

Please sign in to comment.