Skip to content

Commit c99d8aa

Browse files
authored
Merge pull request #173 from workfloworchestrator/1891-refactor-legacy-code
1891: Refactor. Remove some unused code
2 parents 4c0c63a + baffc5d commit c99d8aa

File tree

9 files changed

+117
-214
lines changed

9 files changed

+117
-214
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pydantic-forms': minor
3+
---
4+
5+
Cleans up unused code.

frontend/apps/example/src/app/page.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ export default function Home() {
2121
const pydanticFormApiProvider: PydanticFormApiProvider = async ({
2222
requestBody,
2323
}) => {
24-
const fetchResult = await fetch('http://localhost:8000/form', {
24+
const url = 'http://localhost:8000/form';
25+
26+
const fetchResult = await fetch(url, {
2527
method: 'POST',
28+
body: JSON.stringify(requestBody),
2629
headers: {
2730
'Content-Type': 'application/json',
2831
},
29-
body: JSON.stringify(requestBody),
3032
});
3133
const jsonResult = await fetchResult.json();
3234
return jsonResult;
@@ -87,20 +89,22 @@ export default function Home() {
8789
<h1 style={{ marginBottom: '20px' }}>Pydantic Form </h1>
8890

8991
<PydanticForm
90-
id="theForm"
92+
formKey="theForm"
9193
title="Example form"
92-
successNotice="Custom success notice"
9394
onCancel={() => {
9495
alert('Form cancelled');
9596
}}
97+
onSuccess={() => {
98+
alert('Form submitted successfully');
99+
}}
96100
config={{
97-
allowUntouchedSubmit: true,
98101
apiProvider: pydanticFormApiProvider,
99102
labelProvider: pydanticLabelProvider,
100103
customDataProvider: pydanticCustomDataProvider,
101104
componentMatcherExtender: componentMatcher,
102105
customTranslations: customTranslations,
103106
locale: locale,
107+
loadingComponent: <div>Custom loading component</div>,
104108
}}
105109
/>
106110
</div>

frontend/packages/pydantic-forms/src/PydanticForm.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,26 @@ import React from 'react';
1010

1111
import RenderForm from '@/components/render/RenderForm';
1212
import PydanticFormContextProvider from '@/core/PydanticFormContextProvider';
13+
import type { PydanticFormContextProviderProps } from '@/core/PydanticFormContextProvider';
1314
import { TranslationsProvider } from '@/messages/translationsProvider';
14-
import type {
15-
PydanticFormInitialContextProps,
16-
PydanticFormMetaData,
17-
} from '@/types';
18-
19-
export interface PydanticFormProps
20-
extends Omit<PydanticFormInitialContextProps, 'formKey' | 'children'> {
21-
id: string;
22-
metaData?: PydanticFormMetaData;
23-
}
2415

2516
export const PydanticForm = ({
26-
id,
27-
metaData,
28-
...contextProps
29-
}: PydanticFormProps) => (
17+
config,
18+
formKey,
19+
onCancel,
20+
onSuccess,
21+
title,
22+
}: Omit<PydanticFormContextProviderProps, 'children'>) => (
3023
<TranslationsProvider
31-
customTranslations={contextProps.config.customTranslations}
32-
locale={contextProps.config.locale}
24+
customTranslations={config.customTranslations}
25+
locale={config.locale}
3326
>
3427
<PydanticFormContextProvider
35-
{...contextProps}
36-
formKey={id}
37-
metaData={metaData}
28+
config={config}
29+
onCancel={onCancel}
30+
onSuccess={onSuccess}
31+
title={title}
32+
formKey={formKey}
3833
>
3934
{RenderForm}
4035
</PydanticFormContextProvider>

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

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,11 @@ import { useTranslations } from 'next-intl';
1010
import { usePydanticFormContext } from '@/core';
1111

1212
const Footer = () => {
13-
const {
14-
resetForm,
15-
reactHookForm,
16-
onCancel,
17-
onPrevious,
18-
cancelButton,
19-
resetButtonAlternative,
20-
sendLabel,
21-
allowUntouchedSubmit,
22-
hasNext,
23-
formInputData,
24-
} = usePydanticFormContext();
13+
const { resetForm, onCancel, onPrevious, hasNext, formInputData } =
14+
usePydanticFormContext();
2515

2616
const t = useTranslations('footer');
27-
const submitButtonLabel = sendLabel ?? hasNext ? t('send') : t('submit');
17+
const submitButtonLabel = hasNext ? t('send') : t('submit');
2818
const PreviousButton = () => (
2919
<button
3020
type="button"
@@ -37,31 +27,27 @@ const Footer = () => {
3727

3828
const ResetButton = () => {
3929
return (
40-
resetButtonAlternative ?? (
41-
<button
42-
type="button"
43-
onClick={(e) => {
44-
resetForm(e);
45-
}}
46-
style={{ padding: '12px' }}
47-
>
48-
{t('reset')}
49-
</button>
50-
)
30+
<button
31+
type="button"
32+
onClick={(e) => {
33+
resetForm(e);
34+
}}
35+
style={{ padding: '12px' }}
36+
>
37+
{t('reset')}
38+
</button>
5139
);
5240
};
5341

5442
const CancelButton = () => {
5543
return (
56-
cancelButton ?? (
57-
<button
58-
type="button"
59-
onClick={onCancel}
60-
style={{ padding: '12px' }}
61-
>
62-
{t('cancel')}
63-
</button>
64-
)
44+
<button
45+
type="button"
46+
onClick={onCancel}
47+
style={{ padding: '12px' }}
48+
>
49+
{t('cancel')}
50+
</button>
6551
);
6652
};
6753

@@ -74,11 +60,6 @@ const Footer = () => {
7460
return (
7561
<div style={{ height: '200px', marginTop: '24px' }}>
7662
<div style={{ display: 'flex', gap: '16px' }}>
77-
{reactHookForm.formState.isValid &&
78-
!allowUntouchedSubmit &&
79-
!reactHookForm.formState.isDirty && (
80-
<div>Het formulier is nog niet aangepast</div>
81-
)}
8263
{formInputData && formInputData.length > 0 && (
8364
<PreviousButton />
8465
)}
@@ -89,19 +70,6 @@ const Footer = () => {
8970

9071
<SubmitButton />
9172
</div>
92-
<div
93-
style={{
94-
margin: '8px 0',
95-
color: 'red',
96-
fontWeight: '600',
97-
fontSize: '24px',
98-
}}
99-
>
100-
{!reactHookForm.formState.isValid &&
101-
reactHookForm.formState.isDirty && (
102-
<div>{t('notFilledYet')}</div>
103-
)}
104-
</div>
10573
</div>
10674
);
10775
};

frontend/packages/pydantic-forms/src/components/render/RenderForm.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
2222
config,
2323
isLoading,
2424
isFullFilled,
25-
successNotice,
2625
isSending,
27-
skipSuccessNotice,
28-
loadingComponent,
2926
} = contextProps;
3027

3128
const { formRenderer, footerRenderer, headerRenderer } = config || {};
@@ -38,7 +35,9 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
3835

3936
const t = useTranslations('renderForm');
4037

41-
const LoadingComponent = loadingComponent ?? <div>{t('loading')}</div>;
38+
const LoadingComponent = config.loadingComponent ?? (
39+
<div>{t('loading')}</div>
40+
);
4241

4342
if (isLoading && !isSending) {
4443
return LoadingComponent;
@@ -49,11 +48,7 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
4948
}
5049

5150
if (isFullFilled) {
52-
if (skipSuccessNotice) {
53-
return <></>;
54-
}
55-
56-
return <div>{successNotice ?? t('successfullySent')}</div>;
51+
return <div>{t('successfullySent')}</div>;
5752
}
5853

5954
const FormRenderer = formRenderer ?? Form;

0 commit comments

Comments
 (0)