2020-01-28 13:22:35 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-10-01 18:12:19 +00:00
|
|
|
import { ScrollView, Share, View } from 'react-native';
|
2020-01-28 13:22:35 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import {
|
2021-10-01 18:12:19 +00:00
|
|
|
inviteLinksClear as inviteLinksClearAction,
|
|
|
|
inviteLinksCreate as inviteLinksCreateAction
|
2020-01-28 13:22:35 +00:00
|
|
|
} from '../../actions/inviteLinks';
|
|
|
|
import RCTextInput from '../../containers/TextInput';
|
|
|
|
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';
|
2021-10-01 18:12:19 +00:00
|
|
|
import { events, logEvent } from '../../utils/log';
|
|
|
|
import styles from './styles';
|
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')
|
2021-10-01 18:12:19 +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
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2020-01-28 13:22:35 +00:00
|
|
|
|
|
|
|
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 });
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2020-01-28 13:22:35 +00:00
|
|
|
|
|
|
|
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 });
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2020-01-28 13:22:35 +00:00
|
|
|
|
|
|
|
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;
|
2021-10-01 18:12:19 +00:00
|
|
|
return I18n.t('Your_invite_link_will_expire_on__date__or_after__usesLeft__uses', {
|
|
|
|
date: moment(expiration).format(timeDateFormat),
|
|
|
|
usesLeft
|
|
|
|
});
|
2020-01-28 13:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2020-01-28 13:22:35 +00:00
|
|
|
|
|
|
|
renderExpiration = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
const expirationMessage = this.linkExpirationText();
|
|
|
|
return <Markdown msg={expirationMessage} username='' baseUrl='' theme={theme} />;
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2020-01-28 13:22:35 +00:00
|
|
|
|
|
|
|
render() {
|
2021-10-01 18:12:19 +00:00
|
|
|
const { theme, invite } = this.props;
|
2020-01-28 13:22:35 +00:00
|
|
|
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}
|
2021-10-01 18:12:19 +00:00
|
|
|
showsVerticalScrollIndicator={false}>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
2020-01-28 13:22:35 +00:00
|
|
|
<View style={styles.innerContainer}>
|
2021-10-01 18:12:19 +00:00
|
|
|
<RCTextInput label={I18n.t('Invite_Link')} theme={theme} value={invite && invite.url} editable={false} />
|
2020-01-28 13:22:35 +00:00
|
|
|
{this.renderExpiration()}
|
|
|
|
<View style={[styles.divider, { backgroundColor: themes[theme].separatorColor }]} />
|
2021-10-01 18:12:19 +00:00
|
|
|
<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} />
|
2020-01-28 13:22:35 +00:00
|
|
|
</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));
|