-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): Standalone organization pages - Read alert banner field fr…
…om organization page (#17031) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
fe303df
commit c33e7a2
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
apps/web/layouts/organization/standalone/components/AlertBanner.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Cookies from 'js-cookie' | ||
|
||
import { AlertBanner, AlertBannerVariants } from '@island.is/island-ui/core' | ||
import { stringHash } from '@island.is/shared/utils' | ||
import { OrganizationPage } from '@island.is/web/graphql/schema' | ||
import { linkResolver, LinkType } from '@island.is/web/hooks' | ||
import { useI18n } from '@island.is/web/i18n' | ||
|
||
interface StandaloneAlertBannerProps { | ||
alertBanner: OrganizationPage['alertBanner'] | null | undefined | ||
} | ||
|
||
export const StandaloneAlertBanner = ({ | ||
alertBanner, | ||
}: StandaloneAlertBannerProps) => { | ||
const { activeLocale } = useI18n() | ||
|
||
if (!alertBanner) { | ||
return null | ||
} | ||
|
||
const bannerId = `standalone-alert-${stringHash( | ||
JSON.stringify(alertBanner ?? {}), | ||
)}` | ||
|
||
if (Cookies.get(bannerId) || !alertBanner.showAlertBanner) { | ||
return null | ||
} | ||
|
||
return ( | ||
<AlertBanner | ||
title={alertBanner.title ?? undefined} | ||
description={alertBanner.description ?? undefined} | ||
variant={alertBanner.bannerVariant as AlertBannerVariants} | ||
dismissable={alertBanner.isDismissable} | ||
onDismiss={() => { | ||
if (alertBanner.dismissedForDays !== 0) { | ||
Cookies.set(bannerId, 'hide', { | ||
expires: alertBanner.dismissedForDays, | ||
}) | ||
} | ||
}} | ||
closeButtonLabel={activeLocale === 'is' ? 'Loka' : 'Close'} | ||
link={ | ||
alertBanner.linkTitle && alertBanner.link?.type && alertBanner.link.slug | ||
? { | ||
href: linkResolver(alertBanner.link.type as LinkType, [ | ||
alertBanner.link.slug, | ||
]).href, | ||
title: alertBanner.linkTitle, | ||
} | ||
: undefined | ||
} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters