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