Skip to content

Commit

Permalink
fix: fixed date format in send email
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed May 11, 2022
1 parent a11c5cf commit 758a64a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/components/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useIntl, defineMessages } from 'react-intl';
import { submitForm } from '../actions';
import { getFieldName } from './utils';
import FormView from 'volto-form-block/components/FormView';

import { formatDate } from '@plone/volto/helpers/Utils/Date';
import config from '@plone/volto/registry';

const messages = defineMessages({
Expand Down Expand Up @@ -129,16 +129,25 @@ const View = ({ data, id, path }) => {

if (isValidForm()) {
let attachments = {};

let formattedFormData = { ...formData };
data.subblocks.forEach((subblock, index) => {
let name = getFieldName(subblock.label, subblock.id);
if (formData[name]?.value) {
formData[name].field_id = subblock.field_id;
if (formattedFormData[name]?.value) {
formattedFormData[name].field_id = subblock.field_id;
const isAttachment = subblock.field_type === 'attachment';
const isDate = subblock.field_type === 'date';

if (isAttachment) {
attachments[name] = formData[name].value;
delete formData[name];
attachments[name] = formattedFormData[name].value;
delete formattedFormData[name];
}

if (isDate) {
formattedFormData[name].value = formatDate({
date: formattedFormData[name].value,
format: 'DD-MM-YYYY',
locale: intl.locale,
});
}
}
});
Expand All @@ -147,8 +156,8 @@ const View = ({ data, id, path }) => {
submitForm(
path,
id,
Object.keys(formData).map((name) => ({
...formData[name]
Object.keys(formattedFormData).map((name) => ({
...formattedFormData[name],
})),
attachments,
),
Expand Down

0 comments on commit 758a64a

Please sign in to comment.