Commit 51858167 authored by Karishma Chadha's avatar Karishma Chadha

Display manager limit modal in two scenarios: if the frontend already knows...

Display manager limit modal in two scenarios: if the frontend already knows that the manager limit has been reached, and if we have the promote modal up, but we got response from the server that the manager limit has been reached.
parent e0e53b8d
...@@ -6,15 +6,19 @@ import classNames from 'classnames'; ...@@ -6,15 +6,19 @@ import classNames from 'classnames';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import PromoteModal from './modals/promote-modal.jsx'; import PromoteModal from './modals/promote-modal.jsx';
import ManagerLimitModal from './modals/manager-limit-modal.jsx';
import { import {
selectCanRemoveCurator, selectCanRemoveManager, selectCanPromoteCurators selectCanRemoveCurator, selectCanRemoveManager, selectCanPromoteCurators
} from '../../redux/studio-permissions'; } from '../../redux/studio-permissions';
import { import {
Errors,
promoteCurator, promoteCurator,
removeCurator, removeCurator,
removeManager removeManager
} from './lib/studio-member-actions'; } from './lib/studio-member-actions';
import {selectStudioHasReachedManagerLimit} from '../../redux/studio';
import {useAlertContext} from '../../components/alert/alert-context'; import {useAlertContext} from '../../components/alert/alert-context';
import OverflowMenu from '../../components/overflow-menu/overflow-menu.jsx'; import OverflowMenu from '../../components/overflow-menu/overflow-menu.jsx';
...@@ -22,11 +26,12 @@ import removeIcon from './icons/remove-icon.svg'; ...@@ -22,11 +26,12 @@ import removeIcon from './icons/remove-icon.svg';
import promoteIcon from './icons/curator-icon.svg'; import promoteIcon from './icons/curator-icon.svg';
const StudioMemberTile = ({ const StudioMemberTile = ({
canRemove, canPromote, onRemove, onPromote, isCreator, // mapState props canRemove, canPromote, onRemove, onPromote, isCreator, hasReachedManagerLimit, // mapState props
username, image // own props username, image // own props
}) => { }) => {
const [submitting, setSubmitting] = useState(false); const [submitting, setSubmitting] = useState(false);
const [modalOpen, setModalOpen] = useState(false); const [modalOpen, setModalOpen] = useState(false);
const [managerLimitReached, setManagerLimitReached] = useState(false);
const {errorAlert, successAlert} = useAlertContext(); const {errorAlert, successAlert} = useAlertContext();
const userUrl = `/users/${username}`; const userUrl = `/users/${username}`;
return ( return (
...@@ -80,6 +85,10 @@ const StudioMemberTile = ({ ...@@ -80,6 +85,10 @@ const StudioMemberTile = ({
</OverflowMenu> </OverflowMenu>
} }
{modalOpen && {modalOpen &&
((hasReachedManagerLimit || managerLimitReached) ?
<ManagerLimitModal
handleClose={() => setModalOpen(false)}
/> :
<PromoteModal <PromoteModal
handleClose={() => setModalOpen(false)} handleClose={() => setModalOpen(false)}
handlePromote={() => { handlePromote={() => {
...@@ -90,15 +99,21 @@ const StudioMemberTile = ({ ...@@ -90,15 +99,21 @@ const StudioMemberTile = ({
values: {name: username} values: {name: username}
}); });
}) })
.catch(() => { .catch(error => {
if (error === Errors.MANAGER_LIMIT) {
setManagerLimitReached(true);
setModalOpen(true);
} else {
errorAlert({ errorAlert({
id: 'studio.alertManagerPromoteError', id: 'studio.alertManagerPromoteError',
values: {name: username} values: {name: username}
}); });
}
}); });
}} }}
username={username} username={username}
/> />
)
} }
</div> </div>
); );
...@@ -111,7 +126,8 @@ StudioMemberTile.propTypes = { ...@@ -111,7 +126,8 @@ StudioMemberTile.propTypes = {
onPromote: PropTypes.func, onPromote: PropTypes.func,
username: PropTypes.string, username: PropTypes.string,
image: PropTypes.string, image: PropTypes.string,
isCreator: PropTypes.bool isCreator: PropTypes.bool,
hasReachedManagerLimit: PropTypes.bool
}; };
const ManagerTile = connect( const ManagerTile = connect(
...@@ -128,7 +144,8 @@ const ManagerTile = connect( ...@@ -128,7 +144,8 @@ const ManagerTile = connect(
const CuratorTile = connect( const CuratorTile = connect(
(state, ownProps) => ({ (state, ownProps) => ({
canRemove: selectCanRemoveCurator(state, ownProps.username), canRemove: selectCanRemoveCurator(state, ownProps.username),
canPromote: selectCanPromoteCurators(state) canPromote: selectCanPromoteCurators(state),
hasReachedManagerLimit: selectStudioHasReachedManagerLimit(state)
}), }),
{ {
onRemove: removeCurator, onRemove: removeCurator,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment