Skip to content

Commit

Permalink
fix(options): browser icon bypasses TOS acceptation (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
JalilArfaoui committed Oct 8, 2019
1 parent 283e9be commit be25714
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 41 deletions.
13 changes: 7 additions & 6 deletions src/app/options/App/Onboarding/TOS/TOS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const TOSListItem = styled.li`

interface TosProps {
updatedFromLmem: boolean;
termsOfServiceAccepted: boolean;
termsOfServiceAccepted?: boolean;
onContinue: () => void;
}

Expand Down Expand Up @@ -143,11 +143,12 @@ export default ({
</>
)}

{termsOfServiceAccepted ? (
<TOSAlreadyAccepted />
) : (
<TOSCheckbox onChange={setTosChecked} checked={acceptTosChecked} />
)}
{termsOfServiceAccepted !== undefined &&
(termsOfServiceAccepted ? (
<TOSAlreadyAccepted />
) : (
<TOSCheckbox onChange={setTosChecked} checked={acceptTosChecked} />
))}

<OnboardinButton
disabled={!acceptTosChecked && !termsOfServiceAccepted}
Expand Down
8 changes: 4 additions & 4 deletions src/app/options/App/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface Props extends RouteComponentProps {
currentScreen: OptionsScreen | null;
goToSubscriptions: () => void;
goToSuggestions: () => void;
tosAccepted: boolean;
tosAccepted?: boolean;
}

const UI = ({
Expand All @@ -21,7 +21,9 @@ const UI = ({
match,
tosAccepted
}: Props) =>
tosAccepted ? (
tosAccepted === false ? (
<Redirect to={'/onboarding'} />
) : (
<>
<Header />

Expand All @@ -43,8 +45,6 @@ const UI = ({
/>
</Switch>
</>
) : (
<Redirect to={'/onboarding'} />
);

export default withConnect(UI);
6 changes: 3 additions & 3 deletions src/app/options/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { connectRouter, RouterRootState } from 'connected-react-router';
import { combineReducers } from 'redux';
import { History } from 'history';
import contributors, { ContributorsState } from './contributors.reducer';
import tosAccepted, { TosAcceptedState } from './tosAccepted.reducer';
import tos, { TosState } from './tos.reducer';
import installationDetails, {
InstallationDetailsState
} from 'app/background/reducers/installationDetails';
Expand All @@ -12,11 +12,11 @@ export default (history: History) =>
router: connectRouter(history),
contributors,
installationDetails,
tosAccepted
tos
});

export interface OptionsState extends RouterRootState {
contributors: ContributorsState;
installationDetails: InstallationDetailsState;
tosAccepted: TosAcceptedState;
tos: TosState;
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/* eslint-disable no-unused-expressions, @typescript-eslint/ban-ts-ignore */
import { expect } from 'chai';
import { tosAccepted, transmitTosStatus } from 'app/actions';
import tosAcceptedReducer from './tosAccepted.reducer';
import tosAcceptedReducer from './tos.reducer';

describe('options > reducers > tosAccepted', function() {
// @ts-ignore
const initialState = tosAcceptedReducer(undefined, { type: 'UNKNOWN' });

it('is false initially', () => {
expect(initialState).to.be.false;
it('is empty initially', () => {
expect(initialState).to.eql({});
});
it('saves true on TOS_ACCEPTED', () => {
expect(tosAcceptedReducer(initialState, tosAccepted({}))).to.be.true;
expect(tosAcceptedReducer(initialState, tosAccepted({}))).to.be.eql({
tosAccepted: true
});
});
it('saves given value on TRANSMIT_TOS_STATUS', () => {
expect(tosAcceptedReducer(initialState, transmitTosStatus(false))).to.be
.false;
expect(tosAcceptedReducer(initialState, transmitTosStatus(true))).to.be
.true;
expect(
tosAcceptedReducer(initialState, transmitTosStatus(false))
).to.be.eql({ tosAccepted: false });
expect(tosAcceptedReducer(initialState, transmitTosStatus(true))).to.be.eql(
{ tosAccepted: true }
);
});
});
17 changes: 17 additions & 0 deletions src/app/options/store/reducers/tos.reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as R from 'ramda';
import { AppAction, TRANSMIT_TOS_STATUS } from 'app/actions';

export interface TosState {
tosAccepted?: boolean;
}

export default (state: TosState = {}, action: AppAction): TosState => {
switch (action.type) {
case 'TOS_ACCEPTED':
return R.assoc('tosAccepted', true, state);
case TRANSMIT_TOS_STATUS:
return R.assoc('tosAccepted', action.payload, state);
default:
return state;
}
};
17 changes: 0 additions & 17 deletions src/app/options/store/reducers/tosAccepted.reducer.ts

This file was deleted.

9 changes: 6 additions & 3 deletions src/app/options/store/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { TosAcceptedState } from '../reducers/tosAccepted.reducer';
import { TosState } from '../reducers/tos.reducer';

export const areTosAccepted = (state: { tosAccepted: TosAcceptedState }) =>
state.tosAccepted;
interface StateWithTos {
tos: TosState;
}

export const areTosAccepted = (state: StateWithTos) => state.tos.tosAccepted;

0 comments on commit be25714

Please sign in to comment.