From 68f6eb40de34f1705dfe3503c152128fd06f408e Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:41:32 -0300 Subject: [PATCH] Chore: Hooks app/views/InviteUsersEditView (#4670) * Chore: Hooks app/views/InviteUsersEditView * minor tweak * switch value name --- app/stacks/InsideStack.tsx | 6 +- app/stacks/MasterDetailStack/index.tsx | 6 +- app/views/InviteUsersEditView/Picker.tsx | 92 ++++++++++++ app/views/InviteUsersEditView/index.tsx | 169 +++++------------------ 4 files changed, 131 insertions(+), 142 deletions(-) create mode 100644 app/views/InviteUsersEditView/Picker.tsx diff --git a/app/stacks/InsideStack.tsx b/app/stacks/InsideStack.tsx index 9d9899393..2d8b2c6ae 100644 --- a/app/stacks/InsideStack.tsx +++ b/app/stacks/InsideStack.tsx @@ -105,11 +105,7 @@ const ChatsStackNavigator = () => { /> - + diff --git a/app/stacks/MasterDetailStack/index.tsx b/app/stacks/MasterDetailStack/index.tsx index 0b315a284..dd7cc4d1a 100644 --- a/app/stacks/MasterDetailStack/index.tsx +++ b/app/stacks/MasterDetailStack/index.tsx @@ -142,11 +142,7 @@ const ModalStackNavigator = React.memo(({ navigation }: INavigation) => { component={AddExistingChannelView} options={AddExistingChannelView.navigationOptions} /> - + { + const { colors } = useTheme(); + const inviteLinkParam = useAppSelector(state => state.inviteLinks[param]); + const dispatch = useDispatch(); + + const onValueChangePicker = (value: number) => { + logEvent(events.IU_EDIT_SET_LINK_PARAM); + const params = { + [param]: value + }; + dispatch(inviteLinksSetParams(params)); + }; + + const textInputStyle: TextInputProps = { style: { ...styles.pickerText, color: colors.actionTintColor } }; + const firstEl = [ + { + label: I18n.t(first), + value: 0 + } + ]; + return ( + onValueChangePicker(value)} + items={firstEl.concat(OPTIONS[param])} + /> + ); +}; + +export default Picker; diff --git a/app/views/InviteUsersEditView/index.tsx b/app/views/InviteUsersEditView/index.tsx index 4ee14a9a3..5fc2f3b99 100644 --- a/app/views/InviteUsersEditView/index.tsx +++ b/app/views/InviteUsersEditView/index.tsx @@ -1,149 +1,54 @@ -import { StackNavigationOptions } from '@react-navigation/stack'; -import React from 'react'; -import { TextInputProps, View } from 'react-native'; -import RNPickerSelect from 'react-native-picker-select'; -import { connect } from 'react-redux'; +import { StackNavigationProp } from '@react-navigation/stack'; +import React, { useLayoutEffect } from 'react'; +import { View } from 'react-native'; +import { useDispatch } from 'react-redux'; +import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'; -import { inviteLinksCreate, inviteLinksSetParams } from '../../actions/inviteLinks'; -import { themes } from '../../lib/constants'; +import { inviteLinksCreate } from '../../actions/inviteLinks'; import Button from '../../containers/Button'; import * as List from '../../containers/List'; import SafeAreaView from '../../containers/SafeAreaView'; import StatusBar from '../../containers/StatusBar'; -import { IApplicationState, IBaseScreen } from '../../definitions'; import I18n from '../../i18n'; import { ChatsStackParamList } from '../../stacks/types'; -import { withTheme } from '../../theme'; import { events, logEvent } from '../../lib/methods/helpers/log'; import styles from './styles'; +import Picker from './Picker'; -const OPTIONS = { - days: [ - { - label: '1', - value: 1 - }, - { - label: '7', - value: 7 - }, - { - label: '15', - value: 15 - }, - { - label: '30', - value: 30 - } - ], - maxUses: [ - { - label: '1', - value: 1 - }, - { - label: '5', - value: 5 - }, - { - label: '10', - value: 10 - }, - { - label: '25', - value: 25 - }, - { - label: '50', - value: 50 - }, - { - label: '100', - value: 100 - } - ] -}; +const InviteUsersEditView = () => { + const navigation = useNavigation>(); + const { rid } = useRoute>().params; + const dispatch = useDispatch(); -interface IInviteUsersEditViewProps extends IBaseScreen { - days: number; - maxUses: number; -} + useLayoutEffect(() => { + navigation.setOptions({ + title: I18n.t('Invite_users') + }); + }, [navigation]); -class InviteUsersEditView extends React.Component { - static navigationOptions = (): StackNavigationOptions => ({ - title: I18n.t('Invite_users') - }); - - private rid: string; - - constructor(props: IInviteUsersEditViewProps) { - super(props); - this.rid = props.route.params?.rid; - } - - onValueChangePicker = (key: string, value: number) => { - const { dispatch } = this.props; - logEvent(events.IU_EDIT_SET_LINK_PARAM); - const params = { - [key]: value - }; - dispatch(inviteLinksSetParams(params)); - }; - - createInviteLink = () => { - const { dispatch, navigation } = this.props; + const createInviteLink = () => { logEvent(events.IU_EDIT_CREATE_LINK); - dispatch(inviteLinksCreate(this.rid)); + dispatch(inviteLinksCreate(rid)); navigation.pop(); }; - renderPicker = (key: 'days' | 'maxUses', first: string) => { - const { props } = this; - const { theme } = props; - const textInputStyle: TextInputProps = { style: { ...styles.pickerText, color: themes[theme].actionTintColor } }; - const firstEl = [ - { - label: I18n.t(first), - value: 0 - } - ]; - return ( - this.onValueChangePicker(key, value)} - items={firstEl.concat(OPTIONS[key])} - /> - ); - }; + return ( + + + + + + } /> + + } /> + + + +