handle deprecation of transitionTo

This commit is contained in:
Sérgio Ramos 2017-02-08 21:42:21 +00:00 committed by Sérgio Ramos
parent 935ab4a749
commit eb5e78390e
5 changed files with 10 additions and 62 deletions

View File

@ -34,11 +34,11 @@ const Billing = (props) => {
values, values,
org org
}); });
router.transitionTo(`/${org.id}/projects`); router.push(`/${org.id}/projects`);
}; };
const onNewBilling = (evt) => const onNewBilling = (evt) =>
router.transitionTo(`/${org.id}/new-project/new-billing`); router.push(`/${org.id}/new-project/new-billing`);
return ( return (
<BillingForm <BillingForm

View File

@ -27,14 +27,14 @@ const NewBilling = (props) => {
} = props; } = props;
const onBack = (evt) => const onBack = (evt) =>
router.transitionTo(`/${org.id}/new-project/billing`); router.push(`/${org.id}/new-project/billing`);
const onSubmit = (values) => { const onSubmit = (values) => {
handleNewProject({ handleNewProject({
values, values,
org org
}); });
router.transitionTo(`/${org.id}/projects`); router.push(`/${org.id}/projects`);
}; };
return ( return (

View File

@ -1,7 +1,7 @@
const React = require('react'); const React = require('react');
const ReactRedux = require('react-redux'); const ReactRedux = require('react-redux');
const selectors = require('@state/selectors');
const selectors = require('@state/selectors');
const PropTypes = require('@root/prop-types'); const PropTypes = require('@root/prop-types');
const NewProjectForm = require('@components/new-project'); const NewProjectForm = require('@components/new-project');
@ -17,14 +17,14 @@ const NewProject = (props) => {
const { const {
org, org,
router push
} = props; } = props;
const onCancel = (values) => const onCancel = (values) =>
router.transitionTo(`/${org.id}/projects`); push(`/${org.id}/projects`);
const onSubmit = (values) => const onSubmit = (values) =>
router.transitionTo(`/${org.id}/new-project/billing`); push(`/${org.id}/new-project/billing`);
return ( return (
<NewProjectForm <NewProjectForm
@ -37,7 +37,7 @@ const NewProject = (props) => {
NewProject.propTypes = { NewProject.propTypes = {
org: PropTypes.org.isRequired, org: PropTypes.org.isRequired,
router: React.PropTypes.object push: React.PropTypes.func
}; };
// TODO we'll need to know whether there any cards // TODO we'll need to know whether there any cards
// otherwise go to new billing straight away // otherwise go to new billing straight away

View File

@ -1,18 +1 @@
const transitionTo = (pathname) => (dispatch, getState) => { module.exports = {};
const {
app: {
router: {
transitionTo
}
}
} = getState();
return dispatch({
type: 'TRANSITION_TO',
PAYLOAD: transitionTo(pathname)
});
};
module.exports = {
transitionTo
};

View File

@ -1,35 +0,0 @@
const mock = require('simple-mock');
const test = require('ava');
const thunks = require('@state/thunks');
const {
transitionTo
} = thunks;
test('transitionTo should dispatch', (t) => {
const pathname = '/hello';
const state = {
app: {
router: {
transitionTo: mock.spy((pathname) => pathname)
}
}
};
const dispatch = mock.spy(({
PAYLOAD
}) => {
t.deepEqual(PAYLOAD, pathname);
});
const getState = () => state;
transitionTo(pathname)(dispatch, getState);
t.deepEqual(dispatch.called, true);
t.deepEqual(dispatch.callCount, 1);
t.deepEqual(state.app.router.transitionTo.called, true);
t.deepEqual(state.app.router.transitionTo.callCount, 1);
});