Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Oct 16, 2023
2 parents 5dd9914 + f8586f7 commit c30d16c
Show file tree
Hide file tree
Showing 56 changed files with 1,865 additions and 265 deletions.
Binary file removed .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@
"stylelint"
]
}
}
}
Binary file added public/models/BulkImportTerms.xlsx
Binary file not shown.
37 changes: 37 additions & 0 deletions src/components/blocs/geographical-exceptions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useNavigate } from 'react-router-dom';
import { Tag, TagGroup } from '@dataesr/react-dsfr';
import PropTypes from 'prop-types';

export default function GeographicalExceptionsTags({ data }) {
const navigate = useNavigate();

if (!data) return null;

if (data.length === 0) {
return null;
}

return (
<TagGroup>
{data.map((category) => (
<Tag
size="md"
iconPosition="right"
icon="ri-arrow-right-line"
onClick={() => navigate(`/categories-geographiques/${category.id}`)}
key={category.id}
>
{category.nameFr}
</Tag>
))}
</TagGroup>
);
}

GeographicalExceptionsTags.propTypes = {
data: PropTypes.array,
};

GeographicalExceptionsTags.defaultProps = {
data: [],
};
40 changes: 40 additions & 0 deletions src/components/blocs/geographical-tags/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useNavigate } from 'react-router-dom';
import { Tag, TagGroup } from '@dataesr/react-dsfr';
import PropTypes from 'prop-types';
import { GEOGRAPHICAL_CATEGORIES_LABELS_MAPPER } from '../../../utils/constants';

export default function GeographicalTags({ data }) {
const navigate = useNavigate();

const sortedLevels = ['country', 'region', 'department', 'city', 'academy', 'urbanUnity'];
data?.sort((a, b) => sortedLevels.indexOf(a?.level) - sortedLevels.indexOf(b?.level));

if (!data) return null;

if (data.length === 0) {
return null;
}
return (
<TagGroup>
{data.map((categoryGeo) => (
<Tag
size="md"
iconPosition="right"
icon="ri-arrow-right-line"
onClick={() => navigate(`/categories-geographiques/${categoryGeo.id}`)}
key={categoryGeo.id}
>
{`${GEOGRAPHICAL_CATEGORIES_LABELS_MAPPER[categoryGeo.level]} : ${categoryGeo.nameFr}`}
</Tag>
))}
</TagGroup>
);
}

GeographicalTags.propTypes = {
data: PropTypes.array,
};

GeographicalTags.defaultProps = {
data: [],
};
28 changes: 12 additions & 16 deletions src/components/blocs/historique-et-dates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ function HistoryCard({ creationDate, creationReason, closureDate, closureReason,
Créé
{(creationDate.split('-').length !== 3) ? ` en ${toString(creationDate)}` : ` le ${toString(creationDate)}`}
{createReason}
<br />
{' '}
{creationOfficialText?.id && (
<span className="fr-card__detail">
<a className={`fr-mb-0 fr-text--xs fr-text--regular ${styles['align-after']}`} href={creationOfficialText?.pageUrl} target="_blank" rel="noreferrer">
{creationOfficialText?.nature}
{' '}
{creationOfficialText?.publicationDate && `du ${toString(creationOfficialText.publicationDate)}`}
</a>
</span>
<a className={`fr-mb-0 fr-text--xs fr-text--regular ${styles['align-after']}`} href={creationOfficialText?.pageUrl} target="_blank" rel="noreferrer">
{creationOfficialText?.nature}
{' '}
{creationOfficialText?.publicationDate && `du ${toString(creationOfficialText.publicationDate)}`}
</a>
)}
</p>
)}
Expand All @@ -59,15 +57,13 @@ function HistoryCard({ creationDate, creationReason, closureDate, closureReason,
<p className="fr-text fr-mb-1v">
{closureDate ? displayStatus : null}
{closeReason}
<br />
{' '}
{closureOfficialText?.id && (
<span className="fr-card__detail">
<a className={`fr-mb-0 fr-text--xs fr-text--regular ${styles['align-after']}`} href={closureOfficialText?.pageUrl} target="_blank" rel="noreferrer">
{closureOfficialText?.nature}
{' '}
{closureOfficialText?.publicationDate && `du ${toString(closureOfficialText.publicationDate)}`}
</a>
</span>
<a className={`fr-mb-0 fr-text--xs fr-text--regular ${styles['align-after']}`} href={closureOfficialText?.pageUrl} target="_blank" rel="noreferrer">
{closureOfficialText?.nature}
{' '}
{closureOfficialText?.publicationDate && `du ${toString(closureOfficialText.publicationDate)}`}
</a>
)}
</p>
<div>
Expand Down
217 changes: 116 additions & 101 deletions src/components/blocs/localisations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import useUrl from '../../../hooks/useUrl';
import api from '../../../utils/api';
import { formatDescriptionDates } from '../../../utils/dates';
import { deleteError, deleteSuccess, saveError, saveSuccess } from '../../../utils/notice-contents';
import GeographicalTags from '../geographical-tags';

export default function LocalisationsComponent() {
const { editMode } = useEditMode();
const { notice } = useNotice();
const { url, apiObject } = useUrl('localisations');
const { data, isLoading, error, reload } = useFetch(url);

const [showModal, setShowModal] = useState(false);
const [modalTitle, setModalTitle] = useState('');
const [modalContent, setModalContent] = useState(null);
Expand Down Expand Up @@ -57,47 +59,45 @@ export default function LocalisationsComponent() {
const renderAddress = (localisation) => {
let address = '';
const phoneNumberWithoutSpaces = localisation?.phonenumber?.replace(/\s/g, '');
if (localisation.distributionStatement) { address += `${localisation.distributionStatement },\n`; }
if (localisation.address) { address += `${localisation.address },\n`; }
if (localisation.place) { address += `${localisation.place },\n`; }
if (localisation.postOfficeBoxNumber) { address += `${localisation.postOfficeBoxNumber },\n`; }
if (localisation.postalCode) { address += `${localisation.postalCode },\n`; }
if (localisation.locality) { address += `${localisation.locality },\n`; }
if (localisation.country) { address += `${localisation.country},\n`; }
if (localisation.distributionStatement) { address += `${localisation.distributionStatement},\n`; }
if (localisation.address) { address += `${localisation.address},\n`; }
if (localisation.place) { address += `${localisation.place},\n`; }
if (localisation.postOfficeBoxNumber) { address += `${localisation.postOfficeBoxNumber},\n`; }
if (localisation.postalCode) { address += `${localisation.postalCode},\n`; }
if (localisation.locality) { address += `${localisation.locality},\n`; }
if (localisation.country) { address += `${localisation.country}\n`; }

return (
<div className={`fr-card fr-card--xs fr-card--horizontal fr-card--grey fr-card--no-border card-${apiObject}`}>
<div className="fr-card__body">
<div className="fr-card__content">
<p className="fr-card__title">
<div className="fr-card fr-card--grey fr-card--no-border">
<div className="fr-card__content ">
<p className="fr-card__title">
<span className="fr-pr-1w">
{address}
</span>
<CopyButton
copyText={address}
size="sm"
/>
</p>
{localisation.phonenumber && (
<Text className="fr-card__title">
<Icon name="ri-phone-line" size="xl" />
<span className="fr-pr-1w">
{address}
{phoneNumberWithoutSpaces}
</span>
<CopyButton
copyText={address}
copyText={{ phoneNumberWithoutSpaces }}
size="sm"
/>
</Text>
)}
<div className="fr-card__start">
<p className="fr-card__detail fr-text--sm fr-mb-0">
<Icon name="ri-map-pin-fill" size="1x" />
Adresse
{' '}
{localisation.current ? 'actuelle' : 'historique'}
</p>
<div className="fr-card__start">
<p className="fr-card__detail fr-text--sm fr-mb-0">
<Icon name="ri-map-pin-fill" size="1x" />
Adresse
{' '}
{localisation.current ? 'actuelle' : 'historique'}
</p>
</div>
{localisation.phonenumber && (
<Text className="fr-card__title">
<Icon name="ri-phone-line" size="xl" />
<span className="fr-pr-1w">
{phoneNumberWithoutSpaces}
</span>
<CopyButton
copyText={{ phoneNumberWithoutSpaces }}
size="sm"
/>
</Text>
)}
<div className="fr-card__end fr-mt-0 fr-pt-0">
<p className="fr-card__detail">
{formatDescriptionDates(localisation.startDate || null, localisation.endDate || null)}
Expand All @@ -116,7 +116,7 @@ export default function LocalisationsComponent() {
const currentLocalisation = data.data.find((item) => item.current === true);
const inactives = data.data.filter((el) => (el.current === false)).sort((a, b) => a.startDate - b.startDate);
const actives = data.data.filter((el) => (el.current !== false));
const orderedList = [...actives, ...inactives];
const orderedList = [...actives, ...inactives].filter((address) => !address.current);

return (
<Bloc isLoading={isLoading} error={error} data={data}>
Expand All @@ -125,76 +125,91 @@ export default function LocalisationsComponent() {
Ajouter une adresse
</BlocActionButton>
<BlocContent>
{
data.totalCount === 1 && (
<Row>
{
(currentLocalisation?.coordinates) ? (
<Col n="12" spacing="mb-1w">
<Map
lat={currentLocalisation?.coordinates.lat}
lng={currentLocalisation?.coordinates.lng}
markers={[
{
address: `{${currentLocalisation?.address || ''}, ${currentLocalisation?.postalCode || ''} ${currentLocalisation?.locality || ''}, ${currentLocalisation?.country}}`,
latLng: [
currentLocalisation?.coordinates.lat,
currentLocalisation?.coordinates.lng,
],
},
]}
/>
</Col>
) : null
<Row gutters>
{currentLocalisation?.coordinates?.lat && currentLocalisation?.coordinates?.lng && (
<Col n="6">
<Map
lat={currentLocalisation?.coordinates?.lat}
lng={currentLocalisation?.coordinates?.lng}
markers={[
{
address: `{${currentLocalisation?.address || ''}, ${currentLocalisation?.postalCode || ''} ${currentLocalisation?.locality || ''}, ${currentLocalisation?.country}}`,
latLng: [
currentLocalisation?.coordinates?.lat,
currentLocalisation?.coordinates?.lng,
],
},
]}
/>
</Col>
)}
<Col n="6">
<Tabs>
{data && (
<Tab
className={`fr-card fr-card--xs fr-card--horizontal fr-card--grey fr-card--no-border card-${apiObject}`}
label="Adresse actuelle"
>
<Row>
<Col>
{currentLocalisation?.country ? renderAddress(currentLocalisation) : null}
</Col>
</Row>
{/* <GeographicalTags data={currentLocalisation?.geoCategories} /> */}
</Tab>
)}
{data.totalCount > 1 && (
<Tab
className={`fr-card fr-card--grey fr-card--no-border card-${apiObject}`}
label="Historique des adresses"
>
<Row style={{ overflowY: 'scroll' }}>
<style>
{`
::-webkit-scrollbar {
width: 8px;
}
<Col n="12">
{data.totalCount === 1 && currentLocalisation?.country && renderAddress(currentLocalisation)}
</Col>
</Row>
)
}
::-webkit-scrollbar-vertical {
width: 8px;
}
::-webkit-scrollbar-thumb:vertical {
background-color: gray;
}
::-webkit-scrollbar-track:vertical {
background-color: transparent;
}
`}
</style>

{data.totalCount > 1 && (
<Tabs>
<Tab label="Adresse actuelle" className="fr-p-0 fr-pt-1v">
{currentLocalisation?.coordinates ? (
<Row>
<Col n="12" spacing="mb-1w">
<Map
lat={currentLocalisation?.coordinates.lat}
lng={currentLocalisation?.coordinates.lng}
markers={[
{
address: `{${currentLocalisation?.address || ''}, ${currentLocalisation?.postalCode || ''} ${currentLocalisation?.locality || ''}, ${currentLocalisation?.country}}`,
latLng: [
currentLocalisation?.coordinates.lat,
currentLocalisation?.coordinates.lng,
],
},
]}
/>
</Col>
<Col n="12">
{currentLocalisation?.address ? renderAddress(currentLocalisation) : null}
</Col>
</Row>
) : null}
</Tab>
{(data.totalCount > 1) ? (
<Tab label="Historique des adresses" className="fr-p-0 fr-pt-1v">
<Row gutters as="ul">
{
orderedList.map((item) => (
<Col n="12" as="li" key={`HistoriqueLocalisation${item.id}`}>
{renderAddress(item)}
</Col>
))
}
</Row>
</Tab>
) : null}
</Tabs>
{orderedList.length > 1 && (
<Text style={{ textAlign: 'center', color: 'gray' }}>
Défiler pour voir plus de contenu
</Text>
)}
{orderedList.map((item) => (
<>
<Col n="12" key={`HistoriqueLocalisation${item.id}`}>
{renderAddress(item)}
</Col>
{/* <GeographicalTags data={item.geoCategories} /> */}
</>
))}
</Row>
</Tab>
)}
</Tabs>
</Col>
</Row>
{data && (
<Row className="fr-mt-3w">
<Col>
<BlocTitle as="h3" look="h6">Catégories géographiques de l'adresse actuelle</BlocTitle>
<GeographicalTags data={currentLocalisation?.geoCategories} />
</Col>
</Row>
)}

</BlocContent>
<BlocModal>
<Modal isOpen={showModal} size="lg" hide={() => setShowModal(false)}>
Expand Down
Loading

0 comments on commit c30d16c

Please sign in to comment.