Merge pull request #1333 from ONLYOFFICE/feature/profile-menu

Web: Accounts: fixed profile menu styles
This commit is contained in:
Alexey Safronov 2023-04-07 15:46:41 +04:00 committed by GitHub
commit de6927f273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 484 additions and 420 deletions

View File

@ -1,18 +1,22 @@
import SendClockReactSvgUrl from "PUBLIC_DIR/images/send.clock.react.svg?url";
import PencilOutlineReactSvgUrl from "PUBLIC_DIR/images/pencil.outline.react.svg?url";
import DefaultUserAvatarMax from "PUBLIC_DIR/images/default_user_photo_size_200-200.png";
import React from "react";
import React, { useState, useEffect } from "react";
import { ReactSVG } from "react-svg";
import { useTranslation } from "react-i18next";
import { inject, observer } from "mobx-react";
import Avatar from "@docspace/components/avatar";
import Text from "@docspace/components/text";
import Link from "@docspace/components/link";
import ComboBox from "@docspace/components/combobox";
import IconButton from "@docspace/components/icon-button";
import { isMobileOnly } from "react-device-detect";
import toastr from "@docspace/components/toast/toastr";
import { getUserRole } from "@docspace/common/utils";
import { getUserRole, convertLanguage } from "@docspace/common/utils";
import LanguagesCombo from "./languagesCombo";
import { Trans } from "react-i18next";
//import TimezoneCombo from "./timezoneCombo";
import {
@ -22,14 +26,21 @@ import {
ChangeNameDialog,
} from "SRC_DIR/components/dialogs";
import { StyledWrapper, StyledInfo } from "./styled-main-profile";
import { StyledWrapper, StyledInfo, StyledLabel } from "./styled-main-profile";
import { HelpButton, Tooltip } from "@docspace/components";
import withCultureNames from "@docspace/common/hoc/withCultureNames";
import { isSmallTablet } from "@docspace/components/utils/device";
const MainProfile = (props) => {
const { t } = useTranslation(["Profile", "Common"]);
const {
theme,
profile,
culture,
helpLink,
cultureNames,
setIsLoading,
changeEmailVisible,
setChangeEmailVisible,
changePasswordVisible,
@ -41,8 +52,28 @@ const MainProfile = (props) => {
withActivationBar,
sendActivationLink,
currentColorScheme,
updateProfileCulture,
bookTrainingEmail,
} = props;
const [horizontalOrientation, setHorizontalOrientation] = useState(false);
useEffect(() => {
checkWidth();
window.addEventListener("resize", checkWidth);
return () => window.removeEventListener("resize", checkWidth);
}, []);
const checkWidth = () => {
if (!isMobileOnly) return;
if (!isSmallTablet()) {
setHorizontalOrientation(true);
} else {
setHorizontalOrientation(false);
}
};
const role = getUserRole(profile);
const sendActivationLinkAction = () => {
@ -53,6 +84,55 @@ const MainProfile = (props) => {
? profile.avatarMax
: DefaultUserAvatarMax;
const tooltipLanguage = (
<Text fontSize="13px">
<Trans t={t} i18nKey="NotFoundLanguage" ns="Common">
"In case you cannot find your language in the list of the available
ones, feel free to write to us at
<Link
href={`mailto:${bookTrainingEmail}`}
isHovered={true}
color={theme.profileInfo.tooltipLinkColor}
>
{{ supportEmail: bookTrainingEmail }}
</Link>
to take part in the translation and get up to 1 year free of charge."
</Trans>{" "}
<Link
color={theme.profileInfo.tooltipLinkColor}
isHovered={true}
href={`${helpLink}/guides/become-translator.aspx`}
target="_blank"
>
{t("Common:LearnMore")}
</Link>
</Text>
);
const isMobileHorizontalOrientation = isMobileOnly && horizontalOrientation;
const { cultureName, currentCulture } = profile;
const language = convertLanguage(cultureName || currentCulture || culture);
const selectedLanguage = cultureNames.find((item) => item.key === language) ||
cultureNames.find((item) => item.key === culture) || {
key: language,
label: "",
};
const onLanguageSelect = (language) => {
if (profile.cultureName === language.key) return;
setIsLoading(true);
updateProfileCulture(profile.id, language.key)
.then(() => setIsLoading(false))
.then(() => location.reload())
.catch((error) => {
toastr.error(error && error.message ? error.message : error);
setIsLoading(false);
});
};
return (
<StyledWrapper>
<Avatar
@ -69,12 +149,136 @@ const MainProfile = (props) => {
currentColorScheme={currentColorScheme}
>
<div className="rows-container">
<div className="row">
<div className="field">
<Text as="div" className="label">
<div className="profile-block">
<StyledLabel as="div">{t("Common:Name")}</StyledLabel>
<StyledLabel as="div" marginTopProp="16px">
{t("Common:Email")}
</StyledLabel>
<StyledLabel
as="div"
marginTopProp={withActivationBar ? "34px" : "16px"}
>
{t("Common:Password")}
</StyledLabel>
<StyledLabel
as="div"
className="profile-language"
marginTopProp="15px"
>
{t("Common:Language")}
<HelpButton
size={12}
offsetRight={0}
place="right"
tooltipContent={tooltipLanguage}
/>
</StyledLabel>
</div>
<div className="profile-block">
<div className="profile-block-field">
<Text fontWeight={600} truncate>
{profile.displayName}
</Text>
<IconButton
className="edit-button"
iconName={PencilOutlineReactSvgUrl}
size="12"
onClick={() => setChangeNameVisible(true)}
/>
</div>
<div className="email-container">
<div className="email-edit-container">
<Text
data-for="emailTooltip"
data-tip={t("EmailNotVerified")}
as="div"
className="email-text-container"
fontWeight={600}
>
{profile.email}
</Text>
{withActivationBar && (
<Tooltip
id="emailTooltip"
getContent={(dataTip) => (
<Text fontSize="12px">{dataTip}</Text>
)}
effect="float"
place="bottom"
/>
)}
<IconButton
className="edit-button email-edit-button"
iconName={PencilOutlineReactSvgUrl}
size="12"
onClick={() => setChangeEmailVisible(true)}
/>
</div>
{withActivationBar && (
<div
className="send-again-container"
onClick={sendActivationLinkAction}
>
<ReactSVG
className="send-again-icon"
src={SendClockReactSvgUrl}
/>
<Text className="send-again-text" fontWeight={600} noSelect>
{t("SendAgain")}
</Text>
</div>
)}
</div>
<div className="profile-block-field profile-block-password">
<Text fontWeight={600}>********</Text>
<IconButton
className="edit-button"
iconName={PencilOutlineReactSvgUrl}
size="12"
onClick={() => setChangePasswordVisible(true)}
/>
</div>
<div className="language-combo-box-wrapper">
<ComboBox
className="language-combo-box"
directionY={isMobileHorizontalOrientation ? "bottom" : "both"}
options={cultureNames}
selectedOption={selectedLanguage}
onSelect={onLanguageSelect}
isDisabled={false}
scaled={isMobileOnly}
scaledOptions={false}
size="content"
showDisabledItems={true}
dropDownMaxHeight={364}
manualWidth="250px"
isDefaultMode={
isMobileHorizontalOrientation
? isMobileHorizontalOrientation
: !isMobileOnly
}
withBlur={isMobileHorizontalOrientation ? false : isMobileOnly}
fillIcon={false}
modernView={!isMobileOnly}
/>
</div>
</div>
</div>
<div className="mobile-profile-block">
<div className="mobile-profile-row">
<div className="mobile-profile-field">
<Text className="mobile-profile-label" as="div">
{t("Common:Name")}
</Text>
<Text fontWeight={600} truncate>
<Text
className="mobile-profile-label-field"
fontWeight={600}
truncate
>
{profile.displayName}
</Text>
</div>
@ -85,9 +289,9 @@ const MainProfile = (props) => {
onClick={() => setChangeNameVisible(true)}
/>
</div>
<div className="row">
<div className="field">
<Text as="div" className="label">
<div className="mobile-profile-row">
<div className="mobile-profile-field">
<Text className="mobile-profile-label" as="div">
{t("Common:Email")}
</Text>
<div className="email-container">
@ -96,48 +300,26 @@ const MainProfile = (props) => {
data-for="emailTooltip"
data-tip={t("EmailNotVerified")}
as="div"
className={"email-text-container"}
className="email-text-container"
fontWeight={600}
>
{profile.email}
</Text>
{withActivationBar && (
<Tooltip
id="emailTooltip"
getContent={(dataTip) => (
<Text fontSize="12px">{dataTip}</Text>
)}
effect="float"
place="bottom"
/>
)}
<IconButton
className="edit-button email-edit-button"
iconName={PencilOutlineReactSvgUrl}
size="12"
onClick={() => setChangeEmailVisible(true)}
/>
</div>
{withActivationBar && (
<div
className="send-again-container send-again-desktop"
onClick={sendActivationLinkAction}
>
<ReactSVG
className="send-again-icon"
src={SendClockReactSvgUrl}
/>
<Text className="send-again-text" fontWeight={600} noSelect>
{t("SendAgain")}
</Text>
</div>
<Tooltip
id="emailTooltip"
getContent={(dataTip) => (
<Text fontSize="12px">{dataTip}</Text>
)}
effect="float"
place="bottom"
/>
)}
</div>
{withActivationBar && (
<div
className="send-again-container send-again-mobile"
className="send-again-container"
onClick={sendActivationLinkAction}
>
<ReactSVG
@ -151,18 +333,20 @@ const MainProfile = (props) => {
)}
</div>
<IconButton
className="edit-button email-edit-button-mobile"
className="edit-button"
iconName={PencilOutlineReactSvgUrl}
size="12"
onClick={() => setChangeEmailVisible(true)}
/>
</div>
<div className="row">
<div className="field">
<Text as="div" className="label">
<div className="mobile-profile-row">
<div className="mobile-profile-field">
<Text as="div" className="mobile-profile-label">
{t("Common:Password")}
</Text>
<Text fontWeight={600}>********</Text>
<Text className="mobile-profile-password" fontWeight={600}>
********
</Text>
</div>
<IconButton
className="edit-button"
@ -171,8 +355,41 @@ const MainProfile = (props) => {
onClick={() => setChangePasswordVisible(true)}
/>
</div>
<div className="mobile-language">
<Text as="div" fontWeight={600} className="mobile-profile-label">
{t("Common:Language")}
<HelpButton
size={12}
offsetRight={0}
place="right"
tooltipContent={tooltipLanguage}
/>
</Text>
<ComboBox
className="language-combo-box"
directionY={isMobileHorizontalOrientation ? "bottom" : "both"}
options={cultureNames}
selectedOption={selectedLanguage}
onSelect={onLanguageSelect}
isDisabled={false}
scaled={isMobileOnly}
scaledOptions={false}
size="content"
showDisabledItems={true}
dropDownMaxHeight={364}
manualWidth="250px"
isDefaultMode={
isMobileHorizontalOrientation
? isMobileHorizontalOrientation
: !isMobileOnly
}
withBlur={isMobileHorizontalOrientation ? false : isMobileOnly}
fillIcon={false}
modernView={!isMobileOnly}
/>
</div>
</div>
<LanguagesCombo t={t} />
{/* <TimezoneCombo title={t("Common:ComingSoon")} /> */}
</StyledInfo>
@ -212,11 +429,15 @@ const MainProfile = (props) => {
};
export default inject(({ auth, peopleStore }) => {
const { targetUserStore } = peopleStore;
const { withActivationBar, sendActivationLink } = auth.userStore;
const { currentColorScheme } = auth.settingsStore;
const {
theme,
helpLink,
culture,
currentColorScheme,
bookTrainingEmail,
} = auth.settingsStore;
const { setIsLoading } = peopleStore.loadingStore;
const {
targetUser: profile,
@ -228,10 +449,15 @@ export default inject(({ auth, peopleStore }) => {
setChangeNameVisible,
changeAvatarVisible,
setChangeAvatarVisible,
} = targetUserStore;
updateProfileCulture,
} = peopleStore.targetUserStore;
return {
theme,
profile,
culture,
helpLink,
setIsLoading,
changeEmailVisible,
setChangeEmailVisible,
changePasswordVisible,
@ -243,5 +469,7 @@ export default inject(({ auth, peopleStore }) => {
withActivationBar,
sendActivationLink,
currentColorScheme,
updateProfileCulture,
bookTrainingEmail,
};
})(observer(MainProfile));
})(withCultureNames(observer(MainProfile)));

View File

@ -1,156 +0,0 @@
import React, { useEffect, useState } from "react";
import { inject, observer } from "mobx-react";
import { Trans } from "react-i18next";
import ComboBox from "@docspace/components/combobox";
import Text from "@docspace/components/text";
import Link from "@docspace/components/link";
import HelpButton from "@docspace/components/help-button";
import toastr from "@docspace/components/toast/toastr";
import { convertLanguage } from "@docspace/common/utils";
import withCultureNames from "@docspace/common/hoc/withCultureNames";
import { isMobileOnly } from "react-device-detect";
import { StyledRow } from "./styled-main-profile";
import { isSmallTablet } from "@docspace/components/utils/device";
const LanguagesCombo = (props) => {
const {
t,
profile,
updateProfileCulture,
setIsLoading,
culture,
cultureNames,
helpLink,
theme,
} = props;
const { cultureName, currentCulture } = profile;
const [horizontalOrientation, setHorizontalOrientation] = useState(false);
const language = convertLanguage(cultureName || currentCulture || culture);
const selectedLanguage = cultureNames.find((item) => item.key === language) ||
cultureNames.find((item) => item.key === culture) || {
key: language,
label: "",
};
useEffect(() => {
checkWidth();
window.addEventListener("resize", checkWidth);
return () => window.removeEventListener("resize", checkWidth);
}, []);
const onLanguageSelect = (language) => {
console.log("onLanguageSelect", language);
if (profile.cultureName === language.key) return;
setIsLoading(true);
updateProfileCulture(profile.id, language.key)
.then(() => setIsLoading(false))
.then(() => location.reload())
.catch((error) => {
toastr.error(error && error.message ? error.message : error);
setIsLoading(false);
});
};
const supportEmail = "documentation@onlyoffice.com";
const tooltipLanguage = (
<Text fontSize="13px">
<Trans t={t} i18nKey="NotFoundLanguage" ns="Common">
"In case you cannot find your language in the list of the available
ones, feel free to write to us at
<Link
href={`mailto:${supportEmail}`}
isHovered={true}
color={theme.profileInfo.tooltipLinkColor}
>
{{ supportEmail }}
</Link>
to take part in the translation and get up to 1 year free of charge."
</Trans>{" "}
<Link
color={theme.profileInfo.tooltipLinkColor}
isHovered={true}
href={`${helpLink}/guides/become-translator.aspx`}
target="_blank"
>
{t("Common:LearnMore")}
</Link>
</Text>
);
const checkWidth = () => {
if (!isMobileOnly) return;
if (!isSmallTablet()) {
setHorizontalOrientation(true);
} else {
setHorizontalOrientation(false);
}
};
const isMobileHorizontalOrientation = isMobileOnly && horizontalOrientation;
return (
<StyledRow>
<Text as="div" className="label">
{t("Common:Language")}
<HelpButton
size={12}
offsetRight={0}
place="right"
tooltipContent={tooltipLanguage}
/>
</Text>
<ComboBox
className="language-combo-box"
directionY={isMobileHorizontalOrientation ? "bottom" : "both"}
options={cultureNames}
selectedOption={selectedLanguage}
onSelect={onLanguageSelect}
isDisabled={false}
scaled={isMobileOnly}
scaledOptions={false}
size="content"
showDisabledItems={true}
dropDownMaxHeight={364}
manualWidth="250px"
isDefaultMode={
isMobileHorizontalOrientation
? isMobileHorizontalOrientation
: !isMobileOnly
}
withBlur={isMobileHorizontalOrientation ? false : isMobileOnly}
fillIcon={false}
modernView={!isMobileOnly}
/>
</StyledRow>
);
};
export default withCultureNames(
inject(({ auth, peopleStore }) => {
const { loadingStore, targetUserStore } = peopleStore;
const { settingsStore } = auth;
const { setIsLoading } = loadingStore;
const { updateProfileCulture, targetUser: profile } = targetUserStore;
const { culture, helpLink, theme } = settingsStore;
return {
setIsLoading,
updateProfileCulture,
culture,
profile,
helpLink,
theme,
};
})(observer(LanguagesCombo))
);

View File

@ -1,10 +1,11 @@
import styled, { css } from "styled-components";
import {
hugeMobile,
mobile,
smallTablet,
desktop,
tablet,
} from "@docspace/components/utils/device";
import Text from "@docspace/components/text";
export const StyledWrapper = styled.div`
width: 100%;
@ -34,72 +35,85 @@ export const StyledWrapper = styled.div`
export const StyledInfo = styled.div`
width: 100%;
max-width: 100%;
box-sizing: border-box;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: flex;
flex-direction: column;
gap: 11px;
padding-top: 5px;
@media ${tablet} {
gap: 7px;
}
padding-top: 5px;
@media ${smallTablet} {
width: 100%;
gap: 16px;
}
.label {
min-width: 75px;
max-width: 75px;
white-space: nowrap;
color: ${(props) => props.theme.profile.main.descriptionTextColor};
}
.rows-container {
display: flex;
flex-direction: column;
gap: 16px;
display: grid;
grid-template-columns: minmax(75px, auto) 1fr;
gap: 24px;
max-width: 100%;
@media ${hugeMobile} {
gap: 8px;
}
}
.row {
display: flex;
align-items: baseline;
gap: 8px;
line-height: 20px;
max-width: 100%;
@media ${desktop} {
height: auto;
}
@media ${smallTablet} {
align-items: center;
}
.field {
.profile-block {
display: flex;
gap: 16px;
align-items: baseline;
max-width: calc(100% - 28px);
flex-direction: column;
& > p {
padding-left: 8px;
.profile-block-field {
display: flex;
gap: 8px;
height: 20px;
align-items: baseline;
line-height: 20px;
}
.profile-block-password {
margin-top: 16px;
}
.email-container {
margin-top: 16px;
.send-again-desktop {
display: flex;
}
}
.language-combo-box-wrapper {
display: flex;
height: 28px;
align-items: center;
margin-top: 11px;
@media ${tablet} {
height: 36px;
margin-top: 7px;
}
.language-combo-box {
.combo-button {
margin-left: -16px;
}
}
}
}
}
.mobile-profile-block {
display: none;
}
.edit-button {
min-width: 12px;
svg path {
fill: ${(props) => props.theme.isBase && `#657077`};
}
}
.email-edit-container {
display: flex;
align-items: center;
padding-right: 16px;
line-height: 20px;
.email-text-container {
${(props) =>
@ -109,190 +123,167 @@ export const StyledInfo = styled.div`
`}
}
.send-again-container {
flex-grow: 1;
max-width: 50%;
cursor: pointer;
align-items: center;
cursor: pointer;
height: 18px;
.send-again-text {
margin-left: 5px;
line-height: 15px;
color: ${(props) => props.currentColorScheme.main.accent};
border-bottom: 1px solid
${(props) => props.currentColorScheme.main.accent};
margin-top: 2px;
}
.send-again-icon {
display: block;
width: 12px;
height: 12px;
display: flex;
align-items: center;
justify-content: center;
div {
width: 12px;
height: 12px;
}
svg {
width: 12px;
height: 12px;
path {
fill: ${(props) => props.currentColorScheme.main.accent};
}
}
}
}
.send-again-desktop {
display: flex;
}
.send-again-mobile {
display: none;
}
.edit-button {
min-width: 12px;
svg path {
fill: ${(props) => props.theme.isBase && `#657077`};
}
}
.email-edit-button {
display: block;
padding-left: 8px;
}
}
.email-edit-container {
.send-again-container {
display: flex;
flex-grow: 1;
max-width: 50%;
cursor: pointer;
align-items: center;
cursor: pointer;
height: 18px;
.send-again-text {
margin-left: 5px;
line-height: 15px;
color: ${(props) => props.currentColorScheme.main.accent};
border-bottom: 1px solid
${(props) => props.currentColorScheme.main.accent};
margin-top: 2px;
}
.send-again-icon {
display: block;
width: 12px;
height: 12px;
display: flex;
align-items: center;
padding-right: 16px;
}
justify-content: center;
.email-container {
padding-left: 8px;
display: flex;
flex-wrap: wrap;
align-items: baseline;
}
div {
width: 12px;
height: 12px;
}
.email-edit-button-mobile {
display: none;
}
svg {
width: 12px;
height: 12px;
@media ${smallTablet} {
gap: 8px;
background: ${(props) => props.theme.profile.main.background};
padding: 12px 16px;
border-radius: 6px;
.field {
flex-direction: column;
gap: 2px;
.email-container {
padding-left: 0px;
path {
fill: ${(props) => props.currentColorScheme.main.accent};
}
& > p {
padding-left: 0;
font-size: 12px !important;
line-height: 16px !important;
max-width: 100%;
}
}
.label {
min-width: 100%;
max-width: 100%;
font-size: 12px !important;
line-height: 16px !important;
}
.email-edit-button-mobile {
display: block;
}
.email-edit-button {
display: none;
}
.edit-button {
margin-left: auto;
min-width: 12px;
}
.send-again-desktop {
display: none;
margin-left: 8px;
}
.send-again-mobile {
display: flex;
}
}
}
`;
export const StyledRow = styled.div`
display: flex;
gap: 16px;
@media ${desktop} {
height: 28px;
align-items: center;
}
.label {
.profile-language {
display: flex;
align-items: center;
gap: 4px;
min-width: 75px;
max-width: 75px;
white-space: nowrap;
}
.language-combo-box {
margin-left: -8px;
}
@media ${smallTablet} {
width: 100%;
flex-direction: column;
gap: 4px;
.label {
font-weight: 600;
color: ${(props) => props.theme.profile.main.textColor};
.rows-container {
display: none;
}
.combo {
& > div {
padding-left: 8px !important;
.mobile-profile-block {
display: flex;
flex-direction: column;
gap: 16px;
max-width: 100%;
.mobile-profile-row {
gap: 8px;
background: rgb(248, 249, 249);
padding: 12px 16px;
border-radius: 6px;
display: flex;
align-items: center;
line-height: 20px;
max-width: 100%;
.mobile-profile-field {
display: flex;
align-items: baseline;
max-width: calc(100% - 28px);
flex-direction: column;
gap: 2px;
}
.mobile-profile-label {
min-width: 100%;
max-width: 100%;
font-size: 12px !important;
line-height: 16px !important;
white-space: nowrap;
color: rgb(163, 169, 174);
}
.mobile-profile-label-field {
padding-left: 0px;
max-width: 100%;
font-size: 12px !important;
line-height: 16px;
}
.email-container {
padding-left: 0px;
display: flex;
flex-wrap: wrap;
align-items: baseline;
}
.edit-button {
margin-left: auto;
min-width: 12px;
svg path {
fill: ${(props) => props.theme.isBase && `#657077`};
}
}
.mobile-profile-password {
max-width: 100%;
font-size: 12px !important;
line-height: 16px !important;
}
}
}
.language-combo-box {
margin-left: 0;
.mobile-language {
display: flex;
width: 100%;
flex-direction: column;
gap: 4px;
@media ${mobile} {
margin-top: 8px;
}
.mobile-profile-label {
display: flex;
align-items: center;
gap: 4px;
min-width: 75px;
max-width: 75px;
white-space: nowrap;
}
}
@media ${hugeMobile} {
gap: 8px;
}
}
}
`;
export const StyledLabel = styled(Text)`
display: block;
align-items: center;
gap: 4px;
min-width: 100%;
width: 100%;
line-height: 20px;
white-space: nowrap;
color: ${(props) => props.theme.profile.main.descriptionTextColor};
overflow: hidden;
text-overflow: ellipsis;
margin-top: ${({ marginTopProp }) => (marginTopProp ? marginTopProp : 0)};
`;

View File

@ -122,6 +122,7 @@ class SettingsStore {
tenantStatus = null;
helpLink = null;
bookTrainingEmail = null;
hotkeyPanelVisible = false;
frameConfig = null;