Skip to content

Commit

Permalink
feat(ojoi): add Cases in progress screen for OJOI (#16492)
Browse files Browse the repository at this point in the history
* feat(ojoi): add Cases in progress screen for OJOI

* fix: add status to cases

* fix: cleanup CaseInProgress

* fix: add translations for breadcrumbs

* fix: handle null/empty data

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and svanaeinars committed Oct 23, 2024
1 parent b2ab3ba commit 62aaf84
Show file tree
Hide file tree
Showing 19 changed files with 494 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ReactNode } from 'react'

import {
Box,
GridColumn,
Expand All @@ -17,7 +15,7 @@ import * as s from './OJOIHomeIntro.css'

export type OJOIHomeIntroProps = {
organization?: Organization
breadCrumbs: ReactNode
breadCrumbs: React.ReactNode
searchPlaceholder: string
quickLinks: Array<{ title: string; href: string; variant?: TagVariant }>
searchUrl: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import format from 'date-fns/format'
import is from 'date-fns/locale/is'

import { LinkV2, Table as T, Text } from '@island.is/island-ui/core'
import { Locale } from '@island.is/shared/types'
import { OfficialJournalOfIcelandAdvertsResponse } from '@island.is/web/graphql/schema'
import { useLinkResolver } from '@island.is/web/hooks'

import { formatDate } from './OJOIUtils'

export const OJOISearchListView = ({
adverts,
locale,
Expand All @@ -31,9 +30,7 @@ export const OJOISearchListView = ({
<T.Row key={ad.id}>
<T.Data>
<Text variant="small" whiteSpace="nowrap">
{format(new Date(ad.publicationDate), 'dd.MM.yyyy', {
locale: is,
})}
{formatDate(ad.publicationDate)}
</Text>
</T.Data>
<T.Data>
Expand Down
5 changes: 4 additions & 1 deletion apps/web/components/OfficialJournalOfIceland/OJOIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export const sortCategories = (cats: EntityOption[]) => {
})
}

export const formatDate = (date: string, df = 'dd.MM.yyyy') => {
export const formatDate = (date?: string, df = 'dd.MM.yyyy') => {
if (!date) {
return '-'
}
try {
return format(new Date(date), df, { locale: is })
} catch (e) {
Expand Down
46 changes: 45 additions & 1 deletion apps/web/components/OfficialJournalOfIceland/OJOIWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
BreadCrumbItem,
Breadcrumbs,
Button,
GridColumn,
GridContainer,
GridRow,
LinkV2,
Text,
} from '@island.is/island-ui/core'
Expand All @@ -28,6 +31,7 @@ type WrapperProps = {
sidebarContent?: ReactNode
goBackUrl?: string
hideTitle?: boolean
isHomePage?: boolean
}

export const OJOIWrapper = ({
Expand All @@ -40,6 +44,7 @@ export const OJOIWrapper = ({
sidebarContent,
goBackUrl,
hideTitle,
isHomePage,
}: WrapperProps) => {
const { width } = useWindowSize()
const [isMobile, setIsMobile] = useState<boolean | undefined>()
Expand Down Expand Up @@ -133,7 +138,46 @@ export const OJOIWrapper = ({
</SidebarLayout>
)}

{!sidebarContent && children}
{!sidebarContent && !isHomePage && (
<GridContainer>
<GridRow>
<GridColumn span="12/12">
{breadcrumbItems && (
<Breadcrumbs
items={breadcrumbItems ?? []}
renderLink={(link, item) => {
return item?.href ? (
<NextLink href={item?.href} legacyBehavior>
{link}
</NextLink>
) : (
link
)
}}
/>
)}

{!hideTitle && (
<Text as="h1" variant="h1" marginTop={2} marginBottom={3}>
{pageTitle}
</Text>
)}

{pageDescription && (
<Box className="rs_read" marginTop={3} paddingBottom={4}>
<Text variant="default">{pageDescription}</Text>
</Box>
)}

<Box className="rs_read" marginBottom={'containerGutter'}>
{children}
</Box>
</GridColumn>
</GridRow>
</GridContainer>
)}

{!sidebarContent && isHomePage && children}

<Box className="rs_read" background="blue100">
<WebFooter
Expand Down
11 changes: 11 additions & 0 deletions apps/web/pages/stjornartidindi/mal-i-vinnslu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import withApollo from '@island.is/web/graphql/withApollo'
import { withLocale } from '@island.is/web/i18n'
import OJOICasesInProgress from '@island.is/web/screens/OfficialJournalOfIceland/OJOICasesInProgress'
import { getServerSidePropsWrapper } from '@island.is/web/utils/getServerSidePropsWrapper'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
const Screen = withApollo(withLocale('is')(OJOICasesInProgress))

export default Screen

export const getServerSideProps = getServerSidePropsWrapper(Screen)
2 changes: 1 addition & 1 deletion apps/web/screens/OfficialJournalOfIceland/OJOIAdvert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const OJOIAdvertPage: CustomScreen<OJOIAdvertProps> = ({

const breadcrumbItems = [
{
title: 'Ísland.is',
title: formatMessage(m.breadcrumb.frontpage),
href: linkResolver('homepage', [], locale).href,
},
{
Expand Down
174 changes: 174 additions & 0 deletions apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import { useIntl } from 'react-intl'

import { Table as T } from '@island.is/island-ui/core'
import { Locale } from '@island.is/shared/types'
import {
ContentLanguage,
CustomPageUniqueIdentifier,
OfficialJournalOfIcelandCaseInProgress,
Query,
QueryGetOrganizationArgs,
QueryOfficialJournalOfIcelandCasesInProgressArgs,
} from '@island.is/web/graphql/schema'
import { useLinkResolver } from '@island.is/web/hooks'
import { withMainLayout } from '@island.is/web/layouts/main'
import { CustomNextError } from '@island.is/web/units/errors'

import {
formatDate,
OJOIWrapper,
} from '../../components/OfficialJournalOfIceland'
import {
CustomScreen,
withCustomPageWrapper,
} from '../CustomPage/CustomPageWrapper'
import { GET_ORGANIZATION_QUERY } from '../queries'
import { CASES_IN_PROGRESS_QUERY } from '../queries/OfficialJournalOfIceland'
import { m } from './messages'

const OJOICasesInProgressPage: CustomScreen<OJOICasesInProgressProps> = ({
cases,
organization,
locale,
}) => {
const { formatMessage } = useIntl()
const { linkResolver } = useLinkResolver()

const baseUrl = linkResolver('ojoihome', [], locale).href

const breadcrumbItems = [
{
title: formatMessage(m.breadcrumb.frontpage),
href: linkResolver('homepage', [], locale).href,
},
{
title: organization?.title ?? '',
href: baseUrl,
},
{
title: formatMessage(m.casesInProgress.title),
},
]

return (
<OJOIWrapper
pageTitle={formatMessage(m.casesInProgress.title)}
pageDescription={formatMessage(m.casesInProgress.description)}
organization={organization ?? undefined}
pageFeaturedImage={formatMessage(m.home.featuredImage)}
goBackUrl={baseUrl}
breadcrumbItems={breadcrumbItems}
>
{!cases || cases.length === 0 ? (
<p>{formatMessage(m.casesInProgress.notFoundMessage)}</p>
) : (
<T.Table>
<T.Head>
<T.Row>
<T.HeadData>
{formatMessage(m.casesInProgress.createdAt)}
</T.HeadData>
<T.HeadData>
{formatMessage(m.casesInProgress.requestedPublicationDate)}
</T.HeadData>
<T.HeadData>{formatMessage(m.casesInProgress.status)}</T.HeadData>
<T.HeadData>
{formatMessage(m.casesInProgress.advertTitle)}
</T.HeadData>
<T.HeadData>
{formatMessage(m.casesInProgress.involvedParty)}
</T.HeadData>
</T.Row>
</T.Head>
<T.Body>
{cases.map((c) => (
<T.Row key={c.id}>
<T.Data>{formatDate(c.createdAt ?? '')}</T.Data>
<T.Data>{formatDate(c.requestedPublicationDate ?? '')}</T.Data>
<T.Data>{c.status ?? '-'}</T.Data>
<T.Data>{c.title ?? '-'}</T.Data>
<T.Data>{c.involvedParty ?? '-'}</T.Data>
</T.Row>
))}
</T.Body>
</T.Table>
)}
</OJOIWrapper>
)
}

interface OJOICasesInProgressProps {
cases?: Array<OfficialJournalOfIcelandCaseInProgress>
organization?: Query['getOrganization']
locale: Locale
}

const OJOICasesInProgress: CustomScreen<OJOICasesInProgressProps> = ({
cases,
organization,
customPageData,
locale,
}) => {
return (
<OJOICasesInProgressPage
cases={cases}
organization={organization}
locale={locale}
customPageData={customPageData}
/>
)
}

OJOICasesInProgress.getProps = async ({ apolloClient, locale }) => {
const organizationSlug = 'stjornartidindi'

const [
{
data: { officialJournalOfIcelandCasesInProgress },
},
{
data: { getOrganization },
},
] = await Promise.all([
apolloClient.query<Query, QueryOfficialJournalOfIcelandCasesInProgressArgs>(
{
query: CASES_IN_PROGRESS_QUERY,
variables: {
params: {
pageSize: 30,
},
},
},
),
apolloClient.query<Query, QueryGetOrganizationArgs>({
query: GET_ORGANIZATION_QUERY,
variables: {
input: {
slug: organizationSlug,
lang: locale as ContentLanguage,
},
},
}),
])

if (!getOrganization?.hasALandingPage) {
throw new CustomNextError(404, 'Organization page not found')
}

return {
cases: officialJournalOfIcelandCasesInProgress?.cases,
organization: getOrganization,
locale: locale as Locale,
showSearchInHeader: false,
themeConfig: {
footerVersion: 'organization',
},
}
}

export default withMainLayout(
withCustomPageWrapper(
CustomPageUniqueIdentifier.OfficialJournalOfIceland,
OJOICasesInProgress,
),
)
4 changes: 2 additions & 2 deletions apps/web/screens/OfficialJournalOfIceland/OJOICategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ const OJOICategoriesPage: CustomScreen<OJOICategoriesProps> = ({

const breadcrumbItems = [
{
title: 'Ísland.is',
title: formatMessage(m.breadcrumb.frontpage),
href: linkResolver('homepage', [], locale).href,
},
{
title: organization?.title ?? '',
href: baseUrl,
},
{
title: 'Málaflokkar',
title: formatMessage(m.categories.breadcrumbTitle),
},
]

Expand Down
3 changes: 2 additions & 1 deletion apps/web/screens/OfficialJournalOfIceland/OJOIHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const OJOIHomePage: CustomScreen<OJOIHomeProps> = ({

const breadcrumbItems = [
{
title: 'Ísland.is',
title: formatMessage(m.breadcrumb.frontpage),
href: linkResolver('homepage', [], locale).href,
},
{
Expand Down Expand Up @@ -93,6 +93,7 @@ const OJOIHomePage: CustomScreen<OJOIHomeProps> = ({
pageDescription={formatMessage(m.home.description)}
organization={organization ?? undefined}
pageFeaturedImage={formatMessage(m.home.featuredImage)}
isHomePage
>
<Stack space={SLICE_SPACING}>
<OJOIHomeIntro
Expand Down
4 changes: 2 additions & 2 deletions apps/web/screens/OfficialJournalOfIceland/OJOISearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ const OJOISearchPage: CustomScreen<OJOISearchProps> = ({

const breadcrumbItems = [
{
title: 'Ísland.is',
title: formatMessage(m.breadcrumb.frontpage),
href: linkResolver('homepage', [], locale).href,
},
{
title: organization?.title ?? '',
href: baseUrl,
},
{
title: 'Leitarniðurstöður',
title: formatMessage(m.search.breadcrumbTitle),
},
]

Expand Down
Loading

0 comments on commit 62aaf84

Please sign in to comment.