├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json └── src ├── App.js ├── QuizForm.js ├── QuizFormResult.js ├── index.js ├── registerServiceWorker.js ├── store.js └── validate.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Wing Kam Wong 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-quiz-form 2 | A redux form for creating quizzes in React 3 | 4 | react-quiz-form is a ReactJS component integrated with [Redux From](https://github.com/erikras/redux-form). It aims to allow users to create a quiz manually and outputs a JSON file for [react-quiz-component](https://github.com/wingkwong/react-quiz-component) to process. 5 | 6 | >> react-quiz-form currently only supports [react-quiz-component](https://github.com/wingkwong/react-quiz-component) v0.2.8. 7 | 8 | ## Structure breakdown: 9 | - Quiz Title 10 | - Quiz Synopsis 11 | - Questions 12 | - Title 13 | - Type (Text or Photo) 14 | - Answers 15 | - Answer #n (Max number of n: 4) 16 | - Correct Answer 17 | - Message for Correct Answer 18 | - Message for Incorrect Answer 19 | - Explaination 20 | - Point 21 | 22 | ## Validation 23 | - All fields are required except `messageForCorrectAnswer`, `messageForIncorrectAnswer`, and `explanation` 24 | - At least one question has to be created 25 | - At least two answers have to be created 26 | - Max four answers in one question are allowed 27 | 28 | ## Result 29 | ```json 30 | { 31 | "quizTitle": "React Quiz Demo - https://github.com/wingkwong/react-quiz", 32 | "quizSynopsis": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim", 33 | "questions": [ 34 | { 35 | "question": "How can you access the state of a component from inside of a member function?", 36 | "questionType": "text", 37 | "answers": [ 38 | "this.getState()", 39 | "this.prototype.stateValue", 40 | "this.state", 41 | "this.values" 42 | ], 43 | "correctAnswer": "3", 44 | "messageForCorrectAnswer": "Correct answer. Good job.", 45 | "messageForIncorrectAnswer": "Incorrect answer. Please try again.", 46 | "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", 47 | "point": "20" 48 | }, 49 | { 50 | "question": "ReactJS is developed by _____?", 51 | "questionType": "text", 52 | "answers": [ 53 | "Google Engineers", 54 | "Facebook Engineers" 55 | ], 56 | "correctAnswer": "2", 57 | "messageForCorrectAnswer": "Correct answer. Good job.", 58 | "messageForIncorrectAnswer": "Incorrect answer. Please try again.", 59 | "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", 60 | "point": "20" 61 | }, 62 | { 63 | "question": "ReactJS is an MVC based framework?", 64 | "questionType": "text", 65 | "answers": [ 66 | "True", 67 | "False" 68 | ], 69 | "correctAnswer": "2", 70 | "messageForCorrectAnswer": "Correct answer. Good job.", 71 | "messageForIncorrectAnswer": "Incorrect answer. Please try again.", 72 | "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", 73 | "point": "20" 74 | }, 75 | { 76 | "question": "Which of the following concepts is/are key to ReactJS?", 77 | "questionType": "text", 78 | "answers": [ 79 | "Component-oriented design", 80 | "Event delegation model", 81 | "Both of the above", 82 | ], 83 | "correctAnswer": "3", 84 | "messageForCorrectAnswer": "Correct answer. Good job.", 85 | "messageForIncorrectAnswer": "Incorrect answer. Please try again.", 86 | "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", 87 | "point": "20" 88 | }, 89 | { 90 | "question": "Lorem ipsum dolor sit amet, consectetur adipiscing elit,", 91 | "questionType": "photo", 92 | "answers": [ 93 | "https://dummyimage.com/600x400/000/fff&text=A", 94 | "https://dummyimage.com/600x400/000/fff&text=B", 95 | "https://dummyimage.com/600x400/000/fff&text=C", 96 | "https://dummyimage.com/600x400/000/fff&text=D" 97 | ], 98 | "correctAnswer": "1", 99 | "messageForCorrectAnswer": "Correct answer. Good job.", 100 | "messageForIncorrectAnswer": "Incorrect answer. Please try again.", 101 | "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", 102 | "point": "20" 103 | } 104 | ] 105 | } 106 | ``` 107 | 108 | ## Development 109 | - Clone the project 110 | - run `npm install` 111 | - run `npm run start` 112 | 113 | ## Demo 114 | The demo is available at https://wingkwong.github.io/react-quiz-form/ 115 | 116 | ## License 117 | This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-quiz-form", 3 | "version": "0.1.3", 4 | "private": true, 5 | "homepage": "https://wingkwong.github.io/react-quiz-form/", 6 | "dependencies": { 7 | "react": "^16.3.2", 8 | "react-copy-to-clipboard": "^5.0.1", 9 | "react-dom": "^16.3.2", 10 | "react-redux": "^5.0.7", 11 | "react-scripts": "1.1.4", 12 | "redux": "^4.0.0", 13 | "redux-form": "^7.3.0" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test --env=jsdom", 19 | "eject": "react-scripts eject", 20 | "predeploy": "npm run build", 21 | "deploy": "gh-pages -d build" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wingkwong/react-quiz-form/0c1dd8ba250e778c3d2555e1257fdfeb13af835d/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | 15 | 24 | Reac Quiz Form 25 | 26 | 27 | 30 |
31 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /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 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import QuizForm from './QuizForm'; 3 | import QuizFormResult from './QuizFormResult'; 4 | 5 | class App extends Component { 6 | constructor(props){ 7 | super(props); 8 | this.state = { 9 | result : null 10 | } 11 | } 12 | 13 | setResult = (values) =>{ 14 | this.setState({ 15 | result : JSON.stringify(values, null, 2) 16 | }) 17 | } 18 | 19 | render() { 20 | return ( 21 |
22 | 23 | 24 |
25 | ); 26 | } 27 | } 28 | 29 | export default App; -------------------------------------------------------------------------------- /src/QuizForm.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { connect } from 'react-redux' 3 | import { Field, FieldArray, reduxForm, formValueSelector } from 'redux-form'; 4 | import range from 'lodash/range' 5 | import validate from './validate'; 6 | 7 | class QuizForm extends Component { 8 | 9 | renderInputField = ({ input, label, type, meta: { touched, error } }) => ( 10 |
11 | 12 |
13 | 14 | {touched && error && {error}} 15 |
16 |
17 | ); 18 | 19 | renderTextareaField = ({ input, label, type, meta: { touched, error } }) => ( 20 |
21 | 22 |
23 |