2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-26 21:26:36 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
import useNavigator from "@saleor/hooks/useNavigator";
|
|
|
|
import useNotifier from "@saleor/hooks/useNotifier";
|
|
|
|
import useShop from "@saleor/hooks/useShop";
|
2019-08-26 21:26:36 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import ShippingZoneCreatePage from "../components/ShippingZoneCreatePage";
|
2020-02-11 15:32:47 +00:00
|
|
|
import { useShippingZoneCreate } from "../mutations";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { shippingZonesListUrl, shippingZoneUrl } from "../urls";
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const ShippingZoneCreate: React.FC<{}> = () => {
|
2019-06-19 14:40:52 +00:00
|
|
|
const navigate = useNavigator();
|
2020-02-11 15:32:47 +00:00
|
|
|
const notify = useNotifier();
|
2019-06-19 14:40:52 +00:00
|
|
|
const shop = useShop();
|
2019-08-26 21:26:36 +00:00
|
|
|
const intl = useIntl();
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2020-02-11 15:32:47 +00:00
|
|
|
const [createShippingZone, createShippingZoneOpts] = useShippingZoneCreate({
|
|
|
|
onCompleted: data => {
|
|
|
|
if (data.shippingZoneCreate.errors.length === 0) {
|
|
|
|
notify({
|
|
|
|
text: intl.formatMessage(commonMessages.savedChanges)
|
|
|
|
});
|
|
|
|
navigate(shippingZoneUrl(data.shippingZoneCreate.shippingZone.id));
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
2020-02-11 15:32:47 +00:00
|
|
|
});
|
2019-06-19 14:40:52 +00:00
|
|
|
return (
|
2020-02-11 15:32:47 +00:00
|
|
|
<ShippingZoneCreatePage
|
|
|
|
countries={shop?.countries || []}
|
|
|
|
disabled={createShippingZoneOpts.loading}
|
|
|
|
errors={createShippingZoneOpts.data?.shippingZoneCreate.errors || []}
|
|
|
|
onBack={() => navigate(shippingZonesListUrl())}
|
|
|
|
onSubmit={formData =>
|
|
|
|
createShippingZone({
|
|
|
|
variables: {
|
|
|
|
input: formData
|
2019-12-06 17:11:46 +00:00
|
|
|
}
|
2020-02-11 15:32:47 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
saveButtonBarState={createShippingZoneOpts.status}
|
|
|
|
/>
|
2019-06-19 14:40:52 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
export default ShippingZoneCreate;
|