A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: prefer to show upgrade dialog before opening new notebook/tag/color dialog
Abdullah Atta6881a5f432ea
diff --git a/apps/web/src/dialogs/add-notebook-dialog.tsx b/apps/web/src/dialogs/add-notebook-dialog.tsxindex 11da96bf8..ad95e727a 100644--- a/apps/web/src/dialogs/add-notebook-dialog.tsx+++ b/apps/web/src/dialogs/add-notebook-dialog.tsx@@ -28,8 +28,7 @@ import { store as appStore } from "../stores/app-store";import { db } from "../common/db";import { BaseDialogProps, DialogManager } from "../common/dialog-manager";import { strings } from "@notesnook/intl";-import { isFeatureAvailable } from "@notesnook/common";-import { showFeatureNotAllowedToast } from "../common/toasts";+import { checkFeature } from "../common";type AddNotebookDialogProps = BaseDialogProps<boolean> & {parentId?: string;@@ -47,11 +46,6 @@ export const AddNotebookDialog = DialogManager.register(if (!title.current.trim())return showToast("error", strings.allFieldsRequired());- const result = await isFeatureAvailable("notebooks");- if (!result.isAllowed) {- return showFeatureNotAllowedToast(result);- }-const id = await db.notebooks.add({id: props.notebook?.id,title: title.current,@@ -125,6 +119,9 @@ export const AddNotebookDialog = DialogManager.register(/></Dialog>);+ },+ {+ onBeforeOpen: (props) => (props.edit ? true : checkFeature("notebooks"))});diff --git a/apps/web/src/dialogs/add-reminder-dialog.tsx b/apps/web/src/dialogs/add-reminder-dialog.tsxindex f64881766..78c80ba59 100644--- a/apps/web/src/dialogs/add-reminder-dialog.tsx+++ b/apps/web/src/dialogs/add-reminder-dialog.tsx@@ -31,16 +31,12 @@ import { usePersistentState } from "../hooks/use-persistent-state";import { DayPicker } from "../components/day-picker";import { PopupPresenter } from "@notesnook/ui";import { useStore as useThemeStore } from "../stores/theme-store";-import {- isFeatureAvailable,- getFormattedDate,- useIsFeatureAvailable-} from "@notesnook/common";+import { getFormattedDate, useIsFeatureAvailable } from "@notesnook/common";import { MONTHS_FULL, getTimeFormat } from "@notesnook/core";import { Note, Reminder } from "@notesnook/core";import { BaseDialogProps, DialogManager } from "../common/dialog-manager";import { strings } from "@notesnook/intl";-import { showFeatureNotAllowedToast } from "../common/toasts";+import { checkFeature } from "../common";dayjs.extend(customParseFormat);@@ -183,12 +179,6 @@ export const AddReminderDialog = DialogManager.register(return;}- const feature = await isFeatureAvailable("activeReminders");- if (!feature.isAllowed) {- showFeatureNotAllowedToast(feature);- return;- }-const id = await db.reminders.add({id: reminder?.id,recurringMode,@@ -518,6 +508,10 @@ export const AddReminderDialog = DialogManager.register()}</Dialog>);+ },+ {+ onBeforeOpen: (props) =>+ props.reminder ? true : checkFeature("activeReminders")});diff --git a/apps/web/src/dialogs/create-color-dialog.tsx b/apps/web/src/dialogs/create-color-dialog.tsxindex 623eb355e..e5bb54b90 100644--- a/apps/web/src/dialogs/create-color-dialog.tsx+++ b/apps/web/src/dialogs/create-color-dialog.tsx@@ -25,8 +25,7 @@ import { db } from "../common/db";import { showToast } from "../utils/toast";import { BaseDialogProps, DialogManager } from "../common/dialog-manager";import { strings } from "@notesnook/intl";-import { isFeatureAvailable } from "@notesnook/common";-import { showFeatureNotAllowedToast } from "../common/toasts";+import { checkFeature } from "../common";type CreateColorDialogProps = BaseDialogProps<string | false>;export const CreateColorDialog = DialogManager.register(@@ -62,9 +61,6 @@ export const CreateColorDialog = DialogManager.register(return;}- const result = await isFeatureAvailable("colors");- if (!result.isAllowed) return showFeatureNotAllowedToast(result);-const colorId = await db.colors.add({colorCode: form.color,title: form.title@@ -112,7 +108,8 @@ export const CreateColorDialog = DialogManager.register(</Box></Dialog>);- }+ },+ { onBeforeOpen: () => checkFeature("colors") });const HEX_COLOR_REGEX = /^#(?:[0-9a-fA-F]{3}){1,2}$/;diff --git a/apps/web/src/dialogs/item-dialog.tsx b/apps/web/src/dialogs/item-dialog.tsxindex 2db901c21..e68943239 100644--- a/apps/web/src/dialogs/item-dialog.tsx+++ b/apps/web/src/dialogs/item-dialog.tsx@@ -30,8 +30,7 @@ import { useStore as useNoteStore } from "../stores/note-store";import { useStore as useAppStore } from "../stores/app-store";import { Color, Tag } from "@notesnook/core";import { strings } from "@notesnook/intl";-import { isFeatureAvailable } from "@notesnook/common";-import { showFeatureNotAllowedToast } from "../common/toasts";+import { checkFeature } from "../common";type ItemDialogProps = BaseDialogProps<false | string> & {title: string;@@ -63,14 +62,14 @@ export const ItemDialog = DialogManager.register(function ItemDialog(<Boxas="form"id="itemForm"- onSubmit={async (e) => {+ onSubmit={(e) => {e.preventDefault();setError(undefined);const formData = new FormData(e.target as HTMLFormElement);const title = formData.get("title");if (!title) return;try {- await props.onClose(title as string);+ props.onClose(title as string);} catch (e) {if (e instanceof Error) {setError(e);@@ -94,16 +93,12 @@ export const ItemDialog = DialogManager.register(function ItemDialog(});export const CreateTagDialog = {- show: () =>- ItemDialog.show({+ show: async () => {+ if (!(await checkFeature("tags"))) return;+ await ItemDialog.show({title: strings.addTag(),subtitle: strings.addTagDesc()}).then(async (title) => {- const result = await isFeatureAvailable("tags");- if (!result.isAllowed) {- return showFeatureNotAllowedToast(result);- }-if (!title ||!(await db.tags.add({ title }).catch((e) => {@@ -115,7 +110,8 @@ export const CreateTagDialog = {showToast("success", strings.actions.created.tag(1));useTagStore.getState().refresh();- })+ });+ }};export const EditTagDialog = {