Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3918,6 +3918,11 @@ const ROUTES = {
MULTIFACTOR_AUTHENTICATION_NOT_FOUND: 'multifactor-authentication/not-found',

MULTIFACTOR_AUTHENTICATION_REVOKE: 'multifactor-authentication/revoke',

DOMAIN_GROUPS: {
route: 'domain/:domainAccountID/groups',
getRoute: (domainAccountID: number) => `domain/${domainAccountID}/groups` as const,
},
} as const;

/**
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ const SCREENS = {
ADD_MEMBER: 'Domain_Add_Member',
MEMBERS_SETTINGS: 'Members_Settings',
MEMBERS_SETTINGS_TWO_FACTOR_AUTH: 'Members_Settings_Two_Factor_Auth',
GROUPS: 'Domain_Groups',
},
MULTIFACTOR_AUTHENTICATION: {
MAGIC_CODE: 'Multifactor_Authentication_Magic_Code',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function CustomListHeader({
if (canSelectMultiple) {
return header;
}
return <View style={[styles.flexRow, styles.ph9, styles.pv3, styles.pb5]}>{header}</View>;
return <View style={[styles.flexRow, styles.baseListHeaderWrapperStyle]}>{header}</View>;
}

export default CustomListHeader;
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8495,6 +8495,7 @@ Hier ist ein *Testbeleg*, um dir zu zeigen, wie es funktioniert:`,
forceTwoFactorAuthError: 'Die Erzwingung der Zwei-Faktor-Authentifizierung konnte nicht geändert werden. Bitte versuche es später erneut.',
},
common: {settings: 'Einstellungen'},
groups: {title: 'Gruppen', memberCount: () => ({one: '1 Mitglied', other: (count: number) => `${count} Mitglieder`})},
},
};
export default translations;
9 changes: 9 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8436,6 +8436,15 @@ const translations = {
common: {
settings: 'Settings',
},
groups: {
title: 'Groups',
memberCount: () => {
return {
one: '1 member',
other: (count: number) => `${count} members`,
};
},
},
},
};

Expand Down
9 changes: 9 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8619,6 +8619,15 @@ ${amount} para ${merchant} - ${date}`,
common: {
settings: 'Configuración',
},
groups: {
title: 'Grupos',
memberCount: () => {
return {
one: '1 miembro',
other: (count: number) => `${count} miembros`,
};
},
},
},
gps: {
disclaimer: 'Utiliza el GPS para crear un gasto a partir de tu trayecto. Toca Iniciar a continuación para comenzar el seguimiento.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8515,6 +8515,7 @@ Voici un *reçu test* pour vous montrer comment ça fonctionne :`,
forceTwoFactorAuthError: 'L’activation forcée de l’authentification à deux facteurs n’a pas pu être modifiée. Veuillez réessayer plus tard.',
},
common: {settings: 'Paramètres'},
groups: {title: 'Groupes', memberCount: () => ({one: '1 membre', other: (count: number) => `${count} membres`})},
},
};
export default translations;
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8479,6 +8479,7 @@ Ecco una *ricevuta di prova* per mostrarti come funziona:`,
forceTwoFactorAuthError: 'Impossibile modificare l’impostazione “Forza l’autenticazione a due fattori”. Riprova più tardi.',
},
common: {settings: 'Impostazioni'},
groups: {title: 'Gruppi', memberCount: () => ({one: '1 membro', other: (count: number) => `${count} membri`})},
},
};
export default translations;
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8401,6 +8401,7 @@ ${reportName}
forceTwoFactorAuthError: '2要素認証の強制設定を変更できませんでした。後でもう一度お試しください。',
},
common: {settings: '設定'},
groups: {title: 'グループ', memberCount: () => ({one: 'メンバー 1 人', other: (count: number) => `${count}名のメンバー`})},
},
};
export default translations;
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8464,6 +8464,7 @@ Hier is een *proefbon* om je te laten zien hoe het werkt:`,
forceTwoFactorAuthError: 'Verplichte twee-factor-authenticatie kon niet worden gewijzigd. Probeer het later opnieuw.',
},
common: {settings: 'Instellingen'},
groups: {title: 'Groepen', memberCount: () => ({one: '1 lid', other: (count: number) => `${count} leden`})},
},
};
export default translations;
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8444,6 +8444,7 @@ Oto *paragon testowy*, żeby pokazać Ci, jak to działa:`,
forceTwoFactorAuthError: 'Nie udało się zmienić wymuszania uwierzytelniania dwuskładnikowego. Spróbuj ponownie później.',
},
common: {settings: 'Ustawienia'},
groups: {title: 'Grupy', memberCount: () => ({one: '1 członek', other: (count: number) => `${count} członków`})},
},
};
export default translations;
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8448,6 +8448,7 @@ Aqui está um *comprovante de teste* para mostrar como funciona:`,
forceTwoFactorAuthError: 'Não foi possível alterar a exigência de autenticação em duas etapas. Tente novamente mais tarde.',
},
common: {settings: 'Configurações'},
groups: {title: 'Grupos', memberCount: () => ({one: '1 membro', other: (count: number) => `${count} membros`})},
},
};
export default translations;
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8274,6 +8274,7 @@ ${reportName}
forceTwoFactorAuthError: '无法更改强制启用双重身份验证设置。请稍后再试。',
},
common: {settings: '设置'},
groups: {title: '群组', memberCount: () => ({one: '1 名成员', other: (count: number) => `${count} 名成员`})},
},
};
export default translations;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const loadDomainInitialPage = () => require<ReactComponentModule>('../../../../p
const loadDomainSamlPage = () => require<ReactComponentModule>('../../../../pages/domain/DomainSamlPage').default;
const loadDomainAdminsPage = () => require<ReactComponentModule>('../../../../pages/domain/Admins/DomainAdminsPage').default;
const loadDomainMembersPage = () => require<ReactComponentModule>('../../../../pages/domain/Members/DomainMembersPage').default;
const loadDomainGroupsPage = () => require<ReactComponentModule>('../../../../pages/domain/Groups/DomainGroupsPage').default;

const Split = createSplitNavigator<DomainSplitNavigatorParamList>();

Expand Down Expand Up @@ -57,6 +58,12 @@ function DomainSplitNavigator({route, navigation}: PlatformStackScreenProps<Auth
name={SCREENS.DOMAIN.MEMBERS}
getComponent={loadDomainMembersPage}
/>

<Split.Screen
key={SCREENS.DOMAIN.GROUPS}
name={SCREENS.DOMAIN.GROUPS}
getComponent={loadDomainGroupsPage}
/>
</Split.Navigator>
</View>
</FocusTrapForScreens>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const DOMAIN_TO_RHP: Partial<Record<keyof DomainSplitNavigatorParamList, string[
[SCREENS.DOMAIN.SAML]: [SCREENS.DOMAIN.VERIFY, SCREENS.DOMAIN.VERIFIED],
[SCREENS.DOMAIN.ADMINS]: [SCREENS.DOMAIN.ADMIN_DETAILS, SCREENS.DOMAIN.ADMINS_SETTINGS, SCREENS.DOMAIN.ADD_PRIMARY_CONTACT, SCREENS.DOMAIN.ADD_ADMIN, SCREENS.DOMAIN.RESET_DOMAIN],
[SCREENS.DOMAIN.MEMBERS]: [SCREENS.DOMAIN.MEMBER_DETAILS, SCREENS.DOMAIN.ADD_MEMBER, SCREENS.DOMAIN.MEMBERS_SETTINGS, SCREENS.DOMAIN.MEMBERS_SETTINGS_TWO_FACTOR_AUTH],
[SCREENS.DOMAIN.GROUPS]: [],
};

export default DOMAIN_TO_RHP;
3 changes: 3 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,9 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
[SCREENS.DOMAIN.MEMBERS]: {
path: ROUTES.DOMAIN_MEMBERS.route,
},
[SCREENS.DOMAIN.GROUPS]: {
path: ROUTES.DOMAIN_GROUPS.route,
},
},
},

Expand Down
3 changes: 3 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,9 @@ type DomainSplitNavigatorParamList = {
domainAccountID: number;
accountID: number;
};
[SCREENS.DOMAIN.GROUPS]: {
domainAccountID: number;
};
};

type OnboardingModalNavigatorParamList = {
Expand Down
94 changes: 94 additions & 0 deletions src/pages/domain/Groups/DomainGroupsPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type {DomainSecurityGroupWithID} from '@selectors/Domain';
import {groupsSelector} from '@selectors/Domain';
import React from 'react';
import {View} from 'react-native';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import TableListItem from '@components/SelectionList/ListItem/TableListItem';
import CustomListHeader from '@components/SelectionListWithModal/CustomListHeader';
import Text from '@components/Text';
import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@navigation/Navigation';
import type {PlatformStackScreenProps} from '@navigation/PlatformStackNavigation/types';
import type {DomainSplitNavigatorParamList} from '@navigation/types';
import DomainNotFoundPageWrapper from '@pages/domain/DomainNotFoundPageWrapper';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import getEmptyArray from '@src/types/utils/getEmptyArray';

type DomainGroupsPageProps = PlatformStackScreenProps<DomainSplitNavigatorParamList, typeof SCREENS.DOMAIN.GROUPS>;

function DomainGroupsPage({route}: DomainGroupsPageProps) {
const {domainAccountID} = route.params;

const styles = useThemeStyles();
const {translate} = useLocalize();
const illustrations = useMemoizedLazyIllustrations(['Members']);
const {shouldUseNarrowLayout} = useResponsiveLayout();

const [groups = getEmptyArray<DomainSecurityGroupWithID>()] = useOnyx(`${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`, {canBeMissing: false, selector: groupsSelector});

const data = groups.map((group) => {
return {
keyForList: group.id,
text: group.details.name ?? '',
rightElement: (
<View style={styles.flex1}>
<Text
numberOfLines={1}
style={styles.alignSelfStart}
>
{translate('domain.groups.memberCount', {count: Object.keys(group.details.shared).length})}
Comment thread
mountiny marked this conversation as resolved.
Resolved
Comment thread
mountiny marked this conversation as resolved.
Resolved
Comment thread
mountiny marked this conversation as resolved.
Resolved
</Text>
</View>
),
};
});

const getCustomListHeader = () => {
if (!data || data?.length === 0) {
return null;
}

return (
<CustomListHeader
canSelectMultiple={false}
leftHeaderText={translate('common.name')}
rightHeaderText={translate('common.members')}
shouldDivideEqualWidth
/>
);
};

return (
<DomainNotFoundPageWrapper domainAccountID={domainAccountID}>
<ScreenWrapper
enableEdgeToEdgeBottomSafeAreaPadding
shouldEnableMaxHeight
shouldShowOfflineIndicatorInWideScreen
testID="DomainGroupsPage"
>
<HeaderWithBackButton
title={translate('domain.groups.title')}
onBackButtonPress={Navigation.popToSidebar}
icon={illustrations.Members}
shouldShowBackButton={shouldUseNarrowLayout}
shouldUseHeadlineHeader
/>
<SelectionList
data={data}
ListItem={TableListItem}
onSelectRow={() => null}
customListHeader={getCustomListHeader()}
/>
</ScreenWrapper>
</DomainNotFoundPageWrapper>
);
}

export default DomainGroupsPage;
21 changes: 21 additions & 0 deletions src/selectors/Domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import type {CardFeeds, Domain, DomainPendingActions, DomainSecurityGroup, Domai
import type {SecurityGroupKey, UserSecurityGroupData} from '@src/types/onyx/Domain';
import getEmptyArray from '@src/types/utils/getEmptyArray';

type DomainSecurityGroupWithID = {
id: string;
details: DomainSecurityGroup;
};

const domainMemberSettingsSelector = (domainSettings: OnyxEntry<CardFeeds>) => domainSettings?.settings;

const domainSamlSettingsStateSelector = (domain: OnyxEntry<Domain>) =>
Expand Down Expand Up @@ -141,6 +146,19 @@ const adminPendingActionSelector = (pendingAction: OnyxEntry<DomainPendingAction

const defaultSecurityGroupIDSelector = (domain: OnyxEntry<Domain>) => domain?.domain_defaultSecurityGroupID;

function groupsSelector(domain: OnyxEntry<Domain>): DomainSecurityGroupWithID[] {
Comment thread
mountiny marked this conversation as resolved.
Resolved
if (!domain) {
return getEmptyArray<DomainSecurityGroupWithID>();
}

return Object.entries(domain).reduce<DomainSecurityGroupWithID[]>((acc, [key, value]) => {
if (key.startsWith(CONST.DOMAIN.DOMAIN_SECURITY_GROUP_PREFIX)) {
acc.push({id: key.replace(CONST.DOMAIN.DOMAIN_SECURITY_GROUP_PREFIX, ''), details: value as DomainSecurityGroup});
}
return acc;
}, []);
}

export {
domainMemberSettingsSelector,
domainSettingsPrimaryContactSelector,
Expand All @@ -156,4 +174,7 @@ export {
selectSecurityGroupForAccount,
memberPendingActionSelector,
isSecurityGroupEntry,
groupsSelector,
};

export {type DomainSecurityGroupWithID};
37 changes: 37 additions & 0 deletions tests/unit/DomainSelectorsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
defaultSecurityGroupIDSelector,
domainEmailSelector,
domainSettingsPrimaryContactSelector,
groupsSelector,
isSecurityGroupEntry,
memberAccountIDsSelector,
selectSecurityGroupForAccount,
Expand Down Expand Up @@ -392,4 +393,40 @@ describe('domainSelectors', () => {
expect(isSecurityGroupEntry(entry)).toBe(false);
});
});

describe('groupsSelector', () => {
it('Should return an empty array if the domain object is undefined', () => {
expect(groupsSelector(undefined)).toEqual([]);
});

it('Should return an empty array if the domain object is empty', () => {
const domain = {} as OnyxEntry<Domain>;
expect(groupsSelector(domain)).toEqual([]);
});

it('Should return an array of groups when keys start with the security group prefix', () => {
const domain = {
[`${CONST.DOMAIN.DOMAIN_SECURITY_GROUP_PREFIX}123`]: {name: 'Group 1'},
[`${CONST.DOMAIN.DOMAIN_SECURITY_GROUP_PREFIX}456`]: {name: 'Group 2'},
} as unknown as OnyxEntry<Domain>;

const expectedGroups = [
{id: '123', details: {name: 'Group 1'}},
{id: '456', details: {name: 'Group 2'}},
];

expect(groupsSelector(domain)).toEqual(expectedGroups);
});

it('Should ignore keys that do not start with the security group prefix', () => {
const domain = {
[`${CONST.DOMAIN.DOMAIN_SECURITY_GROUP_PREFIX}123`]: {name: 'Group 1'},
otherKey: 'value',
} as unknown as OnyxEntry<Domain>;

const expectedGroups = [{id: '123', details: {name: 'Group 1'}}];

expect(groupsSelector(domain)).toEqual(expectedGroups);
});
});
});
Loading