mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 09:34:56 -06:00
26 lines
794 B
JavaScript
26 lines
794 B
JavaScript
// @flow
|
|
import { withCreateProductState } from '../enhancers/createProductEnhancers';
|
|
import { withReplaceRoute } from '../enhancers/routeEnhancers';
|
|
import { compose, onlyUpdateForKeys, withHandlers } from 'recompose';
|
|
import { routeWithTitle } from '../helpers/RouteHelpers';
|
|
import TopSaveButton from './TopSaveButton';
|
|
|
|
export default compose(
|
|
withCreateProductState,
|
|
withReplaceRoute,
|
|
withHandlers({
|
|
onSave: ({ saveProduct, setLoading, setError, replaceRoute }) => async () => {
|
|
setError(null);
|
|
setLoading(true);
|
|
try {
|
|
const { id, name } = await saveProduct();
|
|
replaceRoute(routeWithTitle(`/product/${id || ''}`, name));
|
|
} catch (error) {
|
|
setError(error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
},
|
|
}),
|
|
onlyUpdateForKeys(['loading'])
|
|
)(TopSaveButton);
|