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 @@ -53,6 +53,8 @@ props.navigation.navigate(CreateRolesScreenRouteName, { threadInfo, action: 'create_role', + roleName: 'New Role', + rolePermissions: [], }), [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 onCreate = React.useCallback(() => { + callModifyCommunityRole({ + community: threadInfo.id, + action, + name: roleName, + permissions: rolePermissions, + }); + + navigation.goBack(); + }, [ + callModifyCommunityRole, + threadInfo, + action, + roleName, + rolePermissions, + navigation, + ]); + + return ( + + Create + + ); +} + +const unboundStyles = { + onCreateButton: { + 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 @@ -6,6 +6,7 @@ import { configurableCommunityPermissions } from 'lib/types/thread-permission-types.js'; import type { ThreadInfo } from 'lib/types/thread-types.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'; @@ -16,6 +17,8 @@ export type CreateRolesScreenParams = { +threadInfo: ThreadInfo, +action: 'create_role' | 'edit_role', + +roleName: string, + +rolePermissions: string[], }; type CreateRolesScreenProps = { @@ -24,12 +27,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'); - const [selectedPermissions, setSelectedPermissions] = React.useState([]); + React.useState(defaultRoleName); + const [selectedPermissions, setSelectedPermissions] = React.useState( + defaultRolePermissions, + ); const styles = useStyles(unboundStyles); @@ -83,6 +92,21 @@ [isPermissionSelected], ); + React.useEffect(() => { + props.navigation.setParams({ + threadInfo, + action, + roleName: customRoleName, + rolePermissions: selectedPermissions, + }); + }, [ + props.navigation, + threadInfo, + action, + customRoleName, + selectedPermissions, + ]); + const permissionsList = React.useMemo( () => configurableCommunityPermissions.map(permission => ( @@ -101,6 +125,13 @@ setCustomRoleName(roleName); }, []); + React.useEffect(() => { + props.navigation.setOptions({ + // eslint-disable-next-line react/display-name + headerRight: () => , + }); + }, [props.navigation, props.route]); + return (