Skip to content

Commit

Permalink
UPDATE: api and approutes for new page and pvkdokument
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremiahUy committed Oct 29, 2024
1 parent 802a9f3 commit c43bce5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
11 changes: 9 additions & 2 deletions apps/frontend/src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { MainPage } from './pages/MainPage'
import { MyEtterlevelseDokumentasjonerPage } from './pages/MyEtterlevelseDokumentasjonerPage'
import NotFound from './pages/NotFound'
import PvkBehovPage from './pages/PvkBehovPage'
import PvkDokumentPage from './pages/PvkDokumentPage'
import QuestionAndAnswerLogPage from './pages/QuestionAndAnswerLogPage'
import { RelasjonsOversikt } from './pages/RelasjonsOversikt'
import { TemaPage } from './pages/TemaPage'
Expand Down Expand Up @@ -147,6 +148,13 @@ const AppRoutes = (): JSX.Element => {
element={<BehandlingensLivslopPage />}
caseSensitive={true}
/>

<Route path="/dokumentasjon/:id/pvkbehov" element={<PvkBehovPage />} caseSensitive={true} />
<Route
path="/dokumentasjon/:id/pvkdokument/:pvkdokumentId"
element={<PvkDokumentPage />}
caseSensitive={true}
/>
<Route
path="/dokumentasjon/relasjon/:id/"
element={<RelasjonsOversikt />}
Expand All @@ -172,8 +180,7 @@ const AppRoutes = (): JSX.Element => {
element={<GjenbrukEtterlevelseDokumentasjonPage />}
caseSensitive={true}
/>
<Route path="/dokumentasjon/:id/pvkbehov" element={<PvkBehovPage />} caseSensitive={true} />
PvkBehovPage

<Route
path="/admin/codelist/:listname"
element={<PrivateRoute component={<CodeListPage />} adminPage />}
Expand Down
29 changes: 28 additions & 1 deletion apps/frontend/src/api/PvkDokumentApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios'
import { env } from 'process'
import { useEffect, useState } from 'react'
import { EPvkDokumentStatus, IPageResponse, IPvkDokument } from '../constants'

export const getAllPvkDokument = async () => {
Expand Down Expand Up @@ -54,7 +55,33 @@ export const deletePvkDokument = async (id: string) => {
return (await axios.delete<IPvkDokument>(`${env.backendBaseUrl}/pvkdokument/${id}`)).data
}

function pvkDokumentToPvkDokumentDto(pvkDokument: IPvkDokument) {
export const usePvkDokument = (pvkDokumentId?: string) => {
const isCreateNew = pvkDokumentId === 'ny'
const [data, setData] = useState<IPvkDokument | undefined>(
isCreateNew ? mapPvkDokumentToFormValue({}) : undefined
)
const [isLoading, setIsLoading] = useState<boolean>(false)

useEffect(() => {
setIsLoading(true)
if (pvkDokumentId && !isCreateNew) {
;(async () => {
await getPvkDokument(pvkDokumentId).then(async (pvkDokument) => {
setData(pvkDokument)
setIsLoading(false)
})
})()
}
}, [pvkDokumentId])

return [data, setData, isLoading] as [
IPvkDokument | undefined,
(e: IPvkDokument) => void,
boolean,
]
}

const pvkDokumentToPvkDokumentDto = (pvkDokument: IPvkDokument) => {
const dto = {
...pvkDokument,
ytterligereEgenskaper: pvkDokument.ytterligereEgenskaper.map((egenskap) => egenskap.code),
Expand Down
33 changes: 33 additions & 0 deletions apps/frontend/src/pages/PvkDokumentPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useState } from 'react'
import { useParams } from 'react-router-dom'
import { useEtterlevelseDokumentasjon } from '../api/EtterlevelseDokumentasjonApi'
import { usePvkDokument } from '../api/PvkDokumentApi'
import { PageLayout } from '../components/scaffold/Page'
import { IBreadCrumbPath } from '../constants'
import { dokumentasjonerBreadCrumbPath } from './util/BreadCrumbPath'

export const PvkDokumentPage = () => {
const params: Readonly<
Partial<{
id?: string
pvkdokumentId?: string
}>
> = useParams<{ id?: string }>()
const breadcrumbPaths: IBreadCrumbPath[] = [dokumentasjonerBreadCrumbPath]
const [currentPage] = useState<string>('Oversikt')
const [etterlevelseDokumentasjon] = useEtterlevelseDokumentasjon(params.id)
const [pvkDokument] = usePvkDokument(params.pvkdokumentId)

return (
<PageLayout
pageTitle="Pvk Dokument"
currentPage={currentPage}
breadcrumbPaths={breadcrumbPaths}
fullWidth
>
{etterlevelseDokumentasjon && pvkDokument && <div>WIP</div>}
</PageLayout>
)
}

export default PvkDokumentPage

0 comments on commit c43bce5

Please sign in to comment.