"use client"; import { useState, useEffect } from "react"; import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal"; import { Button } from "@/app/_components/GlobalComponents/UIElements/Button"; import { Input } from "@/app/_components/GlobalComponents/FormElements/Input"; import { CronExpressionHelper } from "@/app/_components/FeatureComponents/Scripts/CronExpressionHelper"; import { SelectScriptModal } from "@/app/_components/FeatureComponents/Modals/SelectScriptModal"; import { UserSwitcher } from "@/app/_components/FeatureComponents/User/UserSwitcher"; import { Plus, Terminal, FileText, X, FileOutput } from "lucide-react"; import { getScriptContent } from "@/app/_server/actions/scripts"; import { getHostScriptPath } from "@/app/_server/actions/scripts"; import { useTranslations } from "next-intl"; interface Script { id: string; name: string; description: string; createdAt: string; filename: string; } interface CreateTaskModalProps { isOpen: boolean; onClose: () => void; onSubmit: (e: React.FormEvent) => void; scripts: Script[]; form: { schedule: string; command: string; comment: string; selectedScriptId: string | null; user: string; logsEnabled: boolean; }; onFormChange: (updates: Partial) => void; } export const CreateTaskModal = ({ isOpen, onClose, onSubmit, scripts, form, onFormChange, }: CreateTaskModalProps) => { const [selectedScriptContent, setSelectedScriptContent] = useState(""); const [isSelectScriptModalOpen, setIsSelectScriptModalOpen] = useState(false); const selectedScript = scripts.find((s) => s.id === form.selectedScriptId); const t = useTranslations(); useEffect(() => { const loadScriptContent = async () => { if (selectedScript) { const content = await getScriptContent(selectedScript.filename); setSelectedScriptContent(content); } else { setSelectedScriptContent(""); } }; loadScriptContent(); }, [selectedScript]); const handleScriptSelect = async (script: Script) => { const scriptPath = await getHostScriptPath(script.filename); onFormChange({ selectedScriptId: script.id, command: scriptPath, }); }; const handleCustomCommand = () => { onFormChange({ selectedScriptId: null, command: "", }); }; const handleClearScript = () => { onFormChange({ selectedScriptId: null, command: "", }); }; return ( <>
onFormChange({ user })} />
onFormChange({ schedule: value })} placeholder="* * * * *" showPatterns={true} />
{form.selectedScriptId && selectedScript && (

{selectedScript.name}

{selectedScript.description}

{form.command}
)} {!form.selectedScriptId && !selectedScript && (