Commit ffe14754 authored by Eric Rosenbaum's avatar Eric Rosenbaum

Reload the managers list after transfer

parent 13e3a540
...@@ -41,10 +41,10 @@ const normalizeError = (err, body, res) => { ...@@ -41,10 +41,10 @@ const normalizeError = (err, body, res) => {
return null; return null;
}; };
const loadManagers = () => ((dispatch, getState) => { const loadManagers = (reloadAll = false) => ((dispatch, getState) => {
const state = getState(); const state = getState();
const studioId = selectStudioId(state); const studioId = selectStudioId(state);
const managerCount = managers.selector(state).items.length; const managerCount = reloadAll ? 0 : managers.selector(state).items.length;
const opts = { const opts = {
uri: `/studios/${studioId}/managers/`, uri: `/studios/${studioId}/managers/`,
params: {limit: PER_PAGE_LIMIT, offset: managerCount} params: {limit: PER_PAGE_LIMIT, offset: managerCount}
...@@ -52,6 +52,7 @@ const loadManagers = () => ((dispatch, getState) => { ...@@ -52,6 +52,7 @@ const loadManagers = () => ((dispatch, getState) => {
api(withAdmin(opts, state), (err, body, res) => { api(withAdmin(opts, state), (err, body, res) => {
const error = normalizeError(err, body, res); const error = normalizeError(err, body, res);
if (error) return dispatch(managers.actions.error(error)); if (error) return dispatch(managers.actions.error(error));
if (reloadAll) dispatch(managers.actions.clear());
dispatch(managers.actions.append(body, body.length === PER_PAGE_LIMIT)); dispatch(managers.actions.append(body, body.length === PER_PAGE_LIMIT));
}); });
}); });
......
...@@ -13,7 +13,7 @@ import ValidationMessage from '../../../components/forms/validation-message.jsx' ...@@ -13,7 +13,7 @@ import ValidationMessage from '../../../components/forms/validation-message.jsx'
import {managers} from '../lib/redux-modules'; import {managers} from '../lib/redux-modules';
import {useAlertContext} from '../../../components/alert/alert-context'; import {useAlertContext} from '../../../components/alert/alert-context';
import {Errors, transferHost} from '../lib/studio-member-actions'; import {Errors, transferHost, loadManagers} from '../lib/studio-member-actions';
import './transfer-host-modal.scss'; import './transfer-host-modal.scss';
...@@ -21,6 +21,7 @@ const TransferHostConfirmation = ({ ...@@ -21,6 +21,7 @@ const TransferHostConfirmation = ({
handleBack, handleBack,
handleClose, handleClose,
handleTransferHost, handleTransferHost,
handleLoadManagers,
intl, intl,
items, items,
hostId, hostId,
...@@ -48,6 +49,7 @@ const TransferHostConfirmation = ({ ...@@ -48,6 +49,7 @@ const TransferHostConfirmation = ({
handleTransferHost(passwordInputValue, newHostUsername, selectedId) handleTransferHost(passwordInputValue, newHostUsername, selectedId)
.then(() => { .then(() => {
handleClose(); handleClose();
handleLoadManagers(true); // reload the list of managers, to get them in the correct order
successAlert({ successAlert({
id: 'studio.alertTransfer', id: 'studio.alertTransfer',
values: {name: newHostUsername} values: {name: newHostUsername}
...@@ -176,6 +178,7 @@ TransferHostConfirmation.propTypes = { ...@@ -176,6 +178,7 @@ TransferHostConfirmation.propTypes = {
}) })
})), })),
handleTransferHost: PropTypes.func, handleTransferHost: PropTypes.func,
handleLoadManagers: PropTypes.func,
selectedId: PropTypes.number, selectedId: PropTypes.number,
hostId: PropTypes.number hostId: PropTypes.number
}; };
...@@ -185,7 +188,8 @@ const connectedConfirmationStep = connect( ...@@ -185,7 +188,8 @@ const connectedConfirmationStep = connect(
hostId: state.studio.owner, hostId: state.studio.owner,
...managers.selector(state) ...managers.selector(state)
}), { }), {
handleTransferHost: transferHost handleTransferHost: transferHost,
handleLoadManagers: loadManagers
} }
)(TransferHostConfirmation); )(TransferHostConfirmation);
......
...@@ -45,6 +45,12 @@ describe('loadManagers', () => { ...@@ -45,6 +45,12 @@ describe('loadManagers', () => {
expect(api.mock.calls[1][0].params.offset).toBe(3); expect(api.mock.calls[1][0].params.offset).toBe(3);
items = managers.selector(store.getState()).items; items = managers.selector(store.getState()).items;
expect(items.length).toBe(6); expect(items.length).toBe(6);
// Reload the list
store.dispatch(loadManagers(true));
expect(api.mock.calls[2][0].params.offset).toBe(0);
items = managers.selector(store.getState()).items;
expect(items.length).toBe(3);
}); });
test('it correctly uses the admin route when possible', () => { test('it correctly uses the admin route when possible', () => {
......
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