* [#MM-12410] Custom Terms of Service Modal. - Create a new screen for terms of service - Register it in app navigation - Open it as a modal when login succeeds or app is opened when already logged in. - Get terms of service and render it as markdown * Refactor service terms to terms of service * Show terms modal when launching channel instead of componentDidMount * Remove footer text * Close modal before logging out * Use dismissAllModals instead od this.close * Update header styles * Update the back icon * Add left icon conditinally based on os * Update en.json * - Integrate Accept/Reject API - Refactor show navigator to util - Remove title - Code refactoring * Handle Accept/Reject API errors * Update package-lock * - Show Alert to handle API error - Handle API error for GetTerms error, Accept/Reject error and Reject success - Changes in en.json - Remove error banner - Open terms modal in sso and experimental certificate * Enable navigator buttons after getting terms * Rename Ok to OK in Alert * Add retry for API error * Fix check-style * Fix FailedNetworkAction Error Message * - Use Close button instead of back button - Update en.json * Remove unused import * Disable hashtags and atmentions in terms modal * Enable close button when terms text fails to load * Minor changes * Fix show terms on sso login * Handle restartApp event * Add test cases * Revert change to app/components/formatted_markdown_text.js * Show the terms modal on the channel page * Remove remaining references to showTermsOfService * Disable Hashtags, AtMentions and ChannelLinks * Update the props to markdown component * Pass the text as literal to renderText * Return the generated renderTexts * Fix lint * Render ~, #, @ with Channel link, Hashtags and At Mentions * Fix failing tests Revert unwanted changes * Hide the channel page content before the terms are accepted * Fix lint and failing tests * Revert changes to hide channel while terms are not accepted * Open modal in componentDidMount instead of constructor Code refactoring Disable back button on android * Remove unused import * No need to await for showModal * No need to await for accept and reject * Update flag for updateTermsOfServiceStatus to updateMyTermsOfServiceStatus - as phase 2 redux PR was mered. * Fix check-style * Change opacity in terms of service text - Fix tests * Revert package-lock.json changes
289 lines
8.9 KiB
JavaScript
289 lines
8.9 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {PureComponent} from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import {
|
|
ScrollView,
|
|
Text,
|
|
View,
|
|
Linking,
|
|
} from 'react-native';
|
|
import {intlShape} from 'react-intl';
|
|
|
|
import {displayUsername} from 'mattermost-redux/utils/user_utils';
|
|
import {getUserCurrentTimezone} from 'mattermost-redux/utils/timezone_utils';
|
|
|
|
import ProfilePicture from 'app/components/profile_picture';
|
|
import FormattedText from 'app/components/formatted_text';
|
|
import FormattedTime from 'app/components/formatted_time';
|
|
import StatusBar from 'app/components/status_bar';
|
|
import {alertErrorWithFallback} from 'app/utils/general';
|
|
import {changeOpacity, makeStyleSheetFromTheme, setNavigatorStyles} from 'app/utils/theme';
|
|
import {t} from 'app/utils/i18n';
|
|
|
|
import UserProfileRow from './user_profile_row';
|
|
import Config from 'assets/config';
|
|
|
|
export default class UserProfile extends PureComponent {
|
|
static propTypes = {
|
|
actions: PropTypes.shape({
|
|
makeDirectChannel: PropTypes.func.isRequired,
|
|
setChannelDisplayName: PropTypes.func.isRequired,
|
|
}).isRequired,
|
|
config: PropTypes.object.isRequired,
|
|
currentDisplayName: PropTypes.string,
|
|
navigator: PropTypes.object,
|
|
teammateNameDisplay: PropTypes.string,
|
|
theme: PropTypes.object.isRequired,
|
|
user: PropTypes.object.isRequired,
|
|
militaryTime: PropTypes.bool.isRequired,
|
|
enableTimezone: PropTypes.bool.isRequired,
|
|
};
|
|
|
|
static contextTypes = {
|
|
intl: intlShape.isRequired,
|
|
};
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
if (this.props.theme !== nextProps.theme) {
|
|
setNavigatorStyles(this.props.navigator, nextProps.theme);
|
|
}
|
|
}
|
|
|
|
close = () => {
|
|
const {navigator, theme} = this.props;
|
|
|
|
navigator.resetTo({
|
|
screen: 'Channel',
|
|
animated: true,
|
|
navigatorStyle: {
|
|
animated: true,
|
|
animationType: 'fade',
|
|
navBarHidden: true,
|
|
statusBarHidden: false,
|
|
statusBarHideWithNavBar: false,
|
|
screenBackgroundColor: theme.centerChannelBg,
|
|
},
|
|
passProps: {
|
|
disableTermsModal: true,
|
|
},
|
|
});
|
|
};
|
|
|
|
getDisplayName = () => {
|
|
const {theme, teammateNameDisplay, user} = this.props;
|
|
const style = createStyleSheet(theme);
|
|
|
|
const displayName = displayUsername(user, teammateNameDisplay);
|
|
|
|
if (displayName) {
|
|
return <Text style={style.displayName}>{displayName}</Text>;
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
buildDisplayBlock = (property) => {
|
|
const {theme, user} = this.props;
|
|
const style = createStyleSheet(theme);
|
|
|
|
if (user.hasOwnProperty(property) && user[property].length > 0) {
|
|
return (
|
|
<View>
|
|
<Text style={style.header}>{property.toUpperCase()}</Text>
|
|
<Text style={style.text}>{user[property]}</Text>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
buildTimezoneBlock = () => {
|
|
const {theme, user, militaryTime} = this.props;
|
|
const style = createStyleSheet(theme);
|
|
|
|
const currentTimezone = getUserCurrentTimezone(user.timezone);
|
|
if (!currentTimezone) {
|
|
return null;
|
|
}
|
|
const nowDate = new Date();
|
|
|
|
return (
|
|
<View>
|
|
<FormattedText
|
|
id='mobile.routes.user_profile.local_time'
|
|
defaultMessage='LOCAL TIME'
|
|
style={style.header}
|
|
/>
|
|
<Text style={style.text}>
|
|
<FormattedTime
|
|
timeZone={currentTimezone}
|
|
hour12={!militaryTime}
|
|
value={nowDate}
|
|
/>
|
|
</Text>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
sendMessage = async () => {
|
|
const {intl} = this.context;
|
|
const {actions, currentDisplayName, teammateNameDisplay, user} = this.props;
|
|
|
|
// save the current channel display name in case it fails
|
|
const currentChannelDisplayName = currentDisplayName;
|
|
|
|
const userDisplayName = displayUsername(user, teammateNameDisplay);
|
|
actions.setChannelDisplayName(userDisplayName);
|
|
|
|
const result = await actions.makeDirectChannel(user.id);
|
|
if (result.error) {
|
|
actions.setChannelDisplayName(currentChannelDisplayName);
|
|
alertErrorWithFallback(
|
|
intl,
|
|
result.error,
|
|
{
|
|
id: t('mobile.open_dm.error'),
|
|
defaultMessage: "We couldn't open a direct message with {displayName}. Please check your connection and try again.",
|
|
},
|
|
{
|
|
displayName: userDisplayName,
|
|
}
|
|
);
|
|
} else {
|
|
this.close();
|
|
}
|
|
};
|
|
|
|
handleLinkPress = (link) => {
|
|
const username = this.props.user.username;
|
|
const email = this.props.user.email;
|
|
|
|
return () => {
|
|
var hydrated = link.replace(/{email}/, email);
|
|
hydrated = hydrated.replace(/{username}/, username);
|
|
Linking.openURL(hydrated);
|
|
};
|
|
};
|
|
|
|
renderAdditionalOptions = () => {
|
|
if (!Config.ExperimentalProfileLinks) {
|
|
return null;
|
|
}
|
|
|
|
const profileLinks = Config.ExperimentalProfileLinks;
|
|
|
|
const additionalOptions = profileLinks.map((l) => {
|
|
var action;
|
|
if (l.type === 'link') {
|
|
action = this.handleLinkPress(l.url);
|
|
}
|
|
|
|
return (
|
|
<UserProfileRow
|
|
key={l.defaultMessage}
|
|
action={action}
|
|
defaultMessage={l.defaultMessage}
|
|
textId={l.textId}
|
|
icon={l.icon}
|
|
iconType={l.iconType}
|
|
theme={this.props.theme}
|
|
iconSize={l.iconSize}
|
|
/>
|
|
);
|
|
});
|
|
|
|
return additionalOptions;
|
|
};
|
|
|
|
render() {
|
|
const {config, theme, user, enableTimezone} = this.props;
|
|
const style = createStyleSheet(theme);
|
|
|
|
if (!user) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<View style={style.container}>
|
|
<StatusBar/>
|
|
<ScrollView
|
|
style={style.scrollView}
|
|
>
|
|
<View style={style.top}>
|
|
<ProfilePicture
|
|
userId={user.id}
|
|
size={150}
|
|
statusBorderWidth={6}
|
|
statusSize={40}
|
|
/>
|
|
{this.getDisplayName()}
|
|
<Text style={style.username}>{`@${user.username}`}</Text>
|
|
</View>
|
|
<View style={style.content}>
|
|
{enableTimezone && this.buildTimezoneBlock()}
|
|
{this.buildDisplayBlock('username')}
|
|
{config.ShowEmailAddress === 'true' && this.buildDisplayBlock('email')}
|
|
{this.buildDisplayBlock('nickname')}
|
|
{this.buildDisplayBlock('position')}
|
|
</View>
|
|
<UserProfileRow
|
|
action={this.sendMessage}
|
|
defaultMessage='Send Message'
|
|
icon='paper-plane-o'
|
|
iconType='fontawesome'
|
|
textId={t('mobile.routes.user_profile.send_message')}
|
|
theme={theme}
|
|
/>
|
|
{this.renderAdditionalOptions()}
|
|
</ScrollView>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
const createStyleSheet = makeStyleSheetFromTheme((theme) => {
|
|
return {
|
|
container: {
|
|
flex: 1,
|
|
},
|
|
content: {
|
|
marginBottom: 25,
|
|
marginHorizontal: 15,
|
|
},
|
|
displayName: {
|
|
marginTop: 15,
|
|
color: theme.centerChannelColor,
|
|
fontSize: 17,
|
|
fontWeight: '600',
|
|
},
|
|
header: {
|
|
fontSize: 13,
|
|
fontWeight: '600',
|
|
color: changeOpacity(theme.centerChannelColor, 0.5),
|
|
marginTop: 25,
|
|
marginBottom: 10,
|
|
},
|
|
scrollView: {
|
|
flex: 1,
|
|
backgroundColor: theme.centerChannelBg,
|
|
},
|
|
text: {
|
|
fontSize: 15,
|
|
color: theme.centerChannelColor,
|
|
},
|
|
top: {
|
|
padding: 25,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
},
|
|
username: {
|
|
marginTop: 15,
|
|
color: theme.centerChannelColor,
|
|
fontSize: 15,
|
|
},
|
|
};
|
|
});
|
|
|