Skip to content

IS-3190: Hide alert and store in localstorage #618

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

Merged
merged 1 commit into from
Mar 25, 2025
Merged
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
34 changes: 24 additions & 10 deletions src/components/Systemvarsel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Alert, BodyShort, Label } from '@navikt/ds-react';
import React from 'react';
import { EksternLenke } from '@/components/EksternLenke';
import { StoreKey, useLocalStorageState } from '@/hooks/useLocalStorageState';
import dayjs from 'dayjs';

const texts = {
header: 'Teknisk feil påvirket forhåndsvarsler mellom 27. februar - 12. mars',
@@ -12,16 +14,28 @@ const texts = {
};

export default function Systemvarsel() {
const [hideAlertDate, setHideAlertDate] = useLocalStorageState<Date | null>(
StoreKey.HIDE_ALERT_DATE,
null
);

const showAlert =
!hideAlertDate || dayjs(hideAlertDate).add(1, 'day') < dayjs(new Date());

return (
<Alert
variant={'error'}
size={'medium'}
className={'mb-4'}
contentMaxWidth={false}
>
<Label>{texts.header}</Label>
<BodyShort>{texts.info}</BodyShort>
<EksternLenke href={texts.url}>{texts.linkText}</EksternLenke>
</Alert>
showAlert && (
<Alert
variant={'error'}
size={'medium'}
className={'mb-4'}
contentMaxWidth={false}
onClose={() => setHideAlertDate(new Date())}
closeButton
>
<Label>{texts.header}</Label>
<BodyShort>{texts.info}</BodyShort>
<EksternLenke href={texts.url}>{texts.linkText}</EksternLenke>
</Alert>
)
);
}
1 change: 1 addition & 0 deletions src/hooks/useLocalStorageState.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react';
export enum StoreKey {
SORTING = 'sorting',
FLEXJAR_ARENABRUK_FEEDBACK_DATE = 'flexjarArenabrukFeedbackDate',
HIDE_ALERT_DATE = 'hideAlertDate',
}

export const useLocalStorageState = <T>(key: StoreKey, initialState: T) => {