Change goToPayPal flow

This commit is contained in:
Berkeley Martinez
2015-10-27 20:07:28 -07:00
parent 2dd16796d7
commit d633f74ff9
5 changed files with 35 additions and 17 deletions

View File

@ -27,7 +27,7 @@ app$({ history, location: appLocation })
.flatMap(
({ AppCat }) => {
// instantiate the cat with service
const appCat = AppCat(null, services, history);
const appCat = AppCat(null, services);
// hydrate the stores
return hydrate(appCat, catState)
.map(() => appCat);
@ -36,6 +36,20 @@ app$({ history, location: appLocation })
// redirects in the future
({ nextLocation, props }, appCat) => ({ nextLocation, props, appCat })
)
.doOnNext(({ appCat }) => {
const appStore = appCat.getStore('appStore');
const appActions = appCat.getActions('appActions');
appStore
.distinctUntilChanged()
.subscribe(function({ route = appLocation.pathname }) {
history.pushState(null, route);
});
appActions.goBack.subscribe(function() {
history.goBack();
});
})
.flatMap(({ props, appCat }) => {
props.history = history;
return Render(

View File

@ -5,8 +5,8 @@ import { HikesActions, HikesStore } from './routes/Hikes/flux';
import { JobActions, JobsStore} from './routes/Jobs/flux';
export default Cat()
.init(({ instance: cat, args: [services, history] }) => {
cat.register(AppActions, null, services, history);
.init(({ instance: cat, args: [services] }) => {
cat.register(AppActions, null, services);
cat.register(AppStore, null, cat);
cat.register(HikesActions, null, services);

View File

@ -17,19 +17,13 @@ export default Actions({
},
getUser: null,
goTo: null,
goTo(route) {
return { route };
},
goBack: null
})
.refs({ displayName: 'AppActions' })
.init(({ instance: appActions, args: [services, history] }) => {
appActions.goTo.subscribe((url) => {
history.pushState(null, url);
});
appActions.goBack.subscribe(() => {
history.goBack();
});
.init(({ instance: appActions, args: [services] }) => {
appActions.getUser.subscribe(({ isPrimed }) => {
if (isPrimed) {
debug('isPrimed');

View File

@ -14,10 +14,10 @@ export default Store({
value: initValue
},
init({ instance: appStore, args: [cat] }) {
const { setUser, setTitle } = cat.getActions('appActions');
const { goTo, setUser, setTitle } = cat.getActions('appActions');
const register = createRegistrar(appStore);
register(setter(fromMany(setUser, setTitle)));
register(setter(fromMany(setUser, setTitle, goTo)));
return appStore;
}

View File

@ -12,7 +12,10 @@ const paypalIds = {
export default contain(
{
store: 'JobsStore',
actions: 'jobActions',
actions: [
'jobActions',
'appActions'
],
map({
job: { id, isHighlighted } = {},
buttonId = isHighlighted ?
@ -40,6 +43,7 @@ export default contain(
displayName: 'GoToPayPal',
propTypes: {
appActions: PropTypes.object,
id: PropTypes.string,
isHighlighted: PropTypes.bool,
buttonId: PropTypes.string,
@ -51,6 +55,11 @@ export default contain(
jobActions: PropTypes.object
},
goToJobBoard() {
const { appActions } = this.props;
appActions.goTo('/jobs');
},
renderDiscount(discountAmount) {
if (!discountAmount) {
return null;
@ -217,7 +226,8 @@ export default contain(
<form
action='https://www.sandbox.paypal.com/cgi-bin/webscr'
method='post'
target='_top'>
onClick={ this.goToJobBoard }
target='_blank'>
<input
name='cmd'
type='hidden'