From 51ec18597eadd17c18af4c6733f54ad553d58305 Mon Sep 17 00:00:00 2001 From: Marc Farra Date: Thu, 12 Oct 2023 17:52:39 +0300 Subject: [PATCH] Add corresponding authors --- .../documents/journal-pdf-preview/index.js | 68 +++++++++++++------ 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/app/assets/scripts/components/documents/journal-pdf-preview/index.js b/app/assets/scripts/components/documents/journal-pdf-preview/index.js index f71e3103..f26f0ebb 100644 --- a/app/assets/scripts/components/documents/journal-pdf-preview/index.js +++ b/app/assets/scripts/components/documents/journal-pdf-preview/index.js @@ -427,38 +427,58 @@ function JournalPdfPreview() { const hasAffiliation = contactAffiliations && contactAffiliations.length > 0; - let contactEmail = contact.mechanisms.find( - (mechanism) => mechanism.mechanism_type === 'Email' - )?.mechanism_value; - const item = ( {getContactName(contact, { full: true })} - {contactEmail && ` (${contactEmail})`} + {hasAffiliation && + contactAffiliations.map((affiliation, j) => { + return ( + <> + + {Array.from(affiliations).indexOf(affiliation) + 1} + + + {j < contactAffiliations.length - 1 && , } + + + ); + })} + {i < contacts_link.length - 1 && , } + {i === contacts_link.length - 2 && and } - {hasAffiliation && - contactAffiliations.map((affiliation, j) => { - return ( - <> - - {Array.from(affiliations).indexOf(affiliation) + 1} - - - {j < contactAffiliations.length - 1 && , } - - - ); - })} - {i < contacts_link.length - 1 && , } - {i === contacts_link.length - 2 && and } ); contacts.push(item); } ); + + // create corresponding authors list component + const correspondingAuthors = + contacts_link + ?.filter((c) => + c.roles?.find((r) => r.toLowerCase() === 'corresponding author') + ) + .map(({ contact }) => { + let contactEmail = contact.mechanisms.find( + (mechanism) => mechanism.mechanism_type === 'Email' + )?.mechanism_value; + + let contactName = getContactName(contact, { full: true }); + + return `${contactName} ${contactEmail ? `(${contactEmail})` : ''}`; + }) || []; + + const correspondingAuthorsString = correspondingAuthors.map((author, i) => ( + <> + {author} + {i < correspondingAuthors.length - 1 && , } + {i === correspondingAuthors.length - 2 && and } + + )); return { items: contacts, + correspondingAuthors: correspondingAuthorsString, affiliations_list: Array.from(affiliations), maxIndex: (contacts_link?.length ?? 0) - 1 }; @@ -581,6 +601,14 @@ function JournalPdfPreview() { ))} +
+ {contacts?.correspondingAuthors?.length > 0 && ( +
+ Corresponding Author(s): + {contacts?.correspondingAuthors} +
+ )} +