From 44cc9371e4752f47f1830dae35f375606eca47b4 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Sat, 29 Jul 2023 15:37:49 +0300 Subject: [PATCH] Refactor dialogs --- .../pages/RSFormPage/EditorConstituenta.tsx | 38 +++------ .../src/pages/RSFormPage/EditorItems.tsx | 42 ++++----- .../frontend/src/pages/RSFormPage/RSTabs.tsx | 85 +++++++++++++++---- 3 files changed, 93 insertions(+), 72 deletions(-) diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta.tsx index 857ee281..a3dd0cb2 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta.tsx @@ -7,25 +7,24 @@ import SubmitButton from '../../components/Common/SubmitButton'; import TextArea from '../../components/Common/TextArea'; import { DumpBinIcon, SaveIcon, SmallPlusIcon } from '../../components/Icons'; import { useRSForm } from '../../context/RSFormContext'; -import { type CstType, EditMode, type ICstCreateData, ICstUpdateData, SyntaxTree } from '../../utils/models'; -import { createAliasFor, getCstTypeLabel } from '../../utils/staticUI'; -import DlgCreateCst from './DlgCreateCst'; +import { type CstType, EditMode, ICstUpdateData, SyntaxTree } from '../../utils/models'; +import { getCstTypeLabel } from '../../utils/staticUI'; import EditorRSExpression from './EditorRSExpression'; import ViewSideConstituents from './elements/ViewSideConstituents'; import { RSTabsList } from './RSTabs'; interface EditorConstituentaProps { onShowAST: (ast: SyntaxTree) => void + onShowCreateCst: (position: number | undefined, type: CstType | undefined) => void } -function EditorConstituenta({onShowAST}: EditorConstituentaProps) { +function EditorConstituenta({ onShowAST, onShowCreateCst }: EditorConstituentaProps) { const navigate = useNavigate(); const { activeCst, activeID, schema, setActiveID, processing, isEditable, - cstDelete, cstUpdate, cstCreate + cstDelete, cstUpdate } = useRSForm(); - const [showCstModal, setShowCstModal] = useState(false); const [isModified, setIsModified] = useState(false); const [editMode, setEditMode] = useState(EditMode.TEXT); @@ -107,24 +106,12 @@ function EditorConstituenta({onShowAST}: EditorConstituentaProps) { }, [activeID, schema, cstDelete, navigate]); const handleAddNew = useCallback( - (type?: CstType) => { - if (!activeID || !schema?.items) { + () => { + if (!activeID || !schema) { return; } - if (!type) { - setShowCstModal(true); - } else { - const data: ICstCreateData = { - cst_type: type, - alias: createAliasFor(type, schema), - insert_after: activeID - } - cstCreate(data, newCst => { - navigate(`/rsforms/${schema.id}?tab=${RSTabsList.CST_EDIT}&active=${newCst.id}`); - toast.success(`Конституента добавлена: ${newCst.alias}`); - }); - } - }, [activeID, schema, cstCreate, navigate]); + onShowCreateCst(activeID, activeCst?.cstType); + }, [activeID, activeCst?.cstType, schema, onShowCreateCst]); const handleRename = useCallback(() => { toast.info('Переименование в разработке'); @@ -136,11 +123,6 @@ function EditorConstituenta({onShowAST}: EditorConstituentaProps) { return (
- {showCstModal && { setShowCstModal(false); }} - onCreate={handleAddNew} - defaultType={activeCst?.cstType as CstType} - />}