Simpliify code

This commit is contained in:
dominik-zeglen 2020-09-01 13:47:56 +02:00
parent 2353e54ab2
commit e268ddd3d2
2 changed files with 2 additions and 27 deletions

View file

@ -49,26 +49,11 @@ export const CategoryCreatePage: React.FC<CategoryCreatePageProps> = ({
}) => { }) => {
const intl = useIntl(); const intl = useIntl();
const { const {
isMetadataModified,
isPrivateMetadataModified,
makeChangeHandler: makeMetadataChangeHandler makeChangeHandler: makeMetadataChangeHandler
} = useMetadataChangeTrigger(); } = useMetadataChangeTrigger();
const handleSubmit = (data: FormData) => {
const metadata = isMetadataModified ? data.metadata : undefined;
const privateMetadata = isPrivateMetadataModified
? data.privateMetadata
: undefined;
onSubmit({
...data,
metadata,
privateMetadata
});
};
return ( return (
<Form onSubmit={handleSubmit} initial={initialData} confirmLeave> <Form onSubmit={onSubmit} initial={initialData} confirmLeave>
{({ data, change, submit, hasChanged }) => { {({ data, change, submit, hasChanged }) => {
const changeMetadata = makeMetadataChangeHandler(change); const changeMetadata = makeMetadataChangeHandler(change);

View file

@ -137,8 +137,6 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
); );
const { const {
isMetadataModified,
isPrivateMetadataModified,
makeChangeHandler: makeMetadataChangeHandler makeChangeHandler: makeMetadataChangeHandler
} = useMetadataChangeTrigger(); } = useMetadataChangeTrigger();
@ -179,20 +177,12 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
const collections = getChoices(collectionChoiceList); const collections = getChoices(collectionChoiceList);
const productTypes = getChoices(productTypeChoiceList); const productTypes = getChoices(productTypeChoiceList);
const handleSubmit = (data: FormData) => { const handleSubmit = (data: FormData) =>
const metadata = isMetadataModified ? data.metadata : undefined;
const privateMetadata = isPrivateMetadataModified
? data.privateMetadata
: undefined;
onSubmit({ onSubmit({
...data, ...data,
attributes, attributes,
metadata,
privateMetadata,
stocks stocks
}); });
};
return ( return (
<Form onSubmit={handleSubmit} initial={initialData} confirmLeave> <Form onSubmit={handleSubmit} initial={initialData} confirmLeave>