From c70a5a74a7e245a5172235499bc495388d03a42b Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 25 Feb 2021 14:43:43 +0100 Subject: [PATCH] fix modals --- .../workspace/src/lib/remix-ui-workspace.tsx | 125 +++++++++++------- 1 file changed, 74 insertions(+), 51 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index a25dbbc261..4218873078 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -97,18 +97,13 @@ export const Workspace = (props: WorkspaceProps) => { message: 'Please choose a name for the workspace', ok: { label: '', - fn: () => onFinishRenameWorkspace() + fn: () => {} }, cancel: { label: '', fn: () => {} }, - handleHide: () => { - setState(prevState => { - state.renameModal.hide = true - return { ...prevState, ...state.renameModal } - }) - } + handleHide: null }, deleteModal: { id: 'deleteWorkspace', @@ -117,18 +112,13 @@ export const Workspace = (props: WorkspaceProps) => { message: 'Please confirm workspace deletion', ok: { label: '', - fn: () => onFinishDeleteWorkspace() + fn: () => {} }, cancel: { label: '', fn: () => {} }, - handleHide: () => { - setState(prevState => { - state.deleteModal.hide = true - return { ...prevState, ...state.deleteModal } - }) - } + handleHide: null }, createModal: { id: 'createWorkspace', @@ -137,63 +127,96 @@ export const Workspace = (props: WorkspaceProps) => { message: 'Please choose a name for the workspace', ok: { label: '', - fn: () => onFinishCreateWorkspace() + fn: () => {} }, cancel: { label: '', fn: () => {} }, - handleHide: () => { - setState(prevState => { - state.createModal.hide = true - return { ...prevState, ...state.createModal } - }) - } + handleHide: null } }) /* workspace creation, renaming and deletion */ - // const modal = (title: string, message: string, ok: { label: string, fn: () => void }, cancel: { label: string, fn: () => void }) => { - // setState(prevState => { - // return { - // ...prevState, - // modals: [...prevState.modals, - // { - // message, - // title, - // ok, - // cancel, - // handleHide: handleHideModal - // }] - // } - // }) - // } - - const workspaceRenameInput = useRef() - const workspaceCreateInput = useRef() - - const createWorkspace = () => { + const renameCurrentWorkspace = () => { setState(prevState => { - state.createModal.hide = false - return { ...prevState, ...state.createModal } + return { + ...prevState, + renameModal: { + ...prevState.renameModal, + hide: false, + ok: { + label: '', + fn: () => onFinishRenameWorkspace() + }, + cancel: { + label: '', + fn: () => {} + }, + handleHide: () => { + setState(prevState => { + return { ...prevState, renameModal: {...prevState.renameModal, hide: true } } + }) + } + }, + } }) } - const renameCurrentWorkspace = () => { + const createWorkspace = () => { setState(prevState => { - state.renameModal.hide = false - return { ...prevState, ...state.renameModal } + return { + ...prevState, + createModal: { + ...prevState.createModal, + hide: false, + ok: { + label: '', + fn: () => onFinishCreateWorkspace() + }, + cancel: { + label: '', + fn: () => {} + }, + handleHide: () => { + setState(prevState => { + return { ...prevState, createModal: {...prevState.createModal, hide: true } } + }) + } + } + } }) - } + } const deleteCurrentWorkspace = () => { setState(prevState => { - state.deleteModal.hide = false - return { ...prevState, ...state.deleteModal } + return { + ...prevState, + deleteModal: { + ...prevState.deleteModal, + hide: false, + ok: { + label: '', + fn: () => onFinishDeleteWorkspace() + }, + cancel: { + label: '', + fn: () => {} + }, + handleHide: () => { + setState(prevState => { + return { ...prevState, deleteModal: {...prevState.deleteModal, hide: true } } + }) + } + }, + } }) - } - + } + + const workspaceRenameInput = useRef() + const workspaceCreateInput = useRef() + const onFinishRenameWorkspace = async () => { if (workspaceRenameInput.current === undefined) return // @ts-ignore: Object is possibly 'null'.