From c51501dc0a425fb8521a0514fb269ab803e6279b Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 14 Sep 2022 08:11:58 +0800 Subject: [PATCH] chore: update dialogs --- web/src/components/CreateShortcutDialog.tsx | 101 ++++++++++++++----- web/src/components/CreateWorkspaceDialog.tsx | 64 ++++++++---- web/src/types/modules/shortcut.d.ts | 3 + 3 files changed, 123 insertions(+), 45 deletions(-) diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx index 1df7f6d..db44e69 100644 --- a/web/src/components/CreateShortcutDialog.tsx +++ b/web/src/components/CreateShortcutDialog.tsx @@ -10,40 +10,70 @@ interface Props extends DialogProps { shortcutId?: ShortcutId; } +interface State { + shortcutCreate: ShortcutCreate; +} + const CreateShortcutDialog: React.FC = (props: Props) => { const { destroy, workspaceId, shortcutId } = props; - const [name, setName] = useState(""); - const [link, setLink] = useState(""); - const [visibility, setVisibility] = useState("PRIVATE"); + const [state, setState] = useState({ + shortcutCreate: { + workspaceId: workspaceId, + name: "", + link: "", + description: "", + visibility: "PRIVATE", + }, + }); const requestState = useLoading(false); useEffect(() => { if (shortcutId) { const shortcutTemp = shortcutService.getShortcutById(shortcutId); if (shortcutTemp) { - setName(shortcutTemp.name); - setLink(shortcutTemp.link); + setState({ + ...state, + shortcutCreate: Object.assign(state.shortcutCreate, { + workspaceId: shortcutTemp.workspaceId, + name: shortcutTemp.name, + link: shortcutTemp.link, + description: shortcutTemp.description, + visibility: shortcutTemp.visibility, + }), + }); } } }, [shortcutId]); - const handleNameInputChange = (e: React.ChangeEvent) => { + const handleInputChange = (e: React.ChangeEvent, key: string) => { const text = e.target.value as string; - setName(text); + const tempObject = {} as any; + tempObject[key] = text; + + setState({ + ...state, + shortcutCreate: Object.assign(state.shortcutCreate, tempObject), + }); + }; + + const handleNameInputChange = (e: React.ChangeEvent) => { + handleInputChange(e, "name"); }; const handleLinkInputChange = (e: React.ChangeEvent) => { - const text = e.target.value as string; - setLink(text); + handleInputChange(e, "link"); + }; + + const handleDescriptionInputChange = (e: React.ChangeEvent) => { + handleInputChange(e, "description"); }; const handleVisibilityInputChange = (e: React.ChangeEvent) => { - const text = e.target.value as string; - setVisibility(text as Visibility); + handleInputChange(e, "visibility"); }; const handleSaveBtnClick = async () => { - if (!name) { + if (!state.shortcutCreate.name) { toastHelper.error("Name is required"); return; } @@ -52,16 +82,13 @@ const CreateShortcutDialog: React.FC = (props: Props) => { if (shortcutId) { await shortcutService.patchShortcut({ id: shortcutId, - name, - link, + name: state.shortcutCreate.name, + link: state.shortcutCreate.link, + description: state.shortcutCreate.description, + visibility: state.shortcutCreate.visibility, }); } else { - await shortcutService.createShortcut({ - workspaceId, - name, - link, - visibility: "PRIVATE", - }); + await shortcutService.createShortcut(state.shortcutCreate); } } catch (error: any) { console.error(error); @@ -81,11 +108,33 @@ const CreateShortcutDialog: React.FC = (props: Props) => {
Name - +
Link - + +
+
+ Description +
Visibility @@ -96,7 +145,7 @@ const CreateShortcutDialog: React.FC = (props: Props) => { id="visibility-private" value="PRIVATE" onChange={handleVisibilityInputChange} - checked={visibility === "PRIVATE"} + checked={state.shortcutCreate.visibility === "PRIVATE"} />