saleor-dashboard/src/shipping/views/ShippingZoneCreate.tsx

52 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-08-09 10:26:22 +00:00
import React from "react";
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";
import { commonMessages } from "@saleor/intl";
2019-12-06 17:11:46 +00:00
import { maybe } from "../../misc";
2019-06-19 14:40:52 +00:00
import ShippingZoneCreatePage from "../components/ShippingZoneCreatePage";
import { TypedCreateShippingZone } from "../mutations";
import { CreateShippingZone } from "../types/CreateShippingZone";
import { shippingZonesListUrl, shippingZoneUrl } from "../urls";
const ShippingZoneCreate: React.FC<{}> = () => {
2019-06-19 14:40:52 +00:00
const navigate = useNavigator();
const pushMessage = useNotifier();
const shop = useShop();
const intl = useIntl();
2019-06-19 14:40:52 +00:00
const onShippingZoneCreate = (data: CreateShippingZone) => {
if (data.shippingZoneCreate.errors.length === 0) {
pushMessage({
text: intl.formatMessage(commonMessages.savedChanges)
2019-06-19 14:40:52 +00:00
});
navigate(shippingZoneUrl(data.shippingZoneCreate.shippingZone.id));
}
};
return (
<TypedCreateShippingZone onCompleted={onShippingZoneCreate}>
2019-12-06 17:11:46 +00:00
{(createShippingZone, createShippingZoneOpts) => (
<ShippingZoneCreatePage
countries={maybe(() => shop.countries, [])}
disabled={createShippingZoneOpts.loading}
errors={maybe(
() => createShippingZoneOpts.data.shippingZoneCreate.errors
)}
onBack={() => navigate(shippingZonesListUrl())}
onSubmit={formData =>
createShippingZone({
variables: {
input: formData
}
})
}
saveButtonBarState={createShippingZoneOpts.state}
/>
)}
2019-06-19 14:40:52 +00:00
</TypedCreateShippingZone>
);
};
export default ShippingZoneCreate;