2019-12-07 16:58:52 +05:30
|
|
|
import React from 'react';
|
2017-12-31 03:08:54 +05:30
|
|
|
import { connect } from 'react-redux';
|
2019-11-11 14:10:05 +05:30
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
2017-05-26 00:41:57 +05:30
|
|
|
import { Link } from 'react-router-dom';
|
2016-03-17 11:31:11 +05:30
|
|
|
import Helmet from 'react-helmet';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { ChangeLanguageLink } from 'app/components/languageSwitcher';
|
|
|
|
import { RelativeTime } from 'app/components/ui';
|
|
|
|
import { User } from 'app/components/user';
|
|
|
|
import RulesPage from 'app/pages/rules/RulesPage';
|
|
|
|
import { RootState } from 'app/reducers';
|
2019-11-11 14:10:05 +05:30
|
|
|
|
2016-03-17 11:31:11 +05:30
|
|
|
import ProfileField from './ProfileField';
|
|
|
|
import styles from './profile.scss';
|
2016-04-17 15:05:04 +05:30
|
|
|
import profileForm from './profileForm.scss';
|
2016-05-14 14:11:32 +05:30
|
|
|
import messages from './Profile.intl.json';
|
2019-06-30 19:02:50 +05:30
|
|
|
|
|
|
|
type Props = {
|
2019-12-07 16:58:52 +05:30
|
|
|
user: User;
|
|
|
|
interfaceLocale: string;
|
2019-06-30 19:02:50 +05:30
|
|
|
};
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
class Profile extends React.Component<Props> {
|
|
|
|
UUID: HTMLElement | null;
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
render() {
|
|
|
|
const { user, interfaceLocale } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Message {...messages.accountPreferencesTitle}>
|
|
|
|
{(pageTitle: string) => (
|
|
|
|
<h2 className={styles.indexTitle}>
|
|
|
|
<Helmet title={pageTitle} />
|
|
|
|
{pageTitle}
|
|
|
|
</h2>
|
|
|
|
)}
|
|
|
|
</Message>
|
|
|
|
|
|
|
|
<div className={styles.indexContent}>
|
|
|
|
<div className={styles.descriptionColumn}>
|
|
|
|
<div className={styles.indexDescription}>
|
|
|
|
<Message {...messages.accountDescription} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={styles.formColumn}>
|
|
|
|
<div className={profileForm.form}>
|
|
|
|
<div className={styles.item}>
|
|
|
|
<h3 className={profileForm.title}>
|
|
|
|
<Message {...messages.personalData} />
|
|
|
|
</h3>
|
|
|
|
<p className={profileForm.description}>
|
|
|
|
<Message {...messages.preferencesDescription} />
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<ProfileField
|
|
|
|
link="/profile/change-username"
|
|
|
|
label={<Message {...messages.nickname} />}
|
|
|
|
value={user.username}
|
|
|
|
warningMessage={
|
|
|
|
user.hasMojangUsernameCollision ? (
|
|
|
|
<Message
|
|
|
|
{...messages.mojangPriorityWarning}
|
|
|
|
values={{
|
|
|
|
rules: (
|
|
|
|
<Link
|
|
|
|
to={{
|
|
|
|
pathname: '/rules',
|
|
|
|
hash: `#${RulesPage.getRuleHash(1, 4)}`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Message {...messages.projectRules} />
|
|
|
|
</Link>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ProfileField
|
|
|
|
link="/profile/change-email"
|
|
|
|
label={<Message {...messages.email} />}
|
|
|
|
value={user.email}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ProfileField
|
|
|
|
link="/profile/change-password"
|
|
|
|
label={<Message {...messages.password} />}
|
|
|
|
value={
|
|
|
|
<Message
|
|
|
|
{...messages.changedAt}
|
|
|
|
values={{
|
|
|
|
at: (
|
|
|
|
<RelativeTime
|
|
|
|
timestamp={user.passwordChangedAt * 1000}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ProfileField
|
|
|
|
label={<Message {...messages.siteLanguage} />}
|
|
|
|
value={<ChangeLanguageLink />}
|
|
|
|
warningMessage={
|
|
|
|
user.lang === interfaceLocale ? (
|
|
|
|
''
|
|
|
|
) : (
|
|
|
|
<Message
|
|
|
|
{...messages.languageIsUnavailableWarning}
|
|
|
|
values={{
|
|
|
|
locale: user.lang,
|
|
|
|
participateInTheTranslation: (
|
|
|
|
<a href="http://ely.by/translate" target="_blank">
|
|
|
|
<Message
|
|
|
|
{...messages.participateInTheTranslation}
|
2016-04-17 15:05:04 +05:30
|
|
|
/>
|
2019-11-27 14:33:32 +05:30
|
|
|
</a>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ProfileField
|
|
|
|
link="/profile/mfa"
|
|
|
|
label={<Message {...messages.twoFactorAuth} />}
|
|
|
|
value={
|
|
|
|
user.isOtpEnabled ? (
|
|
|
|
<Message {...messages.enabled} />
|
|
|
|
) : (
|
|
|
|
<Message {...messages.disabled} />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ProfileField
|
|
|
|
label={<Message {...messages.uuid} />}
|
|
|
|
value={
|
|
|
|
<span
|
|
|
|
className={styles.uuid}
|
|
|
|
ref={this.setUUID.bind(this)}
|
|
|
|
onMouseOver={this.handleUUIDMouseOver.bind(this)}
|
|
|
|
>
|
|
|
|
{user.uuid}
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
/>
|
2016-03-17 11:31:11 +05:30
|
|
|
</div>
|
2019-11-27 14:33:32 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUUIDMouseOver() {
|
|
|
|
if (!this.UUID) {
|
|
|
|
return;
|
2016-03-17 11:31:11 +05:30
|
|
|
}
|
2016-05-26 20:51:52 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
const el = this.UUID;
|
2016-05-26 20:51:52 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
try {
|
|
|
|
const selection = window.getSelection();
|
2019-12-07 16:58:52 +05:30
|
|
|
|
|
|
|
if (!selection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
const range = document.createRange();
|
|
|
|
range.selectNodeContents(el);
|
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
|
|
|
} catch (err) {
|
|
|
|
// the browser does not support an API
|
2016-05-26 20:51:52 +05:30
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
}
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
setUUID(el: HTMLElement | null) {
|
2019-11-27 14:33:32 +05:30
|
|
|
this.UUID = el;
|
|
|
|
}
|
2016-03-17 11:31:11 +05:30
|
|
|
}
|
2017-05-26 00:41:57 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export default connect(({ user, i18n }: RootState) => ({
|
2019-11-27 14:33:32 +05:30
|
|
|
user,
|
|
|
|
interfaceLocale: i18n.locale,
|
2017-12-31 03:08:54 +05:30
|
|
|
}))(Profile);
|