122 lines
3.9 KiB
TypeScript
122 lines
3.9 KiB
TypeScript
import { loadTrip } from "@/lib/tripStorage";
|
|
|
|
type LoginDict = {
|
|
hintExplore: string;
|
|
hintProfile: string;
|
|
hintPlan: string;
|
|
hintCompare: string;
|
|
hintTools: string;
|
|
hintDestination: string;
|
|
hintDating: string;
|
|
hintChat: string;
|
|
hintMeetups: string;
|
|
hintJoin: string;
|
|
hintNotifications: string;
|
|
hintGigs: string;
|
|
hintCommunity: string;
|
|
hintSubmit: string;
|
|
redirectTo: string;
|
|
planMergeNote: string;
|
|
destHome: string;
|
|
destProfile: string;
|
|
destPlan: string;
|
|
destCompare: string;
|
|
destTools: string;
|
|
destDestination: string;
|
|
destDating: string;
|
|
destChat: string;
|
|
destMeetups: string;
|
|
destJoin: string;
|
|
destNotifications: string;
|
|
destGigs: string;
|
|
destCommunity: string;
|
|
destSubmit: string;
|
|
submitLoginDefault: string;
|
|
submitLoginPlan: string;
|
|
demoHintDefault: string;
|
|
demoHintPlan: string;
|
|
welcomeToastDefault: string;
|
|
welcomeToastPlan: string;
|
|
};
|
|
|
|
export interface AuthNextMeta {
|
|
path: string;
|
|
label: string;
|
|
hint: string;
|
|
showRedirect: boolean;
|
|
showPlanMerge: boolean;
|
|
submitLogin: string;
|
|
demoHint: string;
|
|
welcomeToast: string;
|
|
}
|
|
|
|
/** Post-login redirect when opening login from site chrome */
|
|
export function loginNextFrom(pathname: string | null): string {
|
|
if (!pathname || pathname === "/" || pathname === "/login") return "/profile";
|
|
return pathname;
|
|
}
|
|
|
|
/** Safe in-app redirect target after auth */
|
|
export function normalizeAuthNext(raw: string | null): string {
|
|
if (!raw || !raw.startsWith("/") || raw.startsWith("//")) return "/profile";
|
|
const path = raw.split("?")[0].split("#")[0];
|
|
if (!path) return "/profile";
|
|
return path;
|
|
}
|
|
|
|
function destLabel(path: string, t: LoginDict): string {
|
|
if (path === "/") return t.destHome;
|
|
if (path === "/profile") return t.destProfile;
|
|
if (path === "/plan") return t.destPlan;
|
|
if (path === "/compare") return t.destCompare;
|
|
if (path === "/tools") return t.destTools;
|
|
if (path.startsWith("/destinations/")) return t.destDestination;
|
|
if (path.startsWith("/dating")) return t.destDating;
|
|
if (path.startsWith("/chat")) return t.destChat;
|
|
if (path.startsWith("/meetups")) return t.destMeetups;
|
|
if (path.startsWith("/join")) return t.destJoin;
|
|
if (path.startsWith("/notifications")) return t.destNotifications;
|
|
if (path.startsWith("/gigs")) return t.destGigs;
|
|
if (path.startsWith("/community")) return t.destCommunity;
|
|
if (path === "/submit") return t.destSubmit;
|
|
return t.destProfile;
|
|
}
|
|
|
|
function hintFor(path: string, t: LoginDict): string {
|
|
if (path === "/plan") return t.hintPlan;
|
|
if (path === "/compare") return t.hintCompare;
|
|
if (path === "/tools") return t.hintTools;
|
|
if (path.startsWith("/destinations/")) return t.hintDestination;
|
|
if (path === "/profile") return t.hintProfile;
|
|
if (path.startsWith("/dating")) return t.hintDating;
|
|
if (path.startsWith("/chat")) return t.hintChat;
|
|
if (path.startsWith("/meetups")) return t.hintMeetups;
|
|
if (path.startsWith("/join")) return t.hintJoin;
|
|
if (path.startsWith("/notifications")) return t.hintNotifications;
|
|
if (path.startsWith("/gigs")) return t.hintGigs;
|
|
if (path.startsWith("/community")) return t.hintCommunity;
|
|
if (path === "/submit") return t.hintSubmit;
|
|
return t.hintExplore;
|
|
}
|
|
|
|
export function resolveAuthNext(raw: string | null, t: LoginDict): AuthNextMeta {
|
|
const path = normalizeAuthNext(raw);
|
|
const hasLocalPlan = loadTrip().length > 0;
|
|
const isPlanFlow = path === "/plan" || path === "/compare";
|
|
const label = destLabel(path, t);
|
|
const hint = hintFor(path, t);
|
|
const showPlanMerge = hasLocalPlan && (isPlanFlow || path === "/profile");
|
|
const showRedirect = path !== "/profile" || showPlanMerge;
|
|
|
|
return {
|
|
path,
|
|
label,
|
|
hint,
|
|
showRedirect,
|
|
showPlanMerge,
|
|
submitLogin: isPlanFlow ? t.submitLoginPlan : t.submitLoginDefault,
|
|
demoHint: isPlanFlow ? t.demoHintPlan : t.demoHintDefault,
|
|
welcomeToast: isPlanFlow ? t.welcomeToastPlan : t.welcomeToastDefault,
|
|
};
|
|
}
|