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: show errors during tag edit/create
Abdullah Attaca59670b68ce
diff --git a/apps/web/src/common/dialog-controller.tsx b/apps/web/src/common/dialog-controller.tsxindex d5200b191..5c4c70f64 100644--- a/apps/web/src/common/dialog-controller.tsx+++ b/apps/web/src/common/dialog-controller.tsx@@ -365,15 +365,10 @@ export function showCreateTagDialog() {perform(false);}}onAction={async (title: string) => {- if (!title) return showToast("error", "Tag title cannot be empty.");- try {- await db.tags.add({ title });- showToast("success", "Tag created!");- tagStore.refresh();- perform(true);- } catch (e) {- if (e instanceof Error) showToast("error", e.message);- }+ await db.tags.add({ title });+ showToast("success", "Tag created!");+ tagStore.refresh();+ perform(true);}}/>));@@ -385,10 +380,8 @@ export function showEditTagDialog(tag: Tag) {title={"Edit tag"}subtitle={`You are editing #${tag.title}.`}defaultValue={tag.title}- item={tag}onClose={() => perform(false)}onAction={async (title: string) => {- if (!title) return;await db.tags.add({ id: tag.id, title });showToast("success", "Tag edited!");await tagStore.refresh();@@ -406,7 +399,6 @@ export function showRenameColorDialog(color: Color) {<Dialogtitle={"Rename color"}subtitle={`You are renaming color ${color.title}.`}- item={color}defaultValue={color.title}onClose={() => perform(false)}onAction={async (title: string) => {diff --git a/apps/web/src/dialogs/item-dialog.jsx b/apps/web/src/dialogs/item-dialog.tsxsimilarity index 65%rename from apps/web/src/dialogs/item-dialog.jsxrename to apps/web/src/dialogs/item-dialog.tsxindex caa281052..5bc1b2911 100644--- a/apps/web/src/dialogs/item-dialog.jsx+++ b/apps/web/src/dialogs/item-dialog.tsx@@ -20,8 +20,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { Box } from "@theme-ui/components";import Dialog from "../components/dialog";import Field from "../components/field";+import { Perform } from "../common/dialog-controller";+import { useState } from "react";+import { ErrorText } from "../components/error-text";++type ItemDialogProps = {+ title: string;+ subtitle?: string;+ onClose: Perform;+ onAction: (title: string) => Promise<void>;+ defaultValue?: string;+};+function ItemDialog(props: ItemDialogProps) {+ const [error, setError] = useState<Error>();-function ItemDialog(props) {return (<DialogtestId="item-dialog"@@ -39,10 +51,19 @@ function ItemDialog(props) {<Boxas="form"id="itemForm"- onSubmit={(e) => {+ onSubmit={async (e) => {e.preventDefault();- const title = e.target.title.value;- props.onAction(title);+ setError(undefined);+ const formData = new FormData(e.target as HTMLFormElement);+ const title = formData.get("title");+ if (!title) return;+ try {+ await props.onAction(title as string);+ } catch (e) {+ if (e instanceof Error) {+ setError(e);+ }+ }}}><Field@@ -54,6 +75,7 @@ function ItemDialog(props) {data-test-id="title-input"defaultValue={props.defaultValue}/>+ <ErrorText error={error?.message} /></Box></Dialog>);