Skip to content

Commit

Permalink
121129
Browse files Browse the repository at this point in the history
  • Loading branch information
remyvdwereld committed Aug 2, 2024
1 parent ca34324 commit e411122
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 16 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"oidc-client-ts": "^3.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.52.1",
"react-oidc-context": "^3.1.0",
"react-router-dom": "^6.25.1",
"styled-components": "^6.1.12",
Expand Down
28 changes: 28 additions & 0 deletions src/app/components/PageHeading/PageHeading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Heading, Icon, IconProps } from "@amsterdam/design-system-react"
import styled from "styled-components"

type Props = {
label: string
icon?: IconProps["svg"]
}

const LEVEL = 4

const Wrapper = styled.span`
display: flex;
`

const StyledIcon = styled(Icon)`
margin-right: 0.5rem;
`

export const PageHeading: React.FC<Props> = ({ label, icon }) => (
<Wrapper>
{ icon && <StyledIcon svg={icon} /> }
<Heading level={ LEVEL } >
{ label }
</Heading>
</Wrapper>
)

export default PageHeading
1 change: 1 addition & 0 deletions src/app/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./DefaultLayout/DefaultLayout"
export * from "./NavMenu/NavMenu"
export * from "./PageHeading/PageHeading"
export * from "./RouterLink/RouterLink"
export * from "./SmallSkeleton/SmallSkeleton"
export * from "./Spinner/Spinner"
Expand Down
68 changes: 68 additions & 0 deletions src/app/pages/CaseCreatePage/CaseCreatePage copy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Button, Field, Grid, Label, Paragraph, TextArea } from "@amsterdam/design-system-react"
import { EditDocumentIcon } from "@amsterdam/design-system-react-icons"
import { SubmitHandler, useForm } from "react-hook-form"
import { PageHeading } from "app/components"
import { useCases } from "app/state/rest"
import styled from "styled-components"


type IFormInput = {
description?: Components.Schemas.CaseCreate["description"]
}

const StyledGrid = styled(Grid)`
padding-left: 0; // Overwrite the default padding of the Grid.
`

export const CaseCreatePage: React.FC = () => {
const {
register,
handleSubmit,
formState: { errors }
} = useForm()
const [ ,{ execPost } ] = useCases()

const onSubmit: SubmitHandler<IFormInput> = (data) => {
console.log("DATA", data)
const values: Components.Schemas.CaseCreate = {
description: data?.description as string
}
execPost(values as Components.Schemas.Case)
.then((resp) => {
console.log("SUCCES", resp)
}).catch((err) => {
console.log("Error", err)
})
}

console.log("errors", errors)
console.log("!errors.description", !errors.description)
console.log("!!errors.description", !!errors.description)
return (
<>
<PageHeading label="Nieuwe zaak aanmaken" icon={ EditDocumentIcon } />
<StyledGrid paddingTop="small" paddingBottom="medium">
<Grid.Cell span={{ narrow: 4, medium: 6, wide: 8 }} start={ 1 }>
<form className="ams-gap--md" id="main" onSubmit={ void handleSubmit(onSubmit)}>
<Field>
<Label htmlFor="body">Toelichting</Label>
<Paragraph id="bodyDescription" size="small">
Geef een toelichting voor deze VVE (niet verplicht).
</Paragraph>
<TextArea
aria-describedby="bodyDescription"
id="body"
rows={4}
// invalid={ !!errors.description }
{...register("description", { required: true, maxLength: 1000 })}
/>
</Field>
<div>
<Button type="submit">Zaak aanmaken</Button>
</div>
</form>
</Grid.Cell>
</StyledGrid>
</>
)
}
70 changes: 70 additions & 0 deletions src/app/pages/CaseCreatePage/CaseCreatePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Button, ErrorMessage, Field, Grid, Label, Paragraph, TextArea } from "@amsterdam/design-system-react"
import { EditDocumentIcon } from "@amsterdam/design-system-react-icons"
import { useForm } from "react-hook-form"
import { PageHeading } from "app/components"
import { useCases } from "app/state/rest"
import styled from "styled-components"
import withExceptionCapturing from "app/utils/withExceptionCapturing"

type FormData = {
description?: Components.Schemas.CaseCreate["description"]
}

const StyledGrid = styled(Grid)`
padding-left: 0; // Overwrite the default padding of the Grid.
`

export const CaseCreatePage: React.FC = () => {
const {
register,
handleSubmit,
formState: { errors, isValid }
} = useForm<FormData>()
const [ ,{ execPost } ] = useCases()

const onSubmit = handleSubmit((data) => {
const values: Components.Schemas.CaseCreate = {
description: data?.description as string
}
execPost(values as Components.Schemas.Case)
.then((resp) => {
console.log("SUCCES", resp)
}).catch((err) => {
console.log("Error", err)
})
})


return (
<>
<PageHeading label="Nieuwe zaak aanmaken" icon={ EditDocumentIcon } />
<StyledGrid paddingTop="small" paddingBottom="medium">
<Grid.Cell span={{ narrow: 4, medium: 6, wide: 8 }} start={ 1 }>
<form className="ams-gap--md" id="main" onSubmit={withExceptionCapturing(onSubmit)}>
<Field>
<Label htmlFor="body">Toelichting</Label>
<Paragraph id="bodyDescription" size="small">
Geef een toelichting voor deze VVE (niet verplicht).
</Paragraph>
<TextArea
aria-describedby="bodyDescription"
id="body"
rows={4}
invalid={ !!errors.description }
{...register("description", { required: true, maxLength: 1000 })}
/>
{ errors.description && (
<ErrorMessage>
Dit is een verplicht veld!
</ErrorMessage>
)}
</Field>
<div>
<Button type="submit" disabled={ !isValid }>Zaak aanmaken</Button>
</div>
</form>
</Grid.Cell>
</StyledGrid>
</>
)
}
13 changes: 6 additions & 7 deletions src/app/pages/CasesPage/CasesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Heading } from "@amsterdam/design-system-react"
import { useCases } from "app/state/rest"
import { ColumnType, Table } from "app/components"
import { ColumnType, Table, PageHeading } from "app/components"

const columns: ColumnType<Components.Schemas.Case>[] = [
{
Expand All @@ -10,7 +9,9 @@ const columns: ColumnType<Components.Schemas.Case>[] = [
}, {
header: "Description",
dataIndex: "description",
sorter: (a: Components.Schemas.Case, b: Components.Schemas.Case) => a.description.localeCompare(b.description),
sorter: (a: Components.Schemas.Case, b: Components.Schemas.Case) => (
a?.description && b?.description ? a.description.localeCompare(b.description) : -1
),
defaultSortOrder: "DESCEND"
}
]
Expand All @@ -20,12 +21,10 @@ export const CasesPage: React.FC = () => {

return (
<>
<Heading level={ 3 } >
Zakenoverzicht
</Heading>
<PageHeading label="Zakenoverzicht" />
<Table
columns={ columns }
data={ data }
data={ data as Components.Schemas.Case[] }
loading={ isBusy }
/>
</>
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/SearchPage/SearchResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const columns: ColumnType<Vve>[] = [
}, {
header: "",
dataIndex: "id",
minWidth: 125,
render: () => <RouterLink label="Start traject" path="" />
minWidth: 170,
render: () => <RouterLink label="Zaak aanmaken" path="" />
}
]

Expand Down
6 changes: 2 additions & 4 deletions src/app/pages/TasksPage/TaskPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Heading } from "@amsterdam/design-system-react"
import { PageHeading } from "app/components"

export const TasksPage: React.FC = () => (
<>
<Heading level={ 3 } >
Takenoverzicht
</Heading>
<PageHeading label="Takenoverzicht" />
</>
)

Expand Down
1 change: 1 addition & 0 deletions src/app/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./AuthPage/AuthPage"
export * from "./CaseCreatePage/CaseCreatePage"
export * from "./CasesPage/CasesPage"
export * from "./NotFoundPage/NotFoundPage"
export * from "./SearchPage/SearchPage"
Expand Down
4 changes: 2 additions & 2 deletions src/app/routing/router.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultLayout } from "app/components"
import {
CasesPage, NotFoundPage, SearchPage, TasksPage, AuthPage
CasesPage, NotFoundPage, SearchPage, TasksPage, AuthPage, CaseCreatePage
} from "app/pages"
import { createBrowserRouter } from "react-router-dom"

Expand Down Expand Up @@ -28,7 +28,7 @@ const router = createBrowserRouter([
},
{
path: "vve/:vveId/zaken/nieuw",
element: <TasksPage />
element: <CaseCreatePage />
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion src/app/state/rest/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import type { Options } from "./"
import { makeApiUrl, useErrorHandler } from "./hooks/utils"
import useApiRequest from "./hooks/useApiRequest"

type CaseApiResponse = Components.Schemas.Case[] | Components.Schemas.Case;

export const useCases = (options?: Options) => {
const handleError = useErrorHandler()
return useApiRequest<Components.Schemas.Case[]>({
return useApiRequest<CaseApiResponse>({
...options,
url: `${ makeApiUrl("cases") }`,
groupName: "cases",
Expand Down
11 changes: 11 additions & 0 deletions src/app/utils/withExceptionCapturing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SyntheticEvent } from "react"

export const withExceptionCapturing = <T>(handler: (event: SyntheticEvent) => Promise<T>) => (event: SyntheticEvent) => {
if (handler) {
handler(event).catch((error) => {
console.log("Unexpected error:", error)
})
}
}

export default withExceptionCapturing

0 comments on commit e411122

Please sign in to comment.