From a89cf53f49642832400c0de246fa39e579c47d6e Mon Sep 17 00:00:00 2001 From: gazizova-vlada Date: Wed, 12 Jul 2023 17:16:17 +0300 Subject: [PATCH] Web:Add Loader, Progress. --- .../dialogs/DataReassignmentDialog/index.js | 273 +++++++++++------- .../sub-components/Progress/Progress.js | 67 +++++ .../client/src/store/SettingsSetupStore.js | 8 +- packages/common/api/settings/index.js | 11 +- 4 files changed, 246 insertions(+), 113 deletions(-) create mode 100644 packages/client/src/components/dialogs/DataReassignmentDialog/sub-components/Progress/Progress.js diff --git a/packages/client/src/components/dialogs/DataReassignmentDialog/index.js b/packages/client/src/components/dialogs/DataReassignmentDialog/index.js index 460c586a21..ffa1f74ba0 100644 --- a/packages/client/src/components/dialogs/DataReassignmentDialog/index.js +++ b/packages/client/src/components/dialogs/DataReassignmentDialog/index.js @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import styled from "styled-components"; import { inject, observer } from "mobx-react"; import { withTranslation } from "react-i18next"; @@ -26,6 +26,9 @@ import { StyledSelectedOwner, } from "../ChangePortalOwnerDialog/StyledDialog"; +import Progress from "./sub-components/Progress/Progress"; +import Loader from "./sub-components/Loader/Loader"; + const StyledModalDialog = styled(ModalDialog)` .avatar-name, .delete-profile-container { @@ -42,8 +45,6 @@ const StyledModalDialog = styled(ModalDialog)` } `; -StyledModalDialog.defaultProps = { theme: Base }; - const StyledCatalogSpamIcon = styled(CatalogSpamIcon)` ${commonIconsStyles} path { @@ -53,13 +54,18 @@ const StyledCatalogSpamIcon = styled(CatalogSpamIcon)` padding-left: 8px; `; +let timerId = null; + const DataReassignmentDialog = ({ visible, user, setDataReassignmentDialogVisible, dataReassignment, + dataReassignmentProgress, currentColorScheme, + idCurrentUser, t, + tReady, }) => { const { id, avatar, displayName, statusType, deleteProfile } = user; @@ -67,6 +73,16 @@ const DataReassignmentDialog = ({ const [selectedUser, setSelectedUser] = useState(null); const [isLoading, setIsLoading] = useState(false); const [isDeleteProfile, setIsDeleteProfile] = useState(deleteProfile); + const [showProgress, setShowProgress] = useState(false); + const [isReassignCurrentUser, setIsReassignCurrentUser] = useState(false); + + const [percent, setPercent] = useState(0); + + useEffect(() => { + if (percent === 100) { + clearInterval(timerId); + } + }, [percent]); const onToggleDeleteProfile = () => { setIsDeleteProfile((remove) => !remove); @@ -89,18 +105,36 @@ const DataReassignmentDialog = ({ return str[0].toUpperCase() + str.slice(1); }; - const onReassign = () => { - setIsLoading(true); + const checkReassignCurrentUser = () => { + setIsReassignCurrentUser(idCurrentUser === selectedUser.id); + }; - dataReassignment(id, selectedUser.id, isDeleteProfile) - .then(() => { - toastr.success(t("Common:ChangesSavedSuccessfully")); - onClose(); + const checkProgress = (id) => { + dataReassignmentProgress(id) + .then((res) => { + setPercent(res.percentage); }) .catch((error) => { toastr.error(error?.response?.data?.error?.message); + }); + }; + + const onReassign = () => { + checkReassignCurrentUser(); + setIsLoading(true); + setShowProgress(true); + + dataReassignment([id], selectedUser.id, isDeleteProfile) + .then(() => { + toastr.success(t("Common:ChangesSavedSuccessfully")); + + timerId = setInterval(() => checkProgress(id), 500); }) - .finally(() => setIsLoading(false)); + .catch((error) => { + toastr.error(error?.response?.data?.error?.message); + }); + + setIsLoading(false); }; return ( @@ -129,113 +163,130 @@ const DataReassignmentDialog = ({ Data reassignment - - } + + {tReady && showProgress && ( + -
-
- - {displayName} - - {statusType === "disabled" && ( - - )} -
- - - {firstLetterToUppercase(statusType)} - -
-
- - - - New data owner - - - User to whom the data will be transferred - - - - {selectedUser ? ( - - - {selectedUser.label} - - - - {t("ChangePortalOwner:ChangeUser")} - - - ) : ( - - - - {t("Translations:ChooseFromList")} - - )} - - - We will transfer rooms created by user and documents stored in - user’s rooms. - - - Note: this action cannot be undone. - + {tReady && !showProgress && ( + <> + + +
+
+ + {displayName} + + {statusType === "disabled" && ( + + )} +
- - More about data transfer - - + + {firstLetterToUppercase(statusType)} + +
+
+ + + New data owner + + + User to whom the data will be transferred + + + {selectedUser ? ( + + + {selectedUser.label} + + + + {t("ChangePortalOwner:ChangeUser")} + + + ) : ( + + + + {t("Translations:ChooseFromList")} + + + )} + + + We will transfer rooms created by user and documents stored in + user’s rooms. + + + Note: this action cannot be undone. + + + + More about data transfer + + + + )}
+ -
- - - Delete profile when reassignment is finished - -
+ {!showProgress && ( +
+ + + Delete profile when reassignment is finished + +
+ )}
-