27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { createFlowStateHasKeys } from "../../../../lib/create/draftHydrationUtils";
|
|
import type { CreateFlowStep } from "../types";
|
|
import { readAnonymousCreateFlowState } from "./anonymousDraftStorage";
|
|
import { CREATE_ROUTES, createFlowStepPath } from "./createFlowPaths";
|
|
import { readCoreValueDetailsFromLocalStorage } from "./coreValueDetailsLocalStorage";
|
|
import { isValidStep } from "./flowSteps";
|
|
|
|
const NON_RESUME_STEPS = new Set<CreateFlowStep>(["completed", "edit-rule"]);
|
|
|
|
export function hasBrowserCreateFlowDraft(): boolean {
|
|
if (createFlowStateHasKeys(readAnonymousCreateFlowState())) return true;
|
|
return Object.keys(readCoreValueDetailsFromLocalStorage()).length > 0;
|
|
}
|
|
|
|
/**
|
|
* Path for header / Home / Profile **Create rule**. Never clears the browser
|
|
* draft or `DELETE`s `/api/drafts/me` — resume where the draft was left.
|
|
*/
|
|
export function createRuleEntryPath(): string {
|
|
const local = readAnonymousCreateFlowState();
|
|
const step = local.currentStep;
|
|
if (isValidStep(step) && !NON_RESUME_STEPS.has(step)) {
|
|
return createFlowStepPath(step);
|
|
}
|
|
return CREATE_ROUTES.createFirstStep;
|
|
}
|