diff --git a/native/roles/community-roles-screen.react.js b/native/roles/community-roles-screen.react.js
--- a/native/roles/community-roles-screen.react.js
+++ b/native/roles/community-roles-screen.react.js
@@ -50,6 +50,8 @@
props.navigation.navigate(CreateRolesScreenRouteName, {
threadInfo,
action: 'create_role',
+ roleName: 'New role',
+ rolePermissions: new Set(),
}),
[threadInfo, props.navigation],
);
diff --git a/native/roles/create-roles-header-right-button.react.js b/native/roles/create-roles-header-right-button.react.js
new file mode 100644
--- /dev/null
+++ b/native/roles/create-roles-header-right-button.react.js
@@ -0,0 +1,56 @@
+// @flow
+
+import { useNavigation } from '@react-navigation/native';
+import * as React from 'react';
+import { TouchableOpacity, Text } from 'react-native';
+
+import { modifyCommunityRole } from 'lib/actions/thread-actions.js';
+import { useServerCall } from 'lib/utils/action-utils.js';
+
+import type { NavigationRoute } from '../navigation/route-names';
+import { useStyles } from '../themes/colors.js';
+
+type Props = {
+ +route: NavigationRoute<'CreateRolesScreen'>,
+};
+
+function CreateRolesHeaderRightButton(props: Props): React.Node {
+ const { threadInfo, action, roleName, rolePermissions } = props.route.params;
+ const navigation = useNavigation();
+ const styles = useStyles(unboundStyles);
+
+ const callModifyCommunityRole = useServerCall(modifyCommunityRole);
+
+ const onPressCreate = React.useCallback(() => {
+ callModifyCommunityRole({
+ community: threadInfo.id,
+ action,
+ name: roleName,
+ permissions: [...rolePermissions],
+ });
+
+ navigation.goBack();
+ }, [
+ callModifyCommunityRole,
+ threadInfo,
+ action,
+ roleName,
+ rolePermissions,
+ navigation,
+ ]);
+
+ return (
+
+ Create
+
+ );
+}
+
+const unboundStyles = {
+ createButton: {
+ color: 'purpleLink',
+ marginRight: 10,
+ },
+};
+
+export default CreateRolesHeaderRightButton;
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
@@ -11,6 +11,7 @@
import type { ThreadInfo } from 'lib/types/thread-types.js';
import { useFilterPermissionOptionsByThreadType } from 'lib/utils/role-utils.js';
+import CreateRolesHeaderRightButton from './create-roles-header-right-button.react.js';
import type { RolesNavigationProp } from './roles-navigator.react.js';
import EnumSettingsOption from '../components/enum-settings-option.react.js';
import SWMansionIcon from '../components/swmansion-icon.react.js';
@@ -21,6 +22,8 @@
export type CreateRolesScreenParams = {
+threadInfo: ThreadInfo,
+action: 'create_role' | 'edit_role',
+ +roleName: string,
+ +rolePermissions: $ReadOnlySet,
};
type CreateRolesScreenProps = {
@@ -29,14 +32,18 @@
};
function CreateRolesScreen(props: CreateRolesScreenProps): React.Node {
- // eslint-disable-next-line no-unused-vars
- const { threadInfo, action } = props.route.params;
+ const {
+ threadInfo,
+ action,
+ roleName: defaultRoleName,
+ rolePermissions: defaultRolePermissions,
+ } = props.route.params;
const [customRoleName, setCustomRoleName] =
- React.useState('New role');
+ React.useState(defaultRoleName);
const [selectedPermissions, setSelectedPermissions] = React.useState<
$ReadOnlySet,
- >(new Set());
+ >(defaultRolePermissions);
const styles = useStyles(unboundStyles);
@@ -88,6 +95,17 @@
[],
);
+ React.useEffect(
+ () =>
+ props.navigation.setParams({
+ threadInfo,
+ action,
+ roleName: customRoleName,
+ rolePermissions: selectedPermissions,
+ }),
+ [props.navigation, threadInfo, action, customRoleName, selectedPermissions],
+ );
+
const filteredUserSurfacedPermissionOptions =
useFilterPermissionOptionsByThreadType(threadInfo.type);
@@ -113,6 +131,15 @@
setCustomRoleName(roleName);
}, []);
+ React.useEffect(
+ () =>
+ props.navigation.setOptions({
+ // eslint-disable-next-line react/display-name
+ headerRight: () => ,
+ }),
+ [props.navigation, props.route],
+ );
+
return (