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: ask for reason when requesting refund
Abdullah Attadc1498d6720a
diff --git a/apps/web/src/app-effects.tsx b/apps/web/src/app-effects.tsxindex 49c5c736b..3fcf526c7 100644--- a/apps/web/src/app-effects.tsx+++ b/apps/web/src/app-effects.tsx@@ -28,7 +28,7 @@ import {scheduleBackups,scheduleFullBackups} from "./common/notices";-import { introduceFeatures, showUpgradeReminderDialogs } from "./common";+import { introduceFeatures } from "./common";import { AppEventManager, AppEvents } from "./common/app-events";import { db } from "./common/db";import { EV, EVENTS } from "@notesnook/core";@@ -65,9 +65,7 @@ export default function AppEffects() {(async function () {await refreshNavItems();await updateLastSynced();- if (await initUser()) {- showUpgradeReminderDialogs();- }+ await initUser();await resetNotices();setIsVaultCreated(await db.vault.exists());diff --git a/apps/web/src/common/index.ts b/apps/web/src/common/index.tsindex a1e3cd44e..7ae17a79f 100644--- a/apps/web/src/common/index.ts+++ b/apps/web/src/common/index.ts@@ -35,7 +35,6 @@ import {useStore as useSettingStore} from "../stores/setting-store";import { showToast } from "../utils/toast";-import { SUBSCRIPTION_STATUS } from "./constants";import { readFile, showFilePicker } from "../utils/file-picker";import { logger } from "../utils/logger";import { PATHS } from "@notesnook/desktop";@@ -49,7 +48,6 @@ import { useEditorStore } from "../stores/editor-store";import { formatDate } from "@notesnook/core";import { showPasswordDialog } from "../dialogs/password-dialog";import { BackupPasswordDialog } from "../dialogs/backup-password-dialog";-import { ReminderDialog } from "../dialogs/reminder-dialog";import { Cipher, SerializedKey } from "@notesnook/crypto";import { ChunkedStream } from "../utils/streams/chunked-stream";import { isFeatureSupported } from "../utils/feature-check";@@ -407,22 +405,6 @@ export function totalSubscriptionConsumed(user: User) {return Math.round((consumed / total) * 100);}-export async function showUpgradeReminderDialogs() {- if (IS_TESTING) return;-- const user = useUserStore.getState().user;- if (!user || !user.subscription || user.subscription?.expiry === 0) return;-- const consumed = totalSubscriptionConsumed(user);- const isTrial = user.subscription?.type === SUBSCRIPTION_STATUS.TRIAL;- const isBasic = user.subscription?.type === SUBSCRIPTION_STATUS.BASIC;- if (isBasic && consumed >= 100) {- await ReminderDialog.show({ reminderKey: "trialexpired" });- } else if (isTrial && consumed >= 75) {- await ReminderDialog.show({ reminderKey: "trialexpiring" });- }-}-async function restore(backup: LegacyBackupFile,password?: string,diff --git a/apps/web/src/common/multi-select.ts b/apps/web/src/common/multi-select.tsindex 581d9afce..9f23608a7 100644--- a/apps/web/src/common/multi-select.ts+++ b/apps/web/src/common/multi-select.ts@@ -82,7 +82,7 @@ async function moveNotebooksToTrash(ids: string[]) {if (!result) return;- if (result.deleteContainingNotes) {+ if (result.checks?.deleteContainingNotes) {await Multiselect.moveNotesToTrash(await db.notebooks.notes(...ids), false);}@@ -186,10 +186,9 @@ async function restoreItemsFromTrash(ids: string[]) {const notebookIds = ids.filter((id) => db.trash.cache.notebooks.includes(id));if (- !(await checkFeature(- "notebooks",- (await db.notebooks.all.count()) + notebookIds.length- ))+ !(await checkFeature("notebooks", {+ value: (await db.notebooks.all.count()) + notebookIds.length+ })))return;diff --git a/apps/web/src/dialogs/confirm.tsx b/apps/web/src/dialogs/confirm.tsxindex 0a7f2f94e..7296f0d6c 100644--- a/apps/web/src/dialogs/confirm.tsx+++ b/apps/web/src/dialogs/confirm.tsx@@ -27,10 +27,22 @@ import { getChangelog } from "../utils/version";import { downloadUpdate } from "../utils/updater";import { ErrorText } from "../components/error-text";import { strings } from "@notesnook/intl";+import Field from "../components/field";type Check = { text: string; default?: boolean };-export type ConfirmDialogProps<TCheckId extends string> = BaseDialogProps<- false | Record<TCheckId, boolean>+type Input = {+ title: string;+ defaultValue?: string;+ multiline?: boolean;+ helpText?: string;+ required?: boolean;+};+export type ConfirmDialogProps = BaseDialogProps<+ | false+ | {+ checks?: Record<string, boolean>;+ inputs?: Record<string, string>;+ }> & {title: string;subtitle?: string;@@ -39,12 +51,13 @@ export type ConfirmDialogProps<TCheckId extends string> = BaseDialogProps<negativeButtonText?: string;message?: string;warnings?: string[];- checks?: Partial<Record<TCheckId, Check>>;+ checks?: Record<string, Check>;+ inputs?: Record<string, Input>;};-export const ConfirmDialog = DialogManager.register(function ConfirmDialog<- TCheckId extends string->(props: ConfirmDialogProps<TCheckId>) {+export const ConfirmDialog = DialogManager.register(function ConfirmDialog<>(+ props: ConfirmDialogProps+) {const {onClose,title,@@ -54,9 +67,11 @@ export const ConfirmDialog = DialogManager.register(function ConfirmDialog<positiveButtonText,message,warnings,- checks+ checks,+ inputs} = props;- const checkedItems = useRef<Record<TCheckId, boolean>>({} as any);+ const checkedItems = useRef<Record<string, boolean>>({} as any);+ const inputItems = useRef<Record<string, string>>({} as any);return (<Dialog@@ -68,15 +83,21 @@ export const ConfirmDialog = DialogManager.register(function ConfirmDialog<onClose={() => onClose(false)}onOpen={() => {for (const checkId in checks) {- checkedItems.current[checkId as TCheckId] =- checks[checkId as TCheckId]?.default || false;+ checkedItems.current[checkId] = checks[checkId]?.default || false;+ }+ for (const inputId in inputs) {+ inputItems.current[inputId] = inputs[inputId]?.defaultValue || "";}}}positiveButton={positiveButtonText? {text: positiveButtonText,- onClick: () => onClose(checkedItems.current),+ onClick: () =>+ onClose({+ checks: checkedItems.current,+ inputs: inputItems.current+ }),autoFocus: !!positiveButtonText}: undefined@@ -108,34 +129,45 @@ export const ConfirmDialog = DialogManager.register(function ConfirmDialog<{warnings?.map((text) => (<ErrorText key={text} error={text} sx={{ mt: 0 }} />))}+ {inputs+ ? Object.entries(inputs).map(([id, input]) => (+ <Field+ as={input.multiline ? "textarea" : "input"}+ key={id}+ label={input.title}+ helpText={input.helpText}+ defaultValue={input.defaultValue}+ required={input.required}+ onChange={(e) => {+ inputItems.current[id] = e.target.value;+ }}+ />+ ))+ : null}{checks- ? Object.entries<Check | undefined>(checks).map(- ([id, check]) =>- check && (- <Label- key={id}- id={id}- variant="text.body"- sx={{ fontWeight: "bold" }}- >- <Checkbox- name={id}- defaultChecked={check.default}- sx={{- mr: "small",- width: 18,- height: 18,- color: "accent"- }}- onChange={(e) =>- (checkedItems.current[id as TCheckId] =- e.currentTarget.checked)- }- />- {check.text}- </Label>- )- )+ ? Object.entries<Check>(checks).map(([id, check]) => (+ <Label+ key={id}+ id={id}+ variant="text.body"+ sx={{ fontWeight: "bold" }}+ >+ <Checkbox+ name={id}+ defaultChecked={check.default}+ sx={{+ mr: "small",+ width: 18,+ height: 18,+ color: "accent"+ }}+ onChange={(e) =>+ (checkedItems.current[id] = e.currentTarget.checked)+ }+ />+ {check.text}+ </Label>+ )): null}</Flex></Dialog>diff --git a/apps/web/src/dialogs/reminder-dialog.tsx b/apps/web/src/dialogs/reminder-dialog.tsxdeleted file mode 100644index 66b35c3de..000000000--- a/apps/web/src/dialogs/reminder-dialog.tsx+++ /dev/null@@ -1,202 +0,0 @@-/*-This file is part of the Notesnook project (https://notesnook.com/)--Copyright (C) 2023 Streetwriters (Private) Limited--This program is free software: you can redistribute it and/or modify-it under the terms of the GNU General Public License as published by-the Free Software Foundation, either version 3 of the License, or-(at your option) any later version.--This program is distributed in the hope that it will be useful,-but WITHOUT ANY WARRANTY; without even the implied warranty of-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-GNU General Public License for more details.--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 { Text, Flex, Box } from "@theme-ui/components";-import Dialog from "../components/dialog";-import {- Sync,- Notebook,- Tag2,- Attachment,- Backup,- Vault,- PDF,- Edit,- Icon-} from "../components/icons";-import { BuyDialog } from "./buy-dialog";-import { BaseDialogProps, DialogManager } from "../common/dialog-manager";-import Config from "../utils/config";--const features = [- { icon: Sync, title: "Instant private sync" },- { icon: Notebook, title: "Unlimited notebooks" },- { icon: Tag2, title: "Unlimited tags" },- { icon: Attachment, title: "Encrypted attachments" },- { icon: Backup, title: "Encrypted backups" },- { icon: Vault, title: "Secure private vault" },- { icon: PDF, title: "Export to PDF" },- { icon: Edit, title: "Rich text editor" }-];--type Reminder = {- title: string;- description: string;- offer: {- title: JSX.Element;- subtitle?: string;- };- features: { icon: Icon; title: string }[];- cta: {- title: string;- action: () => Promise<void> | void;- };-};-// TODO create trial expiry coupon codes-const reminders: Record<string, Reminder> = {- trialexpired: {- title: "Your free trial has expired",- description: "But we have a special offer just for you!",- offer: {- title: (- <>- Subscribe now to{" "}- <Text as="span" sx={{ fontWeight: "bold", color: "accent" }}>- get 30% off- </Text>- *- </>- ),- subtitle: "*Only for yearly plan"- },- features,- // footer: (- // <Flex bg="bgSecondary" pb={2} sx={{justifyContent: "center"}}>- // <Button variant="anchor" sx={{color: "paragraph"}}>- // Can't decide yet? Extend your trial!- // </Button>- // </Flex>- // ),- cta: {- title: "Subscribe now",- action: () => {- setTimeout(async () => {- await BuyDialog.show({ plan: "yearly", couponCode: "TRIAL2PRO" });- }, 0);- }- }- },- trialexpiring: {- title: "Your free trial is ending soon",- description: "But your privacy doesn't have to...",- offer: {- title: (- <>- Upgrade now to continue using all the pro features without- interruption.- </>- )- },- features,- cta: {- title: "Upgrade now",- action: () => {- setTimeout(async () => {- await BuyDialog.show({});- }, 0);- }- }- }-};--type ReminderDialogProps = BaseDialogProps<boolean> & {- reminderKey: keyof typeof reminders;-};-export const ReminderDialog = DialogManager.register(function ReminderDialog(- props: ReminderDialogProps-) {- const { reminderKey } = props;- const reminder = reminders[reminderKey];- if (!reminder) return null;- if (Config.get(reminderKey, false)) return null;-- return (- <Dialog- testId="reminder-dialog"- isOpen={true}- title={reminder.title}- onClose={() => {- Config.set(reminderKey, true);- props.onClose(false);- }}- showCloseButton- description={reminder.description}- positiveButton={{- text: <Flex>{reminder.cta.title}</Flex>,- onClick: async () => {- if (reminder.cta.action) await reminder.cta.action();- Config.set(reminderKey, true);- props.onClose(true);- }- }}- >- <Flex- mt={2}- sx={{- flexDirection: "column",- alignItems: "center",- justifyContent: "center",- overflowY: "auto",- overflow: "hidden"- }}- >- {reminder.offer && (- <>- <Text- variant="body"- sx={{ fontSize: "title", textAlign: "center" }}- >- {reminder.offer.title}- </Text>- <Text variant="body" opacity="0.8" sx={{ textAlign: "center" }}>- {reminder.offer.subtitle}- </Text>- </>- )}- {reminder.features && (- <Box- mt={2}- sx={{- display: "grid",- gridTemplateColumns: "1fr 1fr",- columnGap: 1,- rowGap: 1- }}- >- {reminder.features.map((feature) => (- <Flex- key={feature.title}- p={1}- sx={{- borderRadius: "default",- border: "1px solid var(--border)"- }}- >- <feature.icon size={16} sx={{ alignSelf: "start" }} />- <Text variant="body" ml={1}>- {feature.title}- </Text>- </Flex>- ))}- </Box>- )}- </Flex>- </Dialog>- );-});diff --git a/apps/web/src/dialogs/settings/subscription-settings.ts b/apps/web/src/dialogs/settings/subscription-settings.tsindex 149a4ac71..150a0adb2 100644--- a/apps/web/src/dialogs/settings/subscription-settings.ts+++ b/apps/web/src/dialogs/settings/subscription-settings.ts@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { SettingComponent, SettingsGroup } from "./types";+import { SettingsGroup } from "./types";import { SubscriptionStatus } from "./components/subscription-status";import { showToast } from "../../utils/toast";import { db } from "../../common/db";@@ -218,14 +218,22 @@ export const SubscriptionSettings: SettingsGroup[] = [message:"You will only be issued a refund if you are eligible as per our refund policy. Your account will immediately be downgraded to Basic and your funds will be transferred to your account within 24 hours.",negativeButtonText: "No",- positiveButtonText: "Yes"+ positiveButtonText: "Yes",+ inputs: {+ reason: {+ title: "Reason for refund",+ helpText: "Optional",+ multiline: true+ }+ }});if (refundSubscription) {const result = await TaskManager.startTask({type: "modal",title: "Requesting refund for your subscription",subtitle: "Please wait...",- action: () => db.subscriptions.refund()+ action: () =>+ db.subscriptions.refund(refundSubscription.inputs?.reason)});if (result instanceof Error) {showToast("error", result.message);