Skip to content

Commit b48ea43

Browse files
author
Ruben van Leeuwen
committed
1936: Adds hasNext property for multistep forms
1 parent 4b473f9 commit b48ea43

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

frontend/packages/pydantic-forms/src/components/form/Footer.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ const Footer = () => {
2020
sendLabel,
2121
footerComponent,
2222
allowUntouchedSubmit,
23+
hasNext,
24+
formInputData,
2325
} = usePydanticFormContext();
24-
2526
const t = useTranslations('footer');
2627

2728
const PreviousButton = () => (
@@ -75,7 +76,7 @@ const Footer = () => {
7576
!rhf.formState.isSubmitting)
7677
}
7778
>
78-
{sendLabel ?? t('send')}
79+
{sendLabel ?? hasNext ? t('send') : t('submit')}
7980
</button>
8081
);
8182

@@ -88,8 +89,10 @@ const Footer = () => {
8889
!rhf.formState.isDirty && (
8990
<div>Het formulier is nog niet aangepast</div>
9091
)}
92+
{formInputData && formInputData.length > 0 && (
93+
<PreviousButton />
94+
)}
9195

92-
<PreviousButton />
9396
<ResetButton />
9497

9598
{!!onCancel && <CancelButton />}

frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ function PydanticFormContextProvider({
151151
// we cache the form scheme so when there is an error, we still have the form
152152
// the form is not in the error response
153153
const [rawSchema, setRawSchema] = useState<PydanticFormSchemaRawJson>();
154+
const [hasNext, setHasNext] = useState<boolean>(false);
154155

155156
// extract the JSON schema to a more usable custom schema
156157

@@ -235,6 +236,9 @@ function PydanticFormContextProvider({
235236
// when we receive a form from the JSON, we fully reset the scheme
236237
if (apiResponse?.form) {
237238
setRawSchema(apiResponse.form);
239+
if (apiResponse.meta) {
240+
setHasNext(!!apiResponse.meta.hasNext);
241+
}
238242
setErrorDetails(undefined);
239243
}
240244

@@ -362,6 +366,7 @@ function PydanticFormContextProvider({
362366
setFormInputData([]);
363367
setIsFullFilled(false);
364368
setRawSchema(undefined);
369+
setHasNext(false);
365370
}, []);
366371

367372
const PydanticFormContextState = {
@@ -393,6 +398,8 @@ function PydanticFormContextProvider({
393398
formKey,
394399
formIdKey,
395400
clearForm,
401+
formInputData,
402+
hasNext,
396403
};
397404

398405
return (

frontend/packages/pydantic-forms/src/messages/en-GB.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"footer": {
33
"cancel": "Cancel",
44
"send": "Send",
5+
"submit": "Submit",
56
"reset": "Reset",
67
"previous": "Previous",
78
"next": "Next",

frontend/packages/pydantic-forms/src/messages/nl-NL.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"footer": {
33
"cancel": "Annuleren",
44
"send": "Verzenden",
5+
"submit": "Indienen",
56
"reset": "Resetten",
67
"notModifiedYet": "Het formulier is nog niet aangepast",
78
"notFilledYet": "Het formulier is nog niet ingevuld",

frontend/packages/pydantic-forms/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export interface PydanticFormContextProps {
7878
formKey: string;
7979
formIdKey?: string;
8080
clearForm: () => void;
81+
hasNext: boolean;
82+
formInputData: object[];
8183
}
8284

8385
export enum PydanticFormState {
@@ -384,6 +386,9 @@ export interface PydanticFormApiResponse {
384386
form: PydanticFormSchemaRawJson;
385387
success?: boolean;
386388
validation_errors: PydanticFormApiValidationError[];
389+
meta?: {
390+
hasNext?: boolean;
391+
};
387392
}
388393

389394
export interface PydanticFormBaseSchema {

0 commit comments

Comments
 (0)