chore: update dialog titles

This commit is contained in:
Steven 2023-07-09 01:06:21 +08:00
parent 5db3506cba
commit d82d3701dd
2 changed files with 22 additions and 22 deletions

View File

@ -1,4 +1,5 @@
import { Button, Input, Modal, ModalDialog, Radio, RadioGroup } from "@mui/joy"; import { Button, Input, Modal, ModalDialog, Radio, RadioGroup } from "@mui/joy";
import { isUndefined } from "lodash-es";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { toast } from "react-hot-toast"; import { toast } from "react-hot-toast";
@ -32,7 +33,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
}); });
const [tag, setTag] = useState<string>(""); const [tag, setTag] = useState<string>("");
const requestState = useLoading(false); const requestState = useLoading(false);
const isEditing = !!shortcutId; const isCreating = isUndefined(shortcutId);
useEffect(() => { useEffect(() => {
if (shortcutId) { if (shortcutId) {
@ -134,7 +135,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
<Modal open={true}> <Modal open={true}>
<ModalDialog> <ModalDialog>
<div className="flex flex-row justify-between items-center w-80 sm:w-96 mb-4"> <div className="flex flex-row justify-between items-center w-80 sm:w-96 mb-4">
<span className="text-lg font-medium">{isEditing ? "Edit Shortcut" : "Create Shortcut"}</span> <span className="text-lg font-medium">{isCreating ? "Create Shortcut" : "Edit Shortcut"}</span>
<Button variant="plain" onClick={onClose}> <Button variant="plain" onClick={onClose}>
<Icon.X className="w-5 h-auto text-gray-600" /> <Icon.X className="w-5 h-auto text-gray-600" />
</Button> </Button>

View File

@ -1,4 +1,5 @@
import { Button, Input, Modal, ModalDialog, Radio, RadioGroup } from "@mui/joy"; import { Button, Input, Modal, ModalDialog, Radio, RadioGroup } from "@mui/joy";
import { isUndefined } from "lodash-es";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { toast } from "react-hot-toast"; import { toast } from "react-hot-toast";
import useLoading from "../hooks/useLoading"; import useLoading from "../hooks/useLoading";
@ -29,7 +30,7 @@ const CreateUserDialog: React.FC<Props> = (props: Props) => {
}, },
}); });
const requestState = useLoading(false); const requestState = useLoading(false);
const isEditing = !!user; const isCreating = isUndefined(user);
useEffect(() => { useEffect(() => {
if (user) { if (user) {
@ -85,8 +86,8 @@ const CreateUserDialog: React.FC<Props> = (props: Props) => {
}; };
const handleSaveBtnClick = async () => { const handleSaveBtnClick = async () => {
if (!state.userCreate.email) { if (isCreating && (!state.userCreate.email || !state.userCreate.nickname || !state.userCreate.password)) {
toast.error("Email is required"); toast.error("Please fill all inputs");
return; return;
} }
@ -101,9 +102,6 @@ const CreateUserDialog: React.FC<Props> = (props: Props) => {
if (user.nickname !== state.userCreate.nickname) { if (user.nickname !== state.userCreate.nickname) {
userPatch.nickname = state.userCreate.nickname; userPatch.nickname = state.userCreate.nickname;
} }
if (state.userCreate.password) {
userPatch.password = state.userCreate.password;
}
if (user.role !== state.userCreate.role) { if (user.role !== state.userCreate.role) {
userPatch.role = state.userCreate.role; userPatch.role = state.userCreate.role;
} }
@ -127,7 +125,7 @@ const CreateUserDialog: React.FC<Props> = (props: Props) => {
<Modal open={true}> <Modal open={true}>
<ModalDialog> <ModalDialog>
<div className="flex flex-row justify-between items-center w-80 sm:w-96 mb-4"> <div className="flex flex-row justify-between items-center w-80 sm:w-96 mb-4">
<span className="text-lg font-medium">{isEditing ? "Edit User" : "Create User"}</span> <span className="text-lg font-medium">{isCreating ? "Create User" : "Edit User"}</span>
<Button variant="plain" onClick={onClose}> <Button variant="plain" onClick={onClose}>
<Icon.X className="w-5 h-auto text-gray-600" /> <Icon.X className="w-5 h-auto text-gray-600" />
</Button> </Button>
@ -159,19 +157,20 @@ const CreateUserDialog: React.FC<Props> = (props: Props) => {
onChange={handleNicknameInputChange} onChange={handleNicknameInputChange}
/> />
</div> </div>
<div className="w-full flex flex-col justify-start items-start mb-3"> {isCreating && (
<span className="mb-2"> <div className="w-full flex flex-col justify-start items-start mb-3">
Password <span className="mb-2">
{!isEditing && <span className="text-red-600"> *</span>} Password <span className="text-red-600">*</span>
</span> </span>
<Input <Input
className="w-full" className="w-full"
type="password" type="password"
placeholder="" placeholder=""
value={state.userCreate.password} value={state.userCreate.password}
onChange={handlePasswordInputChange} onChange={handlePasswordInputChange}
/> />
</div> </div>
)}
<div className="w-full flex flex-col justify-start items-start mb-3"> <div className="w-full flex flex-col justify-start items-start mb-3">
<span className="mb-2"> <span className="mb-2">
Role <span className="text-red-600">*</span> Role <span className="text-red-600">*</span>