Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32212979
D8421.1765145455.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D8421.1765145455.diff
View Options
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 (
+ <TouchableOpacity onPress={onPressCreate}>
+ <Text style={styles.createButton}>Create</Text>
+ </TouchableOpacity>
+ );
+}
+
+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<UserSurfacedPermission>,
};
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<string>('New role');
+ React.useState<string>(defaultRoleName);
const [selectedPermissions, setSelectedPermissions] = React.useState<
$ReadOnlySet<UserSurfacedPermission>,
- >(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: () => <CreateRolesHeaderRightButton route={props.route} />,
+ }),
+ [props.navigation, props.route],
+ );
+
return (
<View>
<View style={styles.roleNameContainer}>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 7, 10:10 PM (20 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5846164
Default Alt Text
D8421.1765145455.diff (4 KB)
Attached To
Mode
D8421: [native] Use CreateRolesScreenHeaderRightButton to save a new role
Attached
Detach File
Event Timeline
Log In to Comment