From f5aba700177e53640a77eff9ee01e7b57c7159b4 Mon Sep 17 00:00:00 2001 From: Mohamed Maoulainine Maoulainine <Mohamed_Maoulainine.Maoulainine@enseirb-matmeca.fr> Date: Sat, 10 May 2025 17:59:05 +0200 Subject: [PATCH] feat: add finalise logic --- .../src/components/LoginComponent.vue | 32 ++++++++++++++++--- front/MyINPulse-front/src/router/router.ts | 6 ++++ .../src/services/Apis/Unauth.ts | 10 ++++++ front/MyINPulse-front/src/views/AdminMain.vue | 3 +- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/front/MyINPulse-front/src/components/LoginComponent.vue b/front/MyINPulse-front/src/components/LoginComponent.vue index a68b2c8..70a8833 100644 --- a/front/MyINPulse-front/src/components/LoginComponent.vue +++ b/front/MyINPulse-front/src/components/LoginComponent.vue @@ -3,6 +3,7 @@ import { onMounted, ref } from "vue"; import { useRouter } from "vue-router"; import { jwtDecode } from "jwt-decode"; // i hope this doesn't break the code later import { store } from "../main.ts"; +import { checkPending } from "@/services/Apis/Unauth"; import Header from "@/components/HeaderComponent.vue"; const router = useRouter(); @@ -22,18 +23,39 @@ onMounted(() => { if (roles.includes("MyINPulse-admin")) { router.push("/admin"); - } else if (roles.includes("MyINPulse-entrepreneur")) { + return; + } + + if (roles.includes("MyINPulse-entrepreneur")) { router.push("/canvas"); + return; } - else{ - router.push("/JorCproject") - } + + checkPending( + (response) => { + const isValidated = response.data === true; + if (isValidated) { + router.push("/JorCproject"); + } else { + router.push("/finalize"); + } + }, + (error) => { + if (error.response?.status === 404) { + router.push("/finalize"); + } else { + console.error( + "Unexpected error during checkPending", + error + ); + } + } + ); } catch (err) { console.error("Failed to decode token", err); } } }); - </script> <template> diff --git a/front/MyINPulse-front/src/router/router.ts b/front/MyINPulse-front/src/router/router.ts index 860873b..5704b61 100644 --- a/front/MyINPulse-front/src/router/router.ts +++ b/front/MyINPulse-front/src/router/router.ts @@ -40,6 +40,12 @@ const router = createRouter({ name: "JorCproject", component: () => import("../views/JoinOrCreatProjectForEntrep.vue"), }, + + { + path: "/finalize", + name: "finalize", + component: () => import("../views/FinalizeAccount.vue"), + }, ], }); diff --git a/front/MyINPulse-front/src/services/Apis/Unauth.ts b/front/MyINPulse-front/src/services/Apis/Unauth.ts index 2e5f7f1..90dc2f7 100644 --- a/front/MyINPulse-front/src/services/Apis/Unauth.ts +++ b/front/MyINPulse-front/src/services/Apis/Unauth.ts @@ -74,8 +74,18 @@ function getAllEntrepreneurs( }); } +function checkPending(): Promise<boolean> { + return axiosInstance + .get("/unauth/check-if-not-pending") + .then((response) => response.data) + .catch((error: AxiosError) => { + throw error; + }); +} + export { finalizeAccount, getAllEntrepreneurs, + checkPending, // requestJoinProject, // Not yet implemented [cite: 4] }; diff --git a/front/MyINPulse-front/src/views/AdminMain.vue b/front/MyINPulse-front/src/views/AdminMain.vue index a2f9ef8..5b70d55 100644 --- a/front/MyINPulse-front/src/views/AdminMain.vue +++ b/front/MyINPulse-front/src/views/AdminMain.vue @@ -70,7 +70,6 @@ const fallbackProjects = [ }, ]; - const createFirstAdmin = () => { createAdmin( (response) => { @@ -85,7 +84,7 @@ const createFirstAdmin = () => { ); }; -onMounted(createFirstAdmin) +onMounted(createFirstAdmin); const fetchProjects = () => { getAdminProjects(