diff --git a/native/roles/create-roles-header-right-button.react.js b/native/roles/create-roles-header-right-button.react.js --- a/native/roles/create-roles-header-right-button.react.js +++ b/native/roles/create-roles-header-right-button.react.js @@ -12,16 +12,19 @@ useServerCall, useDispatchActionPromise, } from 'lib/utils/action-utils.js'; +import { values } from 'lib/utils/objects.js'; import type { NavigationRoute } from '../navigation/route-names'; import { useStyles } from '../themes/colors.js'; type Props = { +route: NavigationRoute<'CreateRolesScreen'>, + +setRoleCreationFailed: boolean => void, }; function CreateRolesHeaderRightButton(props: Props): React.Node { const { threadInfo, action, roleName, rolePermissions } = props.route.params; + const { setRoleCreationFailed } = props; const navigation = useNavigation(); const styles = useStyles(unboundStyles); @@ -29,6 +32,12 @@ const dispatchActionPromise = useDispatchActionPromise(); const onPressCreate = React.useCallback(() => { + const threadRoleNames = values(threadInfo.roles).map(role => role.name); + if (threadRoleNames.includes(roleName)) { + setRoleCreationFailed(true); + return; + } + dispatchActionPromise( modifyCommunityRoleActionTypes, callModifyCommunityRole({ @@ -48,6 +57,7 @@ roleName, rolePermissions, navigation, + setRoleCreationFailed, ]); const shouldHeaderRightBeDisabled = roleName.length === 0; diff --git a/native/roles/create-roles-screen.react.js b/native/roles/create-roles-screen.react.js --- a/native/roles/create-roles-screen.react.js +++ b/native/roles/create-roles-screen.react.js @@ -59,8 +59,19 @@ $ReadOnlyArray, >(defaultRolePermissions); + const [roleCreationFailed, setRoleCreationFailed] = + React.useState(false); + const styles = useStyles(unboundStyles); + const errorStyles = React.useMemo( + () => + roleCreationFailed + ? [styles.errorContainer, styles.errorContainerVisible] + : styles.errorContainer, + [roleCreationFailed, styles.errorContainer, styles.errorContainerVisible], + ); + const onClearPermissions = React.useCallback(() => { setSelectedPermissions([]); }, []); @@ -152,6 +163,7 @@ ); const onChangeRoleNameInput = React.useCallback((roleName: string) => { + setRoleCreationFailed(false); setCustomRoleName(roleName); }, []); @@ -170,7 +182,12 @@ ); } - return ; + return ( + + ); }, }), [ @@ -194,6 +211,11 @@ /> + + + There is already a role with this name in the community + + @@ -231,6 +253,18 @@ pencilIcon: { color: 'panelInputSecondaryForeground', }, + errorContainer: { + marginTop: 10, + alignItems: 'center', + opacity: 0, + }, + errorContainerVisible: { + opacity: 1, + }, + errorText: { + color: 'redText', + fontSize: 14, + }, permissionsContainer: { marginTop: 20, paddingBottom: 220,