From 311b34634728c1a2766d830f31a8db54a0945206 Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Fri, 13 May 2022 09:02:01 -0400 Subject: [PATCH] Chore: evaluate `InviteUsersView` (#4100) --- app/stacks/InsideStack.tsx | 2 +- app/stacks/MasterDetailStack/index.tsx | 2 +- app/views/InviteUsersView/index.tsx | 113 ++++++++++--------------- 3 files changed, 48 insertions(+), 69 deletions(-) diff --git a/app/stacks/InsideStack.tsx b/app/stacks/InsideStack.tsx index f2f8c8d4..6b903e9c 100644 --- a/app/stacks/InsideStack.tsx +++ b/app/stacks/InsideStack.tsx @@ -101,7 +101,7 @@ const ChatsStackNavigator = () => { options={SearchMessagesView.navigationOptions} /> - + { options={SearchMessagesView.navigationOptions} /> - + { - timeDateFormat: string; - invite: TInvite; -} -class InviteUsersView extends React.Component { - static navigationOptions = (): StackNavigationOptions => ({ - title: I18n.t('Invite_users') - }); +type IInviteUsersViewProps = IBaseScreen; - private rid: string; +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(); - constructor(props: IInviteUsersViewProps) { - super(props); - this.rid = props.route.params?.rid; - } + useEffect(() => { + navigation.setOptions({ + title: I18n.t('Invite_users') + }); + }, []); - componentDidMount() { - const { dispatch } = this.props; - dispatch(inviteLinksCreate(this.rid)); - } + useEffect(() => { + dispatch(inviteLinksCreate(rid)); + return () => { + dispatch(inviteLinksClear()); + }; + }, []); - componentWillUnmount() { - const { dispatch } = this.props; - dispatch(inviteLinksClear()); - } - - share = () => { + const share = () => { logEvent(events.IU_SHARE); - const { invite } = this.props; if (!invite || !invite.url) { return; } Share.share({ message: invite.url }); }; - edit = () => { + const edit = () => { logEvent(events.IU_GO_IU_EDIT); - const { navigation } = this.props; - navigation.navigate('InviteUsersEditView', { rid: this.rid }); + navigation.navigate('InviteUsersEditView', { rid }); }; - linkExpirationText = () => { - const { timeDateFormat, invite } = this.props; - + const linkExpirationText = () => { if (!invite || !invite.url) { return null; } @@ -90,38 +79,28 @@ class InviteUsersView extends React.Component { return I18n.t('Your_invite_link_will_never_expire'); }; - renderExpiration = () => { - const { theme } = this.props; - const expirationMessage = this.linkExpirationText(); + const renderExpiration = () => { + const expirationMessage = linkExpirationText(); return ; }; - render() { - const { theme, invite } = this.props; - return ( - - {/* @ts-ignore*/} - - - - - {this.renderExpiration()} - -