From 02fb8738ce9eb6ac34317a5d9c4e3ae5ca38014d Mon Sep 17 00:00:00 2001 From: Tatiana Lopaeva Date: Tue, 14 May 2024 18:13:01 +0300 Subject: [PATCH] Web: Refactoring. --- .../components/GlobalEvents/EditRoomEvent.js | 5 +- .../sub-components/VirtualDataRoomBlock.js | 40 +------- .../Watermarks/ImageWatermark.js | 29 +++--- .../sub-components/Watermarks/ViewerInfo.js | 24 ++--- .../Watermarks/WatermarkBlock.js | 98 +++++++++++++++++++ .../client/src/store/CreateEditRoomStore.js | 12 ++- 6 files changed, 140 insertions(+), 68 deletions(-) create mode 100644 packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/WatermarkBlock.js diff --git a/packages/client/src/components/GlobalEvents/EditRoomEvent.js b/packages/client/src/components/GlobalEvents/EditRoomEvent.js index 9e63892019..7e8b056037 100644 --- a/packages/client/src/components/GlobalEvents/EditRoomEvent.js +++ b/packages/client/src/components/GlobalEvents/EditRoomEvent.js @@ -195,9 +195,7 @@ const EditRoomEvent = ({ actions.push(removeTagsFromRoom(room.id, removedTags)); if (watermarksSettings && !isNotWatermarkSet()) { - const request = !watermarksSettings.enabled - ? deleteWatermarkSettings(room.id) - : setWatermarkSettings(room.id, watermarksSettings); + const request = setWatermarkSettings(room.id, watermarksSettings); actions.push(request); } @@ -300,6 +298,7 @@ const EditRoomEvent = ({ const [tags, watermarks] = await Promise.all(requests); setFetchedTags(tags); + console.log("watermarks", watermarks); setWatermarks(watermarks, true); setIsInitLoading(false); diff --git a/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/VirtualDataRoomBlock.js b/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/VirtualDataRoomBlock.js index da5fe16a21..67e9f53af1 100644 --- a/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/VirtualDataRoomBlock.js +++ b/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/VirtualDataRoomBlock.js @@ -7,7 +7,7 @@ import { Text } from "@docspace/shared/components/text"; import { ToggleButton } from "@docspace/shared/components/toggle-button"; import FileLifetime from "./FileLifetime"; -import Watermarks from "../sub-components/Watermarks"; +import WatermarkBlock from "./Watermarks/WatermarkBlock"; const StyledVirtualDataRoomBlock = styled.div` .virtual-data-room-block { @@ -68,21 +68,11 @@ const Block = ({ ); }; -const VirtualDataRoomBlock = ({ - t, - roomParams, - setRoomParams, - isEdit = false, - isWatermarks = false, - setWatermarks, -}) => { +const VirtualDataRoomBlock = ({ t, roomParams, setRoomParams, isEdit }) => { const role = t("Translations:RoleViewer"); const [fileLifetimeChecked, setFileLifetimeChecked] = useState(false); const [copyAndDownloadChecked, setCopyAndDownloadChecked] = useState(false); - const [watermarksChecked, setWatermarksChecked] = useState( - isWatermarks && isEdit, - ); const onChangeAutomaticIndexing = () => { setRoomParams({ ...roomParams, indexing: !roomParams.indexing }); @@ -96,12 +86,6 @@ const VirtualDataRoomBlock = ({ setCopyAndDownloadChecked(!copyAndDownloadChecked); }; - const onChangeAddWatermarksToDocuments = () => { - setWatermarksChecked(!watermarksChecked); - - setWatermarks({ enabled: !watermarksChecked }); - }; - return ( - - - + + ); }; -export default inject(({ createEditRoomStore }) => { - const { watermarksSettings, setWatermarks } = createEditRoomStore; - - return { - setWatermarks, - isWatermarks: watermarksSettings?.enabled, - }; -})(observer(VirtualDataRoomBlock)); +export default VirtualDataRoomBlock; diff --git a/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/ImageWatermark.js b/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/ImageWatermark.js index 85b1ce5bb1..9862f37c6a 100644 --- a/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/ImageWatermark.js +++ b/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/ImageWatermark.js @@ -117,17 +117,17 @@ const ImageWatermark = ({ const initialInfoRef = initialInfo.current; useEffect(() => { - setWatermarks( - { - rotate: initialInfoRef.rotate.key, - imageScale: initialInfoRef.scale.key, - imageUrl: initialInfoRef.url, - text: "", - enabled: true, - additions: 0, - }, - true, - ); + if (!isEdit) + setWatermarks( + { + rotate: initialInfoRef.rotate.key, + imageScale: initialInfoRef.scale.key, + imageUrl: initialInfoRef.url, + text: "", + additions: 0, + }, + true, + ); }, []); const [selectedRotate, setRotate] = useState(initialInfoRef.rotate); @@ -138,8 +138,7 @@ const ImageWatermark = ({ imageProcessing(file) .then((f) => { - if (f instanceof File) - setWatermarks({ ...watermarksSettings, image: f }); + if (f instanceof File) setWatermarks({ image: f }); }) .catch((error) => { if ( @@ -153,13 +152,13 @@ const ImageWatermark = ({ const onScaleChange = (item) => { setScale(item); - setWatermarks({ ...watermarksSettings, imageScale: item.key }); + setWatermarks({ imageScale: item.key }); }; const onRotateChange = (item) => { setRotate(item); - setWatermarks({ ...watermarksSettings, rotate: item.key }); + setWatermarks({ rotate: item.key }); }; const rotateItems = () => { diff --git a/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/ViewerInfo.js b/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/ViewerInfo.js index 488c931f98..253f30dc6e 100644 --- a/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/ViewerInfo.js +++ b/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/ViewerInfo.js @@ -136,15 +136,15 @@ const ViewerInfoWatermark = ({ const initialInfoRef = initialInfo.current; useEffect(() => { - setWatermarks( - { - rotate: initialInfoRef.rotate.key, - text: initialInfoRef.text, - enabled: true, - additions: initialInfoRef.additions, - }, - true, - ); + if (!isEdit) + setWatermarks( + { + rotate: initialInfoRef.rotate.key, + text: initialInfoRef.text, + additions: initialInfoRef.additions, + }, + true, + ); }, []); const [selectedPosition, setSelectedPosition] = useState( @@ -167,20 +167,20 @@ const ViewerInfoWatermark = ({ flagsCount += WatermarkAdditions[key]; } } - setWatermarks({ ...watermarksSettings, additions: flagsCount }); + setWatermarks({ additions: flagsCount }); }; const onPositionChange = (item) => { setSelectedPosition(item); - setWatermarks({ ...watermarksSettings, rotate: item.key }); + setWatermarks({ rotate: item.key }); }; const onTextChange = (e) => { const { value } = e.target; setTextValue(value); - setWatermarks({ ...watermarksSettings, text: value }); + setWatermarks({ text: value }); }; return ( diff --git a/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/WatermarkBlock.js b/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/WatermarkBlock.js new file mode 100644 index 0000000000..7aee4d84db --- /dev/null +++ b/packages/client/src/components/dialogs/CreateEditRoomDialog/sub-components/Watermarks/WatermarkBlock.js @@ -0,0 +1,98 @@ +// (c) Copyright Ascensio System SIA 2009-2024 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode +// (c) Copyright Ascensio System SIA 2009-2024 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + +import { useState, useEffect } from "react"; + +import { inject, observer } from "mobx-react"; + +import Watermarks from "./index"; + +const WatermarkBlock = ({ + BlockComponent, + setWatermarks, + isEdit = false, + isWatermarks = false, + t, +}) => { + useEffect(() => { + console.log("!!!!watermarksChecked", watermarksChecked); + if (!isEdit) setWatermarks({ enabled: watermarksChecked }, true); + }, []); + + const [watermarksChecked, setWatermarksChecked] = useState( + isWatermarks && isEdit, + ); + const onChangeAddWatermarksToDocuments = () => { + setWatermarksChecked(!watermarksChecked); + + setWatermarks({ enabled: !watermarksChecked }); + }; + return ( + + + + ); +}; + +export default inject(({ createEditRoomStore }) => { + const { setWatermarks, watermarksSettings } = createEditRoomStore; + return { + setWatermarks, + + isWatermarks: watermarksSettings?.enabled, + }; +})(observer(WatermarkBlock)); diff --git a/packages/client/src/store/CreateEditRoomStore.js b/packages/client/src/store/CreateEditRoomStore.js index 4c59d8017a..d96632946f 100644 --- a/packages/client/src/store/CreateEditRoomStore.js +++ b/packages/client/src/store/CreateEditRoomStore.js @@ -101,7 +101,10 @@ class CreateEditRoomStore { this.initialWatermarksSettings = watermarksSettings; } - this.watermarksSettings = watermarksSettings; + this.watermarksSettings = { + ...this.watermarksSettings, + ...watermarksSettings, + }; }; setIsImageWatermarkType = (isImageType, isInit) => { @@ -119,7 +122,6 @@ class CreateEditRoomStore { }; isNotWatermarkSet = () => { - if (this.isImageType && !this.watermarksSettings.image) return true; if (!this.isImageType && this.watermarksSettings.additions === 0) @@ -226,7 +228,11 @@ class CreateEditRoomStore { const requests = []; - if (this.watermarksSettings && !this.isNotWatermarkSet()) { + if ( + this.watermarksSettings && + !this.isNotWatermarkSet() && + this.watermarksSettings.enabled + ) { requests.push(this.getWatermarkRequest(room)); } // delete thirdparty account if not needed