Skip to content

Commit 0b44773

Browse files
committed
Merge branch 'staging'
2 parents d797b89 + 67a099d commit 0b44773

File tree

4 files changed

+53
-28
lines changed

4 files changed

+53
-28
lines changed

src/components/blocs/identifiers/index.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
1-
import { Col, Modal, ModalContent, ModalTitle, Text } from '@dataesr/react-dsfr';
1+
import {
2+
Col,
3+
Modal,
4+
ModalContent,
5+
ModalTitle,
6+
Text,
7+
} from '@dataesr/react-dsfr';
28
import { useState } from 'react';
39

4-
import IdentifierForm from '../../forms/identifier';
5-
import ExpendableListCards from '../../card/expendable-list-cards';
6-
import {
7-
Bloc,
8-
BlocActionButton,
9-
BlocContent,
10-
BlocModal,
11-
BlocTitle,
12-
} from '../../bloc';
13-
import KeyValueCard from '../../card/key-value-card';
1410
import useEnums from '../../../hooks/useEnums';
1511
import useFetch from '../../../hooks/useFetch';
1612
import useNotice from '../../../hooks/useNotice';
1713
import useUrl from '../../../hooks/useUrl';
1814
import api from '../../../utils/api';
15+
import getLink from '../../../utils/get-links';
1916
import { getTvaIntraFromSiren } from '../../../utils/get-tva-intra';
2017
import {
2118
deleteError,
2219
deleteSuccess,
20+
saveDuplicate,
2321
saveError,
2422
saveSuccess,
2523
} from '../../../utils/notice-contents';
26-
import getLink from '../../../utils/get-links';
24+
import {
25+
Bloc,
26+
BlocActionButton,
27+
BlocContent,
28+
BlocModal,
29+
BlocTitle,
30+
} from '../../bloc';
31+
import ExpendableListCards from '../../card/expendable-list-cards';
32+
import KeyValueCard from '../../card/key-value-card';
2733
import CopyButton from '../../copy/copy-button';
34+
import IdentifierForm from '../../forms/identifier';
2835

2936
export default function IdentifiersComponent() {
3037
const { notice } = useNotice();
@@ -40,8 +47,8 @@ export default function IdentifiersComponent() {
4047
const method = itemId ? 'patch' : 'post';
4148
const saveUrl = itemId ? `${url}/${itemId}` : url;
4249
await api[method](saveUrl, body)
43-
.then(() => {
44-
notice(saveSuccess);
50+
.then((response) => {
51+
notice(response.status === 204 ? saveDuplicate : saveSuccess);
4552
reload();
4653
})
4754
.catch(() => notice(saveError));
@@ -78,13 +85,13 @@ export default function IdentifiersComponent() {
7885
const renderCards = () => {
7986
if (!data) return null;
8087
const list = [];
81-
const inactives = data.data.filter((el) => (el.active === false));
82-
const actives = data.data.filter((el) => (el.active !== false));
88+
const inactives = data.data.filter((el) => el.active === false);
89+
const actives = data.data.filter((el) => el.active !== false);
8390
const orderedList = [...actives, ...inactives];
8491

8592
if (data) {
8693
orderedList?.forEach((el) => {
87-
const inactive = (el.active === false);
94+
const inactive = el.active === false;
8895
let siretCard = el.value;
8996

9097
if (el.type === 'siret') {
@@ -116,7 +123,7 @@ export default function IdentifiersComponent() {
116123
if (el.type !== 'siret' && el.type !== 'cnrs-unit') {
117124
list.push(
118125
<KeyValueCard
119-
cardKey={options?.find((type) => (el.type === type.value))?.label}
126+
cardKey={options?.find((type) => el.type === type.value)?.label}
120127
cardValue={el.value}
121128
className={`card-${apiObject}`}
122129
copy

src/components/notice/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import PropTypes from 'prop-types';
2+
23
import usePausableTimer from '../../hooks/usePausableTimer';
34

45
import './notice.scss';
56

67
export default function Notice({
7-
content,
88
autoDismissAfter,
9+
content,
910
remove,
1011
type,
1112
}) {
@@ -43,14 +44,14 @@ export default function Notice({
4344
}
4445

4546
Notice.propTypes = {
46-
content: PropTypes.string,
4747
autoDismissAfter: PropTypes.number,
48+
content: PropTypes.string,
4849
remove: PropTypes.func.isRequired,
4950
type: PropTypes.oneOf(['info', 'success', 'error', 'warning']),
5051
};
5152

5253
Notice.defaultProps = {
53-
content: '',
5454
autoDismissAfter: 6000,
55+
content: '',
5556
type: 'info',
5657
};

src/hooks/useNotice.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import PropTypes from 'prop-types';
12
import {
23
createContext,
3-
useContext,
4-
useState,
54
useCallback,
5+
useContext,
66
useMemo,
7+
useState,
78
} from 'react';
89
import { createPortal } from 'react-dom';
9-
import PropTypes from 'prop-types';
10+
1011
import Notice from '../components/notice';
1112

1213
const NoticeContext = createContext();

src/utils/notice-contents.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
export const deleteError = { content: "Une erreur s'est produite. L'élément n'a pas pu être supprimé", autoDismissAfter: 6000, type: 'error' };
2-
export const saveError = { content: "Une erreur s'est produite lors de l'envoi du formulaire.", autoDismissAfter: 6000, type: 'error' };
3-
export const saveSuccess = { content: 'Vos modifications ont été correctement enregistrées', autoDismissAfter: 6000, type: 'success' };
4-
export const deleteSuccess = { content: "L'élément a été supprimé avec succès.", autoDismissAfter: 6000, type: 'success' };
1+
export const deleteError = {
2+
content: "Une erreur s'est produite. L'élément n'a pas pu être supprimé",
3+
type: 'error',
4+
};
5+
export const deleteSuccess = {
6+
content: "L'élément a été supprimé avec succès.",
7+
type: 'success',
8+
};
9+
export const saveError = {
10+
content: "Une erreur s'est produite lors de l'envoi du formulaire.",
11+
type: 'error',
12+
};
13+
export const saveSuccess = {
14+
content: 'Vos modifications ont été correctement enregistrées',
15+
type: 'success',
16+
};
17+
export const saveDuplicate = {
18+
content: "Vos modifications n'ont pas été prises en compte car un élément identique existait déjà.",
19+
type: 'warning',
20+
};

0 commit comments

Comments
 (0)