From 1381bb352c95578aaa1db19a92bb81238f53f2f1 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Fri, 19 Feb 2021 17:30:22 +0200 Subject: [PATCH 01/12] Add hCaptcha dependencies --- package.json | 2 ++ yarn.lock | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/package.json b/package.json index a36627c1..716f80b1 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,11 @@ "@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", + "@types/hcaptcha__react-hcaptcha": "^0.1.4", "axios": "0.21.1", "copy-webpack-plugin": "7.0.0", "fs-extra": "9.1.0", diff --git a/yarn.lock b/yarn.lock index 63e5b831..0d714d25 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1296,6 +1296,11 @@ dependencies: "@hapi/hoek" "^8.3.0" +"@hcaptcha/react-hcaptcha@^0.3.2": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@hcaptcha/react-hcaptcha/-/react-hcaptcha-0.3.2.tgz#8910ea4c111799336fb64de6aa7b74329a7d7579" + integrity sha512-+90hSDwtnKAk3PXJsyABi+wRHS1B+wgWjDO4nz68KpkLnE73rMz/XMdl+ckrwYkFFilzIDKI3o1IqOpMapEwgg== + "@istanbuljs/load-nyc-config@^1.0.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced" @@ -2011,6 +2016,13 @@ dependencies: "@types/node" "*" +"@types/hcaptcha__react-hcaptcha@^0.1.4": + version "0.1.4" + resolved "https://registry.yarnpkg.com/@types/hcaptcha__react-hcaptcha/-/hcaptcha__react-hcaptcha-0.1.4.tgz#145cab4f0ac29fe8925dc98ab16cf2dffacad7d5" + integrity sha512-eqEIBR7yn4Y1fRtxPnFlEP8SAHwX762Z27s/ifd5wfJicviz6HynF8gHCgUPPtfYlaQFHa/A0NkwBA5YNmNCmQ== + dependencies: + "@types/react" "*" + "@types/history@*": version "4.7.8" resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.8.tgz#49348387983075705fe8f4e02fb67f7daaec4934" From 15a4a8654a5ee6b0ce9bd084da1285c98f88d388 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Sat, 20 Feb 2021 10:37:24 +0200 Subject: [PATCH 02/12] Add Redux and React Redux dependencies --- package.json | 2 ++ yarn.lock | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 716f80b1..5334b6c2 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,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", diff --git a/yarn.lock b/yarn.lock index 0d714d25..8b6619ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -974,6 +974,13 @@ dependencies: regenerator-runtime "^0.13.4" +"@babel/runtime@^7.12.1": + version "7.12.18" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.18.tgz#af137bd7e7d9705a412b3caaf991fe6aaa97831b" + integrity sha512-BogPQ7ciE6SYAUPtlm9tWbgI9+2AgqSam6QivMgXgAT+fKbgppaj4ZX15MHeLC1PVF5sNk70huBu20XxWOs8Cg== + dependencies: + regenerator-runtime "^0.13.4" + "@babel/template@^7.10.4": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.10.4.tgz#3251996c4200ebc71d1a8fc405fba940f36ba278" @@ -7271,7 +7278,7 @@ react-dom@17.0.1: object-assign "^4.1.1" scheduler "^0.20.1" -react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1: +react-is@^16.13.1, react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== @@ -7281,6 +7288,17 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339" integrity sha512-NAnt2iGDXohE5LI7uBnLnqvLQMtzhkiAOLXTmv+qnF9Ky7xAPcX8Up/xWIhxvLVGJvuLiNc4xQLtuqDRzb4fSA== +react-redux@^7.2.2: + version "7.2.2" + resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.2.tgz#03862e803a30b6b9ef8582dadcc810947f74b736" + integrity sha512-8+CQ1EvIVFkYL/vu6Olo7JFLWop1qRUeb46sGtIMDCSpgwPQq8fPLpirIB0iTqFe9XYEFPHssdX8/UwN6pAkEA== + dependencies: + "@babel/runtime" "^7.12.1" + hoist-non-react-statics "^3.3.2" + loose-envify "^1.4.0" + prop-types "^15.7.2" + react-is "^16.13.1" + react-router-dom@5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.2.0.tgz#9e65a4d0c45e13289e66c7b17c7e175d0ea15662" @@ -7424,6 +7442,14 @@ redent@^3.0.0: indent-string "^4.0.0" strip-indent "^3.0.0" +redux@^4.0.5: + version "4.0.5" + resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f" + integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w== + dependencies: + loose-envify "^1.4.0" + symbol-observable "^1.2.0" + regenerate-unicode-properties@^8.2.0: version "8.2.0" resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz#e5de7111d655e7ba60c057dbe9ff37c87e65cdec" @@ -8428,6 +8454,11 @@ swc-loader@0.1.12: "@swc/core" "^1.1.48" loader-utils "^2.0.0" +symbol-observable@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" + integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ== + symbol-tree@^3.2.2, symbol-tree@^3.2.4: version "3.2.4" resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2" From c6bf4b1bfebfee518fa038941fce45fc3e4b279f Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Sat, 20 Feb 2021 10:39:45 +0200 Subject: [PATCH 03/12] Add hCaptcha sitekey and allowed hosts to webpack config --- webpack.config.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webpack.config.js b/webpack.config.js index 35c90a74..54b4030d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -70,6 +70,7 @@ module.exports = { }] }, devServer: { + allowedHosts: ["pythondiscord.local"], // hCaptcha don't support localhost (pythondiscord.local:3000) contentBase: path.join(__dirname, 'public'), compress: true, port: 3000, @@ -93,7 +94,8 @@ module.exports = { REACT_APP_SENTRY_DSN: "https://false@notreal.ingest.sentry.io/1234", REACT_APP_OAUTH2_CLIENT_ID: "0", BACKEND_URL: "https://forms-api.pythondiscord.com/", - CONTEXT: "development" + CONTEXT: "development", + HCAPTCHA_SITEKEY: "10000000-ffff-ffff-ffff-000000000001" // This is development key what don't add any protection }), new HtmlWebpackPlugin({ inject: true, template: 'public/index.html' From e4125b11ef0c4edaa1f59148eb728fb9f9fdeb49 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Sat, 20 Feb 2021 10:55:08 +0200 Subject: [PATCH 04/12] Add React-Redux and Redux type packages as dev dependencies --- package.json | 2 ++ yarn.lock | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5334b6c2..d773fe34 100644 --- a/package.json +++ b/package.json @@ -65,8 +65,10 @@ "@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/yarn.lock b/yarn.lock index 8b6619ad..1b9f71c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2035,6 +2035,14 @@ resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.8.tgz#49348387983075705fe8f4e02fb67f7daaec4934" integrity sha512-S78QIYirQcUoo6UJZx9CSP0O2ix9IaeAXwQi26Rhr/+mg7qqPy8TzaxHSUut7eGjL8WmLccT7/MXf304WjqHcA== +"@types/hoist-non-react-statics@^3.3.0": + version "3.3.1" + resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f" + integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA== + dependencies: + "@types/react" "*" + hoist-non-react-statics "^3.3.0" + "@types/html-minifier-terser@^5.0.0": version "5.1.1" resolved "https://registry.yarnpkg.com/@types/html-minifier-terser/-/html-minifier-terser-5.1.1.tgz#3c9ee980f1a10d6021ae6632ca3e79ca2ec4fb50" @@ -2127,6 +2135,16 @@ dependencies: "@types/react" "*" +"@types/react-redux@^7.1.16": + version "7.1.16" + resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.16.tgz#0fbd04c2500c12105494c83d4a3e45c084e3cb21" + integrity sha512-f/FKzIrZwZk7YEO9E1yoxIuDNRiDducxkFlkw/GNMGEnK9n4K8wJzlJBghpSuOVDgEUHoDkDF7Gi9lHNQR4siw== + dependencies: + "@types/hoist-non-react-statics" "^3.3.0" + "@types/react" "*" + hoist-non-react-statics "^3.3.0" + redux "^4.0.0" + "@types/react-router-dom@5.1.7": version "5.1.7" resolved "https://registry.yarnpkg.com/@types/react-router-dom/-/react-router-dom-5.1.7.tgz#a126d9ea76079ffbbdb0d9225073eb5797ab7271" @@ -2159,6 +2177,13 @@ "@types/prop-types" "*" csstype "^3.0.2" +"@types/redux@^3.6.0": + version "3.6.0" + resolved "https://registry.yarnpkg.com/@types/redux/-/redux-3.6.0.tgz#f1ebe1e5411518072e4fdfca5c76e16e74c1399a" + integrity sha1-8evh5UEVGAcuT9/KXHbhbnTBOZo= + dependencies: + redux "*" + "@types/resolve@1.17.1": version "1.17.1" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" @@ -4806,7 +4831,7 @@ history@^4.9.0: tiny-warning "^1.0.0" value-equal "^1.0.1" -hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.1, hoist-non-react-statics@^3.3.2: +hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.0, hoist-non-react-statics@^3.3.1, hoist-non-react-statics@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45" integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw== @@ -7442,7 +7467,7 @@ redent@^3.0.0: indent-string "^4.0.0" strip-indent "^3.0.0" -redux@^4.0.5: +redux@*, redux@^4.0.0, redux@^4.0.5: version "4.0.5" resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f" integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w== From 4eeb24bc3317856b34be6e8eac9b668262b177ae Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Sat, 20 Feb 2021 11:02:08 +0200 Subject: [PATCH 05/12] Move hCaptcha types library to dev-dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d773fe34..78e5acc8 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "@sentry/react": "6.1.0", "@svgr/webpack": "5.5.0", "@swc/core": "1.2.47", - "@types/hcaptcha__react-hcaptcha": "^0.1.4", "axios": "0.21.1", "copy-webpack-plugin": "7.0.0", "fs-extra": "9.1.0", @@ -61,6 +60,7 @@ "@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", From b1f05fa57c862ce8219e5ca464e794353261f842 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Sun, 21 Feb 2021 07:35:29 +0200 Subject: [PATCH 06/12] Migrate from public state map to Redux --- src/App.tsx | 4 +- src/components/InputTypes/Checkbox.tsx | 7 +- src/components/InputTypes/Select.tsx | 40 +++++-- src/components/InputTypes/index.tsx | 13 ++- src/components/Question.tsx | 153 +++++++++++++++---------- src/pages/FormPage.tsx | 38 ++++-- src/store/form/actions.ts | 79 +++++++++++++ src/store/form/reducers.ts | 29 +++++ src/store/form/store.ts | 4 + src/store/form/types.ts | 5 + 10 files changed, 285 insertions(+), 87 deletions(-) create mode 100644 src/store/form/actions.ts create mode 100644 src/store/form/reducers.ts create mode 100644 src/store/form/store.ts create mode 100644 src/store/form/types.ts 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..b3130c6b 100644 --- a/src/components/InputTypes/Checkbox.tsx +++ b/src/components/InputTypes/Checkbox.tsx @@ -3,6 +3,8 @@ 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"; interface CheckboxProps { index: number, @@ -53,10 +55,13 @@ const activeStyles = css` `; export default function Checkbox(props: CheckboxProps): JSX.Element { + const values = useSelector( + state => state.values + ); return (