From 6d758a1f31b035c67bbe33dce28e616ae3ea117c Mon Sep 17 00:00:00 2001
From: Brad Traversy
Date: Fri, 12 Jul 2024 16:01:14 -0400
Subject: [PATCH] Search form
---
components/Hero.jsx | 42 ++----------------
components/PropertySearchForm.jsx | 72 +++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 39 deletions(-)
create mode 100644 components/PropertySearchForm.jsx
diff --git a/components/Hero.jsx b/components/Hero.jsx
index 569e2af..6205e19 100644
--- a/components/Hero.jsx
+++ b/components/Hero.jsx
@@ -1,3 +1,5 @@
+import PropertySearchForm from './PropertySearchForm';
+
const Hero = () => {
return (
@@ -10,45 +12,7 @@ const Hero = () => {
Discover the perfect property that suits your needs.
- {/* */}
-
+
);
diff --git a/components/PropertySearchForm.jsx b/components/PropertySearchForm.jsx
new file mode 100644
index 0000000..3c27e99
--- /dev/null
+++ b/components/PropertySearchForm.jsx
@@ -0,0 +1,72 @@
+'use client';
+import { useState } from 'react';
+import { useRouter } from 'next/navigation';
+
+const PropertySearchForm = () => {
+ const [location, setLocation] = useState('');
+ const [propertyType, setPropertyType] = useState('All');
+
+ const router = useRouter();
+
+ const handleSubmit = (e) => {
+ e.preventDefault();
+
+ if (location === '' && propertyType === 'All') {
+ router.push('/properties');
+ } else {
+ const query = `?location=${location}&propertyType=${propertyType}`;
+
+ router.push(`/properties/search-results${query}`);
+ }
+ };
+
+ return (
+
+ );
+};
+
+export default PropertySearchForm;