Skip to content

Commit

Permalink
chore: split EventoVView Contatti in different components
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Nov 6, 2023
1 parent 561eec9 commit 5abf0d8
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 73 deletions.
81 changes: 8 additions & 73 deletions src/components/ItaliaTheme/View/EventoView/EventoContatti.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import PropTypes from 'prop-types';
import { defineMessages, useIntl } from 'react-intl';
import { Card, CardBody, CardTitle } from 'design-react-kit';
import { Icon } from 'design-comuni-plone-theme/components/ItaliaTheme';
import {
RichText,
richTextHasContent,
RichTextSection,
ContactLink,
OfficeCard,
ContactsCard,
} from 'design-comuni-plone-theme/components/ItaliaTheme/View';
import EventoContattiOrganizzatoreEsterno from 'design-comuni-plone-theme/components/ItaliaTheme/View/EventoView/EventoContattiOrganizzatoreEsterno';
import EventoContattiOrganizzatoreInterno from 'design-comuni-plone-theme/components/ItaliaTheme/View/EventoView/EventoContattiOrganizzatoreInterno';
import EventoContattiSupportatoDa from 'design-comuni-plone-theme/components/ItaliaTheme/View/EventoView/EventoContattiSupportatoDa';

const messages = defineMessages({
supported_by: {
Expand Down Expand Up @@ -48,79 +47,15 @@ const EventoContatti = ({ content }) => {
{content.contact_info.map((contact) => (
<ContactsCard contact={contact} key={contact['@id']} />
))}

{/* ---organizzato da esterno */}
{richTextHasContent(content?.organizzato_da_esterno) ||
content?.telefono ||
content?.email ||
content?.fax ? (
<div className="mb-5">
<Card
className="card card-teaser rounded shadow mt-3"
noWrapper={true}
tag="div"
>
<Icon icon="it-telephone" />
<EventoContattiOrganizzatoreEsterno content={content} />

<CardBody tag="div" className={'card-body pe-3'}>
<RichText data={content.organizzato_da_esterno} />
{content?.telefono && (
<p className="card-text mt-3">
<ContactLink tel={content.telefono} label={true} />
</p>
)}
{content?.fax && (
<p className="card-text mt-3">
<ContactLink fax={content.fax} label={true} />
</p>
)}
{content?.reperibilita?.replace(/(<([^>]+)>)/g, '').length >
0 && (
<p className="card-text mt-3">
{content?.reperibilita?.replace(/(<([^>]+)>)/g, '')}
</p>
)}
{content?.email && (
<p className="card-text mt-3">
<ContactLink email={content.email} label={true} />
</p>
)}
</CardBody>
</Card>
</div>
) : null}
{/* ---contatti interno */}
{content?.organizzato_da_interno?.length > 0 && (
<div className="mb-5">
<h3 className="h5">{intl.formatMessage(messages.organizzato_da)}</h3>
{content?.organizzato_da_interno?.map((item, index) => (
<OfficeCard
margin_bottom={
index < content?.organizzato_da_interno?.length - 1
}
key={item['@id']}
office={item}
icon={'it-telephone'}
>
{richTextHasContent(content?.contatto_reperibilita) && (
<p className="card-text mt-3">
{content?.contatto_reperibilita?.replace(/(<([^>]+)>)/g, '')}
</p>
)}
</OfficeCard>
))}
</div>
)}
<EventoContattiOrganizzatoreInterno content={content} />

{/* ---supportato da */}
{content?.supportato_da?.length > 0 && (
<div className="mb-5">
<h3 className="mt-4 supported-by h5">
{intl.formatMessage(messages.supported_by)}
</h3>
{content?.supportato_da?.map((item) => (
<OfficeCard key={item['@id']} office={item} icon={'it-pa'} />
))}
</div>
)}
<EventoContattiSupportatoDa content={content} />
</RichTextSection>
) : null;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import PropTypes from 'prop-types';
import { Card, CardBody } from 'design-react-kit';
import { Icon } from 'design-comuni-plone-theme/components/ItaliaTheme';
import {
RichText,
richTextHasContent,
ContactLink,
} from 'design-comuni-plone-theme/components/ItaliaTheme/View';

const EventoContattiOrganizzatoreEsterno = ({ content }) => {
return richTextHasContent(content?.organizzato_da_esterno) ||
content?.telefono ||
content?.email ||
content?.fax ? (
<div className="mb-5">
<Card
className="card card-teaser rounded shadow mt-3"
noWrapper={true}
tag="div"
>
<Icon icon="it-telephone" />

<CardBody tag="div" className={'card-body pe-3'}>
<RichText data={content.organizzato_da_esterno} />
{content?.telefono && (
<p className="card-text mt-3">
<ContactLink tel={content.telefono} label={true} />
</p>
)}
{content?.fax && (
<p className="card-text mt-3">
<ContactLink fax={content.fax} label={true} />
</p>
)}
{content?.reperibilita?.replace(/(<([^>]+)>)/g, '').length > 0 && (
<p className="card-text mt-3">
{content?.reperibilita?.replace(/(<([^>]+)>)/g, '')}
</p>
)}
{content?.email && (
<p className="card-text mt-3">
<ContactLink email={content.email} label={true} />
</p>
)}
</CardBody>
</Card>
</div>
) : null;
};

EventoContattiOrganizzatoreEsterno.propTypes = {
content: PropTypes.object.isRequired,
};

export default EventoContattiOrganizzatoreEsterno;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import PropTypes from 'prop-types';
import { defineMessages, useIntl } from 'react-intl';
import {
richTextHasContent,
OfficeCard,
} from 'design-comuni-plone-theme/components/ItaliaTheme/View';

const messages = defineMessages({
organizzato_da: {
id: 'organizzato_da',
defaultMessage: 'Organizzato da',
},
});

const EventoContattiOrganizzatoreInterno = ({ content }) => {
const intl = useIntl();

return content?.organizzato_da_interno?.length > 0 ? (
<div className="mb-5">
<h3 className="h5">{intl.formatMessage(messages.organizzato_da)}</h3>
{content?.organizzato_da_interno?.map((item, index) => (
<OfficeCard
margin_bottom={index < content?.organizzato_da_interno?.length - 1}
key={item['@id']}
office={item}
icon={'it-telephone'}
>
{richTextHasContent(content?.contatto_reperibilita) && (
<p className="card-text mt-3">
{content?.contatto_reperibilita?.replace(/(<([^>]+)>)/g, '')}
</p>
)}
</OfficeCard>
))}
</div>
) : null;
};

EventoContattiOrganizzatoreInterno.propTypes = {
content: PropTypes.object.isRequired,
};

export default EventoContattiOrganizzatoreInterno;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import PropTypes from 'prop-types';
import { defineMessages, useIntl } from 'react-intl';
import { OfficeCard } from 'design-comuni-plone-theme/components/ItaliaTheme/View';

const messages = defineMessages({
supported_by: {
id: 'supported_by',
defaultMessage: 'Con il supporto di',
},
});

const EventoContattiSupportatoDa = ({ content }) => {
const intl = useIntl();

return content?.supportato_da?.length > 0 ? (
<div className="mb-5">
<h3 className="mt-4 supported-by h5">
{intl.formatMessage(messages.supported_by)}
</h3>
{content?.supportato_da?.map((item) => (
<OfficeCard key={item['@id']} office={item} icon={'it-pa'} />
))}
</div>
) : null;
};

EventoContattiSupportatoDa.propTypes = {
content: PropTypes.object.isRequired,
};

export default EventoContattiSupportatoDa;

0 comments on commit 5abf0d8

Please sign in to comment.