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

Commit

Permalink
r oppdaterer oppdaterAmplitudeData til å taimort en funksjon med ampl…
Browse files Browse the repository at this point in the history
…itudeData
  • Loading branch information
zrrrzzt committed Aug 1, 2023
1 parent 30e59f0 commit fd8964e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
27 changes: 10 additions & 17 deletions src/contexts/dagpenger-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,26 @@ export const DagpengerStatusContext = createContext<DagpengerStatusProviderType>

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

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

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

const contextValue = {
dagpengerStatus,
Expand Down
4 changes: 2 additions & 2 deletions src/komponenter/hent-initial-data/amplitude-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ const AmplitudeProvider = (props: { children: React.ReactNode }) => {
*/

const oppdaterAmplitudeData = (data: Partial<AmplitudeData>) => {
setAmplitudeData({
setAmplitudeData((amplitudeData) => ({
...amplitudeData,
...data,
});
}));
};

return (
Expand Down

0 comments on commit fd8964e

Please sign in to comment.