2025-10-02 05:04:42 +00:00
|
|
|
"use client";
|
|
|
|
|
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";
|
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
|
|
|
}
|
|
|
|
|
|
2025-10-02 06:41:49 +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
|
|
|
|
|
if (workflowInfo?.hasWorkflowSetup || pathname?.includes('/admin/settings/tenant') || pathname?.includes('/tenant')) {
|
|
|
|
|
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 (
|
2025-10-02 06:41:49 +00:00
|
|
|
<Dialog
|
|
|
|
|
open={isVisible}
|
|
|
|
|
onOpenChange={(workflowInfo?.hasWorkflowSetup || pathname?.includes('/admin/settings/tenant') || pathname?.includes('/tenant')) ? handleClose : undefined}
|
|
|
|
|
>
|
|
|
|
|
<DialogContent
|
|
|
|
|
className="max-w-md"
|
|
|
|
|
onPointerDownOutside={(e) => {
|
|
|
|
|
// Prevent closing by clicking outside unless workflow is setup or on tenant settings page
|
|
|
|
|
if (!workflowInfo?.hasWorkflowSetup && !pathname?.includes('/admin/settings/tenant') && !pathname?.includes('/tenant')) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
onEscapeKeyDown={(e) => {
|
|
|
|
|
// Prevent closing by pressing ESC unless workflow is setup or on tenant settings page
|
|
|
|
|
if (!workflowInfo?.hasWorkflowSetup && !pathname?.includes('/admin/settings/tenant') && !pathname?.includes('/tenant')) {
|
|
|
|
|
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">
|
|
|
|
|
{!workflowInfo?.hasWorkflowSetup ? (
|
|
|
|
|
// No Workflow Setup
|
|
|
|
|
<Card className="border-orange-200 bg-orange-50">
|
|
|
|
|
<CardContent className="p-4">
|
|
|
|
|
<div className="flex items-start gap-3">
|
2025-10-02 06:41:49 +00:00
|
|
|
<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>
|
2025-10-02 05:04:42 +00:00
|
|
|
<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>
|
2025-10-02 06:41:49 +00:00
|
|
|
{(pathname?.includes('/admin/settings/tenant') || pathname?.includes('/tenant')) && (
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
onClick={handleClose}
|
|
|
|
|
size="sm"
|
|
|
|
|
>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2025-10-02 05:04:42 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2025-10-02 06:41:49 +00:00
|
|
|
) : ''
|
2025-10-02 05:04:42 +00:00
|
|
|
// 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">
|
|
|
|
|
// <Button
|
|
|
|
|
// onClick={handleSetupWorkflow}
|
|
|
|
|
// variant="outline"
|
|
|
|
|
// size="sm"
|
|
|
|
|
// >
|
|
|
|
|
// <SettingsIcon className="h-4 w-4 mr-2" />
|
|
|
|
|
// Manage Workflow
|
|
|
|
|
// </Button>
|
|
|
|
|
// </div>
|
|
|
|
|
// </div>
|
|
|
|
|
// </div>
|
|
|
|
|
// </CardContent>
|
|
|
|
|
// </Card>
|
|
|
|
|
}
|
2025-10-02 05:04:42 +00:00
|
|
|
</div>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
}
|