diff --git a/src/pages/structures/[id]/updates/components/AdresseUpdate.js b/src/pages/structures/[id]/updates/components/AdresseUpdate.js index 87132da9..6951cb5f 100644 --- a/src/pages/structures/[id]/updates/components/AdresseUpdate.js +++ b/src/pages/structures/[id]/updates/components/AdresseUpdate.js @@ -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 = [ @@ -44,10 +46,14 @@ const getSireneValue = (update) =>
{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 (
     <>
       
@@ -88,8 +94,23 @@ export function AdresseUpdate({ update, paysageData, reload }) { { + 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); + }} /> diff --git a/src/pages/structures/[id]/updates/components/NicSiegeUpdate.js b/src/pages/structures/[id]/updates/components/NicSiegeUpdate.js index 2a27aa18..adcdcc9f 100644 --- a/src/pages/structures/[id]/updates/components/NicSiegeUpdate.js +++ b/src/pages/structures/[id]/updates/components/NicSiegeUpdate.js @@ -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; @@ -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); @@ -72,10 +75,20 @@ export function NicSiegeUpdate({ update, paysageData, reload }) { { - 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={[{