Files
My-KOPKB/fe/src/modules/profile/utils/member-digital-card.utils.ts
T
ismailmasseran 580c7d2392
Build Docker Image / build-backend (push) Failing after 23s
Build Docker Image / build-frontend (push) Successful in 21s
DONE: fix error where image not showing on digital card, generate letter not working on prod (#5)
Co-authored-by: ISMAIL MASSERAN <topaz@ISMAILs-Macbook.local>
Reviewed-on: #5
2026-07-06 13:24:42 +08:00

36 lines
1.0 KiB
TypeScript

export function displayCardValue(value: string | number | null | undefined) {
if (value === null || value === undefined || value === '') return '-'
return String(value).trim() || '-'
}
export function buildCardDownloadFileName(
memberNumber: string | number | null | undefined,
side: 'depan' | 'belakang',
) {
const number = memberNumber ?? 'anggota'
return `kad-digital-${number}-${side}.png`
}
export function toProxiedStorageUrl(url: string | null | undefined): string | null | undefined {
if (!url) return url
const apiBase = import.meta.env.VITE_API_BASE_URL?.replace(/\/$/, '')
try {
const parsed = new URL(url, apiBase || window.location.origin)
if (!parsed.pathname.startsWith('/storage/')) {
return url
}
// Production serves the SPA from a different host than Laravel storage files.
if (apiBase) {
return `${apiBase}${parsed.pathname}${parsed.search}`
}
// Dev fallback: Vite proxies /storage to the API.
return `${parsed.pathname}${parsed.search}`
} catch {
return url
}
}