Skip to content

Commit

Permalink
Begynt på henting av statistikk i frontend
Browse files Browse the repository at this point in the history
#deploy-test-frontend
  • Loading branch information
stigus committed Oct 12, 2023
1 parent 9c06bfe commit a61ab52
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 3 deletions.
4 changes: 3 additions & 1 deletion apps/dolly-frontend/src/main/js/src/allRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import GruppeConnector from '@/pages/gruppe/GruppeConnector'
const GruppeOversikt = lazy(() => import('@/pages/gruppeOversikt/GruppeOversiktConnector'))
const Organisasjon = lazy(() => import('@/pages/organisasjoner/OrganisasjonerConnector'))
const BestillingsveilederConnector = lazy(
() => import('@/components/bestillingsveileder/BestillingsveilederConnector')
() => import('@/components/bestillingsveileder/BestillingsveilederConnector'),
)
const Statistikk = lazy(() => import('@/pages/statistikk/Statistikk'))
const MinSide = lazy(() => import('@/pages/minSide/MinSide'))
const UI = lazy(() => import('@/pages/ui/index'))
const TestnorgePage = lazy(() => import('@/pages/testnorgePage/index'))
Expand Down Expand Up @@ -43,6 +44,7 @@ const allRoutes = [
element: () => <BestillingsveilederConnector />,
},
{ path: '/minside', breadcrumb: 'Min side', element: () => <MinSide /> },
{ path: '/statistikk', breadcrumb: 'Statistikk', element: () => <Statistikk /> },
{ path: '/ui', breadcrumb: 'UI demo', element: () => <UI /> },
{ path: '/testnorge', breadcrumb: 'Test-Norge', element: () => <TestnorgePage /> },
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom'
import './Header.less'
import { useBrukerProfil, useBrukerProfilBilde } from '@/utils/hooks/useBruker'
import logoutBruker from '@/components/utlogging/logoutBruker'
import { getDefaultImage } from '@/pages/minSide/Profil'
import { getDefaultImage } from '@/pages/profil/Profil'
import { Dropdown, DropdownContext } from '@navikt/ds-react-internal'
import Icon from '@/components/ui/icon/Icon'
import styled from 'styled-components'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Maler from './maler/Maloversikt'
import Profil from './Profil'
import Profil from '../profil/Profil'

import './MinSide.less'
import { useBrukerProfil, useCurrentBruker } from '@/utils/hooks/useBruker'
Expand Down
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} />}
</>
)
}
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}
</>
)
}
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,
}
}

0 comments on commit a61ab52

Please sign in to comment.