Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
moroshko committed Apr 16, 2021
1 parent 83753d9 commit c1dc1a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
31 changes: 17 additions & 14 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,20 @@ function Form(_props) {
};
const setErrors = useCallback((errorsMap) => {
setState((state) => {
const newErrors = Object.keys(fields.current).reduce((acc, name) => {
if (typeof errorsMap[name] === "string") {
return setPath(acc, name, [errorsMap[name]]);
}
if (Array.isArray(errorsMap[name])) {
return setPath(acc, name, errorsMap[name]);
}
return acc;
}, {...state.errors});
const newErrors = Object.keys(fields.current).reduce(
(acc, name) => {
if (typeof errorsMap[name] === "string") {
return setPath(acc, name, [errorsMap[name]]);
}

if (Array.isArray(errorsMap[name])) {
return setPath(acc, name, errorsMap[name]);
}

return acc;
},
{ ...state.errors }
);

return {
...state,
Expand All @@ -246,13 +251,11 @@ function Form(_props) {
});
}, []);
const resetForm = ({ values, errors } = {}) => {
setState({
setState((state) => ({
...state,
values: values ?? initialValues,
errors: errors ?? initialErrors ?? {},
shouldValidateOnChange: false,
namesToValidate: null,
submitStatus: "READY",
});
}));
};
const responsiveFormCSS = useResponsivePropsCSS(props, DEFAULT_PROPS, {
width: responsiveSize("width"),
Expand Down
4 changes: 2 additions & 2 deletions website/src/pages/components/form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function FormPage() {
return (
<Container padding="8">
<Form initialValues={initialValues} onSubmit={onSubmit}>
<Grid rowsGap="8">
<Stack gap="8">
<Text as="h2" textStyle="heading4">About you</Text>
<Input name="name" label="Name" />
<Select name="relationshipStatus" label="Relationship status" options={relationshipStatusOptions} />
Expand All @@ -148,7 +148,7 @@ function FormPage() {
<TimeSpan name="age" label="Age" />
<Textarea name="aboutYourself" label="Tell us about yourself" height="100" />
<Button type="submit">Submit</Button>
</Grid>
</Stack>
</Form>
</Container>
);
Expand Down

1 comment on commit c1dc1a2

@vercel
Copy link

@vercel vercel bot commented on c1dc1a2 Apr 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.