5 changed files with 90 additions and 1 deletions
-
25src/components/layout/Topbar.tsx
-
63src/features/support/supportPortal.ts
-
1src/locales/ar.json
-
1src/locales/en.json
-
1src/locales/fa.json
@ -0,0 +1,63 @@ |
|||
import { useMemo } from 'react' |
|||
import { useThemeStore } from '@/stores/theme' |
|||
|
|||
export const AQILA_SUPPORT_PORTAL_TOKEN = '76cb859c-24e3-4309-9d99-504ac2e49268' |
|||
export const AQILA_SUPPORT_PORTAL_BASE_URL = `https://teamby.nwhco.ir/portal/${AQILA_SUPPORT_PORTAL_TOKEN}` |
|||
export const FALLBACK_PRIMARY = '#d09460' |
|||
|
|||
function isValidHex(value: string): boolean { |
|||
return /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(value.trim()) |
|||
} |
|||
|
|||
function toCleanSixDigitHex(raw: string): string { |
|||
let clean = raw.trim().replace(/^#/, '') |
|||
if (clean.length === 3) { |
|||
clean = clean |
|||
.split('') |
|||
.map((c) => c + c) |
|||
.join('') |
|||
} |
|||
return clean.toLowerCase() |
|||
} |
|||
|
|||
export function resolveSupportPortalPrimaryHex(): string { |
|||
const candidates = [ |
|||
typeof document !== 'undefined' |
|||
? document.documentElement.style.getPropertyValue('--primary').trim() || |
|||
getComputedStyle(document.documentElement).getPropertyValue('--primary').trim() |
|||
: undefined, |
|||
FALLBACK_PRIMARY, |
|||
] |
|||
|
|||
for (const candidate of candidates) { |
|||
if (candidate && isValidHex(candidate)) { |
|||
return toCleanSixDigitHex(candidate) |
|||
} |
|||
} |
|||
|
|||
return toCleanSixDigitHex(FALLBACK_PRIMARY) |
|||
} |
|||
|
|||
export function buildAqilaSupportPortalUrl(options: { |
|||
primaryHex: string |
|||
theme: 'light' | 'dark' |
|||
}): string { |
|||
const url = new URL(AQILA_SUPPORT_PORTAL_BASE_URL) |
|||
url.searchParams.set('primary', toCleanSixDigitHex(options.primaryHex)) |
|||
url.searchParams.set('theme', options.theme) |
|||
return url.toString() |
|||
} |
|||
|
|||
/** |
|||
* Returns the live TeamBy Support Portal URL parameterized with the active |
|||
* Aqila Panel color palette and light/dark mode. |
|||
*/ |
|||
export function useSupportPortalUrl(): string { |
|||
const isDark = useThemeStore((s) => s.isDark) |
|||
const theme: 'light' | 'dark' = isDark ? 'dark' : 'light' |
|||
|
|||
return useMemo(() => { |
|||
const primaryHex = resolveSupportPortalPrimaryHex() |
|||
return buildAqilaSupportPortalUrl({ primaryHex, theme }) |
|||
}, [theme]) |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue