2022-01-17 21:27:28 +00:00
|
|
|
import { StackNavigationOptions } from '@react-navigation/stack';
|
|
|
|
import moment from 'moment';
|
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 { connect } from 'react-redux';
|
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
import { inviteLinksClear, inviteLinksCreate } from '../../actions/inviteLinks';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2020-01-28 13:22:35 +00:00
|
|
|
import Button from '../../containers/Button';
|
2022-01-17 21:27:28 +00:00
|
|
|
import Markdown from '../../containers/markdown';
|
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2020-01-28 13:22:35 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2022-01-17 21:27:28 +00:00
|
|
|
import RCTextInput from '../../containers/TextInput';
|
|
|
|
import { IApplicationState, IBaseScreen } from '../../definitions';
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { TInvite } from '../../reducers/inviteLinks';
|
|
|
|
import { ChatsStackParamList } from '../../stacks/types';
|
2020-01-28 13:22:35 +00:00
|
|
|
import { withTheme } from '../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { events, logEvent } from '../../utils/log';
|
2022-01-17 21:27:28 +00:00
|
|
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2020-01-28 13:22:35 +00:00
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
interface IInviteUsersViewProps extends IBaseScreen<ChatsStackParamList, 'InviteUsersView'> {
|
2021-10-20 17:49:48 +00:00
|
|
|
timeDateFormat: string;
|
2022-01-17 21:27:28 +00:00
|
|
|
invite: TInvite;
|
2021-10-20 17:49:48 +00:00
|
|
|
}
|
2021-12-03 19:27:57 +00:00
|
|
|
class InviteUsersView extends React.Component<IInviteUsersViewProps, any> {
|
2022-01-17 16:10:39 +00:00
|
|
|
static navigationOptions = (): StackNavigationOptions => ({
|
2020-06-15 14:00:46 +00:00
|
|
|
title: I18n.t('Invite_users')
|
2022-01-17 16:10:39 +00:00
|
|
|
});
|
2020-01-28 13:22:35 +00:00
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
private rid: string;
|
|
|
|
|
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() {
|
2022-01-17 21:27:28 +00:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(inviteLinksCreate(this.rid));
|
2020-01-28 13:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2022-01-17 21:27:28 +00:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(inviteLinksClear());
|
2020-01-28 13:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2022-02-17 15:27:01 +00:00
|
|
|
return <Markdown msg={expirationMessage} 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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2022-01-26 14:00:21 +00:00
|
|
|
timeDateFormat: state.settings.Message_TimeAndDateFormat as string,
|
2020-01-28 13:22:35 +00:00
|
|
|
invite: state.inviteLinks.invite
|
|
|
|
});
|
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(InviteUsersView));
|