diff --git a/README.md b/README.md index 3ac15a6..21eb3a7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). +This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app), using MongoDB. ### Development Server diff --git a/app/actions/addProperty.js b/app/actions/addProperty.js new file mode 100644 index 0000000..1423dff --- /dev/null +++ b/app/actions/addProperty.js @@ -0,0 +1,39 @@ +"use server"; + +async function addProperty(formData) { + const amenities = formData.getAll("amenities"); // gets all values by form field "name" as an Array + + const images = formData + .getAll("images") + .filter((image) => image.name !== "") // filter out with no name + .map((image) => image.name); // only save image name in DB + + const propertyData = { + type: formData.get("type"), + name: formData.get("name"), + description: formData.get("description"), + location: { + street: formData.get("location.street"), + city: formData.get("location.city"), + state: formData.get("location.state"), + zipcode: formData.get("location.zipcode"), + }, + beds: formData.get("beds"), + baths: formData.get("baths"), + square_feet: formData.get("square_feet"), + amenities, + rates: { + nightly: formData.get("rates.nightly"), + weekly: formData.get("rates.weekly"), + monthly: formData.get("rates.monthly"), + }, + seller_info: { + name: FormDataEvent.get("seller_info.name"), + email: FormDataEvent.get("seller_info.email"), + phone: FormDataEvent.get("seller_info.phone"), + }, + images, + } +} + +export default addProperty; diff --git a/app/properties/add/page.jsx b/app/properties/add/page.jsx index dc96b4c..f56a97e 100644 --- a/app/properties/add/page.jsx +++ b/app/properties/add/page.jsx @@ -1,12 +1,15 @@ -import Link from 'next/link' +import PropertyAddForm from "@/components/propertyAddForm" -const PropertiesPage = () => { +const AddPropertiesPage = () => { return ( -