import { CompositeNavigationProp, useNavigation } from '@react-navigation/native'; import { StackNavigationProp } from '@react-navigation/stack'; import React from 'react'; import { View } from 'react-native'; import { useDispatch } from 'react-redux'; import { setLoading } from '../../../actions/selectedUsers'; import * as List from '../../../containers/List'; import { TSubscriptionModel } from '../../../definitions'; import i18n from '../../../i18n'; import { usePermissions } from '../../../lib/hooks'; import log, { events, logEvent } from '../../../lib/methods/helpers/log'; import { Services } from '../../../lib/services'; import { MasterDetailInsideStackParamList } from '../../../stacks/MasterDetailStack/types'; import { ChatsStackParamList } from '../../../stacks/types'; type TNavigation = CompositeNavigationProp< StackNavigationProp, StackNavigationProp >; interface IActionsSection { rid: TSubscriptionModel['rid']; t: TSubscriptionModel['t']; joined: boolean; } export default function ActionsSection({ rid, t, joined }: IActionsSection): React.ReactElement { const { navigate, pop } = useNavigation(); const dispatch = useDispatch(); const [addUserToJoinedRoomPermission, addUserToAnyCRoomPermission, addUserToAnyPRoomPermission, createInviteLinksPermission] = usePermissions(['add-user-to-joined-room', 'add-user-to-any-c-room', 'add-user-to-any-p-room', 'create-invite-links'], rid); const canAddUser = (joined && addUserToJoinedRoomPermission) || (t === 'c' && addUserToAnyCRoomPermission) || (t === 'p' && addUserToAnyPRoomPermission) || false; const canInviteUser = createInviteLinksPermission; const handleOnPress = ({ route, params }: { route: keyof ChatsStackParamList; params: ChatsStackParamList[keyof ChatsStackParamList]; }) => { navigate(route, params); // @ts-ignore logEvent(events[`RM_GO_${route.replace('View', '').toUpperCase()}`]); }; const addUser = async () => { try { dispatch(setLoading(true)); await Services.addUsersToRoom(rid); pop(); } catch (e) { log(e); } finally { dispatch(setLoading(false)); } }; return ( {['c', 'p'].includes(t) && canAddUser ? ( <> handleOnPress({ route: 'SelectedUsersView', params: { title: i18n.t('Add_users'), nextAction: addUser, showSkipText: false } }) } testID='room-actions-add-user' left={() => } showActionIndicator /> ) : null} {['c', 'p'].includes(t) && canInviteUser ? ( <> handleOnPress({ route: 'InviteUsersView', params: { rid } }) } testID='room-actions-invite-user' left={() => } showActionIndicator /> ) : null} ); }