Skip to content

Commit

Permalink
feat(redmine 1301354): response to github comments after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Meriemu committed Jul 10, 2024
1 parent a0846fb commit c5fbf90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function AddressFields(props: IAddressFieldsProps): ReactElement {
},
{
error: errors?.postCode,
handleChange: (e: React.ChangeEvent<HTMLInputElement>) => {
onChange: (e: React.ChangeEvent<HTMLInputElement>) => {
onChangeHandle('postCode', e.target.value);
},
value: value?.postCode,
Expand Down
54 changes: 15 additions & 39 deletions packages/storybook-pages/src/Pages/StepperPage/StepperPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
FullNameFields,
SidebarMenu,
} from '@smile/haring-react';
import { useEffect, useState } from 'react';
import { useState } from 'react';

import { menuMock } from '../BrowsingPage/BrowsingPage.mock';

Expand Down Expand Up @@ -45,40 +45,33 @@ async function getDataAddressGouvRequest(

export function StepperPage(): ReactElement {
const [active, setActive] = useState(0);
const [formData, setFormData] = useState({
address: {
city: '',
country: '',
number: '',
postCode: '',
street: '',
},
fullName: '',
});

const sidebarMenu = menuMock;

const form = useForm({
initialValues: formData,
initialValues: {
address: {
city: '',
country: '',
number: '',
postCode: '',
street: '',
},
fullName: {
firstName: '',
lastName: '',
},
},
});

const nextStep = (): void => {
if (!form.validate().hasErrors) {
setFormData(form.values);
setActive((current) => (current < 3 ? current + 1 : current));
}
};

const prevStep = (): void => {
setFormData(form.values);
setActive((current) => (current > 0 ? current - 1 : current));
};

useEffect(() => {
form.setValues(formData);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

function onOptionSubmitMock(
value: IValue<IAddressGouvData>,
): IAddressFieldsValues {
Expand All @@ -91,21 +84,14 @@ export function StepperPage(): ReactElement {
street: address.street ?? '',
};
form.setFieldValue('address', newAddress);
setFormData((prevData) => {
const updatedData = {
...prevData,
address: newAddress,
};
return updatedData;
});
return newAddress;
}

return (
<FoldableColumnLayout
sidebarContent={
<Flex direction="column">
<SidebarMenu menu={sidebarMenu} />
<SidebarMenu menu={menuMock} />
</Flex>
}
>
Expand All @@ -128,16 +114,6 @@ export function StepperPage(): ReactElement {
postCode: values.postCode ?? '',
street: values.street ?? '',
});
setFormData((prevData) => ({
...prevData,
address: {
city: values.city ?? '',
country: values.country ?? form.values.address.country,
number: values.number ?? '',
postCode: values.postCode ?? '',
street: values.street ?? '',
},
}));
}}
onOptionSubmit={onOptionSubmitMock}
/>
Expand Down

0 comments on commit c5fbf90

Please sign in to comment.