Source

containers/Custom/Group/GroupMessageCreatePostScreen.ts

import {compose, mapProps} from "recompose";
import {connect} from "react-redux";
import {withNavigation} from "../../../components/hocs/withNavigation";
import PropTypes from "prop-types";

import GroupMessageCreatePost from "../../Group/GroupMessageCreatePostScreen";
import withActiveCallBacks from "../../../navigators/react-navigation-addons/withActiveCallBacks";
import withLoadGroup from "../../../components/hocs/withLoadGroup";
import {privacyOptions} from "../../Group/GroupMessageOptionsScreen";
import {getMembers} from "../../../reducers/groupMembers";

const mapStateToProps = (state, ownProps) => {
	const currentUserId = state.user.userObject?.id;
	const groupMembers = getMembers(false)(
		state,
		//@ts-ignore
		"all",
		ownProps.groupId
	);
	return {
		//@ts-ignore
		initialUsers: groupMembers.filter(({id}) => id !== currentUserId)
	};
};

const buildProps = props => {
	const privacyOpen = privacyOptions.find(({value}) => value === "open");
	return {
		useModel: false,
		key: "allMembersGroupMessage",
		isAllSelected: true,
		groupMessagePrivacy: privacyOpen,
		...props
	};
};

/**
 * You can use this component to display Group Message Create Post Screen in your custom screen.
 * This is used to send a message to all members of a group.
 * @component
 * @example
 * //In custom_code/components/MyCustomScreen.js...
 *
 * import React from 'react';
 * import { View, Text } from 'react-native';
 * import GroupMessageCreatePostScreen from "@src/containers/Custom/Group/GroupMessageCreatePostScreen";
 *
 * const MyCustomScreen = (props) => (
 *   <View style={{ flex: 1, marginBottom: 80 }}>
 *     <GroupMessageCreatePostScreen {...props}
 *       groupId={9}
 *       screenTitle="Send to Members"
 *       LoadingComponent={<View style={{ flex: 1, alignSelf: "center", justifyContent: "center" }}>
 *         <Text>Loading, please wait...</Text>
 *       </View>
 *       } />
 *   </View>
 * )
 *
 * export default MyCustomScreen;
 *
 * //In custom_code/index.js...
 * import MyCustomScreen from "./components/MyCustomScreen";
 * export const applyCustomCode = externalCodeSetup => {
 *
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "All"
 *  );
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "Main"
 *  );
 * }
 */

export const GroupMessageCreatePostScreen = compose(
	mapProps(buildProps),
	connect(mapStateToProps),
	withNavigation,
	withActiveCallBacks,
	withLoadGroup
)(GroupMessageCreatePost);

export default GroupMessageCreatePostScreen;

GroupMessageCreatePostScreen.propTypes = {
	/**
	 * Id of group to display
	 * {Number}
	 */
	groupId: PropTypes.number,
	/**
	 * If the group is not yet available in the app state, the component will attempt to load a list of groups.
	 * You can use this field to search for the specific group you want to load instead of loading a list of groups.
	 * {String}
	 */
	searchTerm: PropTypes.string,
	/**
	 * Use `true` to hide the back button
	 * {Boolean}
	 */
	hideBackButton: PropTypes.bool,
	/**
	 * Use `true` to hide cancel button when creating a new message
	 * {Boolean}
	 */
	hideCancelButton: PropTypes.bool,
	/**
	 * Use `true` to hide the screen title container
	 * {Boolean}
	 */
	hideNavigationHeader: PropTypes.bool,
	/**
	 * List screen title
	 * {String}
	 */
	screenTitle: PropTypes.string,
	/**
	 * Use this to display your own loading component while the screen is loading
	 * {ReactComponent}
	 */
	LoadingComponent: PropTypes.elementType
};