From e09da47b07c4f7803496fc76bcf58c05d90b222b Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Mon, 2 Oct 2023 16:02:19 +0200 Subject: [PATCH] =?UTF-8?q?fix(dashboard):=20lorsqu'on=20souhaite=20cr?= =?UTF-8?q?=C3=A9er=20une=20consultation=20sans=20avoir=20s=C3=A9lectionn?= =?UTF-8?q?=C3=A9=20pour=20quelle=20personne=20suivie,=20avant=20l'onglet?= =?UTF-8?q?=20'Documents'=20=C3=A9tait=20bland,=20d=C3=A9sormais=20il=20af?= =?UTF-8?q?fiche=20un=20bouton=20qui=20lance=20le=20message=20d'erreur=20'?= =?UTF-8?q?Veuillez=20s=C3=A9lectionner=20une=20personne=20auparavant'=20l?= =?UTF-8?q?orsqu'on=20le=20clique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src/components/ConsultationModal.js | 78 +++++++++---------- dashboard/src/components/DocumentsGeneric.tsx | 11 +++ 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/dashboard/src/components/ConsultationModal.js b/dashboard/src/components/ConsultationModal.js index 1da18034b..7c1b9e2ab 100644 --- a/dashboard/src/components/ConsultationModal.js +++ b/dashboard/src/components/ConsultationModal.js @@ -455,46 +455,44 @@ function ConsultationContent({ personId, consultation, date, onClose }) { className={['tw-flex tw-h-[50vh] tw-w-full tw-flex-col tw-gap-4 tw-overflow-y-auto', activeTab !== 'Documents' && 'tw-hidden'] .filter(Boolean) .join(' ')}> - {data.person && ( - ({ - ...doc, - type: doc.type ?? 'document', // or 'folder' - linkedItem: { _id: consultation?._id, type: 'consultation' }, - }))} - onAddDocuments={async (nextDocuments) => { - const newData = { - ...data, - documents: [...data.documents, ...nextDocuments], - }; - setData(newData); - const ok = await handleSubmit({ newData }); - if (ok && nextDocuments.length > 1) toast.success('Documents ajoutés'); - }} - onDeleteDocument={async (document) => { - const newData = { ...data, documents: data.documents.filter((d) => d._id !== document._id) }; - setData(newData); - const ok = await handleSubmit({ newData }); - if (ok) toast.success('Document supprimé'); - return ok; - }} - onSubmitDocument={async (document) => { - const newData = { - ...data, - documents: data.documents.map((d) => { - if (d._id === document._id) return document; - return d; - }), - }; - setData(newData); - const ok = await handleSubmit({ newData }); - if (ok) toast.success('Document mis à jour'); - }} - /> - )} + ({ + ...doc, + type: doc.type ?? 'document', // or 'folder' + linkedItem: { _id: consultation?._id, type: 'consultation' }, + }))} + onAddDocuments={async (nextDocuments) => { + const newData = { + ...data, + documents: [...data.documents, ...nextDocuments], + }; + setData(newData); + const ok = await handleSubmit({ newData }); + if (ok && nextDocuments.length > 1) toast.success('Documents ajoutés'); + }} + onDeleteDocument={async (document) => { + const newData = { ...data, documents: data.documents.filter((d) => d._id !== document._id) }; + setData(newData); + const ok = await handleSubmit({ newData }); + if (ok) toast.success('Document supprimé'); + return ok; + }} + onSubmitDocument={async (document) => { + const newData = { + ...data, + documents: data.documents.map((d) => { + if (d._id === document._id) return document; + return d; + }), + }; + setData(newData); + const ok = await handleSubmit({ newData }); + if (ok) toast.success('Document mis à jour'); + }} + />
{ + if (!personId) { + e.preventDefault(); + toast.error('Veuillez sélectionner une personne auparavant'); + return; + } + }} onChange={async (e) => { if (!e.target.files?.length) return; + if (!personId) { + toast.error('Veuillez sélectionner une personne auparavant'); + return; + } const docsResponses = []; for (let i = 0; i < e.target.files.length; i++) { const fileToUpload = e.target.files[i] as any;