diff --git a/frontend/src/components/listing/EditListingModal.tsx b/frontend/src/components/listing/EditListingModal.tsx deleted file mode 100644 index 72bbd013..00000000 --- a/frontend/src/components/listing/EditListingModal.tsx +++ /dev/null @@ -1,180 +0,0 @@ -import { zodResolver } from "@hookform/resolvers/zod"; -import RequireAuthentication from "components/auth/RequireAuthentication"; -import { Button } from "components/ui/Button/Button"; -import { - Dialog, - DialogContent, - DialogFooter, - DialogHeader, - DialogTitle, -} from "components/ui/dialog"; -import ErrorMessage from "components/ui/ErrorMessage"; -import { Input, TextArea } from "components/ui/Input/Input"; -import { paths } from "gen/api"; -import { useAlertQueue } from "hooks/useAlertQueue"; -import { useAuthentication } from "hooks/useAuth"; -import { useEffect, useState } from "react"; -import { SubmitHandler, useForm } from "react-hook-form"; -import { NewListingSchema, NewListingType } from "types"; - -// const dropZoneConfig = { -// maxFiles: 5, -// maxSize: 1024 * 1024 * 4, -// multiple: true, -// }; - -interface AddOrEditProps { - open: boolean; - listingId: string; - onClose: () => void; -} - -type ListingResponse = - paths["/listings/{id}"]["get"]["responses"][200]["content"]["application/json"]; - -const EditListingModal = ({ open, onClose, listingId }: AddOrEditProps) => { - // const [files, setFiles] = useState(null); - const { addAlert, addErrorAlert } = useAlertQueue(); - const auth = useAuthentication(); - const [listing, setListing] = useState(null); - - const { - register, - handleSubmit, - setValue, - formState: { errors }, - } = useForm({ - resolver: zodResolver(NewListingSchema), - }); - - useEffect(() => { - const fetchListing = async () => { - const { data, error } = await auth.client.GET("/listings/{id}", { - params: { - path: { id: listingId }, - }, - }); - if (error) { - addErrorAlert(error); - } else { - setListing(data); - } - }; - fetchListing(); - }, []); - - useEffect(() => { - if (listing) { - setValue("name", listing.name); - setValue("description", listing.description ?? ""); - } - }, [listing, setValue]); - - const onSubmit: SubmitHandler = async ({ - name, - description, - }: NewListingType) => { - const { error } = await auth.client.PUT("/listings/edit/{id}", { - params: { - path: { - id: listingId, - }, - }, - body: { - name, - description, - }, - }); - - if (error) { - addErrorAlert(error); - } else { - addAlert("Listing added successfully", "success"); - onClose(); - window.location.reload(); - } - }; - - return ( - - - - - - Add Robo Details - - -
- {/* Name */} -
- - {errors?.name && ( - {errors?.name?.message} - )} -
- - {/* Description */} -
-