fix: WorkFlowSetupModal

This commit is contained in:
Sabda Yagra 2025-10-02 13:42:40 +07:00
parent 07742a0732
commit 4bede36166
4 changed files with 107 additions and 26 deletions

View File

@ -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;

View File

@ -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<T = any> {
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<T = any> {
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<UserInfo>
| 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]);
}

View File

@ -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: [],
},
],
},
],

View File

@ -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",