Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: add support for adding feature limits on settings

Abdullah Attaeb73de6d8d77
diff --git a/apps/web/src/dialogs/settings/index.tsx b/apps/web/src/dialogs/settings/index.tsx
index 47932a281..a713ec2c6 100644
--- a/apps/web/src/dialogs/settings/index.tsx
+++ b/apps/web/src/dialogs/settings/index.tsx
@@ -70,7 +70,7 @@ import {
SupportSettings
} from "./other-settings";
import { AppearanceSettings } from "./appearance-settings";
-import { debounce, usePromise } from "@notesnook/common";
+import { debounce, useIsFeatureAvailable, usePromise } from "@notesnook/common";
import { SubscriptionSettings } from "./subscription-settings";
import { ScopedThemeProvider } from "../../components/theme-provider";
import { AppLockSettings } from "./app-lock-settings";
@@ -79,6 +79,7 @@ import { ServersSettings } from "./servers-settings";
import { strings } from "@notesnook/intl";
import { mdToHtml } from "../../utils/md";
import { InboxSettings } from "./inbox-settings";
+import { withFeatureCheck } from "../../common";
type SettingsDialogProps = BaseDialogProps<false> & {
activeSection?: SectionKeys;
@@ -432,6 +433,7 @@ function SettingItem(props: { item: Setting }) {
const { item } = props;
const [state, setState] = useState<unknown>();
const [workIndex, setWorkIndex] = useState<number>();
+ const feature = useIsFeatureAvailable(item.featureId);
useEffect(() => {
if (!item.onStateChange) return;
@@ -479,12 +481,17 @@ function SettingItem(props: { item: Setting }) {
}}
>
<Flex sx={{ flexDirection: "column", flex: 1 }}>
- <Text
- variant={"body"}
- sx={{ fontWeight: "medium", color: "heading" }}
- >
- {item.title}
- </Text>
+ <Flex sx={{ alignItems: "center", gap: 1 }}>
+ <Text
+ variant={"body"}
+ sx={{ fontWeight: "medium", color: "heading" }}
+ >
+ {item.title}
+ </Text>
+ {feature && !feature.isAllowed ? (
+ <Pro size={14} color="orange" />
+ ) : null}
+ </Flex>
{item.description && (
<Text
as={"div"}
@@ -518,7 +525,9 @@ function SettingItem(props: { item: Setting }) {
disabled={workIndex === index}
title={component.title}
variant={component.variant}
- onClick={() => workWithLoading(index, component.action)}
+ onClick={withFeatureCheck(feature, () =>
+ workWithLoading(index, component.action)
+ )}
>
{workIndex === index ? (
<Loading size={18} sx={{ mr: 2 }} />
@@ -537,13 +546,22 @@ function SettingItem(props: { item: Setting }) {
: "icon-secondary"
}}
disabled={workIndex === index}
- onChange={() => workWithLoading(index, component.toggle)}
+ onChange={withFeatureCheck(feature, () =>
+ workWithLoading(index, component.toggle)
+ )}
checked={component.isToggled()}
data-checked={component.isToggled()}
/>
);
case "dropdown":
- return <SelectComponent {...component} />;
+ return (
+ <SelectComponent
+ {...component}
+ onSelectionChanged={withFeatureCheck(feature, (value) =>
+ component.onSelectionChanged(value)
+ )}
+ />
+ );
case "input":
return component.inputType === "number" ? (
<Input
diff --git a/apps/web/src/dialogs/settings/types.ts b/apps/web/src/dialogs/settings/types.ts
index 8d40fff29..1152a77fe 100644
--- a/apps/web/src/dialogs/settings/types.ts
+++ b/apps/web/src/dialogs/settings/types.ts
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import { FeatureId } from "@notesnook/common";
import { Icon } from "../../components/icons";
export type SectionKeys =
@@ -84,6 +85,7 @@ export type Setting = {
onStateChange?: (
listener: (state: unknown, prevState: unknown) => void
) => () => void;
+ featureId?: FeatureId;
};
export type SettingComponentType =