2022-05-13 13:02:01 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2022-01-17 21:27:28 +00:00
|
|
|
import moment from 'moment';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { ScrollView, Share, View } from 'react-native';
|
2022-05-13 13:02:01 +00:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2020-01-28 13:22:35 +00:00
|
|
|
|
2022-01-17 21:27:28 +00:00
|
|
|
import { inviteLinksClear, inviteLinksCreate } from '../../actions/inviteLinks';
|
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-06-27 18:46:59 +00:00
|
|
|
import { FormTextInput } from '../../containers/TextInput';
|
2022-01-17 21:27:28 +00:00
|
|
|
import { IApplicationState, IBaseScreen } from '../../definitions';
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { ChatsStackParamList } from '../../stacks/types';
|
2022-05-13 13:02:01 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { events, logEvent } from '../../lib/methods/helpers/log';
|
|
|
|
import scrollPersistTaps from '../../lib/methods/helpers/scrollPersistTaps';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2020-01-28 13:22:35 +00:00
|
|
|
|
2022-05-13 13:02:01 +00:00
|
|
|
type IInviteUsersViewProps = IBaseScreen<ChatsStackParamList, 'InviteUsersView'>;
|
|
|
|
|
|
|
|
const InviteUsersView = ({ route, navigation }: IInviteUsersViewProps): React.ReactElement => {
|
|
|
|
const rid = route.params?.rid;
|
|
|
|
const timeDateFormat = useSelector((state: IApplicationState) => state.settings.Message_TimeAndDateFormat as string);
|
|
|
|
const invite = useSelector((state: IApplicationState) => state.inviteLinks.invite);
|
|
|
|
const { colors, theme } = useTheme();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
navigation.setOptions({
|
|
|
|
title: I18n.t('Invite_users')
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
dispatch(inviteLinksCreate(rid));
|
|
|
|
return () => {
|
|
|
|
dispatch(inviteLinksClear());
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const share = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.IU_SHARE);
|
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
|
|
|
|
2022-05-13 13:02:01 +00:00
|
|
|
const edit = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.IU_GO_IU_EDIT);
|
2022-05-13 13:02:01 +00:00
|
|
|
navigation.navigate('InviteUsersEditView', { rid });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-01-28 13:22:35 +00:00
|
|
|
|
2022-05-13 13:02:01 +00:00
|
|
|
const linkExpirationText = () => {
|
2020-01-28 13:22:35 +00:00
|
|
|
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
|
|
|
|
2022-05-13 13:02:01 +00:00
|
|
|
const renderExpiration = () => {
|
|
|
|
const expirationMessage = 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
|
|
|
|
2022-05-13 13:02:01 +00:00
|
|
|
return (
|
|
|
|
<SafeAreaView style={{ backgroundColor: colors.backgroundColor }}>
|
|
|
|
<ScrollView
|
|
|
|
{...scrollPersistTaps}
|
|
|
|
style={{ backgroundColor: colors.auxiliaryBackground }}
|
|
|
|
showsVerticalScrollIndicator={false}>
|
|
|
|
<StatusBar />
|
|
|
|
<View style={styles.innerContainer}>
|
2022-06-27 18:46:59 +00:00
|
|
|
<FormTextInput label={I18n.t('Invite_Link')} value={invite && invite.url} editable={false} />
|
2022-05-13 13:02:01 +00:00
|
|
|
{renderExpiration()}
|
|
|
|
<View style={[styles.divider, { backgroundColor: colors.separatorColor }]} />
|
2022-05-20 16:37:57 +00:00
|
|
|
<Button title={I18n.t('Share_Link')} type='primary' onPress={share} />
|
|
|
|
<Button title={I18n.t('Edit_Invite')} type='secondary' onPress={edit} />
|
2022-05-13 13:02:01 +00:00
|
|
|
</View>
|
|
|
|
</ScrollView>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default InviteUsersView;
|