├── .eslintrc ├── .gitignore ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.js ├── App.test.js ├── components │ ├── CheckoutPage │ │ ├── CheckoutPage.jsx │ │ ├── CheckoutSuccess │ │ │ ├── CheckoutSuccess.jsx │ │ │ └── index.js │ │ ├── FormModel │ │ │ ├── checkoutFormModel.js │ │ │ ├── formInitialValues.js │ │ │ └── validationSchema.js │ │ ├── Forms │ │ │ ├── AddressForm.jsx │ │ │ └── PaymentForm.jsx │ │ ├── ReviewOrder │ │ │ ├── PaymentDetails.jsx │ │ │ ├── ProductDetails.jsx │ │ │ ├── ReviewOrder.jsx │ │ │ ├── ShippingDetails.jsx │ │ │ ├── index.js │ │ │ └── styles.js │ │ ├── index.js │ │ └── styles.js │ ├── Footer │ │ ├── Footer.jsx │ │ └── index.js │ ├── FormFields │ │ ├── CheckboxField.jsx │ │ ├── DatePickerField.jsx │ │ ├── InputField.jsx │ │ ├── SelectField.jsx │ │ └── index.js │ ├── Header │ │ ├── Header.jsx │ │ ├── index.js │ │ └── styles.js │ └── Layout │ │ ├── MaterialLayout.jsx │ │ └── styles.js ├── index.css ├── index.js ├── logo.svg ├── serviceWorker.js └── setupTests.js └── yarn.lock /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "react-app" 4 | ], 5 | "plugins": [ 6 | "prettier", 7 | "react-hooks" 8 | ], 9 | "rules": { 10 | "prettier/prettier": [ 11 | "error", 12 | { 13 | "singleQuote": true 14 | } 15 | ], 16 | "react-hooks/rules-of-hooks": "error", 17 | "react-hooks/exhaustive-deps": "warn", 18 | "quotes": [ 19 | 2, 20 | "single", 21 | { 22 | "avoidEscape": true 23 | } 24 | ] 25 | } 26 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `yarn start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `yarn test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `yarn build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `yarn eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `yarn build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@date-io/date-fns": "^1.3.13", 7 | "@material-ui/core": "^4.9.0", 8 | "@material-ui/pickers": "^3.2.10", 9 | "@testing-library/jest-dom": "^5.0.2", 10 | "@testing-library/react": "^9.4.0", 11 | "@testing-library/user-event": "^8.1.0", 12 | "date-fns": "^2.9.0", 13 | "formik": "^2.1.3", 14 | "lodash": "^4.17.15", 15 | "moment": "^2.24.0", 16 | "prop-types": "^15.7.2", 17 | "react": "^16.12.0", 18 | "react-dom": "^16.12.0", 19 | "react-scripts": "3.3.0", 20 | "yup": "^0.28.1" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": "react-app" 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | }, 43 | "devDependencies": { 44 | "eslint-plugin-prettier": "^3.1.2", 45 | "eslint-plugin-react": "^7.18.0", 46 | "eslint-plugin-react-hooks": "^2.3.0", 47 | "prettier": "1.19.1" 48 | } 49 | } -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nphivu414/react-multi-step-form/6358e3cf7c3b9e708f4c74d0a516ff79dc94bce4/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nphivu414/react-multi-step-form/6358e3cf7c3b9e708f4c74d0a516ff79dc94bce4/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nphivu414/react-multi-step-form/6358e3cf7c3b9e708f4c74d0a516ff79dc94bce4/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import MaterialLayout from './components/Layout/MaterialLayout'; 3 | import CheckoutPage from './components/CheckoutPage'; 4 | 5 | function App() { 6 | return ( 7 |
8 | 9 | 10 | 11 |
12 | ); 13 | } 14 | 15 | export default App; 16 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/CheckoutPage.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { 3 | Stepper, 4 | Step, 5 | StepLabel, 6 | Button, 7 | Typography, 8 | CircularProgress 9 | } from '@material-ui/core'; 10 | import { Formik, Form } from 'formik'; 11 | 12 | import AddressForm from './Forms/AddressForm'; 13 | import PaymentForm from './Forms/PaymentForm'; 14 | import ReviewOrder from './ReviewOrder'; 15 | import CheckoutSuccess from './CheckoutSuccess'; 16 | 17 | import validationSchema from './FormModel/validationSchema'; 18 | import checkoutFormModel from './FormModel/checkoutFormModel'; 19 | import formInitialValues from './FormModel/formInitialValues'; 20 | 21 | import useStyles from './styles'; 22 | 23 | const steps = ['Shipping address', 'Payment details', 'Review your order']; 24 | const { formId, formField } = checkoutFormModel; 25 | 26 | function _renderStepContent(step) { 27 | switch (step) { 28 | case 0: 29 | return ; 30 | case 1: 31 | return ; 32 | case 2: 33 | return ; 34 | default: 35 | return
Not Found
; 36 | } 37 | } 38 | 39 | export default function CheckoutPage() { 40 | const classes = useStyles(); 41 | const [activeStep, setActiveStep] = useState(0); 42 | const currentValidationSchema = validationSchema[activeStep]; 43 | const isLastStep = activeStep === steps.length - 1; 44 | 45 | function _sleep(ms) { 46 | return new Promise(resolve => setTimeout(resolve, ms)); 47 | } 48 | 49 | async function _submitForm(values, actions) { 50 | await _sleep(1000); 51 | alert(JSON.stringify(values, null, 2)); 52 | actions.setSubmitting(false); 53 | 54 | setActiveStep(activeStep + 1); 55 | } 56 | 57 | function _handleSubmit(values, actions) { 58 | if (isLastStep) { 59 | _submitForm(values, actions); 60 | } else { 61 | setActiveStep(activeStep + 1); 62 | actions.setTouched({}); 63 | actions.setSubmitting(false); 64 | } 65 | } 66 | 67 | function _handleBack() { 68 | setActiveStep(activeStep - 1); 69 | } 70 | 71 | return ( 72 | 73 | 74 | Checkout 75 | 76 | 77 | {steps.map(label => ( 78 | 79 | {label} 80 | 81 | ))} 82 | 83 | 84 | {activeStep === steps.length ? ( 85 | 86 | ) : ( 87 | 92 | {({ isSubmitting }) => ( 93 |
94 | {_renderStepContent(activeStep)} 95 | 96 |
97 | {activeStep !== 0 && ( 98 | 101 | )} 102 |
103 | 112 | {isSubmitting && ( 113 | 117 | )} 118 |
119 |
120 |
121 | )} 122 |
123 | )} 124 |
125 |
126 | ); 127 | } 128 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/CheckoutSuccess/CheckoutSuccess.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Typography } from '@material-ui/core'; 3 | 4 | function CheckoutSuccess() { 5 | return ( 6 | 7 | 8 | Thank you for your order. 9 | 10 | 11 | Your order number is #2001539. We have emailed your order confirmation, 12 | and will send you an update when your order has shipped. 13 | 14 | 15 | ); 16 | } 17 | 18 | export default CheckoutSuccess; 19 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/CheckoutSuccess/index.js: -------------------------------------------------------------------------------- 1 | import CheckoutSuccess from './CheckoutSuccess'; 2 | export default CheckoutSuccess; 3 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/FormModel/checkoutFormModel.js: -------------------------------------------------------------------------------- 1 | export default { 2 | formId: 'checkoutForm', 3 | formField: { 4 | firstName: { 5 | name: 'firstName', 6 | label: 'First name*', 7 | requiredErrorMsg: 'First name is required' 8 | }, 9 | lastName: { 10 | name: 'lastName', 11 | label: 'Last name*', 12 | requiredErrorMsg: 'Last name is required' 13 | }, 14 | address1: { 15 | name: 'address1', 16 | label: 'Address Line 1*', 17 | requiredErrorMsg: 'Address Line 1 is required' 18 | }, 19 | address2: { 20 | name: 'address2', 21 | label: 'Address Line 2' 22 | }, 23 | city: { 24 | name: 'city', 25 | label: 'City*', 26 | requiredErrorMsg: 'City is required' 27 | }, 28 | state: { 29 | name: 'state', 30 | label: 'State/Province/Region' 31 | }, 32 | zipcode: { 33 | name: 'zipcode', 34 | label: 'Zipcode*', 35 | requiredErrorMsg: 'Zipcode is required', 36 | invalidErrorMsg: 'Zipcode is not valid (e.g. 70000)' 37 | }, 38 | country: { 39 | name: 'country', 40 | label: 'Country*', 41 | requiredErrorMsg: 'Country is required' 42 | }, 43 | useAddressForPaymentDetails: { 44 | name: 'useAddressForPaymentDetails', 45 | label: 'Use this address for payment details' 46 | }, 47 | nameOnCard: { 48 | name: 'nameOnCard', 49 | label: 'Name on card*', 50 | requiredErrorMsg: 'Name on card is required' 51 | }, 52 | cardNumber: { 53 | name: 'cardNumber', 54 | label: 'Card number*', 55 | requiredErrorMsg: 'Card number is required', 56 | invalidErrorMsg: 'Card number is not valid (e.g. 4111111111111)' 57 | }, 58 | expiryDate: { 59 | name: 'expiryDate', 60 | label: 'Expiry date*', 61 | requiredErrorMsg: 'Expiry date is required', 62 | invalidErrorMsg: 'Expiry date is not valid' 63 | }, 64 | cvv: { 65 | name: 'cvv', 66 | label: 'CVV*', 67 | requiredErrorMsg: 'CVV is required', 68 | invalidErrorMsg: 'CVV is invalid (e.g. 357)' 69 | } 70 | } 71 | }; 72 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/FormModel/formInitialValues.js: -------------------------------------------------------------------------------- 1 | import checkoutFormModel from './checkoutFormModel'; 2 | const { 3 | formField: { 4 | firstName, 5 | lastName, 6 | address1, 7 | city, 8 | zipcode, 9 | country, 10 | useAddressForPaymentDetails, 11 | nameOnCard, 12 | cardNumber, 13 | expiryDate, 14 | cvv 15 | } 16 | } = checkoutFormModel; 17 | 18 | export default { 19 | [firstName.name]: '', 20 | [lastName.name]: '', 21 | [address1.name]: '', 22 | [city.name]: '', 23 | [zipcode.name]: '', 24 | [country.name]: '', 25 | [useAddressForPaymentDetails.name]: false, 26 | [nameOnCard.name]: '', 27 | [cardNumber.name]: '', 28 | [expiryDate.name]: '', 29 | [cvv.name]: '' 30 | }; 31 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/FormModel/validationSchema.js: -------------------------------------------------------------------------------- 1 | import * as Yup from 'yup'; 2 | import moment from 'moment'; 3 | import checkoutFormModel from './checkoutFormModel'; 4 | const { 5 | formField: { 6 | firstName, 7 | lastName, 8 | address1, 9 | city, 10 | zipcode, 11 | country, 12 | nameOnCard, 13 | cardNumber, 14 | expiryDate, 15 | cvv 16 | } 17 | } = checkoutFormModel; 18 | 19 | const visaRegEx = /^(?:4[0-9]{12}(?:[0-9]{3})?)$/; 20 | 21 | export default [ 22 | Yup.object().shape({ 23 | [firstName.name]: Yup.string().required(`${firstName.requiredErrorMsg}`), 24 | [lastName.name]: Yup.string().required(`${lastName.requiredErrorMsg}`), 25 | [address1.name]: Yup.string().required(`${address1.requiredErrorMsg}`), 26 | [city.name]: Yup.string() 27 | .nullable() 28 | .required(`${city.requiredErrorMsg}`), 29 | [zipcode.name]: Yup.string() 30 | .required(`${zipcode.requiredErrorMsg}`) 31 | .test( 32 | 'len', 33 | `${zipcode.invalidErrorMsg}`, 34 | val => val && val.length === 5 35 | ), 36 | [country.name]: Yup.string() 37 | .nullable() 38 | .required(`${country.requiredErrorMsg}`) 39 | }), 40 | Yup.object().shape({ 41 | [nameOnCard.name]: Yup.string().required(`${nameOnCard.requiredErrorMsg}`), 42 | [cardNumber.name]: Yup.string() 43 | .required(`${cardNumber.requiredErrorMsg}`) 44 | .matches(visaRegEx, cardNumber.invalidErrorMsg), 45 | [expiryDate.name]: Yup.string() 46 | .nullable() 47 | .required(`${expiryDate.requiredErrorMsg}`) 48 | .test('expDate', expiryDate.invalidErrorMsg, val => { 49 | if (val) { 50 | const startDate = new Date(); 51 | const endDate = new Date(2050, 12, 31); 52 | if (moment(val, moment.ISO_8601).isValid()) { 53 | return moment(val).isBetween(startDate, endDate); 54 | } 55 | return false; 56 | } 57 | return false; 58 | }), 59 | [cvv.name]: Yup.string() 60 | .required(`${cvv.requiredErrorMsg}`) 61 | .test('len', `${cvv.invalidErrorMsg}`, val => val && val.length === 3) 62 | }) 63 | ]; 64 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/Forms/AddressForm.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Grid, Typography } from '@material-ui/core'; 3 | import { InputField, CheckboxField, SelectField } from '../../FormFields'; 4 | 5 | const cities = [ 6 | { 7 | value: undefined, 8 | label: 'None' 9 | }, 10 | { 11 | value: '1', 12 | label: 'New York' 13 | }, 14 | { 15 | value: '2', 16 | label: 'Chicago' 17 | }, 18 | { 19 | value: '3', 20 | label: 'Saigon' 21 | } 22 | ]; 23 | 24 | const states = [ 25 | { 26 | value: undefined, 27 | label: 'None' 28 | }, 29 | { 30 | value: '11', 31 | label: 'Florida' 32 | }, 33 | { 34 | value: '22', 35 | label: 'Michigan' 36 | }, 37 | { 38 | value: '33', 39 | label: 'Texas' 40 | } 41 | ]; 42 | 43 | const countries = [ 44 | { 45 | value: null, 46 | label: 'None' 47 | }, 48 | { 49 | value: '111', 50 | label: 'United States' 51 | }, 52 | { 53 | value: '222', 54 | label: 'Italy' 55 | }, 56 | { 57 | value: '333', 58 | label: 'Vietnam' 59 | } 60 | ]; 61 | 62 | export default function AddressForm(props) { 63 | const { 64 | formField: { 65 | firstName, 66 | lastName, 67 | address1, 68 | address2, 69 | city, 70 | state, 71 | zipcode, 72 | country, 73 | useAddressForPaymentDetails 74 | } 75 | } = props; 76 | return ( 77 | 78 | 79 | Shipping address 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 101 | 102 | 103 | 109 | 110 | 111 | 112 | 113 | 114 | 120 | 121 | 122 | 126 | 127 | 128 | 129 | ); 130 | } 131 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/Forms/PaymentForm.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Grid, Typography } from '@material-ui/core'; 3 | import { InputField, DatePickerField } from '../../FormFields'; 4 | 5 | export default function PaymentForm(props) { 6 | const { 7 | formField: { nameOnCard, cardNumber, expiryDate, cvv } 8 | } = props; 9 | 10 | return ( 11 | 12 | 13 | Payment method 14 | 15 | 16 | 17 | 22 | 23 | 24 | 29 | 30 | 31 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | ); 47 | } 48 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/ReviewOrder/PaymentDetails.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import moment from 'moment'; 3 | import { Typography, Grid } from '@material-ui/core'; 4 | import useStyles from './styles'; 5 | 6 | function PaymentDetails(props) { 7 | const { formValues } = props; 8 | const classes = useStyles(); 9 | const { nameOnCard, cardNumber, expiryDate } = formValues; 10 | return ( 11 | 12 | 13 | Payment details 14 | 15 | 16 | 17 | 18 | Card type 19 | 20 | 21 | Visa 22 | 23 | 24 | 25 | 26 | Card holder 27 | 28 | 29 | {nameOnCard} 30 | 31 | 32 | 33 | 34 | Card number 35 | 36 | 37 | {cardNumber} 38 | 39 | 40 | 41 | 42 | Expiry Date 43 | 44 | 45 | 46 | {moment(expiryDate).format('MM/YY')} 47 | 48 | 49 | 50 | 51 | 52 | ); 53 | } 54 | 55 | export default PaymentDetails; 56 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/ReviewOrder/ProductDetails.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Typography, List, ListItem, ListItemText } from '@material-ui/core'; 3 | import useStyles from './styles'; 4 | 5 | const products = [ 6 | { name: 'Product 1', desc: 'A nice thing', price: '$9.99' }, 7 | { name: 'Product 2', desc: 'Another thing', price: '$3.45' }, 8 | { name: 'Product 3', desc: 'Something else', price: '$6.51' }, 9 | { name: 'Product 4', desc: 'Best thing of all', price: '$14.11' }, 10 | { name: 'Shipping', desc: '', price: 'Free' } 11 | ]; 12 | 13 | function ProductDetails() { 14 | const classes = useStyles(); 15 | return ( 16 | 17 | {products.map(product => ( 18 | 19 | 20 | {product.price} 21 | 22 | ))} 23 | 24 | 25 | 26 | $34.06 27 | 28 | 29 | 30 | ); 31 | } 32 | 33 | export default ProductDetails; 34 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/ReviewOrder/ReviewOrder.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { useFormikContext } from 'formik'; 3 | import { Typography, Grid } from '@material-ui/core'; 4 | import ProductDetails from './ProductDetails'; 5 | import ShippingDetails from './ShippingDetails'; 6 | import PaymentDetails from './PaymentDetails'; 7 | 8 | export default function ReviewOrder() { 9 | const { values: formValues } = useFormikContext(); 10 | return ( 11 | 12 | 13 | Order summary 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/ReviewOrder/ShippingDetails.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Typography, Grid } from '@material-ui/core'; 3 | import useStyles from './styles'; 4 | 5 | function PaymentDetails(props) { 6 | const { formValues } = props; 7 | const classes = useStyles(); 8 | const { firstName, lastName, address1 } = formValues; 9 | return ( 10 | 11 | 12 | Shipping 13 | 14 | {`${firstName} ${lastName}`} 15 | {`${address1}`} 16 | 17 | ); 18 | } 19 | 20 | export default PaymentDetails; 21 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/ReviewOrder/index.js: -------------------------------------------------------------------------------- 1 | import ReviewOrder from './ReviewOrder'; 2 | export default ReviewOrder; 3 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/ReviewOrder/styles.js: -------------------------------------------------------------------------------- 1 | import { makeStyles } from '@material-ui/core/styles'; 2 | export default makeStyles(theme => ({ 3 | listItem: { 4 | padding: theme.spacing(1, 0) 5 | }, 6 | total: { 7 | fontWeight: '700' 8 | }, 9 | title: { 10 | marginTop: theme.spacing(2) 11 | } 12 | })); 13 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/index.js: -------------------------------------------------------------------------------- 1 | import CheckoutPage from './CheckoutPage'; 2 | export default CheckoutPage; 3 | -------------------------------------------------------------------------------- /src/components/CheckoutPage/styles.js: -------------------------------------------------------------------------------- 1 | import { makeStyles } from '@material-ui/core/styles'; 2 | export default makeStyles(theme => ({ 3 | stepper: { 4 | padding: theme.spacing(3, 0, 5) 5 | }, 6 | buttons: { 7 | display: 'flex', 8 | justifyContent: 'flex-end' 9 | }, 10 | button: { 11 | marginTop: theme.spacing(3), 12 | marginLeft: theme.spacing(1) 13 | }, 14 | wrapper: { 15 | margin: theme.spacing(1), 16 | position: 'relative' 17 | }, 18 | buttonProgress: { 19 | position: 'absolute', 20 | top: '50%', 21 | left: '50%' 22 | } 23 | })); 24 | -------------------------------------------------------------------------------- /src/components/Footer/Footer.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Link, Typography } from '@material-ui/core/'; 3 | 4 | export default function Footer() { 5 | return ( 6 | 7 | {'Copyright © '} 8 | 9 | Your Website 10 | 11 | {new Date().getFullYear()} 12 | 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /src/components/Footer/index.js: -------------------------------------------------------------------------------- 1 | import Footer from './Footer'; 2 | export default Footer; 3 | -------------------------------------------------------------------------------- /src/components/FormFields/CheckboxField.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { at } from 'lodash'; 3 | import { useField } from 'formik'; 4 | import { 5 | Checkbox, 6 | FormControl, 7 | FormControlLabel, 8 | FormHelperText 9 | } from '@material-ui/core'; 10 | 11 | export default function CheckboxField(props) { 12 | const { label, ...rest } = props; 13 | const [field, meta, helper] = useField(props); 14 | const { setValue } = helper; 15 | 16 | function _renderHelperText() { 17 | const [touched, error] = at(meta, 'touched', 'error'); 18 | if (touched && error) { 19 | return {error}; 20 | } 21 | } 22 | 23 | function _onChange(e) { 24 | setValue(e.target.checked); 25 | } 26 | 27 | return ( 28 | 29 | } 33 | label={label} 34 | /> 35 | {_renderHelperText()} 36 | 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /src/components/FormFields/DatePickerField.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | import { useField } from 'formik'; 3 | import Grid from '@material-ui/core/Grid'; 4 | import { 5 | MuiPickersUtilsProvider, 6 | KeyboardDatePicker 7 | } from '@material-ui/pickers'; 8 | import DateFnsUtils from '@date-io/date-fns'; 9 | 10 | export default function DatePickerField(props) { 11 | const [field, meta, helper] = useField(props); 12 | const { touched, error } = meta; 13 | const { setValue } = helper; 14 | const isError = touched && error && true; 15 | const { value } = field; 16 | const [selectedDate, setSelectedDate] = useState(null); 17 | 18 | useEffect(() => { 19 | if (value) { 20 | const date = new Date(value); 21 | setSelectedDate(date); 22 | } 23 | }, [value]); 24 | 25 | function _onChange(date) { 26 | if (date) { 27 | setSelectedDate(date); 28 | try { 29 | const ISODateString = date.toISOString(); 30 | setValue(ISODateString); 31 | } catch (error) { 32 | setValue(date); 33 | } 34 | } else { 35 | setValue(date); 36 | } 37 | } 38 | 39 | return ( 40 | 41 | 42 | 51 | 52 | 53 | ); 54 | } 55 | -------------------------------------------------------------------------------- /src/components/FormFields/InputField.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { at } from 'lodash'; 3 | import { useField } from 'formik'; 4 | import { TextField } from '@material-ui/core'; 5 | 6 | export default function InputField(props) { 7 | const { errorText, ...rest } = props; 8 | const [field, meta] = useField(props); 9 | 10 | function _renderHelperText() { 11 | const [touched, error] = at(meta, 'touched', 'error'); 12 | if (touched && error) { 13 | return error; 14 | } 15 | } 16 | 17 | return ( 18 | 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /src/components/FormFields/SelectField.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import { at } from 'lodash'; 4 | import { useField } from 'formik'; 5 | import { 6 | InputLabel, 7 | FormControl, 8 | Select, 9 | MenuItem, 10 | FormHelperText 11 | } from '@material-ui/core'; 12 | 13 | function SelectField(props) { 14 | const { label, data, ...rest } = props; 15 | const [field, meta] = useField(props); 16 | const { value: selectedValue } = field; 17 | const [touched, error] = at(meta, 'touched', 'error'); 18 | const isError = touched && error && true; 19 | function _renderHelperText() { 20 | if (isError) { 21 | return {error}; 22 | } 23 | } 24 | 25 | return ( 26 | 27 | {label} 28 | 35 | {_renderHelperText()} 36 | 37 | ); 38 | } 39 | 40 | SelectField.defaultProps = { 41 | data: [] 42 | }; 43 | 44 | SelectField.propTypes = { 45 | data: PropTypes.array.isRequired 46 | }; 47 | 48 | export default SelectField; 49 | -------------------------------------------------------------------------------- /src/components/FormFields/index.js: -------------------------------------------------------------------------------- 1 | import InputField from './InputField'; 2 | import CheckboxField from './CheckboxField'; 3 | import SelectField from './SelectField'; 4 | import DatePickerField from './DatePickerField'; 5 | export { InputField, CheckboxField, SelectField, DatePickerField }; 6 | -------------------------------------------------------------------------------- /src/components/Header/Header.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import AppBar from '@material-ui/core/AppBar'; 3 | import Toolbar from '@material-ui/core/Toolbar'; 4 | import Typography from '@material-ui/core/Typography'; 5 | import useStyles from './styles'; 6 | 7 | export default function Header() { 8 | const classes = useStyles(); 9 | 10 | return ( 11 | 12 | 13 | 14 | Company name 15 | 16 | 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /src/components/Header/index.js: -------------------------------------------------------------------------------- 1 | import Header from './Header'; 2 | export default Header; 3 | -------------------------------------------------------------------------------- /src/components/Header/styles.js: -------------------------------------------------------------------------------- 1 | import { makeStyles } from '@material-ui/core/styles'; 2 | export default makeStyles(theme => ({ 3 | appBar: { 4 | position: 'relative' 5 | } 6 | })); 7 | -------------------------------------------------------------------------------- /src/components/Layout/MaterialLayout.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Paper, CssBaseline } from '@material-ui/core'; 3 | import { ThemeProvider } from '@material-ui/core/styles'; 4 | 5 | import Header from '../Header'; 6 | import Footer from '../Footer'; 7 | 8 | import { theme, useStyle } from './styles'; 9 | 10 | export default function MaterialLayout(props) { 11 | const { children } = props; 12 | const classes = useStyle(); 13 | 14 | return ( 15 | 16 | 17 |
18 |
19 | {children} 20 |
21 |