mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-17 00:21:20 -05:00
Reload the managers list after transfer
This commit is contained in:
parent
13e3a540f7
commit
ffe1475401
3 changed files with 15 additions and 4 deletions
|
@ -41,10 +41,10 @@ const normalizeError = (err, body, res) => {
|
|||
return null;
|
||||
};
|
||||
|
||||
const loadManagers = () => ((dispatch, getState) => {
|
||||
const loadManagers = (reloadAll = false) => ((dispatch, getState) => {
|
||||
const state = getState();
|
||||
const studioId = selectStudioId(state);
|
||||
const managerCount = managers.selector(state).items.length;
|
||||
const managerCount = reloadAll ? 0 : managers.selector(state).items.length;
|
||||
const opts = {
|
||||
uri: `/studios/${studioId}/managers/`,
|
||||
params: {limit: PER_PAGE_LIMIT, offset: managerCount}
|
||||
|
@ -52,6 +52,7 @@ const loadManagers = () => ((dispatch, getState) => {
|
|||
api(withAdmin(opts, state), (err, body, res) => {
|
||||
const error = normalizeError(err, body, res);
|
||||
if (error) return dispatch(managers.actions.error(error));
|
||||
if (reloadAll) dispatch(managers.actions.clear());
|
||||
dispatch(managers.actions.append(body, body.length === PER_PAGE_LIMIT));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ import ValidationMessage from '../../../components/forms/validation-message.jsx'
|
|||
import {managers} from '../lib/redux-modules';
|
||||
|
||||
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';
|
||||
|
||||
|
@ -21,6 +21,7 @@ const TransferHostConfirmation = ({
|
|||
handleBack,
|
||||
handleClose,
|
||||
handleTransferHost,
|
||||
handleLoadManagers,
|
||||
intl,
|
||||
items,
|
||||
hostId,
|
||||
|
@ -48,6 +49,7 @@ const TransferHostConfirmation = ({
|
|||
handleTransferHost(passwordInputValue, newHostUsername, selectedId)
|
||||
.then(() => {
|
||||
handleClose();
|
||||
handleLoadManagers(true); // reload the list of managers, to get them in the correct order
|
||||
successAlert({
|
||||
id: 'studio.alertTransfer',
|
||||
values: {name: newHostUsername}
|
||||
|
@ -176,6 +178,7 @@ TransferHostConfirmation.propTypes = {
|
|||
})
|
||||
})),
|
||||
handleTransferHost: PropTypes.func,
|
||||
handleLoadManagers: PropTypes.func,
|
||||
selectedId: PropTypes.number,
|
||||
hostId: PropTypes.number
|
||||
};
|
||||
|
@ -185,7 +188,8 @@ const connectedConfirmationStep = connect(
|
|||
hostId: state.studio.owner,
|
||||
...managers.selector(state)
|
||||
}), {
|
||||
handleTransferHost: transferHost
|
||||
handleTransferHost: transferHost,
|
||||
handleLoadManagers: loadManagers
|
||||
}
|
||||
)(TransferHostConfirmation);
|
||||
|
||||
|
|
|
@ -45,6 +45,12 @@ describe('loadManagers', () => {
|
|||
expect(api.mock.calls[1][0].params.offset).toBe(3);
|
||||
items = managers.selector(store.getState()).items;
|
||||
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', () => {
|
||||
|
|
Loading…
Reference in a new issue