export default function CreateSlotModal({ channel }) {
const { show, toggleShow } = useModal();
const { data, setData, post, processing, errors, reset } = useForm({
title: "",
type: "",
price: "",
duration_type: "",
duration_value: "",
description: "",
visibility: "",
});
const handleChange = (event) => {
setData(
event.target.name,
event.target.type === "checkbox"
? event.target.checked
: event.target.value
);
};
const submit = (e) => {
e.preventDefault();
post(route("slot.store", channel), {
onSuccess: () => {
reset();
toggleShow();
},
});
};
return (
<React.Fragment>
<Button onClick={toggleShow}>Create Slot</Button>
<Modal
position={"top-center"}
show={show}
onClose={toggleShow}
>
<Modal.Header>Create Slot</Modal.Header>
<Modal.Body>
{channel.title}
<form
onSubmit={submit}
action=""
className="flex flex-col gap-4"
>
<InputRow label="Title" error={errors.title}>
<TextInput
id="title"
type="text"
name="title"
placeholder="slot title"
required={true}
value={data.title}
onChange={handleChange}
/>
</InputRow>
<InputRow label="Price" error={errors.price}>
<TextInput name="price" onChange={handleChange} />
</InputRow>
<InputRow label="Description" error={errors.description}>
<Textarea
name="description"
placeholder="Tell your buyer about your slot"
rows={3}
onChange={handleChange}
value={data.description}
></Textarea>
</InputRow>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<InputRow label="Duration value" error={errors.duration_value}>
<TextInput name="duration_value" onChange={handleChange} />
</InputRow>
<InputRow label="Duration Type" error={errors.duration_type}>
<Select
onChange={handleChange}
value={data.duration_type}
name="duration_type"
>
<option value="">duration type</option>
<option value="year">year</option>
<option value="month">month</option>
<option value="day">day</option>
<option value="hour">hour</option>
<option value="minute">minute</option>
<option value="seconds">seconds</option>
</Select>
</InputRow>
<InputRow label="Visibility" error={errors.visibility}>
<Select
onChange={handleChange}
value={data.visibility}
name="visibility"
>
<option value="">select visibility</option>
<option value="draft">draft</option>
<option value="public">public</option>
</Select>
</InputRow>
</div>
<div className="flex space-x-3">
<Button type="submit">Create</Button>
<Button
color="gray"
onClick={toggleShow}
>
Decline
</Button>
</div>
</form>
</Modal.Body>
</Modal>
</React.Fragment>
);
}