Skip to content

Commit

Permalink
Extract no-permission strings
Browse files Browse the repository at this point in the history
Refs #1817
  • Loading branch information
thewilkybarkid committed Nov 29, 2024
1 parent d526416 commit f8e704f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
8 changes: 8 additions & 0 deletions locales/en-US/no-permission-page.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"noPermissionTitle": {
"message": "You do not have permission to view this page"
},
"shouldHaveAccess": {
"message": "If you think you should have access, please <contact>get in touch</contact>."
}
}
19 changes: 14 additions & 5 deletions src/NoPermissionPage/NoPermissionPage.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { StatusCodes } from 'http-status-codes'
import { html, plainText } from '../html.js'
import { html, plainText, rawHtml } from '../html.js'
import { type SupportedLocale, translate } from '../locales/index.js'
import { PageResponse } from '../response.js'

export const createNoPermissionPage = (): PageResponse =>
export const createNoPermissionPage = (locale: SupportedLocale): PageResponse =>
PageResponse({
status: StatusCodes.FORBIDDEN,
title: plainText`You do not have permission to view this page`,
title: plainText(translate(locale, 'no-permission-page', 'noPermissionTitle')()),
main: html`
<h1>You do not have permission to view this page</h1>
<h1>${translate(locale, 'no-permission-page', 'noPermissionTitle')()}</h1>
<p>If you think you should have access, please <a href="mailto:help@prereview.org">get in touch</a>.</p>
<p>
${rawHtml(
translate(
locale,
'no-permission-page',
'shouldHaveAccess',
)({ contact: text => html`<a href="mailto:help@prereview.org">${text}</a>`.toString() }),
)}
</p>
`,
})
6 changes: 5 additions & 1 deletion src/NoPermissionPage/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Effect } from 'effect'
import { Locale } from '../Context.js'
import type { PageResponse } from '../response.js'
import { createNoPermissionPage } from './NoPermissionPage.js'

export const NoPermissionPage: Effect.Effect<PageResponse> = Effect.sync(createNoPermissionPage)
export const NoPermissionPage: Effect.Effect<PageResponse, never, Locale> = Effect.andThen(
Locale,
createNoPermissionPage,
)
2 changes: 1 addition & 1 deletion src/http-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ export const pageNotFound = Effect.runSync(Effect.provideService(PageNotFound, L

export const havingProblemsPage = Effect.runSync(Effect.provideService(HavingProblemsPage, Locale, DefaultLocale))

export const noPermissionPage = Effect.runSync(NoPermissionPage)
export const noPermissionPage = Effect.runSync(Effect.provideService(NoPermissionPage, Locale, DefaultLocale))
3 changes: 2 additions & 1 deletion visual-regression/NoPermissionPage/NoPermissionPage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DefaultLocale } from '../../src/locales/index.js'
import { createNoPermissionPage } from '../../src/NoPermissionPage/NoPermissionPage.js'
import { expect, test } from '../base.js'

test('content looks right', async ({ showPage }) => {
const content = await showPage(createNoPermissionPage())
const content = await showPage(createNoPermissionPage(DefaultLocale))

await expect(content).toHaveScreenshot()
})

0 comments on commit f8e704f

Please sign in to comment.