-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[*] | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
charset = utf-8 | ||
|
||
[{*.css,*.scss,*.less}] | ||
indent_size = 4 | ||
|
||
[{*.js,*.json}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
container-query-polyfill.modern.js | ||
cypress | ||
node_modules | ||
acceptance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module.exports = { | ||
extends: ['react-app', 'prettier', 'plugin:jsx-a11y/recommended'], | ||
plugins: ['prettier', 'react-hooks', 'jsx-a11y'], | ||
env: { | ||
es6: true, | ||
browser: true, | ||
node: true, | ||
mocha: true, | ||
jasmine: true, | ||
}, | ||
parser: '@babel/eslint-parser', | ||
parserOptions: { | ||
ecmaVersion: 6, | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
legacyDecorators: true, | ||
}, | ||
}, | ||
rules: { | ||
'import/no-unresolved': 0, | ||
'no-alert': 1, | ||
'no-console': 1, | ||
'no-debugger': 1, | ||
'prettier/prettier': ['error', { trailingComma: 'all', singleQuote: true }], | ||
'react-hooks/rules-of-hooks': 'error', | ||
'react-hooks/exhaustive-deps': 'warn', | ||
'react/react-in-jsx-scope': 'off', | ||
}, | ||
globals: { | ||
root: true, | ||
__DEVELOPMENT__: true, | ||
__CLIENT__: true, | ||
__SERVER__: true, | ||
__DISABLE_SSR__: true, | ||
__DEVTOOLS__: true, | ||
__DEBUG__: true, | ||
__SSR__: true, | ||
__SENTRY__: true, | ||
cy: true, | ||
Cypress: true, | ||
jest: true, | ||
socket: true, | ||
webpackIsomorphicTools: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.vscode/ | ||
.history | ||
logs | ||
*.log | ||
npm-debug.log* | ||
.DS_Store | ||
*.swp | ||
yarn-error.log | ||
|
||
coverage | ||
node_modules | ||
build | ||
cache | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# Yarn 3 | ||
.pnp.* | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx --no -- commitlint --edit ${1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CHANGELOG.md | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const projectRootPath = fs.realpathSync('./project'); // __dirname | ||
const packageJson = require(path.join(projectRootPath, 'package.json')); | ||
|
||
let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto'); | ||
|
||
let configFile; | ||
if (fs.existsSync(`${this.projectRootPath}/tsconfig.json`)) | ||
configFile = `${this.projectRootPath}/tsconfig.json`; | ||
else if (fs.existsSync(`${this.projectRootPath}/jsconfig.json`)) | ||
configFile = `${this.projectRootPath}/jsconfig.json`; | ||
|
||
if (configFile) { | ||
const jsConfig = require(configFile).compilerOptions; | ||
const pathsConfig = jsConfig.paths; | ||
if (pathsConfig['@plone/volto']) | ||
voltoPath = `./${jsConfig.baseUrl}/${pathsConfig['@plone/volto'][0]}`; | ||
} | ||
|
||
const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`); | ||
const reg = new AddonConfigurationRegistry(projectRootPath); | ||
|
||
// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons | ||
const addonAliases = Object.keys(reg.packages).map((o) => [ | ||
o, | ||
reg.packages[o].modulePath, | ||
]); | ||
|
||
module.exports = { | ||
extends: `${voltoPath}/.eslintrc`, | ||
settings: { | ||
'import/resolver': { | ||
alias: { | ||
map: [ | ||
['@plone/volto', '@plone/volto/src'], | ||
...addonAliases, | ||
['@package', `${__dirname}/src`], | ||
['@root', `${__dirname}/src`], | ||
['~', `${__dirname}/src`], | ||
], | ||
extensions: ['.js', '.jsx', '.json'], | ||
}, | ||
'babel-plugin-root-import': { | ||
rootPathSuffix: 'src', | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"git": { | ||
"tagName": "v${version}", | ||
"commitMessage": "chore: release v${version}" | ||
}, | ||
"npm": { | ||
"publish": true | ||
}, | ||
"github": { | ||
"release": true, | ||
"releaseName": "${version}" | ||
}, | ||
"plugins": { | ||
"@release-it/conventional-changelog": { | ||
"infile": "CHANGELOG.md", | ||
"preset": { | ||
"name": "conventionalcommits", | ||
"types": [ | ||
{ | ||
"type": "feat", | ||
"section": "Features" | ||
}, | ||
{ | ||
"type": "fix", | ||
"section": "Bug Fixes" | ||
}, | ||
{ | ||
"type": "refactor", | ||
"section": "Changes" | ||
}, | ||
{ | ||
"type": "chore", | ||
"section": "Maintenance" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defaultSemverRangePrefix: "" | ||
|
||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.2.3.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Collective | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# volto-form-block | ||
|
||
Volto addon which adds a customizable form using a block. | ||
Intended to be used with [collective.volto.formsupport](https://github.com/collective/collective.volto.formsupport). | ||
|
||
Install with mrs-developer (see [Volto docs](https://docs.voltocms.com/customizing/add-ons/)) or with: | ||
|
||
```bash | ||
yarn add volto-form-block volto-subblocks | ||
``` | ||
|
||
> **Note**: Since version v2.0.0 of this addon, it's required [collective.volto.formsupport](https://github.com/collective/collective.volto.formsupport) 2.0.0 or higher (and its upgrade steps). | ||
> | ||
> **Note**: Since version v2.1.2 of this addon, it's required Volto 14.2.0 | ||
> | ||
> **Note**: Since version v3.0.0 of this addon, it's required Volto >= 16.0.0-alpha.38 | ||
## Features | ||
|
||
This addon will add in your project the Form block and the needed reducers. | ||
|
||
<img alt="Form block in chooser" src="./docs/form-block-chooser.png" width="300" /> | ||
|
||
![Form block view](./docs/form-block-view.png) | ||
|
||
Using the engine of subblocks, you can manage form fields adding, sorting and deleting items. | ||
|
||
For each field, you can select the field type from: | ||
|
||
- Text | ||
- Textarea | ||
- Select | ||
- Single choice (radio buttons) | ||
- Multiple choice (checkbox buttons) | ||
- Checkbox | ||
- Date picker | ||
- File upload with DnD | ||
- Static rich text (not a fillable field, just text to display between other fields) | ||
|
||
For every field you can set a label and a help text. | ||
For select, radio and checkbox fields, you can select a list of values. | ||
|
||
## Captcha verification | ||
|
||
This form addon is configured to work with [HCaptcha](https://www.hcaptcha.com), [ReCaptcha](https://www.google.com/recaptcha/) and | ||
[NoRobot](https://github.com/collective/collective.z3cform.norobots) to prevent spam. | ||
|
||
In order to make one of these integrations work, you need to add | ||
[https://github.com/plone/plone.formwidget.hcaptcha](https://github.com/plone/plone.formwidget.hcaptcha) and/or | ||
[https://github.com/plone/plone.formwidget.recaptcha](https://github.com/plone/plone.formwidget.recaptcha) and/or | ||
[https://github.com/collective/collective.z3cform.norobots](https://github.com/collective/collective.z3cform.norobots) | ||
Plone addon and configure public and private keys in controlpanels. | ||
|
||
### HCaptcha | ||
|
||
With HCaptcha integration, you also have an additional option in the sidebar in 'Captcha provider' to enable or disable the invisible captcha (see implications [here](https://docs.hcaptcha.com/faq#do-i-need-to-display-anything-on-the-page-when-using-hcaptcha-in-invisible-mode)). | ||
|
||
In some test scenarios it's found that the "Passing Threshold" of HCaptcha must be configured as "Auto" to get the best results. In some test cases if one sets the Threshold to "Moderate" HCaptcha starts to fail. | ||
|
||
### OTP email validation | ||
|
||
To prevent sending spam emails to users via the email address configured as sender, the 'email' fields type flagged as BCC will require the user to enter an OTP code received at the address entered in the field when user fills out the form. | ||
|
||
## Export | ||
|
||
With backend support, you can store data submitted from the form. | ||
In Edit, you can export and clear stored data from the sidebar. | ||
|
||
<img alt="Form export" src="./docs/store-export-data.png" width="400" /> | ||
|
||
## Additional fields | ||
|
||
In addition to the fields described above, you can add any field you want. | ||
If you need a field that is not supported, PRs are always welcome, but if you have to use a custom field tailored on your project needs, then you can add additional custom fields. | ||
|
||
```jsx | ||
config.blocks.blocksConfig.form.additionalFields.push({ | ||
id: 'field type id', | ||
label: | ||
intl.formatMessage(messages.customFieldLabel) || | ||
'Label for field type select, translation obj or string', | ||
component: MyCustomWidget, | ||
isValid: (formData, name) => true, | ||
}); | ||
``` | ||
|
||
The widget component should have the following firm: | ||
|
||
```js | ||
({ | ||
id, | ||
name, | ||
title, | ||
description, | ||
required, | ||
onChange, | ||
value, | ||
isDisabled, | ||
invalid, | ||
}) => ReactElement; | ||
``` | ||
|
||
You should also pass a function to validate your field's data. | ||
The `isValid` function accepts `formData` (the whole form data) and the name of the field, thus you can access to your fields' data as `formData[name]` but you also have access to other fields. | ||
|
||
`isValid` has the firm: | ||
|
||
```js | ||
(formData, name) => boolean; | ||
``` | ||
|
||
Example custom field [here](https://gist.github.com/nzambello/30949078616328e6ee0293e5b302bb40). | ||
|
||
## Static fields | ||
|
||
In backend integration, you can add in block data an object called `static_fields` and the form block will show those in form view as readonly and will aggregate those with user compiled data. | ||
|
||
i.e.: aggregated data from user federated authentication: | ||
|
||
![Static fields](./docs/form-static-fields.png) | ||
|
||
## Schema validators | ||
|
||
If you want to validate configuration field (for example, testing if 'From email' is an address of a specific domain), you could add your validation functions to block config: | ||
|
||
```js | ||
config.blocks.blocksConfig.form = { | ||
...config.blocks.blocksConfig.form, | ||
schemaValidators: { | ||
fieldname: yourValidationFN(data), | ||
}, | ||
}; | ||
``` | ||
|
||
`yourValidationFN` have to return: | ||
|
||
- null if field is valid | ||
- a string with the error message if field is invalid. | ||
|
||
## Upgrade guide | ||
|
||
To upgrade to version 2.4.0 you need to: | ||
|
||
- remove the env vars | ||
- install [https://github.com/plone/plone.formwidget.hcaptcha](https://github.com/plone/plone.formwidget.hcaptcha) or [https://github.com/plone/plone.formwidget.recaptcha](https://github.com/plone/plone.formwidget.recaptcha) or both in Plone. | ||
- insert private and public keys in Plone HCaptcha controlpanel or/and Plone ReCaptcha controlpanel. | ||
|
||
## Video demos | ||
|
||
- [Form usage](https://youtu.be/v5KtjEACRmI) | ||
- [Form editing](https://youtu.be/wmTpzYBtNCQ) | ||
- [Export stored data](https://youtu.be/3zVUaGaaVOg) | ||
|
||
## VERSIONS | ||
|
||
With [email protected] you need to upgrade collective.volto.formsupport to version 2.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = function (api) { | ||
api.cache(true); | ||
const presets = ['razzle']; | ||
const plugins = [ | ||
[ | ||
'react-intl', // React Intl extractor, required for the whole i18n infrastructure to work | ||
{ | ||
messagesDir: './build/messages/', | ||
}, | ||
], | ||
]; | ||
|
||
return { | ||
plugins, | ||
presets, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = { extends: ['@commitlint/config-conventional'] }; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.