[FIX] Add users shouldn't have Skip option (#4828)

This commit is contained in:
Reinaldo Neto 2023-01-25 15:28:03 -03:00 committed by Diego Mello
parent 0c24c1ecce
commit 97029e8840
3 changed files with 15 additions and 8 deletions

View File

@ -94,6 +94,7 @@ export type ChatsStackParamList = {
showButton?: boolean;
title?: string;
buttonText?: string;
showSkipText?: boolean;
nextAction?(): void;
};
InviteUsersView: {

View File

@ -75,7 +75,8 @@ export default function ActionsSection({ rid, t, joined }: IActionsSection): Rea
route: 'SelectedUsersView',
params: {
title: i18n.t('Add_users'),
nextAction: addUser
nextAction: addUser,
showSkipText: false
}
})
}

View File

@ -34,7 +34,7 @@ const SelectedUsersView = () => {
const [chats, setChats] = useState<ISelectedUser[]>([]);
const [search, setSearch] = useState<TSearch[]>([]);
const { maxUsers, showButton, title, buttonText, nextAction } = useRoute<TRoute>().params;
const { maxUsers, showButton, title, buttonText, showSkipText = true, nextAction } = useRoute<TRoute>().params;
const navigation = useNavigation<TNavigation>();
const { colors } = useTheme();
@ -58,20 +58,25 @@ const SelectedUsersView = () => {
const isGroupChat = () => maxUsers && maxUsers > 2;
const handleButtonTitle = (buttonTextHeader: string) => {
if (users.length > 0) {
return buttonTextHeader;
}
return showSkipText ? I18n.t('Skip') : '';
};
useLayoutEffect(() => {
const titleHeader = title ?? I18n.t('Select_Members');
const buttonTextHeader = buttonText ?? I18n.t('Next');
const nextActionHeader = nextAction ?? (() => {});
const buttonTitle = handleButtonTitle(buttonTextHeader);
const options = {
title: titleHeader,
headerRight: () =>
(!maxUsers || showButton || (isGroupChat() && users.length > 1)) && (
(!maxUsers || showButton || (isGroupChat() && users.length > 1)) &&
!!buttonTitle && (
<HeaderButton.Container>
<HeaderButton.Item
title={users.length > 0 ? buttonTextHeader : I18n.t('Skip')}
onPress={nextActionHeader}
testID='selected-users-view-submit'
/>
<HeaderButton.Item title={buttonTitle} onPress={nextActionHeader} testID='selected-users-view-submit' />
</HeaderButton.Container>
)
};