diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx index f41ecff..bbbc156 100644 --- a/web/src/components/CreateShortcutDialog.tsx +++ b/web/src/components/CreateShortcutDialog.tsx @@ -1,4 +1,5 @@ import { Button, Input, Modal, ModalDialog, Radio, RadioGroup } from "@mui/joy"; +import { isUndefined } from "lodash-es"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { toast } from "react-hot-toast"; @@ -32,7 +33,7 @@ const CreateShortcutDialog: React.FC = (props: Props) => { }); const [tag, setTag] = useState(""); const requestState = useLoading(false); - const isEditing = !!shortcutId; + const isCreating = isUndefined(shortcutId); useEffect(() => { if (shortcutId) { @@ -134,7 +135,7 @@ const CreateShortcutDialog: React.FC = (props: Props) => {
- {isEditing ? "Edit Shortcut" : "Create Shortcut"} + {isCreating ? "Create Shortcut" : "Edit Shortcut"} diff --git a/web/src/components/CreateUserDialog.tsx b/web/src/components/CreateUserDialog.tsx index bec12b2..96771cb 100644 --- a/web/src/components/CreateUserDialog.tsx +++ b/web/src/components/CreateUserDialog.tsx @@ -1,4 +1,5 @@ import { Button, Input, Modal, ModalDialog, Radio, RadioGroup } from "@mui/joy"; +import { isUndefined } from "lodash-es"; import { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; import useLoading from "../hooks/useLoading"; @@ -29,7 +30,7 @@ const CreateUserDialog: React.FC = (props: Props) => { }, }); const requestState = useLoading(false); - const isEditing = !!user; + const isCreating = isUndefined(user); useEffect(() => { if (user) { @@ -85,8 +86,8 @@ const CreateUserDialog: React.FC = (props: Props) => { }; const handleSaveBtnClick = async () => { - if (!state.userCreate.email) { - toast.error("Email is required"); + if (isCreating && (!state.userCreate.email || !state.userCreate.nickname || !state.userCreate.password)) { + toast.error("Please fill all inputs"); return; } @@ -101,9 +102,6 @@ const CreateUserDialog: React.FC = (props: Props) => { if (user.nickname !== state.userCreate.nickname) { userPatch.nickname = state.userCreate.nickname; } - if (state.userCreate.password) { - userPatch.password = state.userCreate.password; - } if (user.role !== state.userCreate.role) { userPatch.role = state.userCreate.role; } @@ -127,7 +125,7 @@ const CreateUserDialog: React.FC = (props: Props) => {
- {isEditing ? "Edit User" : "Create User"} + {isCreating ? "Create User" : "Edit User"} @@ -159,19 +157,20 @@ const CreateUserDialog: React.FC = (props: Props) => { onChange={handleNicknameInputChange} />
-
- - Password - {!isEditing && *} - - -
+ {isCreating && ( +
+ + Password * + + +
+ )}
Role *