Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): add support links to grants #17189

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 56 additions & 12 deletions apps/web/screens/Grants/Grant/GrantSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { useMemo } from 'react'

import { Box, Button, LinkV2, Stack, Text } from '@island.is/island-ui/core'
import {
Box,
BoxProps,
Button,
LinkV2,
Stack,
Text,
} from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import { Locale } from '@island.is/shared/types'
import { isDefined } from '@island.is/shared/utils'
import { InstitutionPanel } from '@island.is/web/components'
import { Grant } from '@island.is/web/graphql/schema'
import { LinkType, useLinkResolver } from '@island.is/web/hooks'

import { m } from '../messages'
import { useLocale } from '@island.is/localization'
import { generateStatusTag } from '../utils'

interface Props {
Expand All @@ -30,6 +37,20 @@ const generateLine = (heading: string, content?: React.ReactNode) => {
)
}

const generateSidebarPanel = (
data: Array<React.ReactElement>,
background: BoxProps['background'],
) => {
if (!data) {
return undefined
}
return (
<Box background={background} padding={3} borderRadius="standard">
<Stack space={2}>{data}</Stack>
</Box>
)
}

export const GrantSidebar = ({ grant, locale }: Props) => {
const { linkResolver } = useLinkResolver()
const { formatMessage } = useLocale()
Expand Down Expand Up @@ -100,6 +121,7 @@ export const GrantSidebar = ({ grant, locale }: Props) => {
return (
<LinkV2
key={`${f.url}-${index}`}
newTab
href={f.url}
underlineVisibility="hover"
>
Expand All @@ -113,6 +135,35 @@ export const GrantSidebar = ({ grant, locale }: Props) => {
[grant.files],
)

const supportLinksPanelData = useMemo(
() =>
grant.supportLinks
?.map((link) => {
if (!link.url || !link.text || !link.id) {
return null
}
return (
<LinkV2
newTab
key={link.id}
href={link.url}
underlineVisibility="hover"
>
<Button
size="medium"
icon="link"
iconType="outline"
variant="text"
>
{link.text}
</Button>
</LinkV2>
)
})
.filter(isDefined) ?? [],
[grant.supportLinks],
)

return (
<Stack space={3}>
<InstitutionPanel
Expand All @@ -124,16 +175,9 @@ export const GrantSidebar = ({ grant, locale }: Props) => {
img={grant.fund?.parentOrganization.logo?.url}
locale={locale}
/>
{detailPanelData.length ? (
<Box background="blue100" padding={3} borderRadius="standard">
<Stack space={2}>{detailPanelData}</Stack>
</Box>
) : undefined}
{filesPanelData.length ? (
<Box background="red100" padding={3} borderRadius="standard">
<Stack space={2}>{filesPanelData}</Stack>
</Box>
) : undefined}
{generateSidebarPanel(detailPanelData, 'blue100')}
{generateSidebarPanel(filesPanelData, 'red100')}
{generateSidebarPanel(supportLinksPanelData, 'purple100')}
</Stack>
)
}
6 changes: 6 additions & 0 deletions apps/web/screens/queries/Grants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export const GET_GRANT_QUERY = gql`
id
title
}
supportLinks {
id
text
url
date
}
files {
...AssetFields
}
Expand Down
3 changes: 3 additions & 0 deletions libs/cms/src/lib/generated/contentfulTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,9 @@ export interface IGrantFields {
/** Files */
grantFiles?: Asset[] | undefined

/** Support links */
grantSupportLinks?: ILink[] | undefined

/** Category tags */
grantCategoryTags?: IGenericTag[] | undefined

Expand Down
7 changes: 6 additions & 1 deletion libs/cms/src/lib/models/grant.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { mapDocument, SliceUnion } from '../unions/slice.union'
import { Asset, mapAsset } from './asset.model'
import { ReferenceLink, mapReferenceLink } from './referenceLink.model'
import { Fund, mapFund } from './fund.model'
import { Link, mapLink } from './link.model'

export enum GrantStatus {
CLOSED,
Expand Down Expand Up @@ -66,6 +67,9 @@ export class Grant {
@CacheField(() => [Asset], { nullable: true })
files?: Array<Asset>

@CacheField(() => [Link], { nullable: true })
supportLinks?: Array<Link>

@CacheField(() => [GenericTag], { nullable: true })
categoryTags?: Array<GenericTag>

Expand All @@ -85,7 +89,6 @@ export const mapGrant = ({ fields, sys }: IGrant): Grant => ({
applicationUrl: fields.granApplicationUrl?.fields
? mapReferenceLink(fields.granApplicationUrl)
: undefined,

specialEmphasis: fields.grantSpecialEmphasis
? mapDocument(fields.grantSpecialEmphasis, sys.id + ':special-emphasis')
: [],
Expand Down Expand Up @@ -117,6 +120,8 @@ export const mapGrant = ({ fields, sys }: IGrant): Grant => ({
: undefined,
fund: fields.grantFund ? mapFund(fields.grantFund) : undefined,
files: (fields.grantFiles ?? []).map((file) => mapAsset(file)) ?? [],
supportLinks:
(fields.grantSupportLinks ?? []).map((link) => mapLink(link)) ?? [],
categoryTags: fields.grantCategoryTags
? fields.grantCategoryTags.map((tag) => mapGenericTag(tag))
: undefined,
Expand Down
Loading