import { useRef, useState } from 'react'; import { Button, Textarea } from '@chakra-ui/react'; import { OntimeEvent } from 'ontime-types'; import { useEventAction } from '../../../common/hooks/useEventAction'; import type { EditEvent } from '../Operator'; import style from './EditModal.module.scss'; interface EditModalProps { event: EditEvent; onClose: () => void; } export default function EditModal(props: EditModalProps) { const { event, onClose } = props; const { updateEvent } = useEventAction(); const [loading, setLoading] = useState(false); const inputRef = useRef(new Array()); const handleSave = async () => { if (!inputRef.current) return; setLoading(true); const patchObject: Partial = { id: event.id }; inputRef.current.forEach((element) => { if (element.dataset.field && element.defaultValue != element.value) { if (patchObject.custom) { patchObject.custom[element.dataset.field] = element.value; } else { Object.assign(patchObject, { custom: { [element.dataset.field]: element.value } }); } } }); if (patchObject.custom) { await updateEvent(patchObject); } setLoading(false); onClose(); }; return (
{`Editing fields in cue ${event.cue}`}
{event.subscriptions.map((field) => { return (