Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

900 B
Raw Blame
import type { BillingIntervalKey, BillingPlanKey } from "@/constants/billing";

const KEY = "kaneo:pending-purchase";
const PLANS = new Set<string>(["personal", "team"]);
const INTERVALS = new Set<string>(["monthly", "annual"]);

export type PendingPurchase = {
  plan: BillingPlanKey;
  interval: BillingIntervalKey;
};

export function savePendingPurchase(purchase: PendingPurchase) {
  try {
    sessionStorage.setItem(KEY, `${purchase.plan}-${purchase.interval}`);
  } catch {}
}

export function takePendingPurchase(): PendingPurchase | null {
  try {
    const value = sessionStorage.getItem(KEY);
    sessionStorage.removeItem(KEY);
    const [plan, interval] = value?.split("-") ?? [];
    if (!PLANS.has(plan) || !INTERVALS.has(interval)) return null;
    return {
      plan: plan as BillingPlanKey,
      interval: interval as BillingIntervalKey,
    };
  } catch {
    return null;
  }
}