image.name !== '') // Filter out empty names
+ .map((image) => image.name); // Extract only the names
+
+ // Create the propertyData object with embedded seller_info
+ 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: {
+ weekly: formData.get('rates.weekly'),
+ monthly: formData.get('rates.monthly'),
+ nightly: formData.get('rates.nightly.'),
+ },
+ seller_info: {
+ name: formData.get('seller_info.name'),
+ email: formData.get('seller_info.email'),
+ phone: formData.get('seller_info.phone'),
+ },
+ images,
+ owner: userId,
+ };
+
+ const newProperty = new Property(propertyData);
+ await newProperty.save();
+
+ revalidatePath('/', 'layout');
+
+ redirect(`/properties/${newProperty._id}`);
+}
+
+export default addProperty;
diff --git a/app/properties/add/page.jsx b/app/properties/add/page.jsx
index e57dde3..4dbe940 100644
--- a/app/properties/add/page.jsx
+++ b/app/properties/add/page.jsx
@@ -1,4 +1,14 @@
-const AddPropertyPage = () => {
- return
AddPropertyPage
;
+import PropertyAddForm from '@/components/PropertyAddForm';
+
+const PropertyAddPage = () => {
+ return (
+
+ );
};
-export default AddPropertyPage;
+export default PropertyAddPage;
diff --git a/components/PropertyAddForm.jsx b/components/PropertyAddForm.jsx
new file mode 100644
index 0000000..da03e2d
--- /dev/null
+++ b/components/PropertyAddForm.jsx
@@ -0,0 +1,407 @@
+'use client';
+import addProperty from '@/app/actions/addProperty';
+
+const PropertyAddForm = () => {
+ return (
+
+ );
+};
+
+export default PropertyAddForm;
diff --git a/utils/getSessionUser.js b/utils/getSessionUser.js
new file mode 100644
index 0000000..035f1ef
--- /dev/null
+++ b/utils/getSessionUser.js
@@ -0,0 +1,20 @@
+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;
+ }
+};