Web: Move toastr function to Web Client (mf: "studio/toastr")

This commit is contained in:
Alexey Safronov 2021-03-03 16:46:04 +03:00
parent fe39c60633
commit 68930abdcb
51 changed files with 100 additions and 85 deletions

View File

@ -1,19 +0,0 @@
import i18n from "i18next";
import en from "./locales/en/translation.json";
import ru from "./locales/ru/translation.json";
import { i18nBaseSettings } from "../../constants";
const newInstance = i18n.createInstance();
const resources = {
en: {
translation: en,
},
ru: {
translation: ru,
},
};
newInstance.init({ ...i18nBaseSettings, resources });
export default newInstance;

View File

@ -1 +0,0 @@
export default from "./toastr";

View File

@ -1,4 +1,4 @@
import toastr from "../components/Toast";
import toastr from "@appserver/components/toast/toastr";
import isEmpty from "lodash/isEmpty";
import omit from "lodash/omit";

View File

@ -8,7 +8,7 @@ import Settings from "./components/pages/Settings";
import VersionHistory from "./components/pages/VersionHistory";
import config from "../package.json";
import PrivateRoute from "@appserver/common/components/PrivateRoute";
import toastr from "@appserver/common/components/Toast/toastr";
import toastr from "studio/toastr";
import { updateTempContent } from "@appserver/common/utils";
import initFilesStore from "./store/InitFilesStore";
import filesStore from "./store/FilesStore";

View File

@ -5,7 +5,7 @@ import styled from "styled-components";
//import equal from "fast-deep-equal/react";
import { getFolder } from "@appserver/common/api/files";
import { FolderType, ShareAccessRights } from "@appserver/common/constants";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { onConvertFiles } from "../../../helpers/files-converter";
import { ReactSVG } from "react-svg";

View File

@ -1,6 +1,6 @@
import React from "react";
import toastr from "@appserver/common/components/Toast/toastr";
import toastr from "studio/toastr";
import Loaders from "@appserver/common/components/Loaders";
import TreeFolders from "./TreeFolders";
import TreeSettings from "./TreeSettings";
@ -119,7 +119,7 @@ export default inject(
const { treeFolders, setSelectedNode, setTreeFolders } = treeFoldersStore;
const selectedTreeNode = [selectedFolderStore.id + ""];
return {
return {
selectedFolderTitle: selectedFolderStore.title,
treeFolders,
selectedTreeNode,
@ -129,6 +129,6 @@ export default inject(
fetchFiles,
setSelectedNode,
setTreeFolders,
};
}
};
}
)(observer(ArticleBodyContent));

View File

@ -8,7 +8,7 @@ import Checkbox from "@appserver/components/checkbox";
import Scrollbar from "@appserver/components/scrollbar";
import { withTranslation } from "react-i18next";
import { getProgress, removeFiles } from "@appserver/common/api/files";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { TIMEOUT } from "../../../helpers/constants";
import { loopTreeFolders } from "../../../helpers/files-helpers";
import { inject, observer } from "mobx-react";

View File

@ -4,7 +4,7 @@ import ModalDialog from "@appserver/components/modal-dialog";
import Button from "@appserver/components/button";
import { withTranslation } from "react-i18next";
import { getFolder } from "@appserver/common/api/files";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { loopTreeFolders } from "../../../helpers/files-helpers";
import { inject, observer } from "mobx-react";

View File

@ -6,7 +6,7 @@ import Button from "@appserver/components/button";
import ModalDialog from "@appserver/components/modal-dialog";
import { withTranslation } from "react-i18next";
import { getProgress, emptyTrash } from "@appserver/common/api/files";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { TIMEOUT } from "../../../helpers/constants";
import { inject, observer } from "mobx-react";

View File

@ -18,7 +18,7 @@ import {
} from "@appserver/common/api/files";
import { checkIsAuthenticated } from "@appserver/common/api/user";
import { getUser } from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast/toastr";
import toastr from "studio/toastr";
import { setDocumentTitle } from "../../../helpers/utils";
import { changeTitle, setFavicon, isIPad } from "./utils";

View File

@ -14,7 +14,7 @@ import {
getFileConversationProgress,
} from "@appserver/common/api/files";
import { FileAction, ShareAccessRights } from "@appserver/common/constants";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import FavoriteIcon from "../../../../../../../public/images/favorite.react.svg";
import FileActionsConvertEditDocIcon from "../../../../../../../public/images/file.actions.convert.edit.doc.react.svg";
import FileActionsLockedIcon from "../../../../../../../public/images/file.actions.locked.react.svg";

View File

@ -7,7 +7,7 @@ import Link from "@appserver/components/link";
import Text from "@appserver/components/text";
import { markAsRead } from "@appserver/common/api/files";
import { FileAction } from "@appserver/common/constants";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { getTitleWithoutExst } from "../../../../../helpers/files-helpers";
import { NewFilesPanel } from "../../../../panels";
import EditingWrapperComponent from "./EditingWrapperComponent";

View File

@ -31,7 +31,7 @@ import {
} from "@appserver/common/api/files";
import { FileAction } from "@appserver/common/constants";
import MediaViewer from "@appserver/common/components/MediaViewer";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import Loaders from "@appserver/common/components/Loaders";
import { TIMEOUT } from "../../../../../helpers/constants";
import { loopTreeFolders } from "../../../../../helpers/files-helpers";

View File

@ -2,7 +2,7 @@ import React from "react";
import copy from "copy-to-clipboard";
import styled, { css } from "styled-components";
import { withRouter } from "react-router";
import toastr from "@appserver/common/components/Toast/toastr";
import toastr from "studio/toastr";
import Loaders from "@appserver/common/components/Loaders";
import Headline from "@appserver/common/components/Headline";
import { FilterType, FileAction } from "@appserver/common/constants";

View File

@ -3,7 +3,7 @@ import PropTypes from "prop-types";
import { withRouter } from "react-router";
import { isMobile } from "react-device-detect";
import axios from "axios";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import PageLayout from "@appserver/common/components/PageLayout";
import { showLoader, hideLoader } from "@appserver/common/utils";
import FilesFilter from "@appserver/common/api/files/filter";

View File

@ -7,7 +7,7 @@ import Button from "@appserver/components/button";
import Text from "@appserver/components/text";
import Link from "@appserver/components/link";
import { withTranslation } from "react-i18next";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import OwnerSelector from "./OwnerSelector";
import {
StyledAsidePanel,

View File

@ -8,7 +8,7 @@ import Text from "@appserver/components/text";
import Link from "@appserver/components/link";
import TextInput from "@appserver/components/text-input";
import Textarea from "@appserver/components/textarea";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { withTranslation } from "react-i18next";
import {
StyledEmbeddingPanel,

View File

@ -11,7 +11,7 @@ import RowContainer from "@appserver/components/row-container";
import Button from "@appserver/components/button";
import { withTranslation } from "react-i18next";
import { getNewFiles, markAsRead } from "@appserver/common/api/files";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { ReactSVG } from "react-svg";
import {
StyledAsidePanel,

View File

@ -2,7 +2,7 @@ import React from "react";
import { withRouter } from "react-router";
import ModalDialog from "@appserver/components/modal-dialog";
import { withTranslation } from "react-i18next";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { StyledAsidePanel } from "../StyledPanels";
import TreeFolders from "../../Article/Body/TreeFolders";
import { ThirdPartyMoveDialog } from "../../dialogs";

View File

@ -4,7 +4,7 @@ import ComboBox from "@appserver/components/combobox";
import Row from "@appserver/components/row";
import Text from "@appserver/components/text";
import DropDownItem from "@appserver/components/drop-down-item";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import copy from "copy-to-clipboard";
import LinkRow from "./linkRow";
import AccessComboBox from "./AccessComboBox";

View File

@ -10,7 +10,7 @@ import DropDownItem from "@appserver/components/drop-down-item";
import Textarea from "@appserver/components/textarea";
import { withRouter } from "react-router";
import { withTranslation, Trans } from "react-i18next";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { ShareAccessRights } from "@appserver/common/constants";
import {
StyledAsidePanel,

View File

@ -4,7 +4,7 @@ import { Switch } from "react-router";
import PeopleStore from "./store/PeopleStore";
import Home from "./components/pages/Home";
import Loader from "@appserver/components/loader";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import PrivateRoute from "@appserver/common/components/PrivateRoute";
import { updateTempContent } from "@appserver/common/utils";
const Profile = React.lazy(() => import("./components/pages/Profile"));

View File

@ -6,7 +6,7 @@ import MainButton from "@appserver/components/main-button";
import DropDownItem from "@appserver/components/drop-down-item";
import InviteDialog from "./../../dialogs/InviteDialog/index";
import { withTranslation } from "react-i18next";
import toastr from "@appserver/common/components/Toast/toastr";
import toastr from "studio/toastr";
import Loaders from "@appserver/common/components/Loaders";
import { inject, observer } from "mobx-react";
import config from "../../../../package.json";

View File

@ -8,7 +8,7 @@ import FieldContainer from "@appserver/components/field-container";
import { withTranslation } from "react-i18next";
import ModalDialogContainer from "../ModalDialogContainer";
import { sendInstructionsToChangeEmail } from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
class ChangeEmailDialogComponent extends React.Component {
constructor(props) {

View File

@ -6,7 +6,7 @@ import Link from "@appserver/components/link";
import Text from "@appserver/components/text";
import { withTranslation, Trans } from "react-i18next";
import { sendInstructionsToChangePassword } from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
class ChangePasswordDialogComponent extends React.Component {
constructor() {

View File

@ -4,7 +4,7 @@ import ModalDialog from "@appserver/components/modal-dialog";
import Button from "@appserver/components/button";
import Text from "@appserver/components/text";
import { withTranslation } from "react-i18next";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
class ChangePhoneDialogComponent extends React.Component {
constructor(props) {

View File

@ -12,7 +12,7 @@ import CustomScrollbarsVirtualList from "@appserver/components/scrollbar/custom-
import { FixedSizeList as List, areEqual } from "react-window";
import AutoSizer from "react-virtualized-auto-sizer";
import { withTranslation } from "react-i18next";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { EmployeeStatus } from "@appserver/common/constants";
import ModalDialogContainer from "../ModalDialogContainer";
import { inject, observer } from "mobx-react";

View File

@ -12,7 +12,7 @@ import CustomScrollbarsVirtualList from "@appserver/components/scrollbar/custom-
import { withTranslation } from "react-i18next";
import { FixedSizeList as List, areEqual } from "react-window";
import AutoSizer from "react-virtualized-auto-sizer";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { EmployeeType } from "@appserver/common/constants";
import ModalDialogContainer from "../ModalDialogContainer";

View File

@ -9,7 +9,7 @@ import history from "@appserver/common/history";
import { withTranslation, Trans } from "react-i18next";
import api from "@appserver/common/api";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import ModalDialogContainer from "../ModalDialogContainer";

View File

@ -9,7 +9,7 @@ import Text from "@appserver/components/text";
import { withTranslation } from "react-i18next";
import ModalDialogContainer from "../ModalDialogContainer";
import { sendInstructionsToDelete } from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
class DeleteSelfProfileDialogComponent extends React.Component {
constructor(props) {

View File

@ -13,7 +13,7 @@ import { FixedSizeList as List, areEqual } from "react-window";
import AutoSizer from "react-virtualized-auto-sizer";
import { withTranslation } from "react-i18next";
import Filter from "@appserver/common/api/people/filter";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import ModalDialogContainer from "../ModalDialogContainer";
import { inject, observer } from "mobx-react";

View File

@ -13,7 +13,7 @@ import { FixedSizeList as List, areEqual } from "react-window";
import AutoSizer from "react-virtualized-auto-sizer";
import { withTranslation } from "react-i18next";
import { resendUserInvites } from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import ModalDialogContainer from "../ModalDialogContainer";
import { inject, observer } from "mobx-react";

View File

@ -6,7 +6,7 @@ import SelectedItem from "@appserver/components/selected-item";
import TextInput from "@appserver/components/text-input";
import { tablet } from "@appserver/components/utils/device";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import Loaders from "@appserver/common/components/Loaders";
import PeopleSelector from "studio/PeopleSelector";
import { GUID_EMPTY } from "../../../../../helpers/constants";

View File

@ -5,7 +5,7 @@ import UserContent from "./userContent";
import history from "@appserver/common/history";
import { inject, observer } from "mobx-react";
import { Trans, useTranslation } from "react-i18next";
import toastr from "@appserver/common/components/Toast/toastr";
import toastr from "studio/toastr";
import { EmployeeStatus } from "@appserver/common/constants";
import { resendUserInvites } from "@appserver/common/api/people"; //TODO: Move to store action

View File

@ -1,7 +1,7 @@
import React from "react";
import RowContainer from "@appserver/components/row-container";
import { Consumer } from "@appserver/components/utils/context";
import toastr from "@appserver/common/components/Toast/toastr";
import toastr from "studio/toastr";
import Loaders from "@appserver/common/components/Loaders";
import EmptyScreen from "./EmptyScreen";

View File

@ -9,7 +9,7 @@ import { tablet, desktop } from "@appserver/components/utils/device";
import { Consumer } from "@appserver/components/utils/context";
import Headline from "@appserver/common/components/Headline";
import toastr from "@appserver/common/components/Toast/toastr";
import toastr from "studio/toastr";
import Loaders from "@appserver/common/components/Loaders";
import { EmployeeType, EmployeeStatus } from "@appserver/common/constants";
import { withTranslation } from "react-i18next";

View File

@ -7,7 +7,7 @@ import ComboBox from "@appserver/components/combobox";
import HelpButton from "@appserver/components/help-button";
import styled from "styled-components";
import { resendUserInvites } from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import Loaders from "@appserver/common/components/Loaders";
import { inject, observer } from "mobx-react";

View File

@ -3,7 +3,7 @@ import IconButton from "@appserver/components/icon-button";
import ContextMenuButton from "@appserver/components/context-menu-button";
import AvatarEditor from "@appserver/components/avatar-editor";
import Headline from "@appserver/common/components/Headline";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { withRouter } from "react-router";
import { withTranslation, Trans } from "react-i18next";
import styled from "styled-components";

View File

@ -1,7 +1,7 @@
import React from "react";
import PropTypes from "prop-types";
import PageLayout from "@appserver/common/components/PageLayout";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import Loaders from "@appserver/common/components/Loaders";
import {
ArticleHeaderContent,

View File

@ -10,7 +10,7 @@ import {
loadAvatar,
deleteAvatar,
} from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { isMobile } from "react-device-detect";
import { inject, observer } from "mobx-react";
import { toEmployeeWrapper } from "../../../../../helpers/people-helpers";

View File

@ -8,7 +8,7 @@ import { isTablet } from "@appserver/components/utils/device";
import {
/*createThumbnailsAvatar,*/ loadAvatar,
} from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { isMobile } from "react-device-detect";
import { inject, observer } from "mobx-react";
import { toEmployeeWrapper } from "../../../../../helpers/people-helpers";

View File

@ -27,7 +27,7 @@ import {
createThumbnailsAvatar,
loadAvatar,
} from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import { isMobile } from "react-device-detect";
import { inject, observer } from "mobx-react";
import {

View File

@ -30,7 +30,7 @@ import {
loadAvatar,
deleteAvatar,
} from "@appserver/common/api/people";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import {
ChangeEmailDialog,
ChangePasswordDialog,

View File

@ -11,7 +11,7 @@ import ErrorBoundary from "@appserver/common/components/ErrorBoundary";
import Layout from "./components/Layout";
import ScrollToTop from "./components/Layout/ScrollToTop";
import history from "@appserver/common/history";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import RectangleLoader from "@appserver/common/components/Loaders/RectangleLoader";
import { updateTempContent } from "@appserver/common/utils";
import { Provider as MobxProvider } from "mobx-react";

View File

@ -9,7 +9,7 @@ import Box from "@appserver/components/box";
import EmptyScreenContainer from "@appserver/components/empty-screen-container";
import ExternalLinkIcon from "../../../../../../public/images/external.link.react.svg";
import Loaders from "@appserver/common/components/Loaders";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import PageLayout from "@appserver/common/components/PageLayout";
import { useTranslation } from "react-i18next";
import styled from "styled-components";

View File

@ -4,7 +4,7 @@ import { withRouter } from "react-router";
import { useTranslation } from "react-i18next";
import styled from "styled-components";
import Text from "@appserver/components/text";
import toastr from "@appserver/common/components/Toast";
import toastr from "studio/toastr";
import PageLayout from "@appserver/common/components/PageLayout";
import history from "@appserver/common/history";
import ModuleTile from "./ModuleTile";

View File

@ -0,0 +1,39 @@
import i18n from "i18next";
import Backend from "i18next-http-backend";
import { LANGUAGE } from "@appserver/common/constants";
//import LanguageDetector from "i18next-browser-languagedetector";
// not like to use this?
// have a look at the Quick start guide
// for passing in lng and translations on init
const languages = ["en", "ru"];
const newInstance = i18n.createInstance();
newInstance.use(Backend).init({
lng: localStorage.getItem(LANGUAGE) || "en",
supportedLngs: languages,
whitelist: languages,
fallbackLng: "en",
load: "languageOnly",
//debug: true,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
format: function (value, format) {
if (format === "lowercase") return value.toLowerCase();
return value;
},
},
backend: {
loadPath: `/locales/{{lng}}/ToastHeaders.json`,
},
react: {
useSuspense: false,
},
});
export default newInstance;

View File

@ -1,23 +1,12 @@
import Toastr from "@appserver/components/toast/toastr";
import toastr from "@appserver/components/toast/toastr";
import i18n from "./i18n";
import { LANGUAGE } from "../../constants";
import { changeLanguage } from "../../utils";
const toastr = {
clear: clear,
error: error,
info: info,
success: success,
warning: warning,
};
const getTitleTranslation = (title) => {
const currentLng = localStorage.getItem(LANGUAGE);
if (i18n.language !== currentLng) changeLanguage(i18n, currentLng);
return i18n.t(title);
};
function success(data, title, timeout, withCross, centerPosition) {
return Toastr.success(
return toastr.success(
data,
title ? title : getTitleTranslation("Done"),
timeout,
@ -27,7 +16,7 @@ function success(data, title, timeout, withCross, centerPosition) {
}
function error(data, title, timeout, withCross, centerPosition) {
return Toastr.error(
return toastr.error(
data,
title ? title : getTitleTranslation("Warning"),
timeout,
@ -37,7 +26,7 @@ function error(data, title, timeout, withCross, centerPosition) {
}
function warning(data, title, timeout, withCross, centerPosition) {
return Toastr.warning(
return toastr.warning(
data,
title ? title : getTitleTranslation("Alert"),
timeout,
@ -47,7 +36,7 @@ function warning(data, title, timeout, withCross, centerPosition) {
}
function info(data, title, timeout, withCross, centerPosition) {
return Toastr.info(
return toastr.info(
data,
title ? title : getTitleTranslation("Info"),
timeout,
@ -57,7 +46,13 @@ function info(data, title, timeout, withCross, centerPosition) {
}
function clear() {
return Toastr.clear();
return toastr.clear();
}
export default toastr;
export default {
clear: clear,
error: error,
info: info,
success: success,
warning: warning,
};

View File

@ -130,6 +130,7 @@ const config = {
"./PeopleSelector": "./src/components/PeopleSelector",
"./PeopleSelector/UserTooltip":
"./src/components/PeopleSelector/sub-components/UserTooltip.js",
"./toastr": "./src/helpers/toastr",
},
shared: {
...deps,