Skip to content

Commit

Permalink
fix: init
Browse files Browse the repository at this point in the history
  • Loading branch information
thorkellmani committed Jan 14, 2025
1 parent 10bf465 commit 59d403d
Showing 1 changed file with 52 additions and 15 deletions.
67 changes: 52 additions & 15 deletions apps/web/components/GrantCardsList/GrantCardsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import localeEN from 'date-fns/locale/en-GB'
import localeIS from 'date-fns/locale/is'
import { useRouter } from 'next/router'

import { ActionCard, Box, InfoCardGrid } from '@island.is/island-ui/core'
import { ActionCard, Box, InfoCardGrid, Text } from '@island.is/island-ui/core'
import { Locale } from '@island.is/shared/types'
import { isDefined } from '@island.is/shared/utils'
import {
Expand All @@ -20,6 +20,12 @@ interface SliceProps {
slice: GrantCardsListSchema
}

const OPEN_GRANT_STATUSES = [
GrantStatus.AlwaysOpen,
GrantStatus.Open,
GrantStatus.OpenWithNote,
]

const formatDate = (
date: Date,
locale: Locale,
Expand Down Expand Up @@ -108,24 +114,48 @@ const GrantCardsList = ({ slice }: SliceProps) => {
}
}

if (slice.resolvedGrantsList?.items.length === 1) {
const grant = slice.resolvedGrantsList.items[0]
const grantItems = slice.resolvedGrantsList?.items ?? []

if (grantItems.length !== 1) {
const grant = grantItems[0]

const cardText = `${getTranslationString(
grant?.status && OPEN_GRANT_STATUSES.includes(grant.status)
? 'applicationOpen'
: 'applicationClosed',
)} / ${parseStatus(grant)}`

return (
<ActionCard
heading={grant.name}
backgroundColor="blue"
cta={{
disabled: !grant.applicationUrl?.slug,
label: grant.applicationButtonLabel ?? getTranslationString('apply'),
onClick: () => router.push(grant.applicationUrl?.slug ?? ''),
icon: 'open',
iconType: 'outline',
}}
/>
<>
{slice.displayTitle && (
<Box marginBottom={2}>
<Text variant="h3" as="span" color="dark400">
{slice.title}
</Text>
</Box>
)}
<ActionCard
heading={grant.name}
text={cardText}
backgroundColor="blue"
cta={{
disabled:
!grant?.status ||
grant.status === GrantStatus.Closed ||
grant.status === GrantStatus.Unknown,
size: 'small',
label:
grant.applicationButtonLabel ?? getTranslationString('apply'),
onClick: () => router.push(grant.applicationUrl?.slug ?? ''),
icon: 'open',
iconType: 'outline',
}}
/>
</>
)
}

const cards = slice.resolvedGrantsList?.items
const cards = grantItems
?.map((grant) => {
if (grant.id) {
return {
Expand Down Expand Up @@ -184,6 +214,13 @@ const GrantCardsList = ({ slice }: SliceProps) => {

return (
<Box padding={1} borderColor="blue100" borderRadius="large">
{slice.displayTitle && (
<Box marginBottom={2}>
<Text variant="h3" as="span" color="dark400">
{slice.title}
</Text>
</Box>
)}
<InfoCardGrid
columns={1}
cardsBorder="blue200"
Expand Down

0 comments on commit 59d403d

Please sign in to comment.