From 3474c97659682cb69539cd99436654d7f3c03636 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Mon, 20 Apr 2026 10:21:23 +0530 Subject: [PATCH] refactor: simplify listing type selection by dynamically mapping agent types instead of hardcoded categories --- src/app/(user)/user/profiles/page.tsx | 60 ++++++++++++--------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/src/app/(user)/user/profiles/page.tsx b/src/app/(user)/user/profiles/page.tsx index 78a2896..04b525b 100644 --- a/src/app/(user)/user/profiles/page.tsx +++ b/src/app/(user)/user/profiles/page.tsx @@ -379,7 +379,7 @@ function ProfilesPageContent() { const nameFromUrl = searchParams.get('name') || ''; const locationFromUrl = searchParams.get('location') || ''; const filtersFromUrl = searchParams.get('filters') || ''; - const listingFromUrl = searchParams.get('listing') as 'agents' | 'lenders' | null; + const listingFromUrl = searchParams.get('listing'); // State for API data const [agents, setAgents] = useState([]); @@ -395,7 +395,6 @@ function ProfilesPageContent() { // State for search and filters - initialize from URL params const [searchQuery, setSearchQuery] = useState(nameFromUrl); const [activeTypeId, setActiveTypeId] = useState(typeFromUrl); - const [listingType, setListingType] = useState<'agents' | 'lenders'>(listingFromUrl || 'agents'); const [isFilterModalOpen, setIsFilterModalOpen] = useState(false); const [filters, setFilters] = useState(() => { if (filtersFromUrl) { @@ -428,10 +427,10 @@ function ProfilesPageContent() { const types = await agentsService.getAgentTypes(); setAgentTypes(types); - // If listing param is set, auto-select the matching agent type + // If listing param is set, auto-select the matching agent type by name (case-insensitive) if (listingFromUrl && !typeFromUrl) { - const typeName = listingFromUrl === 'lenders' ? 'Lender' : 'Professional'; - const matchedType = types.find((t: AgentType) => t.name === typeName); + const target = listingFromUrl.toLowerCase().replace(/s$/, ''); + const matchedType = types.find((t: AgentType) => t.name.toLowerCase() === target); if (matchedType) { setActiveTypeId(matchedType.id); } @@ -575,24 +574,6 @@ function ProfilesPageContent() { const handleTypeChange = (typeId: string | null) => { setActiveTypeId(typeId); setCurrentPage(1); - // Sync listing type sidebar with agent type tab selection - if (typeId) { - const matchedType = agentTypes.find(t => t.id === typeId); - if (matchedType?.name === 'Lender') { - setListingType('lenders'); - } else { - setListingType('agents'); - } - } - }; - - const handleListingTypeChange = (type: 'agents' | 'lenders') => { - setListingType(type); - // Map listing type to the corresponding agent type and filter - const typeName = type === 'agents' ? 'Professional' : 'Lender'; - const matchedType = agentTypes.find(t => t.name === typeName); - setActiveTypeId(matchedType?.id || null); - setCurrentPage(1); }; // Get filter field by slug for sidebar @@ -603,6 +584,16 @@ function ProfilesPageContent() { // Define which fields to show in sidebar (main filter categories) const sidebarFilterSlugs = ['client_specialization', 'loan_type', 'property_type', 'price_point']; + // Pluralize agent type names for sidebar display (e.g. "Agent" → "Agents", "Property Manager" → "Property Managers") + const pluralize = (name: string): string => { + const trimmed = name.trim(); + if (!trimmed) return trimmed; + const lower = trimmed.toLowerCase(); + if (lower.endsWith('s')) return trimmed; + if (lower.endsWith('y')) return `${trimmed.slice(0, -1)}ies`; + return `${trimmed}s`; + }; + return (
@@ -615,19 +606,20 @@ function ProfilesPageContent() {

Listing Type

- + {agentTypes.map((type) => ( + + ))}