From 64f4234220143bf84832272129f44184f81eaa91 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Fri, 20 Mar 2026 12:43:23 +0530 Subject: [PATCH] feat: Implement contact form submission with API integration and status feedback, refactor user profiles page layout and scrolling, and remove `updateSession` call from profile settings. --- src/app/(user)/user/profiles/page.tsx | 60 +++++++++---------- src/app/contact/page.tsx | 44 ++++++++++++-- .../settings/ProfileSettingsForm.tsx | 11 +--- src/services/api.ts | 1 + 4 files changed, 69 insertions(+), 47 deletions(-) diff --git a/src/app/(user)/user/profiles/page.tsx b/src/app/(user)/user/profiles/page.tsx index 91bff01..edfe3cf 100644 --- a/src/app/(user)/user/profiles/page.tsx +++ b/src/app/(user)/user/profiles/page.tsx @@ -612,8 +612,8 @@ function ProfilesPageContent() {
- {/* Left Sidebar - hidden on mobile, sticky */} -
+ {/* Left Sidebar - hidden on mobile */} +
{/* Listing Type */}

Listing Type

@@ -774,37 +774,35 @@ function ProfilesPageContent() {
)} - {/* Profile Cards - nested scroll matching filter sidebar height */} + {/* Profile Cards */} {!loading && !error && agents.length > 0 && ( -
-
- {agents.map((profile) => ( - - ))} -
+
+ {agents.map((profile) => ( + + ))} +
+ )} - {/* Pagination - sticky at bottom of scroll area */} - {totalPages > 1 && ( -
- - - Page {currentPage} of {totalPages} - - -
- )} + {/* Pagination */} + {!loading && !error && totalPages > 1 && ( +
+ + + Page {currentPage} of {totalPages} + +
)}
diff --git a/src/app/contact/page.tsx b/src/app/contact/page.tsx index 1d728fc..93874ac 100644 --- a/src/app/contact/page.tsx +++ b/src/app/contact/page.tsx @@ -6,6 +6,7 @@ import { useState, useEffect } from 'react'; import { CommonHeader } from '@/components/layout/CommonHeader'; import { Footer } from '@/components/layout/Footer'; import { cmsService } from '@/services/cms.service'; +import api from '@/services/api'; interface ContactDetails { title: string; @@ -55,6 +56,8 @@ export default function ContactPage() { const [contactDetails, setContactDetails] = useState(defaultContactDetails); const [cta, setCta] = useState(defaultCta); + const [isSubmitting, setIsSubmitting] = useState(false); + const [submitStatus, setSubmitStatus] = useState<'idle' | 'success' | 'error'>('idle'); useEffect(() => { const loadCms = async () => { @@ -73,10 +76,27 @@ export default function ContactPage() { setFormData(prev => ({ ...prev, [name]: value })); }; - const handleSubmit = (e: React.FormEvent) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - // Handle form submission - console.log('Form submitted:', formData); + if (!formData.name.trim() || !formData.email.trim() || !formData.message.trim()) return; + + setIsSubmitting(true); + setSubmitStatus('idle'); + try { + await api.post('/contact', { + name: formData.name.trim(), + email: formData.email.trim(), + phone: formData.phone.trim() || undefined, + message: formData.message.trim(), + }); + setSubmitStatus('success'); + setFormData({ name: '', phone: '', email: '', message: '' }); + setTimeout(() => setSubmitStatus('idle'), 5000); + } catch { + setSubmitStatus('error'); + } finally { + setIsSubmitting(false); + } }; const handleCancel = () => { @@ -188,19 +208,31 @@ export default function ContactPage() {
{/* Buttons */} + {submitStatus === 'success' && ( +
+

Message sent successfully! We'll get back to you shortly.

+
+ )} + {submitStatus === 'error' && ( +
+

Failed to send message. Please try again.

+
+ )}
diff --git a/src/components/settings/ProfileSettingsForm.tsx b/src/components/settings/ProfileSettingsForm.tsx index 6f270ee..403e8f2 100644 --- a/src/components/settings/ProfileSettingsForm.tsx +++ b/src/components/settings/ProfileSettingsForm.tsx @@ -311,17 +311,8 @@ export function ProfileSettingsForm({ }); } - // Update session name without causing a page refresh - try { - const fullName = `${formData.firstName} ${formData.lastName}`.trim(); - await updateSession({ - user: { name: fullName }, - }); - } catch { - // Session update can fail silently - profile is already saved - } - // Dispatch event to notify header and other components to refresh profile data + // (Don't call updateSession as it can trigger a full page reload in next-auth v5) window.dispatchEvent(new Event('profile-updated')); if (onSave) { diff --git a/src/services/api.ts b/src/services/api.ts index a86e7f2..5cefd4b 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -110,6 +110,7 @@ const publicEndpoints = [ '/agent-types', '/agents', '/cms', + '/contact', '/profile-fields/filterable', '/stripe/plans', '/upload/presigned-download-url',