diff --git a/package.json b/package.json index a36627c1..78e5acc8 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "@fortawesome/free-brands-svg-icons": "5.15.2", "@fortawesome/free-solid-svg-icons": "5.15.2", "@fortawesome/react-fontawesome": "0.1.14", + "@hcaptcha/react-hcaptcha": "^0.3.2", "@sentry/react": "6.1.0", "@svgr/webpack": "5.5.0", "@swc/core": "1.2.47", @@ -20,9 +21,11 @@ "react": "17.0.1", "react-app-polyfill": "2.0.0", "react-dom": "17.0.1", + "react-redux": "^7.2.2", "react-router-dom": "5.2.0", "react-spinners": "0.10.4", "react-transition-group": "4.4.1", + "redux": "^4.0.5", "smoothscroll-polyfill": "0.4.4", "swc-loader": "0.1.12", "typescript": "4.1.5", @@ -57,12 +60,15 @@ "@testing-library/jest-dom": "5.11.9", "@testing-library/react": "11.2.5", "@testing-library/user-event": "12.6.3", + "@types/hcaptcha__react-hcaptcha": "^0.1.4", "@types/jest": "26.0.20", "@types/node": "14.14.25", "@types/react": "17.0.1", "@types/react-dom": "17.0.0", + "@types/react-redux": "^7.1.16", "@types/react-router-dom": "5.1.7", "@types/react-transition-group": "4.4.0", + "@types/redux": "^3.6.0", "@types/smoothscroll-polyfill": "0.3.1", "@typescript-eslint/eslint-plugin": "4.15.0", "@typescript-eslint/parser": "4.15.0", diff --git a/src/App.tsx b/src/App.tsx index 523e5834..14e53291 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,6 +3,7 @@ import React, { Suspense } from "react"; import { jsx, css, Global } from "@emotion/react"; +import { Provider } from "react-redux"; import { BrowserRouter as Router, Route, @@ -14,6 +15,7 @@ import { PropagateLoader } from "react-spinners"; import { CSSTransition, TransitionGroup } from "react-transition-group"; import globalStyles from "./globalStyles"; +import { store } from "./store/form/store"; const LandingPage = React.lazy(() => import("./pages/LandingPage")); const FormPage = React.lazy(() => import("./pages/FormPage")); @@ -51,7 +53,7 @@ function App(): JSX.Element { {routes.map(({path, Component}) => ( }> - + {path == "/form/:id" ? : } ))} diff --git a/src/components/InputTypes/Checkbox.tsx b/src/components/InputTypes/Checkbox.tsx index 3093caf6..9c633f0b 100644 --- a/src/components/InputTypes/Checkbox.tsx +++ b/src/components/InputTypes/Checkbox.tsx @@ -3,11 +3,15 @@ import { jsx, css } from "@emotion/react"; import React, { ChangeEvent } from "react"; import colors from "../../colors"; import { multiSelectInput, hiddenInput } from "../../commonStyles"; +import { useSelector } from "react-redux"; +import { FormState } from "../../store/form/types"; +import { Question } from "../../api/question"; interface CheckboxProps { index: number, option: string, - handler: (event: ChangeEvent) => void + handler: (event: ChangeEvent) => void, + question: Question } const generalStyles = css` @@ -53,10 +57,19 @@ const activeStyles = css` `; export default function Checkbox(props: CheckboxProps): JSX.Element { + const values = useSelector( + state => state.values + ); + let value = values[props.question.id]; + if (typeof value !== "object" || !value) { + value = {}; + } + const checked = value[`${("000" + props.index).slice(-4)}. ${props.option}`]; + return (