fix search feature
Build & Push / Pipeline Tests (push) Failing after 1m14s
Build & Push / Build & Push Docker Image (push) Has been skipped
Test / Type Check (all packages) (push) Successful in 53s
Test / API Unit Tests (push) Failing after 50s
Test / Homepage Unit Tests (push) Successful in 45s
Test / Carplace Unit Tests (push) Successful in 44s
Test / Admin Unit Tests (push) Successful in 42s
Test / Dashboard Unit Tests (push) Successful in 43s
Test / API Integration Tests (push) Successful in 1m4s

This commit is contained in:
root
2026-07-26 01:18:05 -04:00
parent f6fcd7ce54
commit 2b422ca197
23 changed files with 880 additions and 51 deletions
@@ -351,6 +351,7 @@ const dictionaries: Record<DashboardLanguage, DashboardDictionary> = {
'/subscription': 'Subscription',
'/billing': 'Billing',
'/contracts': 'Contracts',
'/search': 'Search',
'/notifications': 'Notifications',
'/settings': 'Settings',
},
@@ -720,6 +721,7 @@ const dictionaries: Record<DashboardLanguage, DashboardDictionary> = {
'/subscription': 'Abonnement',
'/billing': 'Facturation',
'/contracts': 'Contrats',
'/search': 'Recherche',
'/notifications': 'Notifications',
'/settings': 'Paramètres',
},
@@ -1089,6 +1091,7 @@ const dictionaries: Record<DashboardLanguage, DashboardDictionary> = {
'/subscription': 'الاشتراك',
'/billing': 'الفوترة',
'/contracts': 'العقود',
'/search': 'البحث',
'/notifications': 'الإشعارات',
'/settings': 'الإعدادات',
},
@@ -5,7 +5,7 @@ import { Bell, Search, Settings } from 'lucide-react'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { useState, useEffect } from 'react'
import { io } from 'socket.io-client'
import { EMPLOYEE_PROFILE_KEY, apiFetch } from '@/lib/api'
import { EMPLOYEE_PROFILE_KEY, apiFetch, resolveApiOrigin } from '@/lib/api'
import { useDashboardI18n } from '@/components/I18nProvider'
import { toDashboardAppPath } from '@/lib/dashboardPaths'
@@ -16,30 +16,6 @@ function computeInitials(name: string): string {
return `${parts[0].slice(0, 1)}${parts[1].slice(0, 1)}`.toUpperCase()
}
function resolveSocketOrigin(): string | null {
if (typeof window === 'undefined') return null
const configuredApiUrl = process.env.NEXT_PUBLIC_API_URL
if (configuredApiUrl) {
try {
return new URL(configuredApiUrl, window.location.origin).origin
} catch {}
}
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
return 'http://localhost:4000'
}
return window.location.origin
}
const SEARCHABLE_ROUTES = ['/reservations', '/fleet', '/customers', '/contracts', '/billing']
function getSearchTarget(appPath: string): string {
const match = SEARCHABLE_ROUTES.find((route) => appPath === route || appPath.startsWith(`${route}/`))
return match ?? '/reservations'
}
export default function TopBar() {
const { dict } = useDashboardI18n()
const pathname = usePathname()
@@ -100,12 +76,14 @@ export default function TopBar() {
useEffect(() => {
if (!socketEnabled) return
const socketOrigin = resolveSocketOrigin()
const socketOrigin = resolveApiOrigin()
if (!socketOrigin) return
const socket = io(socketOrigin, {
autoConnect: false,
withCredentials: true,
reconnectionAttempts: 3,
timeout: 5000,
transports: ['polling', 'websocket'],
})
@@ -210,14 +188,13 @@ export default function TopBar() {
event.preventDefault()
const query = globalSearch.trim()
const target = getSearchTarget(appPath)
const params = new URLSearchParams()
if (query) {
params.set('search', query)
router.push(`${target}?${params.toString()}`)
router.push(`/search?${params.toString()}`)
} else {
router.push(target)
router.push('/search')
}
}