Files
cozsweet-frontend-nextjs/src/lib/payment/payment_search_params.ts
T
admin 9deb320cf6 feat(profile)!: replace sidebar and add avatar navigation
Rename the global Sidebar route, UI, assets, analytics, and payment return context to Profile. Add accessible message-avatar navigation and preserve the source character across auth and logout flows.

BREAKING CHANGE: /sidebar has been removed; use /profile instead.
2026-07-21 18:08:12 +08:00

48 lines
1.4 KiB
TypeScript

import type { PayChannel } from "@/data/schemas/payment";
import type { AppSubscriptionReturnTo } from "@/router/navigation-types";
export type PaymentSearchParamValue = string | string[] | undefined;
export type PaymentSearchParams = Record<string, PaymentSearchParamValue>;
export interface PaymentReturnSearchParams {
initialPayChannel: PayChannel | null;
shouldResumePendingOrder: boolean;
}
export function getFirstPaymentSearchParam(
value: PaymentSearchParamValue,
): string | null {
return Array.isArray(value) ? (value[0] ?? null) : (value ?? null);
}
export function parsePaymentPayChannel(
value: PaymentSearchParamValue,
): PayChannel | null {
const channel = getFirstPaymentSearchParam(value);
return channel === "ezpay" || channel === "stripe" ? channel : null;
}
export function parseSubscriptionReturnTo(
value: PaymentSearchParamValue,
): AppSubscriptionReturnTo {
const returnTo = getFirstPaymentSearchParam(value);
if (
returnTo === "chat" ||
returnTo === "private-room" ||
returnTo === "profile"
) {
return returnTo;
}
return null;
}
export function parsePaymentReturnSearchParams(
searchParams: PaymentSearchParams,
): PaymentReturnSearchParams {
return {
initialPayChannel: parsePaymentPayChannel(searchParams.payChannel),
shouldResumePendingOrder:
getFirstPaymentSearchParam(searchParams.paymentReturn) === "1",
};
}