import React, { useState } from "react"; import { X } from "@phosphor-icons/react"; import System from "@/models/system"; import showToast from "@/utils/toast"; export default function AddVariableModal({ closeModal, onRefresh }) { const [error, setError] = useState(null); const handleCreate = async (e) => { e.preventDefault(); setError(null); const formData = new FormData(e.target); const newVariable = {}; for (const [key, value] of formData.entries()) newVariable[key] = value.trim(); if (!newVariable.key || !newVariable.value) { setError("Key and value are required"); return; } try { await System.promptVariables.create(newVariable); showToast("Variable created successfully", "success", { clear: true }); if (onRefresh) onRefresh(); closeModal(); } catch (error) { console.error("Error creating variable:", error); setError("Failed to create variable"); } }; return (