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 ( -
-

PropertiesPage

- Go Home -
+
+
+
+ +
+
+
) } -export default PropertiesPage +export default AddPropertiesPage diff --git a/components/Navbar.jsx b/components/Navbar.jsx index 392b5c6..04cd616 100644 --- a/components/Navbar.jsx +++ b/components/Navbar.jsx @@ -209,7 +209,7 @@ const Navbar = () => { + + + ) +} +export default PropertyAddForm \ No newline at end of file diff --git a/middleware.js b/middleware.js new file mode 100644 index 0000000..60f8daa --- /dev/null +++ b/middleware.js @@ -0,0 +1,5 @@ +export { default } from "next-auth/middleware"; + +export const config = { + matcher: ["/properties/add", "/profile", "/properties/saved", "/messages" ] +} diff --git a/next.config.mjs b/next.config.mjs index 4678774..c3f2205 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,14 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + images: { + remotePatterns: [ + { + protocol: "https", + hostname: "lh3.googleusercontent.com", + pathname: "**", + } + ] + }, +}; export default nextConfig; diff --git a/utils/getSessionUser.js b/utils/getSessionUser.js new file mode 100644 index 0000000..f2bc391 --- /dev/null +++ b/utils/getSessionUser.js @@ -0,0 +1,18 @@ +import { getServerSession } from "next-auth/next"; +import { authOptions } from "@/utils/authOptions"; + +export const getSessionUser = async () => { + try { + const session = await getServerSession(authOptions); + + if (!session || !session.user) return null; + + return { + user: session.user, + userId: session.user.id + } + } catch (error) { + console.error(error); + return null; + } +} \ No newline at end of file