From 5b779b4f14d2c09a30edd5dfe573bb4e2f28d61d Mon Sep 17 00:00:00 2001 From: GyDi Date: Sun, 13 Feb 2022 19:33:24 +0800 Subject: [PATCH] feat: new profile able to edit name and desc --- src/components/profile/profile-new.tsx | 64 ++++++++++++++++++++++++++ src/pages/profiles.tsx | 21 ++++++--- 2 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 src/components/profile/profile-new.tsx diff --git a/src/components/profile/profile-new.tsx b/src/components/profile/profile-new.tsx new file mode 100644 index 0000000..bd2a5e8 --- /dev/null +++ b/src/components/profile/profile-new.tsx @@ -0,0 +1,64 @@ +import { useState } from "react"; +import { + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + TextField, +} from "@mui/material"; +import Notice from "../base/base-notice"; + +interface Props { + open: boolean; + onClose: () => void; + onSubmit: (name: string, desc: string) => void; +} + +const ProfileNew = (props: Props) => { + const { open, onClose, onSubmit } = props; + const [name, setName] = useState(""); + const [desc, setDesc] = useState(""); + + const onCreate = () => { + if (!name.trim()) { + Notice.error("`Name` should not be null"); + return; + } + onSubmit(name, desc); + }; + + return ( + + Create Profile + + setName(e.target.value)} + /> + + setDesc(e.target.value)} + /> + + + + + + + ); +}; + +export default ProfileNew; diff --git a/src/pages/profiles.tsx b/src/pages/profiles.tsx index 299658a..3f75eb0 100644 --- a/src/pages/profiles.tsx +++ b/src/pages/profiles.tsx @@ -10,9 +10,10 @@ import { } from "../services/cmds"; import { getProxies, updateProxy } from "../services/api"; import noop from "../utils/noop"; -import Notice from "../components/notice"; -import BasePage from "../components/base-page"; -import ProfileItem from "../components/profile-item"; +import Notice from "../components/base/base-notice"; +import BasePage from "../components/base/base-page"; +import ProfileItem from "../components/profile/profile-item"; +import ProfileNew from "../components/profile/profile-new"; const ProfilePage = () => { const [url, setUrl] = useState(""); @@ -96,13 +97,15 @@ const ProfilePage = () => { }; const lockNewRef = useRef(false); - const onNew = async () => { + const [dialogOpen, setDialogOpen] = useState(false); + const onNew = async (name: string, desc: string) => { if (lockNewRef.current) return; lockNewRef.current = true; try { - await newProfile("New Profile", "no desc"); + await newProfile(name, desc); mutate("getProfiles"); + setDialogOpen(false); } catch (err: any) { err && Notice.error(err.toString()); } finally { @@ -131,7 +134,7 @@ const ProfilePage = () => { > Import - @@ -148,6 +151,12 @@ const ProfilePage = () => { ))} + + setDialogOpen(false)} + onSubmit={onNew} + /> ); };