20 lines
789 B
TypeScript
20 lines
789 B
TypeScript
// 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
|
||
}
|