2025-10-02 05:04:42 +00:00
|
|
|
"use client";
|
|
|
|
|
import React, { useState, useEffect } from "react";
|
2026-03-03 09:26:11 +00:00
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "@/components/ui/dialog";
|
2025-10-02 05:04:42 +00:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Card, CardContent } from "@/components/ui/card";
|
2025-10-02 06:41:49 +00:00
|
|
|
import { IconX, SettingsIcon } from "@/components/icons";
|
|
|
|
|
import { useRouter, usePathname } from "next/navigation";
|
2025-10-02 05:04:42 +00:00
|
|
|
|
|
|
|
|
interface WorkflowSetupModalProps {
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
workflowInfo?: {
|
|
|
|
|
hasWorkflowSetup: boolean;
|
|
|
|
|
defaultWorkflowId?: number;
|
|
|
|
|
defaultWorkflowName?: string;
|
|
|
|
|
requiresApproval?: boolean;
|
|
|
|
|
autoPublishArticles?: boolean;
|
|
|
|
|
isApprovalActive?: boolean;
|
|
|
|
|
};
|
2025-10-02 06:41:49 +00:00
|
|
|
onRefresh?: () => Promise<void>;
|
2025-10-02 05:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 09:26:11 +00:00
|
|
|
export default function WorkflowSetupModal({
|
|
|
|
|
isOpen,
|
|
|
|
|
onClose,
|
|
|
|
|
workflowInfo,
|
|
|
|
|
onRefresh,
|
|
|
|
|
}: WorkflowSetupModalProps) {
|
2025-10-02 05:04:42 +00:00
|
|
|
const router = useRouter();
|
2025-10-02 06:41:49 +00:00
|
|
|
const pathname = usePathname();
|
2025-10-02 05:04:42 +00:00
|
|
|
const [isVisible, setIsVisible] = useState(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isOpen) {
|
|
|
|
|
setIsVisible(true);
|
|
|
|
|
}
|
|
|
|
|
}, [isOpen]);
|
|
|
|
|
|
|
|
|
|
const handleClose = () => {
|
2025-10-02 06:41:49 +00:00
|
|
|
// Allow closing if workflow is setup OR if user is on tenant settings page
|
2026-03-03 09:26:11 +00:00
|
|
|
if (
|
|
|
|
|
workflowInfo?.hasWorkflowSetup ||
|
|
|
|
|
pathname?.includes("/admin/settings/tenant") ||
|
|
|
|
|
pathname?.includes("/tenant")
|
|
|
|
|
) {
|
2025-10-02 06:41:49 +00:00
|
|
|
setIsVisible(false);
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
onClose();
|
|
|
|
|
}, 200);
|
|
|
|
|
}
|
2025-10-02 05:04:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSetupWorkflow = () => {
|
2025-10-02 06:41:49 +00:00
|
|
|
// Navigate to tenant settings
|
2025-10-02 05:04:42 +00:00
|
|
|
router.push("/admin/settings/tenant");
|
2025-10-02 06:41:49 +00:00
|
|
|
// Modal will be auto-hidden by WorkflowModalProvider when user reaches tenant settings page
|
2025-10-02 05:04:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!isOpen) return null;
|
|
|
|
|
|
|
|
|
|
return (
|
2026-03-03 09:26:11 +00:00
|
|
|
<Dialog
|
|
|
|
|
open={isVisible}
|
|
|
|
|
onOpenChange={
|
|
|
|
|
workflowInfo?.hasWorkflowSetup ||
|
|
|
|
|
pathname?.includes("/admin/settings/tenant") ||
|
|
|
|
|
pathname?.includes("/tenant")
|
|
|
|
|
? handleClose
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
2025-10-02 06:41:49 +00:00
|
|
|
>
|
2026-03-03 09:26:11 +00:00
|
|
|
<DialogContent
|
2025-10-02 06:41:49 +00:00
|
|
|
className="max-w-md"
|
|
|
|
|
onPointerDownOutside={(e) => {
|
|
|
|
|
// Prevent closing by clicking outside unless workflow is setup or on tenant settings page
|
2026-03-03 09:26:11 +00:00
|
|
|
if (
|
|
|
|
|
!workflowInfo?.hasWorkflowSetup &&
|
|
|
|
|
!pathname?.includes("/admin/settings/tenant") &&
|
|
|
|
|
!pathname?.includes("/tenant")
|
|
|
|
|
) {
|
2025-10-02 06:41:49 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
onEscapeKeyDown={(e) => {
|
|
|
|
|
// Prevent closing by pressing ESC unless workflow is setup or on tenant settings page
|
2026-03-03 09:26:11 +00:00
|
|
|
if (
|
|
|
|
|
!workflowInfo?.hasWorkflowSetup &&
|
|
|
|
|
!pathname?.includes("/admin/settings/tenant") &&
|
|
|
|
|
!pathname?.includes("/tenant")
|
|
|
|
|
) {
|
2025-10-02 06:41:49 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-10-02 05:04:42 +00:00
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle className="flex items-center gap-2">
|
|
|
|
|
{workflowInfo?.hasWorkflowSetup ? (
|
2025-10-02 06:41:49 +00:00
|
|
|
<div className="h-5 w-5 rounded-full bg-green-600 flex items-center justify-center">
|
|
|
|
|
<span className="text-white text-xs">✓</span>
|
|
|
|
|
</div>
|
2025-10-02 05:04:42 +00:00
|
|
|
) : (
|
2025-10-02 06:41:49 +00:00
|
|
|
<div className="h-5 w-5 rounded-full bg-orange-600 flex items-center justify-center">
|
|
|
|
|
<span className="text-white text-xs">!</span>
|
|
|
|
|
</div>
|
2025-10-02 05:04:42 +00:00
|
|
|
)}
|
|
|
|
|
Workflow Status
|
|
|
|
|
</DialogTitle>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-4">
|
2026-03-03 09:26:11 +00:00
|
|
|
{
|
|
|
|
|
!workflowInfo?.hasWorkflowSetup ? (
|
|
|
|
|
// No Workflow Setup
|
|
|
|
|
<Card className="border-orange-200 bg-orange-50">
|
|
|
|
|
<CardContent className="p-4">
|
|
|
|
|
<div className="flex items-start gap-3">
|
|
|
|
|
<div className="h-6 w-6 rounded-full bg-orange-600 flex items-center justify-center mt-1">
|
|
|
|
|
<span className="text-white text-sm">!</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<h3 className="font-medium text-orange-900 mb-2">
|
|
|
|
|
Workflow Belum Dikonfigurasi
|
|
|
|
|
</h3>
|
|
|
|
|
<p className="text-sm text-orange-700 mb-4">
|
|
|
|
|
Anda belum melakukan setup workflow, silahkan setup
|
|
|
|
|
terlebih dahulu.
|
|
|
|
|
</p>
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
onClick={handleSetupWorkflow}
|
|
|
|
|
className="bg-orange-600 hover:bg-orange-700 text-white"
|
|
|
|
|
size="sm"
|
|
|
|
|
>
|
|
|
|
|
<SettingsIcon className="h-4 w-4 mr-2" />
|
|
|
|
|
Setup Workflow
|
|
|
|
|
</Button>
|
|
|
|
|
{(pathname?.includes("/admin/settings/tenant") ||
|
|
|
|
|
pathname?.includes("/tenant")) && (
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
onClick={handleClose}
|
|
|
|
|
size="sm"
|
|
|
|
|
>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-10-02 06:41:49 +00:00
|
|
|
</div>
|
2026-03-03 09:26:11 +00:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
) : (
|
|
|
|
|
<Card className="border-green-200 bg-green-50">
|
|
|
|
|
<CardContent className="p-5 space-y-4">
|
|
|
|
|
<div className="flex items-start gap-3">
|
|
|
|
|
<div className="h-6 w-6 rounded-full bg-green-600 flex items-center justify-center mt-1">
|
|
|
|
|
<span className="text-white text-sm">✓</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<h3 className="font-semibold text-green-900 mb-3">
|
|
|
|
|
Workflow Sudah Dikonfigurasi
|
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2 text-sm">
|
|
|
|
|
<div className="flex justify-between">
|
|
|
|
|
<span className="text-gray-600">
|
|
|
|
|
Default Workflow
|
|
|
|
|
</span>
|
|
|
|
|
<span className="font-medium">
|
|
|
|
|
{workflowInfo.defaultWorkflowName}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex justify-between">
|
|
|
|
|
<span className="text-gray-600">Workflow ID</span>
|
|
|
|
|
<span className="font-mono">
|
|
|
|
|
#{workflowInfo.defaultWorkflowId}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex justify-between">
|
|
|
|
|
<span className="text-gray-600">
|
|
|
|
|
Requires Approval
|
|
|
|
|
</span>
|
|
|
|
|
<span
|
|
|
|
|
className={
|
|
|
|
|
workflowInfo.requiresApproval
|
|
|
|
|
? "text-green-600 font-medium"
|
|
|
|
|
: "text-gray-500"
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{workflowInfo.requiresApproval ? "Yes" : "No"}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex justify-between">
|
|
|
|
|
<span className="text-gray-600">Auto Publish</span>
|
|
|
|
|
<span
|
|
|
|
|
className={
|
|
|
|
|
workflowInfo.autoPublishArticles
|
|
|
|
|
? "text-green-600 font-medium"
|
|
|
|
|
: "text-gray-500"
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{workflowInfo.autoPublishArticles ? "Yes" : "No"}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex justify-between">
|
|
|
|
|
<span className="text-gray-600">Approval Status</span>
|
|
|
|
|
<span
|
|
|
|
|
className={
|
|
|
|
|
workflowInfo.isApprovalActive
|
|
|
|
|
? "text-green-600 font-medium"
|
|
|
|
|
: "text-red-600 font-medium"
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{workflowInfo.isApprovalActive
|
|
|
|
|
? "Active"
|
|
|
|
|
: "Inactive"}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* <div className="flex gap-2 mt-4">
|
|
|
|
|
<Button
|
2025-10-02 05:04:42 +00:00
|
|
|
onClick={handleSetupWorkflow}
|
2026-03-03 09:26:11 +00:00
|
|
|
variant="outline"
|
2025-10-02 05:04:42 +00:00
|
|
|
size="sm"
|
|
|
|
|
>
|
|
|
|
|
<SettingsIcon className="h-4 w-4 mr-2" />
|
2026-03-03 09:26:11 +00:00
|
|
|
Manage Workflow
|
2025-10-02 05:04:42 +00:00
|
|
|
</Button>
|
2026-03-03 09:26:11 +00:00
|
|
|
|
|
|
|
|
<Button variant="outline" onClick={handleClose} size="sm">
|
|
|
|
|
Close
|
|
|
|
|
</Button>
|
|
|
|
|
</div> */}
|
2025-10-02 05:04:42 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-03 09:26:11 +00:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
// Workflow Setup Complete
|
2025-10-02 06:41:49 +00:00
|
|
|
// <Card className="border-green-200 bg-green-50">
|
|
|
|
|
// <CardContent className="p-4">
|
|
|
|
|
// <div className="flex items-start gap-3">
|
|
|
|
|
// <div className="h-6 w-6 rounded-full bg-green-600 flex items-center justify-center mt-1">
|
|
|
|
|
// <span className="text-white text-sm">✓</span>
|
|
|
|
|
// </div>
|
|
|
|
|
// <div className="flex-1">
|
|
|
|
|
// <h3 className="font-medium text-green-900 mb-2">
|
|
|
|
|
// Workflow Sudah Dikonfigurasi
|
|
|
|
|
// </h3>
|
|
|
|
|
// <div className="space-y-2 text-sm text-green-700">
|
|
|
|
|
// <div className="flex items-center justify-between">
|
|
|
|
|
// <span>Workflow:</span>
|
|
|
|
|
// <span className="font-medium">{workflowInfo.defaultWorkflowName}</span>
|
|
|
|
|
// </div>
|
|
|
|
|
// <div className="flex items-center justify-between">
|
|
|
|
|
// <span>Requires Approval:</span>
|
|
|
|
|
// <span className={`font-medium ${workflowInfo.requiresApproval ? 'text-green-600' : 'text-gray-500'}`}>
|
|
|
|
|
// {workflowInfo.requiresApproval ? 'Yes' : 'No'}
|
|
|
|
|
// </span>
|
|
|
|
|
// </div>
|
|
|
|
|
// <div className="flex items-center justify-between">
|
|
|
|
|
// <span>Auto Publish:</span>
|
|
|
|
|
// <span className={`font-medium ${workflowInfo.autoPublishArticles ? 'text-green-600' : 'text-gray-500'}`}>
|
|
|
|
|
// {workflowInfo.autoPublishArticles ? 'Yes' : 'No'}
|
|
|
|
|
// </span>
|
|
|
|
|
// </div>
|
|
|
|
|
// <div className="flex items-center justify-between">
|
|
|
|
|
// <span>Status:</span>
|
|
|
|
|
// <span className={`font-medium ${workflowInfo.isApprovalActive ? 'text-green-600' : 'text-gray-500'}`}>
|
|
|
|
|
// {workflowInfo.isApprovalActive ? 'Active' : 'Inactive'}
|
|
|
|
|
// </span>
|
|
|
|
|
// </div>
|
|
|
|
|
// </div>
|
|
|
|
|
// <div className="flex gap-2 mt-4">
|
2026-03-03 09:26:11 +00:00
|
|
|
// <Button
|
2025-10-02 06:41:49 +00:00
|
|
|
// onClick={handleSetupWorkflow}
|
|
|
|
|
// variant="outline"
|
|
|
|
|
// size="sm"
|
|
|
|
|
// >
|
|
|
|
|
// <SettingsIcon className="h-4 w-4 mr-2" />
|
|
|
|
|
// Manage Workflow
|
|
|
|
|
// </Button>
|
|
|
|
|
// </div>
|
|
|
|
|
// </div>
|
|
|
|
|
// </div>
|
|
|
|
|
// </CardContent>
|
|
|
|
|
// </Card>
|
2026-03-03 09:26:11 +00:00
|
|
|
)
|
|
|
|
|
|
2025-10-02 06:41:49 +00:00
|
|
|
}
|
2025-10-02 05:04:42 +00:00
|
|
|
</div>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
}
|