diff --git a/frontend/src/pages/NewListing.tsx b/frontend/src/pages/NewListing.tsx index 706c97c3..3c66b959 100644 --- a/frontend/src/pages/NewListing.tsx +++ b/frontend/src/pages/NewListing.tsx @@ -5,22 +5,38 @@ import { Dispatch, FormEvent, SetStateAction, useState } from "react"; import { Col, Form } from "react-bootstrap"; import { useNavigate } from "react-router-dom"; -interface ListingFormProps { - title: string; - name: string; - setName: Dispatch>; - description: string; - setDescription: Dispatch>; - handleSubmit: (event: FormEvent) => void; -} +const NewListing = () => { + const auth = useAuthentication(); + const [name, setName] = useState(""); + const [description, setDescription] = useState(""); + + const { addAlert, addErrorAlert } = useAlertQueue(); + const navigate = useNavigate(); + + // On submit, add the listing to the database and navigate to the + // newly-created listing. + const handleSubmit = async (event: FormEvent) => { + event.preventDefault(); + + const { data, error } = await auth.client.POST("/listings/add", { + body: { + name, + description, + child_ids: [], + }, + }); -const ListingForm = (props: ListingFormProps) => { - const { title, name, setName, description, setDescription, handleSubmit } = - props; + if (error) { + addErrorAlert(error); + } else { + addAlert("Listing added successfully", "success"); + navigate(`/listing/${data.listing_id}`); + } + }; return ( <> -

{title}

+

Create Listing

{/* Name */} @@ -60,45 +76,4 @@ const ListingForm = (props: ListingFormProps) => { ); }; -const NewListing = () => { - const auth = useAuthentication(); - const [name, setName] = useState(""); - const [description, setDescription] = useState(""); - - const { addAlert, addErrorAlert } = useAlertQueue(); - const navigate = useNavigate(); - - // On submit, add the listing to the database and navigate to the - // newly-created listing. - const handleSubmit = async (event: FormEvent) => { - event.preventDefault(); - - const { data, error } = await auth.client.POST("/listings/add", { - body: { - name, - description, - child_ids: [], - }, - }); - - if (error) { - addErrorAlert(error); - } else { - addAlert("Listing added successfully", "success"); - navigate(`/listing/${data.listing_id}`); - } - }; - - return ( - - ); -}; - export default NewListing;