Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion web/core/components/pages/dropdowns/quick-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,26 @@ export const PageQuickActions: React.FC<Props> = observer((props) => {
const MENU_ITEMS: TContextMenuItem[] = [
{
key: "make-public-private",
action: access === 0 ? makePrivate : makePublic,
action: async () => {
const changedPageType = access === 0 ? "private" : "public";

try {
if (access === 0) await makePrivate();
else await makePublic();

setToast({
type: TOAST_TYPE.SUCCESS,
title: "Success!",
message: `The page has been marked ${changedPageType} and moved to the ${changedPageType} section.`,
});
} catch (err) {
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: `The page couldn't be marked ${changedPageType}. Please try again.`,
});
}
},
Comment on lines +51 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve changes with suggestions for enhanced error handling.

The asynchronous function within the action property of MENU_ITEMS is well-implemented, providing clear user feedback through toast notifications. The use of a try-catch block for error handling is a good practice.

However, consider enhancing the error handling by logging the error or providing more detailed feedback to the user. This could help in diagnosing issues more effectively in production.

+ import { logError } from "@/helpers/error.helper";

  try {
    if (access === 0) await makePrivate();
    else await makePublic();
    setToast({
      type: TOAST_TYPE.SUCCESS,
      title: "Success!",
      message: `The page has been marked ${changedPageType} and moved to the ${changedPageType} section.`,
    });
  } catch (err) {
    logError(err); // Log the error for better diagnostics
    setToast({
      type: TOAST_TYPE.ERROR,
      title: "Error!",
      message: `The page couldn't be marked ${changedPageType}. Please try again. Error: ${err.message}`,
    });
  }

Committable suggestion was skipped due to low confidence.

title: access === 0 ? "Make private" : "Make public",
icon: access === 0 ? Lock : UsersRound,
shouldRender: canCurrentUserChangeAccess && !archived_at,
Expand Down