mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
web: fix features reset on subscription change
This commit is contained in:
@@ -61,6 +61,7 @@ import { MenuItem } from "@notesnook/ui";
|
||||
import { showFeatureNotAllowedToast } from "./toasts";
|
||||
import { UpgradeDialog } from "../dialogs/buy-dialog/upgrade-dialog";
|
||||
import { setToolbarPreset } from "./toolbar-config";
|
||||
import { useKeyStore } from "../interfaces/key-store";
|
||||
|
||||
export const CREATE_BUTTON_MAP = {
|
||||
notes: {
|
||||
@@ -512,8 +513,12 @@ export async function resetFeatures() {
|
||||
"defaultSidebarTab",
|
||||
"disableTrashCleanup",
|
||||
"syncControls",
|
||||
"fullOfflineMode"
|
||||
"fullOfflineMode",
|
||||
"appLock"
|
||||
]);
|
||||
if (!features.appLock.isAllowed) {
|
||||
await useKeyStore.getState().disable();
|
||||
}
|
||||
|
||||
if (!features.customHomepage.isAllowed)
|
||||
useSettingStore.getState().setHomepage();
|
||||
|
||||
@@ -270,14 +270,19 @@ class KeyStore extends BaseStore<KeyStore> {
|
||||
throw e;
|
||||
});
|
||||
if (options?.permanent) {
|
||||
await this.resetCredentials();
|
||||
await this.storeKey(key);
|
||||
this.#key = undefined;
|
||||
await this.disable();
|
||||
} else this.#key = key;
|
||||
|
||||
this.set({ isLocked: false });
|
||||
};
|
||||
|
||||
disable = async () => {
|
||||
if (!this.#key) return;
|
||||
await this.resetCredentials();
|
||||
await this.storeKey(this.#key);
|
||||
this.#key = undefined;
|
||||
};
|
||||
|
||||
relock = () => {
|
||||
this.#key = undefined;
|
||||
this.set({ isLocked: true });
|
||||
|
||||
@@ -28,6 +28,7 @@ import { ConfirmDialog } from "../dialogs/confirm";
|
||||
import { OnboardingDialog } from "../dialogs/onboarding-dialog";
|
||||
import { strings } from "@notesnook/intl";
|
||||
import { isUserSubscribed } from "../hooks/use-is-user-premium";
|
||||
import { resetFeatures } from "../common";
|
||||
|
||||
class UserStore extends BaseStore<UserStore> {
|
||||
isLoggedIn?: boolean;
|
||||
@@ -65,6 +66,7 @@ class UserStore extends BaseStore<UserStore> {
|
||||
state.user.subscription = subscription;
|
||||
});
|
||||
if (!wasSubscribed && isUserSubscribed()) OnboardingDialog.show({});
|
||||
resetFeatures();
|
||||
});
|
||||
|
||||
EV.subscribe(EVENTS.userEmailConfirmed, () => {
|
||||
|
||||
@@ -69,12 +69,7 @@ export default function AppLock(props: PropsWithChildren<unknown>) {
|
||||
|
||||
await useKeyStore
|
||||
.getState()
|
||||
.unlock(
|
||||
{ ...credential, password },
|
||||
{
|
||||
permanent: !(await isFeatureAvailable("appLock")).isAllowed
|
||||
}
|
||||
)
|
||||
.unlock({ ...credential, password })
|
||||
.catch((e) => {
|
||||
setError(
|
||||
typeof e === "string"
|
||||
|
||||
@@ -354,6 +354,7 @@ class UserManager {
|
||||
);
|
||||
if (user) {
|
||||
const oldUser = await this.getUser();
|
||||
await this.setUser(user);
|
||||
if (
|
||||
oldUser &&
|
||||
(oldUser.subscription.plan !== user.subscription.plan ||
|
||||
@@ -365,7 +366,6 @@ class UserManager {
|
||||
}
|
||||
if (oldUser && !oldUser.isEmailConfirmed && user.isEmailConfirmed)
|
||||
EV.publish(EVENTS.userEmailConfirmed);
|
||||
await this.setUser(user);
|
||||
EV.publish(EVENTS.userFetched, user);
|
||||
return user;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user