on master help sign in
fix: disclaimer freezing because of incorrect router and mount order
commit7446bf694b198ddfc7ee5697c8ba360d15e56a4e authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 27 Aug 2019, 11:26 (7 years ago) parent3d8d2c7
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
@@ -64,10 +64,10 @@ export default function ActivateCode() {
6464 ]);
6565
6666 const goToPassport = useCallback(() => {
67− push(names.PASSPORT);
68−
6967 if (!hasDisclaimed) {
70− push(names.DISCLAIMER);
68+ push(names.DISCLAIMER, { next: names.PASSPORT });
69+ } else {
70+ push(names.PASSPORT);
7171 }
7272 }, [hasDisclaimed, names.DISCLAIMER, names.PASSPORT, push]);
7373
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 <>