Skip to content

Commit

Permalink
production 3 - Update CreateEditReservation.js
Browse files Browse the repository at this point in the history
  • Loading branch information
NolaDodd authored Jun 8, 2024
1 parent 10f303d commit fbc9c14
Showing 1 changed file with 16 additions and 141 deletions.
157 changes: 16 additions & 141 deletions front-end/src/layout/CreateEditReservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,22 @@ function CreateEditReservation(){

const navigate = useNavigate()

const handleEdit = async (event) => {
event.preventDefault()
const handleSubmit = async (event) => {
event.preventDefault();
try {
console.log("handleSubmitEdit")
await updateReservationEdit(formData, reservationId);
setFormData(initialFormState);
navigate(`/dashboard`);
} catch (error) {
setFormError(error)
}
}

const handleSubmit = async (event) => {
event.preventDefault()
try {
console.log("handleSubmit")
await createReservation(formData);
setFormData(initialFormState);
navigate(`/dashboard`);
if (reservationId) {
await updateReservationEdit(formData, reservationId);
} else {
await createReservation(formData);
}
setFormData(initialFormState);
navigate(`/dashboard`);
} catch (error) {

setFormError(error)
setFormError(error);
}
}
};

const createReservationForm = (
const createEditReservationForm = (
<div className="formtext">
<form onSubmit={handleSubmit}>
<label htmlFor="first_name">
Expand Down Expand Up @@ -165,129 +155,14 @@ function CreateEditReservation(){
</form>
<ErrorAlert error={formError} />
</div>
)


const editReservationForm = (
<div className="formtext">
<form onSubmit={handleEdit}>
<label htmlFor="first_name">
<b>First Name:</b>
<br />
<input
id="first_name"
type="text"
name="first_name"
onChange={handleChange}
value={formData.first_name}
placeholder="First Name"
required
/>
</label>
<br/>
<label htmlFor="last_name">
<b>Last Name:</b>
<br />
<input
id="last_name"
type="text"
name="last_name"
onChange={handleChange}
value={formData.last_name}
placeholder="Last Name"
required
/>
</label>
<br/>
<label htmlFor="mobile_number">
<b>Mobile Number:</b>
<br />
<input
id="mobile_number"
type="text"
name="mobile_number"
placeholder="XXX-XXX-XXXX"
pattern="(\d{3}-\d{3}-\d{4}|\d{10})"
onChange={handleChange}
value={formData.mobile_number}
required
title="Please enter a valid phone number with 10 digits"
>
</input>
</label>
<br/>
<label htmlFor="reservation_date">
<b>Reservation Date:</b>
<br />
<input
id="reservation_date"
type="date"
name="reservation_date"
onChange={handleChange}
value={formData.reservation_date}
placeholder="YYYY-MM-DD"
pattern="\d{4}-\d{2}-\d{2}"
required
/>
</label>
<br/>
<label htmlFor="reservation_time">
<b>Reservation Time:</b>
<br />
<input
id="reservation_time"
type="time"
name="reservation_time"
onChange={handleChange}
value={formData.reservation_time}
placeholder="HH:MM"
pattern="[0-9]{2}:[0-9]{2}"
required
/>
</label>
<br/>
<label htmlFor="people">
<b>Number of People:</b>
<br />
<input
id="people"
type="number"
name="people"
min="1"
onChange={handleChange}
value={formData.people}
required
/>
</label>
<br/>
<button type="submit" className="btn btn-primary">Submit</button>
<button onClick={() => navigate(-1)} className= "btn btn-secondary">Cancel</button>
</form>
<ErrorAlert error={formError} />
</div>
)
)

return (
<div>
{reservationId ? (
<>
<h3 className="title">Edit Reservation</h3>
{editReservationForm}
</>
) : (
<>
<h3 className="title">New Reservation</h3>
{createReservationForm}
</>
)}
{createEditReservationForm}
</div>
)



)

}



export default CreateEditReservation
export default CreateEditReservation

0 comments on commit fbc9c14

Please sign in to comment.