diff --git a/components/modals/WorkflowSetupModal.tsx b/components/modals/WorkflowSetupModal.tsx index cf57f1c..b896bbf 100644 --- a/components/modals/WorkflowSetupModal.tsx +++ b/components/modals/WorkflowSetupModal.tsx @@ -3,8 +3,8 @@ import React, { useState, useEffect } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; -import { AlertTriangleIcon, CheckCircleIcon, SettingsIcon } from "@/components/icons"; import { useRouter } from "next/navigation"; +import { AlertTriangleIcon, CheckCircleIcon, SettingsIcon } from "lucide-react"; interface WorkflowSetupModalProps { isOpen: boolean; diff --git a/hooks/useWorkflowStatusCheck.ts b/hooks/useWorkflowStatusCheck.ts index 65e2959..862d1f8 100644 --- a/hooks/useWorkflowStatusCheck.ts +++ b/hooks/useWorkflowStatusCheck.ts @@ -1,7 +1,7 @@ "use client"; import { useEffect } from "react"; -import { useWorkflowModal } from "./WorkflowModalProvider"; import { httpGetInterceptor } from "@/service/http-config/http-interceptor-service"; +import { useWorkflowModal } from "@/components/modals/WorkflowModalProvider"; interface UserInfo { id: number; @@ -36,11 +36,55 @@ interface UserInfo { }; } -interface ApiResponse { - success: boolean; - code: number; - messages: string[]; - data: UserInfo; +// interface ApiResponse { +// success: boolean; +// code: number; +// messages: string[]; +// data: UserInfo | null; +// } +interface ApiResponse { + error: boolean; + message: string; + data: T | null; +} + +interface UserInfo { + id: number; + username: string; + email: string; + fullname: string; + address: string; + phoneNumber: string; + workType?: string; + genderType?: string; + identityType?: string; + identityNumber?: string; + dateOfBirth?: string; + lastEducation?: string; + keycloakId: string; + userRoleId: number; + userLevelId: number; + userLevelGroup: string; + statusId: number; + createdById?: number; + profilePicturePath?: string; + isActive: boolean; + createdAt: string; + updatedAt: string; + approvalWorkflowInfo: { + hasWorkflowSetup: boolean; + defaultWorkflowId?: number; + defaultWorkflowName?: string; + requiresApproval?: boolean; + autoPublishArticles?: boolean; + isApprovalActive?: boolean; + }; +} + +interface ApiResponse { + error: boolean; + message: string; + data: T | null; } export function useWorkflowStatusCheck() { @@ -48,19 +92,16 @@ export function useWorkflowStatusCheck() { const checkWorkflowStatus = async () => { try { - const response = await httpGetInterceptor("users/info") as ApiResponse; - - if (response?.success && response?.data?.approvalWorkflowInfo) { + const response = (await httpGetInterceptor("users/info")) as + | ApiResponse + | undefined; + + if (response && !response.error && response.data?.approvalWorkflowInfo) { const workflowInfo = response.data.approvalWorkflowInfo; - - // Show modal if workflow is not setup + if (!workflowInfo.hasWorkflowSetup) { showWorkflowModal(workflowInfo); } - // Optional: Also show modal if workflow is setup (for confirmation) - // else { - // showWorkflowModal(workflowInfo); - // } } } catch (error) { console.error("Error checking workflow status:", error); @@ -70,12 +111,10 @@ export function useWorkflowStatusCheck() { return { checkWorkflowStatus }; } -// Hook untuk auto-check saat component mount export function useAutoWorkflowCheck() { const { checkWorkflowStatus } = useWorkflowStatusCheck(); useEffect(() => { - // Check workflow status when component mounts checkWorkflowStatus(); }, [checkWorkflowStatus]); } diff --git a/lib/menus.ts b/lib/menus.ts index 23457e7..b171dea 100644 --- a/lib/menus.ts +++ b/lib/menus.ts @@ -230,6 +230,13 @@ export function getMenuList(pathname: string, t: any): Group[] { icon: "ic:outline-image", children: [], }, + { + href: "/admin/settings/tenant", + label: "Tenant", + active: pathname.includes("/tenant"), + icon: "ic:outline-image", + children: [], + }, ], }, ], diff --git a/service/http-config/http-interceptor-service.ts b/service/http-config/http-interceptor-service.ts index 8be4db6..af5d7e8 100644 --- a/service/http-config/http-interceptor-service.ts +++ b/service/http-config/http-interceptor-service.ts @@ -27,12 +27,46 @@ export async function httpGetInterceptorForMetadata(pathUrl: any) { } } +// export async function httpGetInterceptor(pathUrl: any) { +// const pathname = window?.location.pathname; +// const response = await axiosInterceptorInstance +// .get(pathUrl) +// .catch((error) => error.response); +// console.log("Response interceptor : ", response); +// if (response?.status == 200 || response?.status == 201) { +// return { +// error: false, +// message: "success", +// data: response?.data, +// }; +// } else if (response?.status == 401) { +// Object.keys(Cookies.get()).forEach((cookieName) => { +// Cookies.remove(cookieName); +// }); +// if ( +// pathname?.includes("/contributor/") || +// pathname?.includes("/admin/") || +// pathname?.includes("/supervisor/") +// ) { +// window.location.href = "/"; +// } +// } else { +// return { +// error: true, +// message: response?.data?.message || response?.data || null, +// data: null, +// }; +// } +// } + export async function httpGetInterceptor(pathUrl: any) { const pathname = window?.location.pathname; const response = await axiosInterceptorInstance .get(pathUrl) .catch((error) => error.response); + console.log("Response interceptor : ", response); + if (response?.status == 200 || response?.status == 201) { return { error: false, @@ -50,13 +84,14 @@ export async function httpGetInterceptor(pathUrl: any) { ) { window.location.href = "/"; } - } else { - return { - error: true, - message: response?.data?.message || response?.data || null, - data: null, - }; } + + // 🔹 Tambahkan return default biar tidak undefined + return { + error: true, + message: response?.data?.message || response?.data || "Unknown error", + data: null, + }; } // export async function httpPostInterceptor( @@ -107,8 +142,8 @@ export async function httpPostInterceptor( const resCsrf = await getCsrfToken(); const csrfToken = resCsrf?.data?.token; - const token = Cookies.get("token"); - const clientKey = process.env.NEXT_PUBLIC_CLIENT_KEY; + const token = Cookies.get("token"); + const clientKey = process.env.NEXT_PUBLIC_CLIENT_KEY; const defaultHeaders = { "Content-Type": "application/json",