Skip to content
This repository has been archived by the owner on Nov 23, 2022. It is now read-only.

fix: fixed recaptcha in customer satisfaction to avoid Timeout error #426

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
"typeface-titillium-web": "0.0.72",
"volto-blocks-widget": "collective/volto-blocks-widget#v2.0.1",
"volto-cookie-banner": "collective/volto-cookie-banner#v2.0.0",
"volto-customer-satisfaction": "collective/volto-customer-satisfaction#v0.2.5",
"volto-customer-satisfaction": "collective/volto-customer-satisfaction#v0.2.7",
"volto-dropdownmenu": "collective/volto-dropdownmenu#v2.2.9",
"volto-editablefooter": "RedTurtle/volto-editablefooter#v3.1.3",
"volto-form-block": "collective/volto-form-block#v2.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
resetSubmitCustomerSatisfaction,
GoogleReCaptchaWidget,
} from 'volto-customer-satisfaction';

import { isCmsUi } from '@plone/volto/helpers';

const messages = defineMessages({
Expand Down Expand Up @@ -86,11 +87,28 @@ const CustomerSatisfaction = () => {
}
};

const cleanGoogleRecaptcha = () => {
// remove badge
const nodeBadge = document.querySelector('.grecaptcha-badge');

if (nodeBadge && nodeBadge.parentNode) {
document.body.removeChild(nodeBadge.parentNode);
}

// remove script
const script = document.querySelector(`#google-recaptcha-v3`);

if (script) {
script.remove();
}
};

useEffect(() => {
setSatisfaction(null);
setValidToken(null);
return () => {
dispatch(resetSubmitCustomerSatisfaction());
cleanGoogleRecaptcha();
};
}, [path]);

Expand Down Expand Up @@ -166,71 +184,73 @@ const CustomerSatisfaction = () => {
{!submitResults.error &&
!submitResults?.loading &&
!submitResults.loaded && (
<form
onSubmit={() => {
sendFormData();
}}
>
<div className="buttons" aria-labelledby="cs-radiogroup-label">
<Button
color="success"
icon
outline={satisfaction !== true}
onClick={(e) => {
changeSatisfaction(e, true);
}}
aria-controls="cs-more"
active={satisfaction === true}
title={intl.formatMessage(messages.yes)}
>
<FontAwesomeIcon icon={['far', 'thumbs-up']} />
</Button>

<Button
color="danger"
icon
outline={satisfaction !== false}
onClick={(e) => {
changeSatisfaction(e, false);
}}
aria-controls="cs-more"
active={satisfaction === false}
title={intl.formatMessage(messages.no)}
>
<FontAwesomeIcon icon={['far', 'thumbs-down']} />
</Button>
</div>

<div
id="cs-more"
role="region"
aria-expanded={satisfaction !== null}
aria-hidden={satisfaction != null}
<>
<form
onSubmit={() => {
sendFormData();
}}
>
<div className="comment">
<Input
id="cs-comment"
label={intl.formatMessage(messages.suggestions_placeholder)}
onChange={(e) => {
setFormData({ ...formData, comment: e.target.value });
<div className="buttons" aria-labelledby="cs-radiogroup-label">
<Button
color="success"
icon
outline={satisfaction !== true}
onClick={(e) => {
changeSatisfaction(e, true);
}}
rows="3"
type="textarea"
/>
</div>
aria-controls="cs-more"
active={satisfaction === true}
title={intl.formatMessage(messages.yes)}
>
<FontAwesomeIcon icon={['far', 'thumbs-up']} />
</Button>

<GoogleReCaptchaWidget
key={action}
onVerify={onVerifyCaptcha}
action={action}
/>
<div className="submit-wrapper">
<Button type="submit" color="primary" disabled={!validToken}>
{intl.formatMessage(messages.submit)}
<Button
color="danger"
icon
outline={satisfaction !== false}
onClick={(e) => {
changeSatisfaction(e, false);
}}
aria-controls="cs-more"
active={satisfaction === false}
title={intl.formatMessage(messages.no)}
>
<FontAwesomeIcon icon={['far', 'thumbs-down']} />
</Button>
</div>
</div>
</form>

<div
id="cs-more"
role="region"
aria-expanded={satisfaction !== null}
aria-hidden={satisfaction != null}
>
<div className="comment">
<Input
id="cs-comment"
label={intl.formatMessage(messages.suggestions_placeholder)}
onChange={(e) => {
setFormData({ ...formData, comment: e.target.value });
}}
rows="3"
type="textarea"
/>
</div>

<GoogleReCaptchaWidget
key={action}
onVerify={onVerifyCaptcha}
action={action}
/>
<div className="submit-wrapper">
<Button type="submit" color="primary" disabled={!validToken}>
{intl.formatMessage(messages.submit)}
</Button>
</div>
</div>
</form>
</>
)}
{submitResults?.loading && (
<Progress
Expand Down
112 changes: 109 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,17 @@
dependencies:
"@octokit/openapi-types" "^6.0.0"

"@plone/scripts@*":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@plone/scripts/-/scripts-1.0.3.tgz#ea3e5f29b6fcb8f088b32e43394d71748d5538b4"
integrity sha512-wE0vsWpOI5jeoVJVP0T2IpBGz6wdlQrOqicK0EsC0+6hYqmPJb2cGUXNe0JhUDONF6Gi/Ubklcgd05Lpb2+bjA==
dependencies:
babel-plugin-react-intl "5.1.17"
babel-preset-razzle "3.4.5"
commander "8.2.0"
pofile "1.0.10"
razzle "3.4.5"

"@plone/volto@plone/volto#12918408c90fb69cd649a113a418eed5b83ba742":
version "14.0.0-alpha.8"
resolved "https://codeload.github.com/plone/volto/tar.gz/12918408c90fb69cd649a113a418eed5b83ba742"
Expand Down Expand Up @@ -3673,6 +3684,29 @@ babel-preset-jest@^24.9.0:
"@babel/plugin-syntax-object-rest-spread" "^7.0.0"
babel-plugin-jest-hoist "^24.9.0"

[email protected]:
version "3.4.5"
resolved "https://registry.yarnpkg.com/babel-preset-razzle/-/babel-preset-razzle-3.4.5.tgz#203be645cd707686bdf41bcb3d3da4ecdef0d9f6"
integrity sha512-0GU6pKSSUjKBH5wcmp+MMdSE06dh7mrRfJmQ9D6uDdQ4dVgqyw4DbpJd6RIv7g92c/K99ZTY964P4Q7UrX5TSQ==
dependencies:
"@babel/core" "7.11.1"
"@babel/plugin-proposal-class-properties" "^7.8.3"
"@babel/plugin-proposal-nullish-coalescing-operator" "7.10.4"
"@babel/plugin-proposal-numeric-separator" "7.10.4"
"@babel/plugin-proposal-object-rest-spread" "^7.9.5"
"@babel/plugin-proposal-optional-chaining" "7.11.0"
"@babel/plugin-syntax-bigint" "7.8.3"
"@babel/plugin-syntax-dynamic-import" "^7.8.3"
"@babel/plugin-transform-modules-commonjs" "^7.9.0"
"@babel/plugin-transform-react-jsx-source" "^7.9.0"
"@babel/plugin-transform-runtime" "^7.9.0"
"@babel/preset-env" "^7.9.5"
"@babel/preset-react" "^7.9.4"
"@babel/preset-typescript" "^7.9.0"
"@babel/runtime" "^7.9.2"
babel-plugin-dynamic-import-node "2.3.0"
babel-plugin-transform-react-remove-prop-types "0.4.24"

babel-preset-razzle@latest:
version "3.3.8"
resolved "https://registry.yarnpkg.com/babel-preset-razzle/-/babel-preset-razzle-3.3.8.tgz#c572be11794f762faca466c360c477eff65bee98"
Expand Down Expand Up @@ -4893,6 +4927,11 @@ combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

[email protected]:
version "8.2.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-8.2.0.tgz#37fe2bde301d87d47a53adeff8b5915db1381ca8"
integrity sha512-LLKxDvHeL91/8MIyTAD5BFMNtoIwztGPMiM/7Bl8rIPmHCZXRxmSWr91h57dpOpnQ6jIUqEWdXE/uBYMfiVZDA==

commander@^2.11.0, commander@^2.20.0:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
Expand Down Expand Up @@ -14047,6 +14086,21 @@ [email protected]:
iconv-lite "0.4.24"
unpipe "1.0.0"

[email protected]:
version "3.4.5"
resolved "https://registry.yarnpkg.com/razzle-dev-utils/-/razzle-dev-utils-3.4.5.tgz#08830de9b75757b2b415c88a0ed83c3f77a7b0ad"
integrity sha512-4aosuS8aJPCq6SwCTH6DQbSKaO1lQf5P0YzJwkdxlzLbjuaP6yP+a4T/ttQ3Jd10LAjTw0ceug03z1guvsZD5A==
dependencies:
"@babel/code-frame" "^7.8.3"
chalk "3.0.0"
jest-message-util "^24.9.0"
react-dev-utils "10.2.0"
react-error-overlay "^6.0.7"
resolve "1.17.0"
sockjs-client "~1.4.0"
strip-ansi "6.0.0"
webpack-dev-server "~3.10.3"

razzle-dev-utils@latest:
version "3.3.8"
resolved "https://registry.yarnpkg.com/razzle-dev-utils/-/razzle-dev-utils-3.3.8.tgz#1a2cbfd3685526fd773109bb23ebe7d79197306f"
Expand Down Expand Up @@ -14134,6 +14188,57 @@ [email protected]:
webpack-node-externals "^1.7.2"
webpackbar "^4.0.0"

[email protected]:
version "3.4.5"
resolved "https://registry.yarnpkg.com/razzle/-/razzle-3.4.5.tgz#c8c6e2d37623aa40990de90ff6af9aeea3c60a3e"
integrity sha512-SKZJjLJXTaVT9USiBlZAppU94/Jr8yJWL+9UDigGqLgxembKnoWqS9+deCJM25RrL+FMFRdxCXwi/4wOmp5Ivw==
dependencies:
"@babel/core" "7.11.1"
"@pmmmwh/react-refresh-webpack-plugin" "0.3.0"
assets-webpack-plugin "3.9.12"
babel-core "^7.0.0-bridge.0"
babel-jest "^24.9.0"
babel-loader "^8.0.6"
babel-plugin-syntax-jsx "6.18.0"
babel-plugin-transform-define "2.0.0"
babel-preset-razzle "3.4.5"
chalk "^3.0.0"
copy-webpack-plugin "5.1.2"
css-loader "3.5.3"
deepmerge "4.2.2"
dotenv "8.2.0"
dotenv-expand "5.1.0"
file-loader "^4.3.0"
fs-extra "8.1.0"
html-webpack-plugin "^4.0.4"
jest "^24.9.0"
mini-css-extract-plugin "^0.9.0"
mri "^1.1.4"
optimize-css-assets-webpack-plugin "^5.0.3"
pnp-webpack-plugin "^1.6.4"
postcss-flexbugs-fixes "^4.2.0"
postcss-loader "^3.0.0"
postcss-preset-env "^6.7.0"
postcss-safe-parser "^4.0.2"
razzle-dev-utils "3.4.5"
react-dev-utils "10.2.0"
react-error-overlay "^6.0.6"
react-refresh "^0.8.1"
resolve "1.17.0"
sade "^1.4.2"
source-map-support "^0.5.16"
start-server-webpack-plugin "^2.2.5"
string-hash "1.1.3"
style-loader "^1.1.3"
terser-webpack-plugin "^2.3.5"
tiny-async-pool "^1.1.0"
url-loader "^2.3.0"
webpack "^4.42.0"
webpack-dev-server "~3.10.3"
webpack-manifest-plugin "^2.2.0"
webpack-node-externals "^1.7.2"
webpackbar "^4.0.0"

rc-align@^2.4.0:
version "2.4.5"
resolved "https://registry.yarnpkg.com/rc-align/-/rc-align-2.4.5.tgz#c941a586f59d1017f23a428f0b468663fb7102ab"
Expand Down Expand Up @@ -17785,10 +17890,11 @@ volto-cookie-banner@collective/volto-cookie-banner#v2.0.0:
dependencies:
react-cookie-consent "^3.0.0"

volto-customer-satisfaction@collective/volto-customer-satisfaction#v0.2.5:
version "0.2.5"
resolved "https://codeload.github.com/collective/volto-customer-satisfaction/tar.gz/0282bb883c756ce7b89146d326705ab1c968b433"
volto-customer-satisfaction@collective/volto-customer-satisfaction#v0.2.7:
version "0.2.7"
resolved "https://codeload.github.com/collective/volto-customer-satisfaction/tar.gz/ab437238e361ebdc98ffcb61a03bf1654982582d"
dependencies:
"@plone/scripts" "*"
react-google-recaptcha-v3 "1.9.5"

volto-dropdownmenu@collective/volto-dropdownmenu#v2.2.9:
Expand Down