From 2e175fb6aa3edd92e710463cc486877de35a2cb4 Mon Sep 17 00:00:00 2001 From: aminecherif Date: Sun, 27 Aug 2023 14:48:46 +0100 Subject: [PATCH] Clear data and fix the short link when the close button is clicked from new room. --- .../src/components/AddLabelForm.tsx | 9 +- .../src/components/AddPresetForm.tsx | 2 +- .../src/components/AddRoomForm.tsx | 394 +++++++++--------- 3 files changed, 209 insertions(+), 196 deletions(-) diff --git a/bbbeasy-frontend/src/components/AddLabelForm.tsx b/bbbeasy-frontend/src/components/AddLabelForm.tsx index 03701784..d1e19bc8 100644 --- a/bbbeasy-frontend/src/components/AddLabelForm.tsx +++ b/bbbeasy-frontend/src/components/AddLabelForm.tsx @@ -46,13 +46,14 @@ type formType = { let addForm: FormInstance = null; export const AddLabelForm = (props: Props) => { + const [initialColor, setInitialColor] = React.useState('#fbbc0b'); const { defaultColor } = props; const initialAddValues: formType = { name: '', description: '', - color: '#fbbc0b', + color: initialColor, }; - const [color, setColor] = React.useState(defaultColor ? defaultColor : '#fbbc0b'); + const [color, setColor] = React.useState(defaultColor ? defaultColor : initialColor); const dataContext = React.useContext(DataContext); const [data, setData] = React.useState([]); const [loading, setLoading] = React.useState(false); @@ -87,8 +88,8 @@ export const AddLabelForm = (props: Props) => { }; const cancelAdd = () => { props.close(); - addForm?.resetFields(); + setColor(initialColor); }; const failedAdd = () => { @@ -102,7 +103,7 @@ export const AddLabelForm = (props: Props) => { centered open={props.isModalShow} onOk={handleAdd} - onCancel={props.close} + onCancel={cancelAdd} footer={null} maskClosable={true} > diff --git a/bbbeasy-frontend/src/components/AddPresetForm.tsx b/bbbeasy-frontend/src/components/AddPresetForm.tsx index b7af5b6c..d75fea46 100644 --- a/bbbeasy-frontend/src/components/AddPresetForm.tsx +++ b/bbbeasy-frontend/src/components/AddPresetForm.tsx @@ -95,7 +95,7 @@ export const AddPresetForm = (props: Props) => { centered open={props.isModalShow} onOk={handleAdd} - onCancel={props.close} + onCancel={cancelAdd} footer={null} maskClosable={true} > diff --git a/bbbeasy-frontend/src/components/AddRoomForm.tsx b/bbbeasy-frontend/src/components/AddRoomForm.tsx index 8e675b67..ca36951f 100644 --- a/bbbeasy-frontend/src/components/AddRoomForm.tsx +++ b/bbbeasy-frontend/src/components/AddRoomForm.tsx @@ -69,6 +69,10 @@ export const AddRoomForm = (props: Props) => { const dataContext = React.useContext(DataContext); const currentUser: UserType = AuthService.getCurrentUser(); + useEffect(() => { + setReadOnly(true); + }, [props.close]); + useEffect(() => { PresetsService.list_presets(currentUser.id) @@ -113,13 +117,18 @@ export const AddRoomForm = (props: Props) => { setShortLink(''); setErrorsAdd([]); }; - + const cancelEdit = () => { + setShortLink(shortlink); + setReadOnly(true); + }; const cancelAdd = () => { - props.close(); setShortLink(''); addForm?.resetFields(); - }; + setReadOnly(false); + props.close(); + + }; const toggleEdit = () => { setReadOnly(false); @@ -130,9 +139,7 @@ export const AddRoomForm = (props: Props) => { addForm.setFieldValue('shortlink', shortLink); } }; - const cancelEdit = () => { - setReadOnly(true); - }; + const handleSaveEdit = async () => { setReadOnly(true); @@ -162,200 +169,205 @@ export const AddRoomForm = (props: Props) => { const handleChange = (event) => { addForm.setFieldValue('shortlink', event.target.value); - setShortLink(event.target.value); }; return ( <> - } - className="add-modal large-modal" - centered - open={props.isModalShow} - onOk={handleAdd} - onCancel={props.close} - footer={null} - maskClosable={true} - > -
(addForm = form)} - initialValues={props.initialAddValues} - hideRequiredMark - onFinish={handleAdd} - onFinishFailed={failedAdd} - validateTrigger="onSubmit" - > - - - } - name="name" - {...('name' in errorsAdd && { - help: ( - EN_US[elem] == errorsAdd['name'] - )} - /> - ), - validateStatus: 'error', - })} - rules={[ - { - required: true, - message: , - }, - { - min: 4, - message: , - }, - { - max: 256, - message: , - }, - ]} - > - - + { + props.isModalShow ? + } + className="add-modal large-modal" + centered + open={props.isModalShow} + onOk={handleAdd} + onCancel={cancelAdd} + footer={null} + maskClosable={true} + > + (addForm = form)} + initialValues={props.initialAddValues} + hideRequiredMark + onFinish={handleAdd} + onFinishFailed={failedAdd} + validateTrigger="onSubmit" + > + + + } + name="name" + {...('name' in errorsAdd && { + help: ( + EN_US[elem] == errorsAdd['name'] + )} + /> + ), + validateStatus: 'error', + })} + rules={[ + { + required: true, + message: , + }, + { + min: 4, + message: , + }, + { + max: 256, + message: , + }, + ]} + > + + - } - name="preset" - rules={[ - { - required: true, - message: , - }, - ]} - > - - - - - } - name="shortlink" - {...('short_link' in errorsAdd && { - help: ( - EN_US[elem] == errorsAdd['short_link'] - )} - /> - ), - validateStatus: 'error', - })} - rules={[ - { - required: true, - message: , - }, - ]} - > - {readOnly ? ( - - - + - - - - - - - - - + +
+ : + null + } ); };