-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca34324
commit e411122
Showing
13 changed files
with
211 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
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
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> | ||
</> | ||
) | ||
} |
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,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> | ||
</> | ||
) | ||
} |
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
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
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,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 |