Skip to content

Commit

Permalink
aojouter Address et Nic
Browse files Browse the repository at this point in the history
  • Loading branch information
folland87 committed Feb 5, 2025
1 parent d21f8d2 commit cec7c1e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
25 changes: 23 additions & 2 deletions src/pages/structures/[id]/updates/components/AdresseUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Button from '../../../../../components/button';
import Modal from '../../../../../components/modal';
import LocalisationForm from '../../../../../components/forms/localisation';
import DismissButton from './DismissButton';
import api from '../../../../../utils/api';
import useNotice from '../../../../../hooks/useNotice';

function transformAddress(input, startDate = null) {
const address = [
Expand Down Expand Up @@ -44,10 +46,14 @@ const getSireneValue = (update) => <pre className="fr-text--xs">{formatAddress(t

export function AdresseUpdate({ update, paysageData, reload }) {
const [showModal, setShowModal] = useState(false);
const { notice } = useNotice();

const paysageValue = getPaysageValue(paysageData);
const sireneValue = getSireneValue(update);

const sirenAdress = transformAddress(update.value, update.changeEffectiveDate);
const sireneQuery = `${sirenAdress.address} ${sirenAdress.city}`;

return (
<>
<div style={{ width: '100%', display: 'flex', gap: '2rem' }}>
Expand Down Expand Up @@ -88,8 +94,23 @@ export function AdresseUpdate({ update, paysageData, reload }) {
</ModalTitle>
<ModalContent>
<LocalisationForm
data={transformAddress(update.value)}
defaultQuery={transformAddress(update.value).address}
data={sirenAdress}
defaultQuery={sireneQuery}
onSave={async (body) => {
try {
await api.patch(
`/structures/${update.paysage}/localisations/${paysageData.currentLocalisation.id}`,
{ active: false, endDate: update.changeEffectiveDate },
);
await api.post(`/structures/${update.paysage}/localisations`, body);
await api.patch(`/sirene/updates/${update._id}`, { status: 'ok' });
reload();
notice({ content: 'OK', autoDismissAfter: 6000, type: 'success' });
} catch {
notice({ content: 'KO', autoDismissAfter: 6000, type: 'error' });
}
setShowModal(false);
}}
/>
</ModalContent>
</Modal>
Expand Down
19 changes: 16 additions & 3 deletions src/pages/structures/[id]/updates/components/NicSiegeUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Button from '../../../../../components/button';
import Modal from '../../../../../components/modal';
import IdentifierForm from '../../../../../components/forms/identifier';
import DismissButton from './DismissButton';
import api from '../../../../../utils/api';
import useNotice from '../../../../../hooks/useNotice';

export const getPaysageValue = (paysageData) => paysageData.currentSiret?.value;

Expand All @@ -20,6 +22,7 @@ export const getForm = (update) => ({

export function NicSiegeUpdate({ update, paysageData, reload }) {
const [showModal, setShowModal] = useState(false);
const { notice } = useNotice();

const paysageValue = getPaysageValue(paysageData);
const sireneValue = getSireneValue(update);
Expand Down Expand Up @@ -72,10 +75,20 @@ export function NicSiegeUpdate({ update, paysageData, reload }) {
</ModalTitle>
<ModalContent>
<IdentifierForm
id={update.id}
data={getForm(update)}
onSave={() => {
console.log('save');
onSave={async (body) => {
try {
await api.patch(
`/structures/${update.paysage}/identifiers/${paysageData.currentSiret.id}`,
{ active: false, endDate: update.changeEffectiveDate },
);
await api.post(`/structures/${update.paysage}/identifiers`, body);
await api.patch(`/sirene/updates/${update._id}`, { status: 'ok' });
reload();
notice({ content: 'OK', autoDismissAfter: 6000, type: 'success' });
} catch {
notice({ content: 'KO', autoDismissAfter: 6000, type: 'error' });
}
setShowModal(false);
}}
options={[{
Expand Down

0 comments on commit cec7c1e

Please sign in to comment.