/* Copyright (C) 2024 Manuel Bustillo*/ 'use client'; import { Group } from '@/app/lib/definitions'; import { getCsrfToken } from '@/app/lib/utils'; import { classNames } from '@/app/ui/components/button'; import { Dialog } from 'primereact/dialog'; import { Dropdown } from 'primereact/dropdown'; import { FloatLabel } from 'primereact/floatlabel'; import { InputText } from 'primereact/inputtext'; import { useState } from 'react'; export default function CreationDialog({ groups, onCreate }: { groups: Group[], onCreate?: () => void }) { const [visible, setVisible] = useState(false); const [name, setName] = useState(''); const [group, setGroup] = useState(null); function createGuest() { fetch("/api/guests", { method: 'POST', body: JSON.stringify({ name: name, group_id: group }), headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': getCsrfToken(), } }) .then((response) => response.json()) .then((data) => { console.log(data); setVisible(false); onCreate && onCreate(); }) .catch((error) => console.error(error)); } return ( <> { if (!visible) return; setVisible(false); }}>
setName(e.target.value)} /> setGroup(e.target.value)} options={ groups.map((group) => { return { label: group.name, value: group.id }; }) } />
); }