/* Copyright (C) 2024 Manuel Bustillo*/ 'use client'; import { createGuest } from '@/app/api/guests'; import { Group } from '@/app/lib/definitions'; 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 submitGuest() { name && group && createGuest(name, group, () => { setVisible(false); setName(''); setGroup(null); onCreate && onCreate(); }); } return ( <> setVisible(true)} className={classNames('primary')}>Add new { if (!visible) return; setVisible(false); }}> setName(e.target.value)} /> Username setGroup(e.target.value)} options={ groups.map((group) => { return { label: group.name, value: group.id }; }) } /> Group 0 && group)}>Create > ); }