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:
adilallo committed 2026-11-23 14:48:01 -07:00
1 parent 077942166c
commit 0535f6f167
14 files changed
+377 -225

No files matched your search

@@ -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();