-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begynt på henting av statistikk i frontend
#deploy-test-frontend
- Loading branch information
Showing
7 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
apps/dolly-frontend/src/main/js/src/pages/statistikk/Statistikk.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,17 @@ | ||
import Profil from '../profil/Profil' | ||
|
||
import { useBrukerProfil, useCurrentBruker } from '@/utils/hooks/useBruker' | ||
import DollyStatistikk from '@/pages/statistikk/dollyStatistikk/DollyStatistikk' | ||
|
||
export default () => { | ||
const { brukerProfil } = useBrukerProfil() | ||
const { currentBruker } = useCurrentBruker() | ||
|
||
return ( | ||
<> | ||
<h1>Statistikk</h1> | ||
<Profil /> | ||
{brukerProfil && <DollyStatistikk brukerId={currentBruker?.brukerId} />} | ||
</> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
apps/dolly-frontend/src/main/js/src/pages/statistikk/dollyStatistikk/DollyStatistikk.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,17 @@ | ||
import Loading from '@/components/ui/loading/Loading' | ||
import { useCurrentBrukerStatistikk } from '@/utils/hooks/useDollyStatistikk' | ||
|
||
export default (brukerId: string) => { | ||
const { dollyStatistikk, loading } = useCurrentBrukerStatistikk(brukerId) | ||
if (loading) { | ||
return <Loading label={'Laster Statistikk...'} /> | ||
} | ||
|
||
return ( | ||
<> | ||
<h1>Dolly statistikk</h1> | ||
<h2>Antall bestillinger</h2> | ||
{dollyStatistikk.antallBestillinger} | ||
</> | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
apps/dolly-frontend/src/main/js/src/utils/hooks/useDollyStatistikk.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,23 @@ | ||
import useSWR from 'swr' | ||
import { fetcher } from '@/api' | ||
|
||
const getStatistikkUrl = (brukerId: string) => | ||
`/dolly-backend/api/v1/statistikk?brukerId=${brukerId}` | ||
|
||
type DollyStatistikk = { | ||
antallBestillinger: number | ||
antallIdenter: number | ||
} | ||
|
||
export const useCurrentBrukerStatistikk = (brukerId: string) => { | ||
const { data, isLoading, error } = useSWR<DollyStatistikk, Error>( | ||
getStatistikkUrl(brukerId), | ||
fetcher, | ||
) | ||
|
||
return { | ||
dollyStatistikk: data, | ||
loading: isLoading, | ||
error: error, | ||
} | ||
} |