2020-01-28 13:22:35 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { View, Share, ScrollView } from 'react-native';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import {
|
|
|
|
inviteLinksCreate as inviteLinksCreateAction,
|
|
|
|
inviteLinksClear as inviteLinksClearAction
|
|
|
|
} from '../../actions/inviteLinks';
|
|
|
|
import RCTextInput from '../../containers/TextInput';
|
|
|
|
import styles from './styles';
|
|
|
|
import Markdown from '../../containers/markdown';
|
|
|
|
import Button from '../../containers/Button';
|
|
|
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import StatusBar from '../../containers/StatusBar';
|
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { withTheme } from '../../theme';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2020-08-05 13:15:56 +00:00
|
|
|
import { logEvent, events } from '../../utils/log';
|
2020-01-28 13:22:35 +00:00
|
|
|
|
|
|
|
class InviteUsersView extends React.Component {
|
2020-07-31 18:30:36 +00:00
|
|
|
static navigationOptions = () => ({
|
2020-06-15 14:00:46 +00:00
|
|
|
title: I18n.t('Invite_users')
|
2020-07-31 18:30:36 +00:00
|
|
|
})
|
2020-01-28 13:22:35 +00:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object,
|
2020-06-15 14:00:46 +00:00
|
|
|
route: PropTypes.object,
|
2020-01-28 13:22:35 +00:00
|
|
|
theme: PropTypes.string,
|
|
|
|
timeDateFormat: PropTypes.string,
|
|
|
|
invite: PropTypes.object,
|
|
|
|
createInviteLink: PropTypes.func,
|
|
|
|
clearInviteLink: PropTypes.func
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-06-15 14:00:46 +00:00
|
|
|
this.rid = props.route.params?.rid;
|
2020-01-28 13:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const { createInviteLink } = this.props;
|
|
|
|
createInviteLink(this.rid);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
const { clearInviteLink } = this.props;
|
|
|
|
clearInviteLink();
|
|
|
|
}
|
|
|
|
|
|
|
|
share = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.IU_SHARE);
|
2020-01-28 13:22:35 +00:00
|
|
|
const { invite } = this.props;
|
2020-02-05 16:40:44 +00:00
|
|
|
if (!invite || !invite.url) {
|
2020-01-28 13:22:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Share.share({ message: invite.url });
|
|
|
|
}
|
|
|
|
|
|
|
|
edit = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.IU_GO_IU_EDIT);
|
2020-01-28 13:22:35 +00:00
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('InviteUsersEditView', { rid: this.rid });
|
|
|
|
}
|
|
|
|
|
|
|
|
linkExpirationText = () => {
|
|
|
|
const { timeDateFormat, invite } = this.props;
|
|
|
|
|
|
|
|
if (!invite || !invite.url) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invite.expires) {
|
|
|
|
const expiration = new Date(invite.expires);
|
|
|
|
|
|
|
|
if (invite.maxUses) {
|
|
|
|
const usesLeft = invite.maxUses - invite.uses;
|
|
|
|
return I18n.t('Your_invite_link_will_expire_on__date__or_after__usesLeft__uses', { date: moment(expiration).format(timeDateFormat), usesLeft });
|
|
|
|
}
|
|
|
|
|
|
|
|
return I18n.t('Your_invite_link_will_expire_on__date__', { date: moment(expiration).format(timeDateFormat) });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invite.maxUses) {
|
|
|
|
const usesLeft = invite.maxUses - invite.uses;
|
|
|
|
return I18n.t('Your_invite_link_will_expire_after__usesLeft__uses', { usesLeft });
|
|
|
|
}
|
|
|
|
|
|
|
|
return I18n.t('Your_invite_link_will_never_expire');
|
|
|
|
}
|
|
|
|
|
|
|
|
renderExpiration = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
const expirationMessage = this.linkExpirationText();
|
|
|
|
return <Markdown msg={expirationMessage} username='' baseUrl='' theme={theme} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
theme, invite
|
|
|
|
} = this.props;
|
|
|
|
return (
|
2020-10-30 13:59:44 +00:00
|
|
|
<SafeAreaView style={{ backgroundColor: themes[theme].backgroundColor }}>
|
2020-01-28 13:22:35 +00:00
|
|
|
<ScrollView
|
|
|
|
{...scrollPersistTaps}
|
|
|
|
style={{ backgroundColor: themes[theme].auxiliaryBackground }}
|
|
|
|
contentContainerStyle={styles.contentContainer}
|
|
|
|
showsVerticalScrollIndicator={false}
|
|
|
|
>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
2020-01-28 13:22:35 +00:00
|
|
|
<View style={styles.innerContainer}>
|
|
|
|
<RCTextInput
|
|
|
|
label={I18n.t('Invite_Link')}
|
|
|
|
theme={theme}
|
|
|
|
value={invite && invite.url}
|
|
|
|
editable={false}
|
|
|
|
/>
|
|
|
|
{this.renderExpiration()}
|
|
|
|
<View style={[styles.divider, { backgroundColor: themes[theme].separatorColor }]} />
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Share_Link')}
|
|
|
|
type='primary'
|
|
|
|
onPress={this.share}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Edit_Invite')}
|
|
|
|
type='secondary'
|
|
|
|
onPress={this.edit}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</ScrollView>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
timeDateFormat: state.settings.Message_TimeAndDateFormat,
|
|
|
|
days: state.inviteLinks.days,
|
|
|
|
maxUses: state.inviteLinks.maxUses,
|
|
|
|
invite: state.inviteLinks.invite
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
createInviteLink: rid => dispatch(inviteLinksCreateAction(rid)),
|
|
|
|
clearInviteLink: () => dispatch(inviteLinksClearAction())
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(InviteUsersView));
|