Skip to content

Commit

Permalink
created checkbox component and wired up subscribed to mailing list
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilt committed Jun 14, 2018
1 parent 8376079 commit ab12bdd
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"no-trailing-spaces":["error"], // disallow trailing whitespace at the end of lines
"no-underscore-dangle":["off"], // disallow dangling underscores in identifiers
"no-mixed-spaces-and-tabs":["error"], // disallow mixed spaces and tabs for indentation
"quotes": ["error", "backtick"], // specify whether double or single quotes should be used
"quotes": ["error", "single"], // specify whether double or single quotes should be used
"quote-props":["off"], // require quotes around object literal property names (off by default)
"semi":["error"], // require or disallow use of semicolons instead of ASI
"sort-vars":["off"], // sort variables within the same declaration block (off by default)
Expand Down
52 changes: 52 additions & 0 deletions src/components/Checkbox/Checkbox.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { PureComponent } from 'react';

import PropTypes from 'prop-types';

import './Checkbox.css';

const greenCheckmark = require('./check.svg');

export default class Checkbox extends PureComponent {
static propTypes = {
onChange: PropTypes.func.isRequired,
label: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
checked: PropTypes.bool.isRequired,
};

static defaultProps = {
checked: false,
};

handleOnChange = ({ target: { checked } }) => {
const { onChange } = this.props;

onChange(checked);
};

render() {
const { id, checked, label } = this.props;

return (
<label htmlFor={id} className={'Checkbox__container'}>
<div className={'Checkbox__input-container'}>
<input
type={'checkbox'}
className={'visuallyhidden'}
id={id}
onChange={this.handleOnChange}
checked={checked}
/>
{checked && (
<img
className={'Checkbox__check'}
src={greenCheckmark}
alt={'checked'}
/>
)}
</div>
<div className={'Checkbox_label'}>{label}</div>
</label>
);
}
}
27 changes: 27 additions & 0 deletions src/components/Checkbox/Checkbox.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.Checkbox__container {
display: flex;
}

.Checkbox__input-container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 34px;
height: 34px;
background-color: #F7F7F7;
border-radius: 5px;
border: 2px solid #F1F1F1;
}

.Checkbox_label {
color: #333;
font-size: 1.4rem;
margin-left: 10px;
}

.Checkbox__check {
width: 18px;
height: 14px;
}
14 changes: 14 additions & 0 deletions src/components/Checkbox/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/components/Checkbox/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Checkbox } from "./Checkbox.component";
8 changes: 4 additions & 4 deletions src/components/Completed/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./Completed";
export * from "./CompletedHeader";
export * from "./CompletedResultsList";
export * from "./Results";
export * from './Completed';
export * from './CompletedHeader';
export * from './CompletedResultsList';
export * from './Results';
6 changes: 3 additions & 3 deletions src/components/EmailCapture/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./EmailCapture";
export * from "./EmailCaptureContinueButton";
export * from "./EmailCaptureEmailInput";
export * from './EmailCapture';
export * from './EmailCaptureContinueButton';
export * from './EmailCaptureEmailInput';
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { PureComponent } from "react";
import {
NameCaptureNameInput,
NameCaptureContinueButton,
SubscribeToMailingListCheckbox,
} from "src/components";

import "./NameCapture.css";
Expand All @@ -17,6 +18,7 @@ export default class NameCapture extends PureComponent {
</p>
<div className={`NameCapture__form-wrapper`}>
<NameCaptureNameInput />
<SubscribeToMailingListCheckbox/>
<div className={`NameCapture__continue-button`}>
<NameCaptureContinueButton />
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/NameCapture/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./NameCapture";
export * from "./NameCaptureContinueButton";
export * from "./NameCaptureNameInput";
export * from './NameCapture';
export * from './NameCaptureContinueButton';
export * from './NameCaptureNameInput';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { PureComponent } from "react";

import PropTypes from "prop-types";

import { Checkbox } from "src/components";

export default class SubscribeToMailingListCheckbox extends PureComponent {
static propTypes = {
onChange: PropTypes.func.isRequired,
checked: PropTypes.bool.isRequired,
};

render() {
return (
<Checkbox
{...this.props}
id='mailing-list-checkbox'
label={`Yes, I would like to receive periodic updates from Dan Wilt Coaching.`}
/>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { connect } from 'react-redux';

import { subscribedToMailingListSelector } from 'src/selectors';

import { toggleSubscribedToMailingListAction as onChange } from 'src/store/quiz/quiz.actions';

import SubscribeToMailingListCheckbox from './SubscribeToMailingListCheckbox.component';

export default connect((st) => ({
checked: subscribedToMailingListSelector(st),
}), {
onChange,
})(SubscribeToMailingListCheckbox);
1 change: 1 addition & 0 deletions src/components/SubscribeToMailingListCheckbox/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as SubscribeToMailingListCheckbox } from './SubscribeToMailingListCheckbox.container';
30 changes: 16 additions & 14 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
export * from "./ActionButton";
export * from "./ActivityIndicator";
export * from "./Answer";
export * from "./App";
export * from "./CodeFigure";
export * from "./Completed";
export * from "./EmailCapture";
export * from "./NameCapture";
export * from "./Question";
export * from "./QuestionAnswer";
export * from "./Quiz";
export * from "./QuizProgressIndicator";
export * from "./QuizQuestion";
export * from "./TextInput";
export * from './ActionButton';
export * from './ActivityIndicator';
export * from './Answer';
export * from './App';
export * from './Checkbox';
export * from './CodeFigure';
export * from './Completed';
export * from './EmailCapture';
export * from './NameCapture';
export * from './Question';
export * from './QuestionAnswer';
export * from './Quiz';
export * from './QuizProgressIndicator';
export * from './QuizQuestion';
export * from './SubscribeToMailingListCheckbox';
export * from './TextInput';
20 changes: 10 additions & 10 deletions src/selectors/quiz.selectors.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import { createSelector } from "reselect";
import { createSelector } from 'reselect';

import { questions } from "src/questions";
import { questions } from 'src/questions';

import { isValidEmail } from "src/helpers";
import { isValidEmail } from 'src/helpers';

const quizSelector = (state) => state.quiz;
const quizSelector = ({ quiz }) => quiz;

export const quizStateSelector = createSelector(
quizSelector,
(quiz) => quiz.state
({ state }) => state
);

export const quizSelectedAnswerSelector = createSelector(
quizSelector,
(quiz) => quiz.selectedAnswer
({ selectedAnswer }) => selectedAnswer
);

export const quizAnswersSelector = createSelector(
quizSelector,
(quiz) => quiz.answers
({ answers }) => answers
);

export const quizNameSelector = createSelector(quizSelector, (quiz) => quiz.name);
export const quizNameSelector = createSelector(quizSelector, ({ name }) => name);

export const quizEmailSelector = createSelector(
quizSelector,
(quiz) => quiz.email
({ email }) => email
);

export const quizEmailIsValidSelector = createSelector(
Expand All @@ -45,7 +45,7 @@ export const quizQuestionIdSelector = createSelector(

export const subscribedToMailingListSelector = createSelector(
[quizSelector],
(quiz) => quiz.subscribedToMailingList
({ subscribedToMailingList }) => subscribedToMailingList
);

export const quizScoreSelector = createSelector(
Expand Down
8 changes: 2 additions & 6 deletions src/store/quiz/quiz.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ export const addAnswerAction = (answer) => ({
},
});

export const subscribeToMailingListAction = () => ({
type: `SUBSCRIBE_TO_MAILING_LIST`,
});

export const unsubscribeToMailingListAction = () => ({
type: `UNSUBSCRIBE_TO_MAILING_LIST`,
export const toggleSubscribedToMailingListAction = () => ({
type: `TOGGLE_SUBSCRIBED_TO_MAILING_LIST`,
});

export const submitAnswerAction = () => ({
Expand Down
23 changes: 9 additions & 14 deletions src/store/quiz/quiz.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import {
addAnswerAction,
setNameAction,
setEmailAction,
subscribeToMailingListAction,
unsubscribeToMailingListAction,
} from "./quiz.actions";
toggleSubscribedToMailingListAction,
} from './quiz.actions';

import { createReducer } from "src/helpers";
import { createReducer } from 'src/helpers';

export default createReducer(
{
state: `nameCapture`,
state: 'nameCapture',
selectedAnswer: null,
answers: [],
email: ``,
name: ``,
subscribedToMailingList: false,
email: '',
name: '',
subscribedToMailingList: true,
},
{
[setStateAction().type]: (st, { state }) => ({
Expand All @@ -40,13 +39,9 @@ export default createReducer(
...st,
email,
}),
[subscribeToMailingListAction().type]: (st) => ({
[toggleSubscribedToMailingListAction().type]: (st) => ({
...st,
subscribedToMailingList: true,
}),
[unsubscribeToMailingListAction().type]: (st) => ({
...st,
subscribedToMailingList: false,
subscribedToMailingList: !st.subscribedToMailingList,
}),
}
);

0 comments on commit ab12bdd

Please sign in to comment.