Skip to content

Commit

Permalink
Go back to the list of other authors from the add-an-author step if t…
Browse files Browse the repository at this point in the history
…here are other authors already

Refs #388
  • Loading branch information
thewilkybarkid committed Oct 20, 2022
1 parent 435424d commit 5edd175
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
7 changes: 7 additions & 0 deletions integration/posting-a-prereview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,13 @@ test.extend(canAddAuthors)('see existing values when going back a step', async (

await expect(page.locator('h1')).toContainText('You have added 1 other author')

await page.check('text="Yes"')
await page.click('text="Continue"')

await page.click('text="Back"')

await expect(page.locator('h1')).toContainText('You have added 1 other author')

await page.click('text="Back"')

await expect(page.locator('text="Yes"')).toBeChecked()
Expand Down
23 changes: 16 additions & 7 deletions src/write-review/write-review-add-author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ export const writeReviewAddAuthor = flow(
)

const showAddAuthorForm = flow(
fromReaderK(({ preprint }: { preprint: Preprint }) =>
addAuthorForm(preprint, { name: E.right(undefined), orcid: E.right(undefined) }),
fromReaderK(({ form, preprint }: { form: Form; preprint: Preprint }) =>
addAuthorForm(preprint, form.otherAuthors ? form.otherAuthors.length > 0 : false, {
name: E.right(undefined),
orcid: E.right(undefined),
}),
),
RM.ichainFirst(() => RM.status(Status.OK)),
RM.ichainMiddlewareK(sendHtml),
)

const showAddAuthorErrorForm = (preprint: Preprint) =>
const showAddAuthorErrorForm = (preprint: Preprint, otherAuthors: boolean) =>
flow(
fromReaderK((form: AddAuthorForm) => addAuthorForm(preprint, form)),
fromReaderK((form: AddAuthorForm) => addAuthorForm(preprint, otherAuthors, form)),
RM.ichainFirst(() => RM.status(Status.BadRequest)),
RM.ichainMiddlewareK(sendHtml),
)
Expand Down Expand Up @@ -106,7 +109,7 @@ const handleAddAuthorForm = ({ form, preprint, user }: { form: Form; preprint: P
RM.map(updateForm(form)),
RM.chainFirstReaderTaskK(saveForm(user.orcid, preprint.doi)),
RM.ichainMiddlewareK(() => seeOther(format(writeReviewAddAuthorsMatch.formatter, { doi: preprint.doi }))),
RM.orElseW(showAddAuthorErrorForm(preprint)),
RM.orElseW(showAddAuthorErrorForm(preprint, form.otherAuthors ? form.otherAuthors.length > 0 : false)),
)

const OrcidD = pipe(
Expand All @@ -126,14 +129,20 @@ type AddAuthorForm = {
readonly orcid: E.Either<InvalidE, Orcid | undefined>
}

function addAuthorForm(preprint: Preprint, form: AddAuthorForm) {
function addAuthorForm(preprint: Preprint, otherAuthors: boolean, form: AddAuthorForm) {
const error = hasAnError(form)

return page({
title: plainText`${error ? 'Error: ' : ''}Add an author – PREreview of “${preprint.title}”`,
content: html`
<nav>
<a href="${format(writeReviewAuthorsMatch.formatter, { doi: preprint.doi })}" class="back">Back</a>
<a
href="${otherAuthors
? format(writeReviewAddAuthorsMatch.formatter, { doi: preprint.doi })
: format(writeReviewAuthorsMatch.formatter, { doi: preprint.doi })}"
class="back"
>Back</a
>
</nav>
<main>
Expand Down

0 comments on commit 5edd175

Please sign in to comment.