Skip to content

Commit

Permalink
fix(dashboard): lorsqu'on souhaite créer une consultation sans avoir …
Browse files Browse the repository at this point in the history
…sélectionné pour quelle personne suivie, avant l'onglet 'Documents' était bland, désormais il affiche un bouton qui lance le message d'erreur 'Veuillez sélectionner une personne auparavant' lorsqu'on le clique (#1687)
  • Loading branch information
arnaudambro authored Oct 3, 2023
1 parent 747e5f3 commit 46cd68d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
78 changes: 38 additions & 40 deletions dashboard/src/components/ConsultationModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
<DocumentsModule
personId={data.person}
color="blue-900"
showAssociatedItem={false}
documents={data.documents.map((doc) => ({
...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');
}}
/>
)}
<DocumentsModule
personId={data.person}
color="blue-900"
showAssociatedItem={false}
documents={data.documents.map((doc) => ({
...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');
}}
/>
</div>
<div
className={['tw-flex tw-h-[50vh] tw-w-full tw-flex-col tw-gap-4 tw-overflow-y-auto', activeTab !== 'Commentaires' && 'tw-hidden']
Expand Down
11 changes: 11 additions & 0 deletions dashboard/src/components/DocumentsGeneric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,19 @@ function AddDocumentInput({ personId, onAddDocuments }: AddDocumentInputProps) {
key={resetFileInputKey}
name="file"
className="tw-hidden"
onClick={(e) => {
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;
Expand Down

0 comments on commit 46cd68d

Please sign in to comment.