2026-06-12 20:16:14 +03:30
|
|
|
import type { LocationQuery } from 'vue-router';
|
|
|
|
|
|
|
|
|
|
export function sanitizeRedirectPath(value: unknown): string | null {
|
|
|
|
|
if (typeof value !== 'string' || !value.startsWith('/') || value.startsWith('//')) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function redirectFromQuery(query: LocationQuery, fallback = '/app'): string {
|
|
|
|
|
return sanitizeRedirectPath(query.redirect) ?? fallback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function loginRouteWithRedirect(redirectPath: string) {
|
|
|
|
|
return {
|
|
|
|
|
name: 'login' as const,
|
|
|
|
|
query: { redirect: redirectPath },
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-06-14 17:28:19 +03:30
|
|
|
|
|
|
|
|
export function businessBookingPath(businessId: string, hash?: string) {
|
|
|
|
|
const normalizedHash = hash?.replace(/^#/, '');
|
|
|
|
|
const base = `/app/businesses/${businessId}`;
|
|
|
|
|
return normalizedHash ? `${base}#${normalizedHash}` : base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function bookingDestination(
|
|
|
|
|
businessId: string,
|
|
|
|
|
isLoggedIn: boolean,
|
|
|
|
|
hash?: string,
|
|
|
|
|
) {
|
|
|
|
|
if (!isLoggedIn) {
|
|
|
|
|
return loginRouteWithRedirect(businessBookingPath(businessId, hash));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const normalizedHash = hash?.replace(/^#/, '');
|
|
|
|
|
return {
|
|
|
|
|
name: 'app-business-detail' as const,
|
|
|
|
|
params: { id: businessId },
|
|
|
|
|
...(normalizedHash ? { hash: normalizedHash } : {}),
|
|
|
|
|
};
|
|
|
|
|
}
|