diff --git a/src/components/item/publish/CoEditorSettings.js b/src/components/item/publish/CoEditorSettings.js index 75da5bc10..917c95b25 100644 --- a/src/components/item/publish/CoEditorSettings.js +++ b/src/components/item/publish/CoEditorSettings.js @@ -9,11 +9,10 @@ import { RadioGroup, FormControlLabel, } from '@material-ui/core'; -import { useParams } from 'react-router'; import { MUTATION_KEYS } from '@graasp/query-client'; import { useMutation } from '../../../config/queryClient'; import { CurrentUserContext } from '../../context/CurrentUserContext'; -import { DISPLAY_CO_EDITOR_OPTIONS } from '../../../config/constants'; +import { DISPLAY_CO_EDITORS_OPTIONS } from '../../../config/constants'; const useStyles = makeStyles((theme) => ({ title: { @@ -36,14 +35,13 @@ const CoEditorSettings = ({ item }) => { const { isLoading: isMemberLoading } = useContext(CurrentUserContext); // current item - const { itemId } = useParams(); - + const itemId = item?.get('id'); const settings = item?.get('settings'); const itemName = item?.get('name'); // by default, co editors will not be displayed const [optionValue, setOptionValue] = useState( - DISPLAY_CO_EDITOR_OPTIONS.NO.value, + DISPLAY_CO_EDITORS_OPTIONS.NO.value, ); useEffect(() => { @@ -71,7 +69,7 @@ const CoEditorSettings = ({ item }) => { {t( - 'Do you want to display co-editors after published? All users with edit permission will be displayed.', + 'Do you want to display co-editors on the publication page? All users with edit or admin permissions will be displayed.', )} { value={optionValue} onChange={handleChange} > - } - label={t(DISPLAY_CO_EDITOR_OPTIONS.YES.label)} - /> - } - label={t(DISPLAY_CO_EDITOR_OPTIONS.NO.label)} - /> + { + Object.values(DISPLAY_CO_EDITORS_OPTIONS).map((option) => ( + } + label={t(option.label)} + /> + )) + } ); diff --git a/src/components/item/publish/ItemPublishButton.js b/src/components/item/publish/ItemPublishButton.js index cd8ee9de6..c48882787 100644 --- a/src/components/item/publish/ItemPublishButton.js +++ b/src/components/item/publish/ItemPublishButton.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import { useParams } from 'react-router'; import { Loader } from '@graasp/ui'; -import { Button, makeStyles, Typography } from '@material-ui/core'; +import { Button, makeStyles, Typography, FormControlLabel, Checkbox } from '@material-ui/core'; import CheckCircleIcon from '@material-ui/icons/CheckCircle'; import { MUTATION_KEYS } from '@graasp/query-client'; import { useMutation, hooks } from '../../../config/queryClient'; @@ -20,7 +20,7 @@ import { } from '../../../config/selectors'; const { POST_ITEM_TAG, DELETE_ITEM_TAG } = MUTATION_KEYS; -const { useTags, useItemTags } = hooks; +const { useTags, useItemTags, useItemMemberships } = hooks; const useStyles = makeStyles((theme) => ({ button: { @@ -38,6 +38,7 @@ const ItemPublishButton = ({ item, isValidated }) => { // current item const { itemId } = useParams(); + // item tags const { mutate: postItemTag } = useMutation(POST_ITEM_TAG); const { mutate: deleteItemTag } = useMutation(DELETE_ITEM_TAG); @@ -48,8 +49,15 @@ const ItemPublishButton = ({ item, isValidated }) => { isError, } = useItemTags(itemId); + // item memberships for co-editors + const { data: memberships } = useItemMemberships([itemId]); + + // TODO: send emails to co-editors, this can be moved to backend + const coEditors = memberships.filter((membership) => membership?.permission === "admin" || membership?.permission === "write"); + const [isPublished, setIsPublished] = useState(false); const [isDisabled, setIsDisabled] = useState(false); + const [emailNotification, setEmailNotification] = useState(false); // update state variables depending on fetch values useEffect(() => { @@ -97,6 +105,10 @@ const ItemPublishButton = ({ item, isValidated }) => { } }; + const toggleEmailNotification = () => { + setEmailNotification(!emailNotification); + } + return ( <> +
+ + )} + label="Send email notifications to all co-editors" + /> +
{isPublished && ( {t( diff --git a/src/config/constants.js b/src/config/constants.js index b9d5450fe..b92def0f4 100644 --- a/src/config/constants.js +++ b/src/config/constants.js @@ -254,7 +254,7 @@ export const MEMBERSHIP_TABLE_ROW_HEIGHT = 75; // signin page path from auth host export const SIGN_IN_PATH = buildSignInPath({ host: AUTHENTICATION_HOST }); -export const DISPLAY_CO_EDITOR_OPTIONS = { +export const DISPLAY_CO_EDITORS_OPTIONS = { YES: { value: 'yes', label: 'Yes',