Let anyone finish a Rule without an account or email.
Continue on final review and Finish without inviting no longer open a login wall. The header stays Exit until Save your progress is done, and Send invitations is the only invite-path login.
This commit is contained in:
1 parent
077942166c
commit
0535f6f167
14 files changed
+377
-225
No files matched your search
@@ -73,10 +73,6 @@ import {
|
||||
CREATE_FLOW_COPIED_QUERY,
|
||||
CREATE_FLOW_COPIED_VALUE,
|
||||
} from "../../../lib/create/invitePaths";
|
||||
import {
|
||||
clearPendingKeepRuleLogin,
|
||||
hasPendingKeepRuleLogin,
|
||||
} from "../../../lib/create/pendingKeepRuleLogin";
|
||||
import { runCompletedStepExit } from "./utils/runCompletedStepExit";
|
||||
import messages from "../../../messages/en/index";
|
||||
import {
|
||||
@@ -144,8 +140,8 @@ function CreateFlowSessionShell({ children }: { children: ReactNode }) {
|
||||
const sessionResolved = sessionUser !== undefined;
|
||||
// Mirror in-progress draft to localStorage for ALL visitors once we know who
|
||||
// they are. Refresh-survival is the same UX for guest and signed-in users.
|
||||
// Save & Exit: guests open the save-progress login modal; signed-in users
|
||||
// PUT the server draft (`useCreateFlowExit`).
|
||||
// Save and exit is only for signed-in users (progress is already saved).
|
||||
// Guests keep Exit; Save your progress stays the optional community-save step.
|
||||
const enableLocalDraftMirroring = sessionResolved;
|
||||
|
||||
return (
|
||||
@@ -364,24 +360,7 @@ function CreateFlowLayoutContent({
|
||||
|
||||
if (!sessionResolved) return;
|
||||
|
||||
// Completed is post-publish. Guests still need Save & Exit → keep-this-rule
|
||||
// login (the document is live but unclaimed). Signed-in users just leave.
|
||||
if (currentStep === "completed") {
|
||||
if (sessionUser === null) {
|
||||
openLogin({
|
||||
variant: "keepRule",
|
||||
nextPath: CREATE_ROUTES.completed,
|
||||
backdropVariant: "blurredYellow",
|
||||
onDismiss: () => {
|
||||
runCompletedStepExit({
|
||||
clearState,
|
||||
clearAnonymousCreateFlowStorage,
|
||||
router,
|
||||
});
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
runCompletedStepExit({
|
||||
clearState,
|
||||
clearAnonymousCreateFlowStorage,
|
||||
@@ -580,26 +559,6 @@ function CreateFlowLayoutContent({
|
||||
setCompletedCopiedReady(Boolean(last?.copiedFromTitle));
|
||||
}, [currentStep]);
|
||||
|
||||
useEffect(() => {
|
||||
if (currentStep !== "completed") return;
|
||||
if (!sessionResolved) return;
|
||||
if (sessionUser !== null) {
|
||||
clearPendingKeepRuleLogin();
|
||||
return;
|
||||
}
|
||||
if (!hasPendingKeepRuleLogin()) return;
|
||||
const timeoutId = window.setTimeout(() => {
|
||||
if (!hasPendingKeepRuleLogin()) return;
|
||||
clearPendingKeepRuleLogin();
|
||||
openLogin({
|
||||
variant: "keepRule",
|
||||
nextPath: CREATE_ROUTES.completed,
|
||||
backdropVariant: "blurredYellow",
|
||||
});
|
||||
}, 0);
|
||||
return () => window.clearTimeout(timeoutId);
|
||||
}, [currentStep, sessionResolved, sessionUser, openLogin]);
|
||||
|
||||
const handleCommunitySaveMagicLinkSubmit = useCallback(async (
|
||||
formEl?: HTMLFormElement | null,
|
||||
) => {
|
||||
@@ -705,7 +664,7 @@ function CreateFlowLayoutContent({
|
||||
const mainResponsiveLayout = `${mainMaxMdCross} ${mainMaxMdJustify} md:flex-row md:justify-center`;
|
||||
const saveDraftOnExit =
|
||||
shouldOfferCreateFlowSaveAndExit(currentStep, sessionUser) ||
|
||||
isCreateTemplatesPickerRoute;
|
||||
(isCreateTemplatesPickerRoute && Boolean(sessionUser));
|
||||
|
||||
const proportionBarProgress = getProportionBarProgressForCreateFlowStep(
|
||||
currentStep,
|
||||
@@ -1275,6 +1234,18 @@ function CreateFlowLayoutContent({
|
||||
disabled={isPublishing || !sessionResolved}
|
||||
className={CREATE_FLOW_FOOTER_BUTTON_CLASS}
|
||||
onClick={() => {
|
||||
if (!sessionResolved) return;
|
||||
if (sessionUser === null) {
|
||||
openLogin({
|
||||
variant: "invite",
|
||||
nextPath:
|
||||
createFlowStepPathWithSyncDraft(
|
||||
"confirm-stakeholders",
|
||||
),
|
||||
backdropVariant: "blurredYellow",
|
||||
});
|
||||
return;
|
||||
}
|
||||
void handleFinalize({ skipInvites: false });
|
||||
}}
|
||||
>
|
||||
@@ -1293,8 +1264,7 @@ function CreateFlowLayoutContent({
|
||||
isPublishing ||
|
||||
(isEditRuleStep && !sessionResolved) ||
|
||||
(currentStep === "final-review" &&
|
||||
(!sessionResolved ||
|
||||
isFinalReviewContinueBlocked(state)))
|
||||
isFinalReviewContinueBlocked(state))
|
||||
}
|
||||
className={CREATE_FLOW_FOOTER_BUTTON_CLASS}
|
||||
onClick={() => {
|
||||
@@ -1304,18 +1274,6 @@ function CreateFlowLayoutContent({
|
||||
}
|
||||
if (currentStep === "final-review") {
|
||||
if (isFinalReviewContinueBlocked(state)) return;
|
||||
if (!sessionResolved) return;
|
||||
if (sessionUser === null) {
|
||||
openLogin({
|
||||
variant: "invite",
|
||||
nextPath:
|
||||
createFlowStepPathWithSyncDraft(
|
||||
"confirm-stakeholders",
|
||||
),
|
||||
backdropVariant: "blurredYellow",
|
||||
});
|
||||
return;
|
||||
}
|
||||
goToNextStep();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ interface CreateFlowProviderProps {
|
||||
* `create-flow-anonymous` in localStorage so refresh / dev-restart never wipes
|
||||
* progress. When false, in-memory only (e.g. unit tests, pre-session-resolve).
|
||||
*
|
||||
* Signed-in users additionally get an explicit "Save & Exit" that PUTs to the
|
||||
* server (`useCreateFlowExit`); the server draft is the cross-device snapshot,
|
||||
* localStorage is the on-every-keystroke buffer.
|
||||
* Signed-in users additionally get an explicit "Save and exit" that PUTs to
|
||||
* the server (`useCreateFlowExit`); the server draft is the cross-device
|
||||
* snapshot, localStorage is the on-every-keystroke buffer.
|
||||
*/
|
||||
enableLocalDraftMirroring?: boolean;
|
||||
}
|
||||
|
||||
@@ -8,16 +8,7 @@ import {
|
||||
type ChangeEvent,
|
||||
type RefObject,
|
||||
} from "react";
|
||||
import { fetchAuthSession } from "../../../../lib/create/api";
|
||||
import {
|
||||
COMMUNITY_AVATAR_ACCEPT,
|
||||
messageKeyForCreateFlowUploadReason,
|
||||
validateCreateFlowUploadFile,
|
||||
} from "../../../../lib/create/createFlowUploadValidation";
|
||||
import {
|
||||
clearPendingCommunityAvatarFile,
|
||||
storePendingCommunityAvatarFile,
|
||||
} from "../../../../lib/create/pendingCommunityAvatarUpload";
|
||||
import { COMMUNITY_AVATAR_ACCEPT } from "../../../../lib/create/createFlowUploadValidation";
|
||||
import {
|
||||
createFlowUploadFailureMessageKey,
|
||||
uploadCreateFlowFile,
|
||||
@@ -30,8 +21,9 @@ function hasCommunityAvatarUrl(url: string | undefined): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick and store a community logo for the create flow. Signed-in users upload
|
||||
* immediately; guests keep the file in IndexedDB until they sign in.
|
||||
* Pick and store a community logo for the create flow. Guests and signed-in
|
||||
* users upload immediately (`POST /api/uploads` accepts `communityAvatar`
|
||||
* without a session).
|
||||
*
|
||||
* @example
|
||||
* const avatar = useCommunityAvatarUpload();
|
||||
@@ -52,22 +44,11 @@ export function useCommunityAvatarUpload(): {
|
||||
const tUpload = useTranslation("create.upload");
|
||||
const { markCreateFlowInteraction, state, updateState } = useCreateFlow();
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const [signedIn, setSignedIn] = useState<boolean | null>(null);
|
||||
const [localPreviewUrl, setLocalPreviewUrl] = useState<string | null>(null);
|
||||
const [localFileName, setLocalFileName] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void fetchAuthSession().then(({ user }) => {
|
||||
if (!cancelled) setSignedIn(Boolean(user));
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (localPreviewUrl) URL.revokeObjectURL(localPreviewUrl);
|
||||
@@ -104,61 +85,25 @@ export function useCommunityAvatarUpload(): {
|
||||
if (!file) return;
|
||||
markCreateFlowInteraction();
|
||||
setErrorMessage(null);
|
||||
|
||||
if (signedIn === true) {
|
||||
setBusy(true);
|
||||
try {
|
||||
const { url } = await uploadCreateFlowFile(file, "communityAvatar");
|
||||
setLocalPreviewUrl((prev) => {
|
||||
if (prev) URL.revokeObjectURL(prev);
|
||||
return null;
|
||||
});
|
||||
setLocalFileName(file.name);
|
||||
updateState({
|
||||
communityAvatarUrl: url,
|
||||
communityAvatarFileName: file.name,
|
||||
});
|
||||
} catch (err) {
|
||||
setErrorMessage(resolveUploadError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const validated = await validateCreateFlowUploadFile(
|
||||
file,
|
||||
"communityAvatar",
|
||||
);
|
||||
if (validated.ok === false) {
|
||||
setErrorMessage(
|
||||
validated.reason === "tooLarge"
|
||||
? u.fileTooLarge
|
||||
: tUpload(messageKeyForCreateFlowUploadReason(validated.reason)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
try {
|
||||
await storePendingCommunityAvatarFile(file);
|
||||
const { url } = await uploadCreateFlowFile(file, "communityAvatar");
|
||||
setLocalPreviewUrl((prev) => {
|
||||
if (prev) URL.revokeObjectURL(prev);
|
||||
return URL.createObjectURL(file);
|
||||
return null;
|
||||
});
|
||||
setLocalFileName(file.name);
|
||||
updateState({ communityAvatarFileName: file.name });
|
||||
} catch {
|
||||
await clearPendingCommunityAvatarFile().catch(() => undefined);
|
||||
setErrorMessage(tUpload("errors.generic"));
|
||||
updateState({
|
||||
communityAvatarUrl: url,
|
||||
communityAvatarFileName: file.name,
|
||||
});
|
||||
} catch (err) {
|
||||
setErrorMessage(resolveUploadError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
markCreateFlowInteraction,
|
||||
resolveUploadError,
|
||||
signedIn,
|
||||
tUpload,
|
||||
u.fileTooLarge,
|
||||
updateState,
|
||||
],
|
||||
[markCreateFlowInteraction, resolveUploadError, updateState],
|
||||
);
|
||||
|
||||
const handlePickFile = useCallback(() => {
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
updatePublishedRule,
|
||||
} from "../../../../lib/create/api";
|
||||
import { writeLastPublishedRule } from "../../../../lib/create/lastPublishedRule";
|
||||
import { writePendingKeepRuleLogin } from "../../../../lib/create/pendingKeepRuleLogin";
|
||||
import messages from "../../../../messages/en/index";
|
||||
import type { CreateFlowState } from "../types";
|
||||
import {
|
||||
@@ -142,7 +141,6 @@ export function useCreateFlowFinalize({
|
||||
document: ruleDocument,
|
||||
});
|
||||
updateState({ editingPublishedRuleId: undefined });
|
||||
writePendingKeepRuleLogin();
|
||||
onGuestPublished?.({ skippedInvites: false });
|
||||
router.push(createFlowStepPath("completed"));
|
||||
return;
|
||||
@@ -215,7 +213,6 @@ export function useCreateFlowFinalize({
|
||||
: {}),
|
||||
});
|
||||
if (isGuest) {
|
||||
writePendingKeepRuleLogin();
|
||||
onGuestPublished?.({ skippedInvites: skippedGuestInvites });
|
||||
} else {
|
||||
void deleteServerDraftAfterPublish();
|
||||
|
||||
@@ -13,20 +13,17 @@ import { useCreateFlow } from "../../context/CreateFlowContext";
|
||||
import { CreateFlowHeaderLockup } from "../../components/CreateFlowHeaderLockup";
|
||||
import { CreateFlowStepShell } from "../../components/CreateFlowStepShell";
|
||||
import { CREATE_FLOW_MD_UP_COLUMN_MAX_CLASS } from "../../components/createFlowLayoutTokens";
|
||||
import { fetchAuthSession } from "../../../../../lib/create/api";
|
||||
import {
|
||||
createFlowUploadFailureMessageKey,
|
||||
uploadCreateFlowFile,
|
||||
} from "../../../../../lib/create/uploadToServer";
|
||||
import {
|
||||
COMMUNITY_AVATAR_ACCEPT,
|
||||
messageKeyForCreateFlowUploadReason,
|
||||
validateCreateFlowUploadFile,
|
||||
} from "../../../../../lib/create/createFlowUploadValidation";
|
||||
import {
|
||||
clearPendingCommunityAvatarFile,
|
||||
readPendingCommunityAvatarFile,
|
||||
storePendingCommunityAvatarFile,
|
||||
} from "../../../../../lib/create/pendingCommunityAvatarUpload";
|
||||
|
||||
function hasCommunityAvatarUrl(url: string | undefined): boolean {
|
||||
@@ -41,22 +38,11 @@ export function CommunityUploadScreen() {
|
||||
const tUpload = useTranslation("create.upload");
|
||||
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const [signedIn, setSignedIn] = useState<boolean | null>(null);
|
||||
const [localPreviewUrl, setLocalPreviewUrl] = useState<string | null>(null);
|
||||
const [localFileName, setLocalFileName] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void fetchAuthSession().then(({ user }) => {
|
||||
if (!cancelled) setSignedIn(Boolean(user));
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (localPreviewUrl) URL.revokeObjectURL(localPreviewUrl);
|
||||
@@ -133,60 +119,25 @@ export function CommunityUploadScreen() {
|
||||
if (!file) return;
|
||||
markCreateFlowInteraction();
|
||||
setErrorMessage(null);
|
||||
|
||||
if (signedIn === true) {
|
||||
setBusy(true);
|
||||
try {
|
||||
const { url } = await uploadCreateFlowFile(file, "communityAvatar");
|
||||
setLocalPreviewUrl((prev) => {
|
||||
if (prev) URL.revokeObjectURL(prev);
|
||||
return null;
|
||||
});
|
||||
setLocalFileName(file.name);
|
||||
updateState({
|
||||
communityAvatarUrl: url,
|
||||
communityAvatarFileName: file.name,
|
||||
});
|
||||
} catch (err) {
|
||||
setErrorMessage(resolveUploadError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const validated = await validateCreateFlowUploadFile(
|
||||
file,
|
||||
"communityAvatar",
|
||||
);
|
||||
if (validated.ok === false) {
|
||||
setErrorMessage(
|
||||
validated.reason === "tooLarge"
|
||||
? u.fileTooLarge
|
||||
: tUpload(messageKeyForCreateFlowUploadReason(validated.reason)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
try {
|
||||
await storePendingCommunityAvatarFile(file);
|
||||
const { url } = await uploadCreateFlowFile(file, "communityAvatar");
|
||||
setLocalPreviewUrl((prev) => {
|
||||
if (prev) URL.revokeObjectURL(prev);
|
||||
return URL.createObjectURL(file);
|
||||
return null;
|
||||
});
|
||||
setLocalFileName(file.name);
|
||||
updateState({ communityAvatarFileName: file.name });
|
||||
} catch {
|
||||
setErrorMessage(tUpload("errors.generic"));
|
||||
updateState({
|
||||
communityAvatarUrl: url,
|
||||
communityAvatarFileName: file.name,
|
||||
});
|
||||
} catch (err) {
|
||||
setErrorMessage(resolveUploadError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
markCreateFlowInteraction,
|
||||
resolveUploadError,
|
||||
signedIn,
|
||||
tUpload,
|
||||
u.fileTooLarge,
|
||||
updateState,
|
||||
],
|
||||
[markCreateFlowInteraction, resolveUploadError, updateState],
|
||||
);
|
||||
|
||||
const handlePickFile = useCallback(() => {
|
||||
|
||||
@@ -299,7 +299,7 @@ export interface CreateFlowContextValue {
|
||||
*
|
||||
* Current consumer: {@link SignedInDraftHydration} — when a signed-in user
|
||||
* has already started editing, we skip replaying their server draft on top
|
||||
* of in-progress local state. Save & Exit visibility is
|
||||
* of in-progress local state. Save and exit visibility is
|
||||
* `shouldOfferCreateFlowSaveAndExit` in `utils/flowSteps.ts`, not this flag.
|
||||
*/
|
||||
interactionTouched: boolean;
|
||||
|
||||
@@ -189,23 +189,24 @@ export function getStepIndex(step: CreateFlowStep | null | undefined): number {
|
||||
return FLOW_STEP_ORDER.indexOf(step);
|
||||
}
|
||||
|
||||
/** First wizard step that offers Save and exit (after the community is ready to keep). */
|
||||
/** First wizard step that offers Save and exit once progress can actually be saved. */
|
||||
const SAVE_EXIT_FROM_STEP_INDEX = getStepIndex("community-save");
|
||||
|
||||
/**
|
||||
* Top-nav Save and exit (vs Exit). Guests and signed-in users share this from
|
||||
* `community-save` onward and on `edit-rule`. On completed, guests still
|
||||
* get Save and exit (claim/login); signed-in users get Exit (already owned).
|
||||
* Top-nav Save and exit (vs Exit). The header stays Exit until Save your
|
||||
* progress is done — a signed-in session. Guests (and session-in-flight)
|
||||
* keep Exit, including on completed and edit-rule.
|
||||
*
|
||||
* @param sessionUser `null` is a guest. `undefined` (session in flight) is
|
||||
* not a guest — completed stays Exit until the session resolves.
|
||||
* treated like a guest so the label does not flash Save and exit.
|
||||
*/
|
||||
export function shouldOfferCreateFlowSaveAndExit(
|
||||
currentStep: CreateFlowStep | null | undefined,
|
||||
sessionUser?: { id: string } | null,
|
||||
): boolean {
|
||||
if (currentStep == null) return false;
|
||||
if (currentStep === "completed") return sessionUser === null;
|
||||
if (!sessionUser) return false;
|
||||
if (currentStep === "completed") return false;
|
||||
if (currentStep === "edit-rule") return true;
|
||||
return getStepIndex(currentStep) >= SAVE_EXIT_FROM_STEP_INDEX;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user