Save a guest edit on the published Rule, and publish a new one when that update is refused.
A leftover editing id was treated as a successful finish in this browser only, so the public Rule stayed stale and a later Finish could skip creating a new Rule.
This commit is contained in:
1 parent
0535f6f167
commit
2644023b5a
6 files changed
+207
-44
No files matched your search
@@ -485,10 +485,13 @@ function CreateFlowLayoutContent({
|
||||
* Still merge {@link methodSectionsPinsFromPublishedHydratePatch}: selections
|
||||
* may already match draft state while compact CardStack pins stayed false
|
||||
* (pins are normally set only on facet **Confirm**).
|
||||
*
|
||||
* An empty id with that same content is a finished edit. Writing the id
|
||||
* back would make the next Finish update the old Rule.
|
||||
*/
|
||||
if (
|
||||
titleOk &&
|
||||
editingId === last.id &&
|
||||
(editingId === last.id || editingId.length === 0) &&
|
||||
sectionsClear &&
|
||||
!isPublishedRuleHydratePatchIncomplete(state, patch)
|
||||
) {
|
||||
|
||||
@@ -132,28 +132,14 @@ export function useCreateFlowFinalize({
|
||||
? state.editingPublishedRuleId.trim()
|
||||
: "";
|
||||
|
||||
if (editingId.length > 0 && sessionUser === null) {
|
||||
setIsPublishing(false);
|
||||
writeLastPublishedRule({
|
||||
id: editingId,
|
||||
title,
|
||||
summary: summary ?? null,
|
||||
document: ruleDocument,
|
||||
});
|
||||
updateState({ editingPublishedRuleId: undefined });
|
||||
onGuestPublished?.({ skippedInvites: false });
|
||||
router.push(createFlowStepPath("completed"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (editingId.length > 0) {
|
||||
const updateResult = await updatePublishedRule(editingId, {
|
||||
title,
|
||||
summary: summary ?? null,
|
||||
document: ruleDocument,
|
||||
});
|
||||
setIsPublishing(false);
|
||||
if (updateResult.ok === true) {
|
||||
setIsPublishing(false);
|
||||
writeLastPublishedRule({
|
||||
id: editingId,
|
||||
title,
|
||||
@@ -161,28 +147,39 @@ export function useCreateFlowFinalize({
|
||||
document: ruleDocument,
|
||||
});
|
||||
updateState({ editingPublishedRuleId: undefined });
|
||||
void deleteServerDraftAfterPublish();
|
||||
if (sessionUser === null) {
|
||||
onGuestPublished?.({ skippedInvites: false });
|
||||
} else {
|
||||
void deleteServerDraftAfterPublish();
|
||||
}
|
||||
router.push(createFlowStepPath("completed"));
|
||||
return;
|
||||
}
|
||||
if (updateResult.status === 401) {
|
||||
openLogin({
|
||||
variant: sessionUser === null ? "keepRule" : "default",
|
||||
nextPath:
|
||||
sessionUser === null
|
||||
? createFlowStepPath("completed")
|
||||
: loginReturnPath,
|
||||
backdropVariant: "blurredYellow",
|
||||
});
|
||||
// A leftover id must not block a new Rule. This browser cannot update
|
||||
// that id, so publish a new one instead of pretending the edit saved.
|
||||
const guestCannotUpdate =
|
||||
sessionUser === null &&
|
||||
(updateResult.status === 401 ||
|
||||
updateResult.status === 403 ||
|
||||
updateResult.status === 404);
|
||||
if (!guestCannotUpdate) {
|
||||
setIsPublishing(false);
|
||||
if (updateResult.status === 401) {
|
||||
openLogin({
|
||||
variant: "default",
|
||||
nextPath: loginReturnPath,
|
||||
backdropVariant: "blurredYellow",
|
||||
});
|
||||
return;
|
||||
}
|
||||
showFailedBanner(
|
||||
updateResult.error.trim() !== ""
|
||||
? updateResult.error
|
||||
: messages.create.reviewAndComplete.publish.genericPublishFailed,
|
||||
false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
showFailedBanner(
|
||||
updateResult.error.trim() !== ""
|
||||
? updateResult.error
|
||||
: messages.create.reviewAndComplete.publish.genericPublishFailed,
|
||||
false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const isGuest = sessionUser === null;
|
||||
@@ -212,6 +209,7 @@ export function useCreateFlowFinalize({
|
||||
? { finishedAt: publishResult.createdAt }
|
||||
: {}),
|
||||
});
|
||||
updateState({ editingPublishedRuleId: undefined });
|
||||
if (isGuest) {
|
||||
onGuestPublished?.({ skippedInvites: skippedGuestInvites });
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user