forked from italia/design-comuni-plone-theme
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: updated volto-form-block customizations
- Loading branch information
1 parent
ad65f0c
commit 00e44c7
Showing
3 changed files
with
206 additions
and
58 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/customizations/volto-form-block/components/FormResult.jsx
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,78 @@ | ||
/* | ||
CUSTOMIZATIONS: | ||
- used design-react-kit components to render form result | ||
*/ | ||
import React from 'react'; | ||
import { useIntl, defineMessages } from 'react-intl'; | ||
import { Button, Alert } from 'design-react-kit/dist/design-react-kit'; | ||
import { getFieldName } from 'volto-form-block/components/utils'; | ||
|
||
const messages = defineMessages({ | ||
success: { | ||
id: 'form_submit_success', | ||
defaultMessage: 'Sent!', | ||
}, | ||
reset: { | ||
id: 'form_reset', | ||
defaultMessage: 'Clear', | ||
}, | ||
}); | ||
|
||
const alertTransition = { | ||
appear: true, | ||
baseClass: 'fade', | ||
baseClassActive: 'show', | ||
enter: true, | ||
exit: true, | ||
in: true, | ||
mountOnEnter: false, | ||
tag: 'div', | ||
timeout: 150, | ||
unmountOnExit: true, | ||
}; | ||
|
||
/* Function that replaces variables from the user customized message */ | ||
const replaceMessage = (text, sent_data) => { | ||
let i = 0; | ||
while (i < sent_data.length) { | ||
let idField = getFieldName(sent_data[i].label, sent_data[i].field_id); | ||
text = text.replaceAll('${' + idField + '}', sent_data[i].value ?? ''); | ||
i++; | ||
} | ||
text = text.replaceAll(/\$\{[^}]*\}/gm, ''); //replace empty fields with nothing | ||
text = text.replaceAll('\n', '<br/>'); | ||
return text; | ||
}; | ||
|
||
const FormResult = ({ formState, data, resetFormState }) => { | ||
const intl = useIntl(); | ||
return ( | ||
<Alert color="success" fade isOpen tag="div" transition={alertTransition}> | ||
<h4>{intl.formatMessage(messages.success)}</h4> | ||
<br /> | ||
{/* Custom message */} | ||
{data.send_message && ( | ||
<> | ||
<p | ||
dangerouslySetInnerHTML={{ | ||
__html: replaceMessage(data.send_message, formState.result.data), | ||
}} | ||
/> | ||
<br /> | ||
</> | ||
)} | ||
<Button | ||
color="primary" | ||
outline | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
resetFormState(); | ||
}} | ||
> | ||
{intl.formatMessage(messages.reset)} | ||
</Button> | ||
</Alert> | ||
); | ||
}; | ||
export default FormResult; |
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
50 changes: 50 additions & 0 deletions
50
src/customizations/volto-form-block/components/Widget/Button.jsx
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 @@ | ||
/** | ||
* customizations: | ||
* used design-react-kit button | ||
* | ||
* | ||
* Button component. | ||
* This is a wrapper for Buttons, to eventually customize Button component if you don't like to use semantic-ui, for example. | ||
* @module components/Widget/OTPWidget | ||
*/ | ||
|
||
import { Button as DesignButton } from 'design-react-kit/dist/design-react-kit'; | ||
|
||
const Button = (props) => { | ||
let _props = { ...props }; | ||
if (props.primary) { | ||
_props.color = 'primary'; | ||
delete _props.primary; | ||
} | ||
if (props.secondary) { | ||
_props.color = 'secondary'; | ||
delete _props.secondary; | ||
} | ||
if (props.basic) { | ||
_props.outline = true; | ||
delete _props.basic; | ||
} | ||
if (props.size) { | ||
switch (props.size) { | ||
case 'mini': | ||
case 'tiny': | ||
case 'small': | ||
_props.size = 'xs'; | ||
break; | ||
case 'medium': | ||
case 'large': | ||
_props.size = 'sm'; | ||
break; | ||
case 'big': | ||
case 'huge': | ||
case 'massive': | ||
_props.size = 'lg'; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
return <DesignButton {..._props} />; | ||
}; | ||
|
||
export default Button; |