Files
tripwithbonus/frontend/lib/utils/pathMapper.ts

20 lines
789 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// export type SourceType = 'main' | 'admin' | 'userAccount' | 'contactUs' | 'support'
import { SourceType } from '@/app/types'
const pathToSourceMap: Record<string, SourceType> = {
'account/support': 'support',
'': 'main', // без слеша -- так работает usePathname
'contact-us': 'contactUs', // URL путь с дефисом -> значение в camelCase
}
export const getSourceFromPath = (pathname: string): SourceType => {
const cleanPath = pathname.replace(/^\//, '')
// для путей аккаунта (кроме support)
if (cleanPath.startsWith('account/') && cleanPath !== 'account/support') {
return 'userAccount'
}
const source = pathToSourceMap[cleanPath] || 'contactUs' // дефолтное значение
return source
}