Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
r oppdaterer hele amplitudeData
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Aug 1, 2023
1 parent 3f945e9 commit 30e59f0
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/contexts/dagpenger-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,33 @@ export const DagpengerStatusContext = createContext<DagpengerStatusProviderType>

function DagpengerStatusProvider(props: { children: ReactNode }) {
const { securityLevel } = useAutentiseringData();
const { oppdaterAmplitudeData } = useAmplitudeData();
const { amplitudeData, oppdaterAmplitudeData } = useAmplitudeData();

const [dagpengerStatus, settDagpengerStatus] = useState<DagpengerStatus | null>(null);
const [erOppdatert, setErOppdatert] = useState(false);

useEffect(() => {
const hentDagpengerStatus = async () => {
try {
const response: DagpengerStatusResponse = await fetchToJson(DAGPENGER_STATUS, requestConfig());
settDagpengerStatus(response.dagpengerStatus);
console.log('oppdaterer amplitude for dagpengestatus');
oppdaterAmplitudeData({
dagpengerStatus: response.dagpengerStatus,
antallDagerSidenDagpengerStanset: response.antallDagerSidenDagpengerStanset,
});
if (!erOppdatert) {
const response: DagpengerStatusResponse = await fetchToJson(DAGPENGER_STATUS, requestConfig());
settDagpengerStatus(response.dagpengerStatus);
setErOppdatert(true);
console.log('oppdaterer amplitude for dagpengestatus');
oppdaterAmplitudeData({
...amplitudeData,
...{
dagpengerStatus: response.dagpengerStatus,
antallDagerSidenDagpengerStanset: response.antallDagerSidenDagpengerStanset,
},
});
}
} catch (err) {}
};
if (securityLevel === InnloggingsNiva.LEVEL_4) {
if (securityLevel === InnloggingsNiva.LEVEL_4 && !erOppdatert) {
hentDagpengerStatus();
}
}, [securityLevel]);
}, [securityLevel, amplitudeData, erOppdatert]);

const contextValue = {
dagpengerStatus,
Expand Down

0 comments on commit 30e59f0

Please sign in to comment.