2020-01-28 13:22:35 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +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';
|
2021-10-20 17:49:48 +00:00
|
|
|
import { StackNavigationProp, StackNavigationOptions } from '@react-navigation/stack';
|
|
|
|
import { RouteProp } from '@react-navigation/core';
|
|
|
|
import { Dispatch } from 'redux';
|
2020-01-28 13:22:35 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
import { ChatsStackParamList } from '../../stacks/types';
|
2020-01-28 13:22:35 +00:00
|
|
|
import {
|
2021-09-13 20:41:05 +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-09-13 20:41:05 +00:00
|
|
|
import { events, logEvent } from '../../utils/log';
|
|
|
|
import styles from './styles';
|
2020-01-28 13:22:35 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
interface IInviteUsersViewProps {
|
|
|
|
navigation: StackNavigationProp<ChatsStackParamList, 'InviteUsersView'>;
|
|
|
|
route: RouteProp<ChatsStackParamList, 'InviteUsersView'>;
|
2021-10-20 17:49:48 +00:00
|
|
|
theme: string;
|
|
|
|
timeDateFormat: string;
|
|
|
|
invite: {
|
|
|
|
url: string;
|
|
|
|
expires: number;
|
|
|
|
maxUses: number;
|
|
|
|
uses: number;
|
|
|
|
};
|
|
|
|
createInviteLink(rid: string): void;
|
|
|
|
clearInviteLink(): void;
|
|
|
|
}
|
2021-12-03 19:27:57 +00:00
|
|
|
class InviteUsersView extends React.Component<IInviteUsersViewProps, any> {
|
2021-10-20 17:49:48 +00:00
|
|
|
private rid: string;
|
|
|
|
|
|
|
|
static navigationOptions: StackNavigationOptions = {
|
2020-06-15 14:00:46 +00:00
|
|
|
title: I18n.t('Invite_users')
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-01-28 13:22:35 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
constructor(props: IInviteUsersViewProps) {
|
2020-01-28 13:22:35 +00:00
|
|
|
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-09-13 20:41:05 +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-09-13 20:41:05 +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-09-13 20:41:05 +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-09-13 20:41:05 +00:00
|
|
|
};
|
2020-01-28 13:22:35 +00:00
|
|
|
|
|
|
|
renderExpiration = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
const expirationMessage = this.linkExpirationText();
|
2021-10-20 17:49:48 +00:00
|
|
|
// @ts-ignore
|
2020-01-28 13:22:35 +00:00
|
|
|
return <Markdown msg={expirationMessage} username='' baseUrl='' theme={theme} />;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-01-28 13:22:35 +00:00
|
|
|
|
|
|
|
render() {
|
2021-09-13 20:41:05 +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 }}>
|
2021-10-20 17:49:48 +00:00
|
|
|
{/* @ts-ignore*/}
|
2020-01-28 13:22:35 +00:00
|
|
|
<ScrollView
|
|
|
|
{...scrollPersistTaps}
|
|
|
|
style={{ backgroundColor: themes[theme].auxiliaryBackground }}
|
2021-09-13 20:41:05 +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-09-13 20:41:05 +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-09-13 20:41:05 +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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 17:49:48 +00:00
|
|
|
const mapStateToProps = (state: any) => ({
|
2020-01-28 13:22:35 +00:00
|
|
|
timeDateFormat: state.settings.Message_TimeAndDateFormat,
|
|
|
|
days: state.inviteLinks.days,
|
|
|
|
maxUses: state.inviteLinks.maxUses,
|
|
|
|
invite: state.inviteLinks.invite
|
|
|
|
});
|
|
|
|
|
2021-10-20 17:49:48 +00:00
|
|
|
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
|
|
|
createInviteLink: (rid: string) => dispatch(inviteLinksCreateAction(rid)),
|
2020-01-28 13:22:35 +00:00
|
|
|
clearInviteLink: () => dispatch(inviteLinksClearAction())
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(InviteUsersView));
|