fix: WorkFlowSetupModal
This commit is contained in:
parent
07742a0732
commit
4bede36166
|
|
@ -3,8 +3,8 @@ import React, { useState, useEffect } from "react";
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
import { AlertTriangleIcon, CheckCircleIcon, SettingsIcon } from "@/components/icons";
|
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
import { AlertTriangleIcon, CheckCircleIcon, SettingsIcon } from "lucide-react";
|
||||||
|
|
||||||
interface WorkflowSetupModalProps {
|
interface WorkflowSetupModalProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useWorkflowModal } from "./WorkflowModalProvider";
|
|
||||||
import { httpGetInterceptor } from "@/service/http-config/http-interceptor-service";
|
import { httpGetInterceptor } from "@/service/http-config/http-interceptor-service";
|
||||||
|
import { useWorkflowModal } from "@/components/modals/WorkflowModalProvider";
|
||||||
|
|
||||||
interface UserInfo {
|
interface UserInfo {
|
||||||
id: number;
|
id: number;
|
||||||
|
|
@ -36,11 +36,55 @@ interface UserInfo {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ApiResponse {
|
// interface ApiResponse {
|
||||||
success: boolean;
|
// success: boolean;
|
||||||
code: number;
|
// code: number;
|
||||||
messages: string[];
|
// messages: string[];
|
||||||
data: UserInfo;
|
// 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() {
|
export function useWorkflowStatusCheck() {
|
||||||
|
|
@ -48,19 +92,16 @@ export function useWorkflowStatusCheck() {
|
||||||
|
|
||||||
const checkWorkflowStatus = async () => {
|
const checkWorkflowStatus = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await httpGetInterceptor("users/info") as ApiResponse;
|
const response = (await httpGetInterceptor("users/info")) as
|
||||||
|
| ApiResponse<UserInfo>
|
||||||
|
| undefined;
|
||||||
|
|
||||||
if (response?.success && response?.data?.approvalWorkflowInfo) {
|
if (response && !response.error && response.data?.approvalWorkflowInfo) {
|
||||||
const workflowInfo = response.data.approvalWorkflowInfo;
|
const workflowInfo = response.data.approvalWorkflowInfo;
|
||||||
|
|
||||||
// Show modal if workflow is not setup
|
|
||||||
if (!workflowInfo.hasWorkflowSetup) {
|
if (!workflowInfo.hasWorkflowSetup) {
|
||||||
showWorkflowModal(workflowInfo);
|
showWorkflowModal(workflowInfo);
|
||||||
}
|
}
|
||||||
// Optional: Also show modal if workflow is setup (for confirmation)
|
|
||||||
// else {
|
|
||||||
// showWorkflowModal(workflowInfo);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error checking workflow status:", error);
|
console.error("Error checking workflow status:", error);
|
||||||
|
|
@ -70,12 +111,10 @@ export function useWorkflowStatusCheck() {
|
||||||
return { checkWorkflowStatus };
|
return { checkWorkflowStatus };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook untuk auto-check saat component mount
|
|
||||||
export function useAutoWorkflowCheck() {
|
export function useAutoWorkflowCheck() {
|
||||||
const { checkWorkflowStatus } = useWorkflowStatusCheck();
|
const { checkWorkflowStatus } = useWorkflowStatusCheck();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Check workflow status when component mounts
|
|
||||||
checkWorkflowStatus();
|
checkWorkflowStatus();
|
||||||
}, [checkWorkflowStatus]);
|
}, [checkWorkflowStatus]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,13 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
||||||
icon: "ic:outline-image",
|
icon: "ic:outline-image",
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
href: "/admin/settings/tenant",
|
||||||
|
label: "Tenant",
|
||||||
|
active: pathname.includes("/tenant"),
|
||||||
|
icon: "ic:outline-image",
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
export async function httpGetInterceptor(pathUrl: any) {
|
||||||
const pathname = window?.location.pathname;
|
const pathname = window?.location.pathname;
|
||||||
const response = await axiosInterceptorInstance
|
const response = await axiosInterceptorInstance
|
||||||
.get(pathUrl)
|
.get(pathUrl)
|
||||||
.catch((error) => error.response);
|
.catch((error) => error.response);
|
||||||
|
|
||||||
console.log("Response interceptor : ", response);
|
console.log("Response interceptor : ", response);
|
||||||
|
|
||||||
if (response?.status == 200 || response?.status == 201) {
|
if (response?.status == 200 || response?.status == 201) {
|
||||||
return {
|
return {
|
||||||
error: false,
|
error: false,
|
||||||
|
|
@ -50,13 +84,14 @@ export async function httpGetInterceptor(pathUrl: any) {
|
||||||
) {
|
) {
|
||||||
window.location.href = "/";
|
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(
|
// export async function httpPostInterceptor(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue