on master help sign in
Merge pull request #252 from urbit/fix/disclaimer-freeze

fix: disclaimer freezing because of incorrect router and mount order

commita0c5cd46d21c19e235de9e88b4255ae59c7a8cfa authorMatt Condon <mattgcondon@gmail.com> dateTue 27 Aug 2019, 13:39 (7 years ago) parent047d86f7446bf6
3 files changed+22−15
src/Bridge.js+9−6 src/views/Activate/ActivateCode.js+3−3 src/views/Disclaimer.js+10−6
src/Bridge.js+9−6
@@ -48,12 +48,15 @@ function useInitialRoutes() {
4848 ];
4949 }
5050
51− return hasImpliedTicket
52− ? [{ key: ROUTE_NAMES.ACTIVATE }]
53− : [
54− { key: ROUTE_NAMES.LOGIN },
55− ...(!hasDisclaimed ? [{ key: ROUTE_NAMES.DISCLAIMER }] : []),
56− ];
51+ if (hasImpliedTicket) {
52+ return [{ key: ROUTE_NAMES.ACTIVATE }];
53+ }
54+
55+ if (!hasDisclaimed) {
56+ return [{ key: ROUTE_NAMES.DISCLAIMER, data: { next: ROUTE_NAMES.LOGIN } }];
57+ }
58+
59+ return [{ key: ROUTE_NAMES.LOGIN }];
5760}
5861
5962function Bridge() {
src/views/Activate/ActivateCode.js+3−3
@@ -65,10 +65,10 @@ export default function ActivateCode() {
6565 ]);
6666
6767 const goToPassport = useCallback(() => {
68− push(names.PASSPORT);
69−
7068 if (!hasDisclaimed) {
71− push(names.DISCLAIMER);
69+ push(names.DISCLAIMER, { next: names.PASSPORT });
70+ } else {
71+ push(names.PASSPORT);
7272 }
7373 }, [hasDisclaimed, names.DISCLAIMER, names.PASSPORT, push]);
7474
src/views/Disclaimer.js+10−6
@@ -2,8 +2,8 @@ import React, { useCallback, useMemo } from 'react';
22import cn from 'classnames';
33import { Grid, H3, B, Text, CheckboxInput } from 'indigo-react';
44
5−import { useHistory } from 'store/history';
65import useHasDisclaimed from 'lib/useHasDisclaimed';
6+import { useLocalRouter } from 'lib/LocalRouter';
77
88import View from 'components/View';
99import WarningBox from 'components/WarningBox';
@@ -14,7 +14,7 @@ import { composeValidator, buildCheckboxValidator } from 'form/validators';
1414const TEXT_STYLE = 'f5';
1515
1616export default function ActivateDisclaimer() {
17− const { pop } = useHistory();
17+ const { pop, popAndPush, data } = useLocalRouter();
1818 const [, setHasDisclaimed] = useHasDisclaimed();
1919
2020 const validate = useMemo(
@@ -24,10 +24,14 @@ export default function ActivateDisclaimer() {
2424
2525 const initialValues = useMemo(() => ({ checkbox: false }), []);
2626
27− const goBack = useCallback(async () => {
27+ const goNext = useCallback(async () => {
2828 setHasDisclaimed(true);
29− pop();
30− }, [pop, setHasDisclaimed]);
29+ if (data.next) {
30+ popAndPush(data.next);
31+ } else {
32+ pop();
33+ }
34+ }, [data, pop, popAndPush, setHasDisclaimed]);
3135
3236 return (
3337 <View>
@@ -81,7 +85,7 @@ export default function ActivateDisclaimer() {
8185 </Grid.Item>
8286 <BridgeForm
8387 validate={validate}
84− afterSubmit={goBack}
88+ afterSubmit={goNext}
8589 initialValues={initialValues}>
8690 {({ handleSubmit }) => (
8791 <>