Turn a saved draft into the finished Rule, and greet with congratulations.

This commit is contained in:
adilallo committed 2026-11-22 18:01:56 -07:00
1 parent a2815ae05f
commit 851133e56d
11 files changed
+150 -23

No files matched your search

@@ -3,7 +3,11 @@
import { useCallback, useState } from "react";
import { buildPublishPayload } from "../../../../lib/create/buildPublishPayload";
import { stateWithPendingCommunityAvatar } from "../../../../lib/create/flushPendingCommunityAvatar";
import { publishRule, updatePublishedRule } from "../../../../lib/create/api";
import {
deleteServerDraft,
publishRule,
updatePublishedRule,
} from "../../../../lib/create/api";
import { writeLastPublishedRule } from "../../../../lib/create/lastPublishedRule";
import { writePendingKeepRuleLogin } from "../../../../lib/create/pendingKeepRuleLogin";
import messages from "../../../../messages/en/index";
@@ -150,6 +154,7 @@ export function useCreateFlowFinalize({
document: ruleDocument,
});
updateState({ editingPublishedRuleId: undefined });
void deleteServerDraft();
router.push(createFlowStepPath("completed"));
return;
}
@@ -203,6 +208,8 @@ export function useCreateFlowFinalize({
if (isGuest) {
writePendingKeepRuleLogin();
onGuestPublished?.({ skippedInvites: skippedGuestInvites });
} else {
void deleteServerDraft();
}
router.push(
createFlowStepPath("completed", {
+9
View File
@@ -247,6 +247,15 @@ export function isValidStep(
);
}
/** Resume a saved draft on the screen it was left on. */
export function resumeCreateFlowStep(
state: { currentStep?: CreateFlowStep } | null | undefined,
): CreateFlowStep {
const step = state?.currentStep;
if (step && isValidStep(step)) return step;
return FIRST_STEP;
}
/**
* Parses `/create/{screenId}` (and optional trailing segments) from pathname.
* Returns null for non-wizard paths (e.g. `/create/review-template/...`).
+2 -12
View File
@@ -33,10 +33,8 @@ import {
CREATE_FLOW_MANAGE_STAKEHOLDERS_QUERY,
CREATE_FLOW_MANAGE_STAKEHOLDERS_VALUE,
CREATE_FLOW_REVIEW_RETURN_QUERY_KEY,
FIRST_STEP,
isValidStep,
resumeCreateFlowStep,
} from "../create/utils/flowSteps";
import type { CreateFlowStep } from "../create/types";
import { clearAnonymousCreateFlowStorage } from "../create/utils/anonymousDraftStorage";
import { clearBrowserRuleData } from "../create/utils/clearBrowserRuleData";
import { clearCoreValueDetailsLocalStorage } from "../create/utils/coreValueDetailsLocalStorage";
@@ -48,14 +46,6 @@ import {
ProfilePageView,
} from "./_components/ProfilePage.view";
function resolveContinueStepState(
state: { currentStep?: CreateFlowStep } & Record<string, unknown>,
): CreateFlowStep {
const s = state.currentStep;
if (s && isValidStep(s)) return s;
return FIRST_STEP;
}
export default function ProfilePageClient() {
const t = useTranslation("pages.profile");
const router = useRouter();
@@ -303,7 +293,7 @@ export default function ProfilePageClient() {
const handleContinueDraft = useCallback(() => {
if (draft == null || !draft.hasDraft) return;
const step = resolveContinueStepState(draft.state);
const step = resumeCreateFlowStep(draft.state);
clearAnonymousCreateFlowStorage();
clearCoreValueDetailsLocalStorage();
router.push(`/create/${step}`);