Skip to content

Commit

Permalink
Get ready to extract write-review/add-author-page strings
Browse files Browse the repository at this point in the history
Refs: #1817
  • Loading branch information
erkannt committed Oct 17, 2024
1 parent 7e85018 commit d1601e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/write-review/add-author-page/add-author-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Status } from 'hyper-ts'
import { P, match } from 'ts-pattern'
import { type InvalidE, type MissingE, hasAnError } from '../../form.js'
import { html, plainText, rawHtml } from '../../html.js'
import type { SupportedLocale } from '../../locales/index.js'
import type { PreprintTitle } from '../../preprint.js'
import { StreamlinePageResponse } from '../../response.js'
import { writeReviewAddAuthorMatch, writeReviewAddAuthorsMatch, writeReviewAuthorsMatch } from '../../routes.js'
Expand All @@ -18,6 +19,7 @@ export function addAuthorForm({
form: AddAuthorForm
preprint: PreprintTitle
otherAuthors?: boolean
locale: SupportedLocale
}) {
const error = hasAnError(form)
const backMatch = otherAuthors ? writeReviewAddAuthorsMatch : writeReviewAuthorsMatch
Expand Down
13 changes: 11 additions & 2 deletions src/write-review/add-author-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { get } from 'spectacles-ts'
import { P, match } from 'ts-pattern'
import { getInput, invalidE, missingE } from '../../form.js'
import { havingProblemsPage, pageNotFound } from '../../http-error.js'
import { DefaultLocale } from '../../locales/index.js'
import { type GetPreprintTitleEnv, type PreprintTitle, getPreprintTitle } from '../../preprint.js'
import { type PageResponse, RedirectResponse, type StreamlinePageResponse } from '../../response.js'
import { writeReviewAddAuthorsMatch, writeReviewMatch } from '../../routes.js'
Expand Down Expand Up @@ -45,6 +46,7 @@ export const writeReviewAddAuthor = ({
pipe(
RTE.Do,
RTE.apS('user', RTE.fromNullable('no-session' as const)(user)),
RTE.apS('locale', RTE.of(DefaultLocale)),
RTE.let('preprint', () => preprint),
RTE.let('method', () => method),
RTE.let('body', () => body),
Expand All @@ -62,7 +64,7 @@ export const writeReviewAddAuthor = ({
state =>
match(state)
.with({ form: { moreAuthors: 'yes' }, method: 'POST' }, handleAddAuthorForm)
.with({ form: { moreAuthors: 'yes' } }, ({ form, preprint }) =>
.with({ form: { moreAuthors: 'yes' } }, ({ form, preprint, locale }) =>
RT.of(
addAuthorForm({
form: {
Expand All @@ -71,6 +73,7 @@ export const writeReviewAddAuthor = ({
},
preprint,
otherAuthors: (form.otherAuthors ?? []).length > 0,
locale,
}),
),
)
Expand All @@ -94,6 +97,7 @@ const handleAddAuthorForm = ({
pipe(
RTE.Do,
RTE.let('name', () => pipe(NameFieldD.decode(body), E.mapLeft(missingE))),
RTE.apS('locale', RTE.of(DefaultLocale)),
RTE.let('emailAddress', () =>
pipe(
EmailAddressFieldD.decode(body),
Expand Down Expand Up @@ -121,7 +125,12 @@ const handleAddAuthorForm = ({
match(error)
.with('form-unavailable', () => havingProblemsPage)
.with({ name: P.any }, error =>
addAuthorForm({ form: error, preprint, otherAuthors: (form.otherAuthors ?? []).length > 0 }),
addAuthorForm({
form: error,
preprint,
otherAuthors: (form.otherAuthors ?? []).length > 0,
locale: error.locale,
}),
)
.exhaustive(),
() => RedirectResponse({ location: format(writeReviewAddAuthorsMatch.formatter, { id: preprint.id }) }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Doi } from 'doi-ts'
import * as E from 'fp-ts/lib/Either.js'
import { DefaultLocale } from '../../assets/locales/index.js'
import { invalidE, missingE } from '../../src/form.js'
import { html } from '../../src/html.js'
import type { PreprintTitle } from '../../src/preprint.js'
Expand All @@ -15,6 +16,7 @@ const preprint = {
title: html`The role of LHCBM1 in non-photochemical quenching in <i>Chlamydomonas reinhardtii</i>`,
language: 'en',
} satisfies PreprintTitle
const locale = DefaultLocale

test('content looks right', async ({ showPage }) => {
const response = addAuthorForm({
Expand All @@ -23,6 +25,7 @@ test('content looks right', async ({ showPage }) => {
emailAddress: E.right(undefined),
},
preprint,
locale,
})

const content = await showPage(response)
Expand All @@ -37,6 +40,7 @@ test('content looks right when fields are missing', async ({ showPage }) => {
emailAddress: E.left(missingE()),
},
preprint,
locale,
})

const content = await showPage(response)
Expand All @@ -51,6 +55,7 @@ test('content looks right when fields are invalid', async ({ showPage }) => {
emailAddress: E.left(invalidE('not an email address')),
},
preprint,
locale,
})

const content = await showPage(response)
Expand Down

0 comments on commit d1601e4

Please sign in to comment.