Skip create save page when logged in
This commit is contained in:
@@ -93,13 +93,16 @@ function CreateFlowLayoutContent({
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const { openLogin } = useAuthModal();
|
const { openLogin } = useAuthModal();
|
||||||
|
const skipCommunitySave = sessionResolved && Boolean(sessionUser);
|
||||||
const {
|
const {
|
||||||
currentStep,
|
currentStep,
|
||||||
nextStep,
|
nextStep,
|
||||||
previousStep,
|
previousStep,
|
||||||
goToNextStep,
|
goToNextStep,
|
||||||
goToPreviousStep,
|
goToPreviousStep,
|
||||||
} = useCreateFlowNavigation();
|
} = useCreateFlowNavigation(
|
||||||
|
skipCommunitySave ? { skipCommunitySave: true } : undefined,
|
||||||
|
);
|
||||||
const { state, clearState, updateState } = useCreateFlow();
|
const { state, clearState, updateState } = useCreateFlow();
|
||||||
const { draftSaveBannerMessage, setDraftSaveBannerMessage } =
|
const { draftSaveBannerMessage, setDraftSaveBannerMessage } =
|
||||||
useCreateFlowDraftSaveBanner();
|
useCreateFlowDraftSaveBanner();
|
||||||
@@ -240,6 +243,16 @@ function CreateFlowLayoutContent({
|
|||||||
await runAuthenticatedExit(opts);
|
await runAuthenticatedExit(opts);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
sessionResolved &&
|
||||||
|
sessionUser &&
|
||||||
|
currentStep === "community-save"
|
||||||
|
) {
|
||||||
|
router.replace("/create/review");
|
||||||
|
}
|
||||||
|
}, [sessionResolved, sessionUser, currentStep, router]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentStep !== "community-save") {
|
if (currentStep !== "community-save") {
|
||||||
setCommunitySaveMagicLinkError(null);
|
setCommunitySaveMagicLinkError(null);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { usePathname, useRouter } from "next/navigation";
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import type { CreateFlowStep } from "../types";
|
import type { CreateFlowStep } from "../types";
|
||||||
import {
|
import {
|
||||||
|
type CreateFlowNavigationOptions,
|
||||||
getNextStep,
|
getNextStep,
|
||||||
getPreviousStep,
|
getPreviousStep,
|
||||||
parseCreateFlowScreenFromPathname,
|
parseCreateFlowScreenFromPathname,
|
||||||
@@ -26,7 +27,9 @@ const blurActiveElement = (): void => {
|
|||||||
*
|
*
|
||||||
* Resolves the active step from `/create/{screenId}` via {@link parseCreateFlowScreenFromPathname} (flowSteps).
|
* Resolves the active step from `/create/{screenId}` via {@link parseCreateFlowScreenFromPathname} (flowSteps).
|
||||||
*/
|
*/
|
||||||
export function useCreateFlowNavigation(): {
|
export function useCreateFlowNavigation(
|
||||||
|
options?: CreateFlowNavigationOptions,
|
||||||
|
): {
|
||||||
currentStep: CreateFlowStep | null;
|
currentStep: CreateFlowStep | null;
|
||||||
goToNextStep: () => void;
|
goToNextStep: () => void;
|
||||||
goToPreviousStep: () => void;
|
goToPreviousStep: () => void;
|
||||||
@@ -41,8 +44,8 @@ export function useCreateFlowNavigation(): {
|
|||||||
|
|
||||||
const validStep = parseCreateFlowScreenFromPathname(pathname ?? null);
|
const validStep = parseCreateFlowScreenFromPathname(pathname ?? null);
|
||||||
|
|
||||||
const nextStep = getNextStep(validStep);
|
const nextStep = getNextStep(validStep, options);
|
||||||
const previousStep = getPreviousStep(validStep);
|
const previousStep = getPreviousStep(validStep, options);
|
||||||
|
|
||||||
const goToNextStep = useCallback(() => {
|
const goToNextStep = useCallback(() => {
|
||||||
blurActiveElement();
|
blurActiveElement();
|
||||||
|
|||||||
@@ -37,16 +37,26 @@ export const VALID_STEPS: readonly CreateFlowStep[] = FLOW_STEP_ORDER;
|
|||||||
*/
|
*/
|
||||||
export const FIRST_STEP: CreateFlowStep = FLOW_STEP_ORDER[0];
|
export const FIRST_STEP: CreateFlowStep = FLOW_STEP_ORDER[0];
|
||||||
|
|
||||||
|
/** Options for navigation when the email / magic-link save step is not shown (signed-in users). */
|
||||||
|
export type CreateFlowNavigationOptions = {
|
||||||
|
skipCommunitySave?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next step in the flow, or null if current is last/invalid
|
* Returns the next step in the flow, or null if current is last/invalid
|
||||||
*/
|
*/
|
||||||
export function getNextStep(
|
export function getNextStep(
|
||||||
currentStep: CreateFlowStep | null | undefined,
|
currentStep: CreateFlowStep | null | undefined,
|
||||||
|
options?: CreateFlowNavigationOptions,
|
||||||
): CreateFlowStep | null {
|
): CreateFlowStep | null {
|
||||||
if (!currentStep) return null;
|
if (!currentStep) return null;
|
||||||
const index = FLOW_STEP_ORDER.indexOf(currentStep);
|
const index = FLOW_STEP_ORDER.indexOf(currentStep);
|
||||||
if (index === -1 || index === FLOW_STEP_ORDER.length - 1) return null;
|
if (index === -1 || index === FLOW_STEP_ORDER.length - 1) return null;
|
||||||
return FLOW_STEP_ORDER[index + 1] as CreateFlowStep;
|
const next = FLOW_STEP_ORDER[index + 1] as CreateFlowStep;
|
||||||
|
if (options?.skipCommunitySave && next === "community-save") {
|
||||||
|
return getNextStep("community-save", options);
|
||||||
|
}
|
||||||
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,11 +64,16 @@ export function getNextStep(
|
|||||||
*/
|
*/
|
||||||
export function getPreviousStep(
|
export function getPreviousStep(
|
||||||
currentStep: CreateFlowStep | null | undefined,
|
currentStep: CreateFlowStep | null | undefined,
|
||||||
|
options?: CreateFlowNavigationOptions,
|
||||||
): CreateFlowStep | null {
|
): CreateFlowStep | null {
|
||||||
if (!currentStep) return null;
|
if (!currentStep) return null;
|
||||||
const index = FLOW_STEP_ORDER.indexOf(currentStep);
|
const index = FLOW_STEP_ORDER.indexOf(currentStep);
|
||||||
if (index <= 0) return null;
|
if (index <= 0) return null;
|
||||||
return FLOW_STEP_ORDER[index - 1] as CreateFlowStep;
|
const prev = FLOW_STEP_ORDER[index - 1] as CreateFlowStep;
|
||||||
|
if (options?.skipCommunitySave && prev === "community-save") {
|
||||||
|
return getPreviousStep("community-save", options);
|
||||||
|
}
|
||||||
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -55,4 +55,17 @@ describe("flowSteps", () => {
|
|||||||
expect(getNextStep("community-structure")).toBe("community-context");
|
expect(getNextStep("community-structure")).toBe("community-context");
|
||||||
expect(getNextStep("community-context")).toBe("community-size");
|
expect(getNextStep("community-context")).toBe("community-size");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("skipCommunitySave bridges upload → review and review → upload", () => {
|
||||||
|
const opts = { skipCommunitySave: true } as const;
|
||||||
|
expect(getNextStep("community-upload", opts)).toBe("review");
|
||||||
|
expect(getPreviousStep("review", opts)).toBe("community-upload");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("skipCommunitySave does not change steps outside the save segment", () => {
|
||||||
|
const opts = { skipCommunitySave: true } as const;
|
||||||
|
expect(getNextStep("community-size", opts)).toBe("community-upload");
|
||||||
|
expect(getNextStep("review", opts)).toBe("cards");
|
||||||
|
expect(getPreviousStep("cards", opts)).toBe("review");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user