Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Update views to display loading state only when submitting form

dominik-zeglen594ea94daf5b
diff --git a/saleor/static/dashboard-next/collections/containers/CollectionOperations.tsx b/saleor/static/dashboard-next/collections/containers/CollectionOperations.tsx
index 1c88948838..c4d57532e0 100644
--- a/saleor/static/dashboard-next/collections/containers/CollectionOperations.tsx
+++ b/saleor/static/dashboard-next/collections/containers/CollectionOperations.tsx
@@ -110,6 +110,7 @@ const CollectionOperations: React.StatelessComponent<
mutate: variables => unassignProduct({ variables })
},
updateCollection: {
+ called: updateCollection.called,
data: updateCollection.data,
loading: updateCollection.loading,
mutate: variables =>
diff --git a/saleor/static/dashboard-next/collections/containers/CollectionUpdateProvider.tsx b/saleor/static/dashboard-next/collections/containers/CollectionUpdateProvider.tsx
index 64733c5ccd..e88262f1a2 100644
--- a/saleor/static/dashboard-next/collections/containers/CollectionUpdateProvider.tsx
+++ b/saleor/static/dashboard-next/collections/containers/CollectionUpdateProvider.tsx
@@ -23,8 +23,9 @@ const CollectionUUpdateProvider: React.StatelessComponent<
CollectionUpdateProviderProps
> = ({ children, onError, onSuccess }) => (
<TypedCollectionUpdateMutation onCompleted={onSuccess} onError={onError}>
- {(mutate, { data, error, loading }) =>
+ {(mutate, { called, data, error, loading }) =>
children({
+ called,
data,
error,
loading,
diff --git a/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx b/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
index 22e4bb5a46..2aa6e72039 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
@@ -4,7 +4,7 @@ import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
-import { maybe } from "../../misc";
+import { getMutationState, maybe } from "../../misc";
import CollectionCreatePage from "../components/CollectionCreatePage/CollectionCreatePage";
import { TypedCollectionCreateMutation } from "../mutations";
import { CreateCollection } from "../types/CreateCollection";
@@ -36,33 +36,39 @@ export const CollectionCreate: React.StatelessComponent<{}> = () => (
<TypedCollectionCreateMutation
onCompleted={handleCollectionCreateSuccess}
>
- {(createCollection, { data, loading }) => (
- <>
- <WindowTitle title={i18n.t("Create collection")} />
- <CollectionCreatePage
- errors={maybe(() => data.collectionCreate.errors, [])}
- onBack={() => navigate(collectionListUrl)}
- disabled={loading}
- onSubmit={formData =>
- createCollection({
- variables: {
- input: {
- backgroundImage: formData.backgroundImage.value,
- isPublished: formData.isPublished,
- name: formData.name,
- seo: {
- description: formData.seoDescription,
- title: formData.seoTitle
- },
- // FIXME: remove after closing #3142
- slug: formData.name.toLowerCase()
+ {(createCollection, { called, data, loading }) => {
+ const formTransitionState = getMutationState(
+ called,
+ loading,
+ maybe(() => data.collectionCreate.errors)
+ );
+ return (
+ <>
+ <WindowTitle title={i18n.t("Create collection")} />
+ <CollectionCreatePage
+ errors={maybe(() => data.collectionCreate.errors, [])}
+ onBack={() => navigate(collectionListUrl)}
+ disabled={loading}
+ onSubmit={formData =>
+ createCollection({
+ variables: {
+ input: {
+ backgroundImage: formData.backgroundImage.value,
+ isPublished: formData.isPublished,
+ name: formData.name,
+ seo: {
+ description: formData.seoDescription,
+ title: formData.seoTitle
+ }
+ }
}
- }
- })
- }
- />
- </>
- )}
+ })
+ }
+ saveButtonBarState={formTransitionState}
+ />
+ </>
+ );
+ }}
</TypedCollectionCreateMutation>
);
}}
diff --git a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
index 28370ba1e7..63ce62917e 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
@@ -8,7 +8,7 @@ import Navigator from "../../components/Navigator";
import { createPaginationState, Paginator } from "../../components/Paginator";
import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
-import { maybe } from "../../misc";
+import { getMutationState, maybe } from "../../misc";
import { productUrl } from "../../products/urls";
import CollectionAssignProductDialog from "../components/CollectionAssignProductDialog/CollectionAssignProductDialog";
import CollectionDetailsPage, {
@@ -155,6 +155,15 @@ export const CollectionDetails: React.StatelessComponent<
});
}
};
+
+ const formTransitionState = getMutationState(
+ updateCollection.called,
+ updateCollection.loading,
+ maybe(
+ () =>
+ updateCollection.data.collectionUpdate.errors
+ )
+ );
return (
<>
<WindowTitle
@@ -233,6 +242,7 @@ export const CollectionDetails: React.StatelessComponent<
navigate(
productUrl(encodeURIComponent(id))
)}
+ saveButtonBarState={formTransitionState}
/>
)}
</Paginator>
diff --git a/saleor/static/dashboard-next/components/ConfirmButton/ConfirmButton.tsx b/saleor/static/dashboard-next/components/ConfirmButton/ConfirmButton.tsx
index c068d890f0..a9926d4184 100644
--- a/saleor/static/dashboard-next/components/ConfirmButton/ConfirmButton.tsx
+++ b/saleor/static/dashboard-next/components/ConfirmButton/ConfirmButton.tsx
@@ -65,13 +65,15 @@ const ConfirmButton = decorate<ConfirmButtonProps>(
ConfirmButtonState
> {
static getDerivedStateFromProps(
- nextProps: ConfirmButtonProps
+ nextProps: ConfirmButtonProps,
+ prevState: ConfirmButtonState
): ConfirmButtonState {
if (nextProps.transitionState === "loading") {
return {
displayCompletedActionState: true
};
}
+ return prevState;
}
state: ConfirmButtonState = {
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftFinalizeDialog/OrderDraftFinalizeDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftFinalizeDialog/OrderDraftFinalizeDialog.tsx
index a8c9d55a3a..51af584525 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDraftFinalizeDialog/OrderDraftFinalizeDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftFinalizeDialog/OrderDraftFinalizeDialog.tsx
@@ -2,9 +2,11 @@ import DialogContentText from "@material-ui/core/DialogContentText";
import * as React from "react";
import ActionDialog from "../../../components/ActionDialog";
+import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton/ConfirmButton";
import i18n from "../../../i18n";
export interface OrderDraftFinalizeDialogProps {
+ confirmButtonState: ConfirmButtonTransitionState;
open: boolean;
orderNumber: string;
onClose: () => void;
@@ -13,7 +15,7 @@ export interface OrderDraftFinalizeDialogProps {
const OrderDraftFinalizeDialog: React.StatelessComponent<
OrderDraftFinalizeDialogProps
-> = ({ open, onClose, onConfirm, orderNumber }) => (
+> = ({ confirmButtonState, open, onClose, onConfirm, orderNumber }) => (
<ActionDialog
onClose={onClose}
onConfirm={onConfirm}
@@ -21,6 +23,7 @@ const OrderDraftFinalizeDialog: React.StatelessComponent<
title={i18n.t("Finalize draft order", {
context: "modal title"
})}
+ confirmButtonState={confirmButtonState}
>
<DialogContentText
dangerouslySetInnerHTML={{
diff --git a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
index 2382ca6d0a..ff54020bbb 100644
--- a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
+++ b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
@@ -4,7 +4,7 @@ import { Route } from "react-router-dom";
import ErrorMessageCard from "../../../components/ErrorMessageCard";
import Navigator from "../../../components/Navigator";
import { WindowTitle } from "../../../components/WindowTitle";
-import { maybe, transformAddressToForm } from "../../../misc";
+import { maybe, transformAddressToForm, getMutationState } from "../../../misc";
import { productUrl } from "../../../products/urls";
import { OrderStatus } from "../../../types/globalTypes";
import OrderAddressEditDialog from "../../components/OrderAddressEditDialog";
@@ -126,506 +126,537 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
orderDraftCancel,
orderDraftFinalize,
orderPaymentMarkAsPaid
- }) => (
- <>
- {maybe(
- () => order.status !== OrderStatus.DRAFT
- ) ? (
- <>
- <WindowTitle
- title={maybe(
- () => "Order #" + data.order.number
- )}
- />
- <OrderDetailsPage
- errors={errors}
- onNoteAdd={variables =>
- orderAddNote.mutate({
- input: variables,
- order: id
- })
- }
- onBack={() => navigate(orderListUrl())}
- order={order}
- shippingMethods={maybe(
- () => data.order.availableShippingMethods,
- []
- )}
- onOrderCancel={() =>
- navigate(orderCancelUrl(encodedId))
- }
- onOrderFulfill={() =>
- navigate(orderFulfillUrl(encodedId))
- }
- onFulfillmentCancel={fulfillmentId =>
- navigate(
- orderFulfillmentCancelUrl(
- encodedId,
- encodeURIComponent(fulfillmentId)
+ }) => {
+ const finalizeTransitionState = getMutationState(
+ orderDraftFinalize.called,
+ orderDraftFinalize.loading,
+ maybe(
+ () =>
+ orderDraftFinalize.data.draftOrderComplete
+ .errors
+ )
+ );
+ return (
+ <>
+ {maybe(
+ () => order.status !== OrderStatus.DRAFT
+ ) ? (
+ <>
+ <WindowTitle
+ title={maybe(
+ () => "Order #" + data.order.number
+ )}
+ />
+ <OrderDetailsPage
+ errors={errors}
+ onNoteAdd={variables =>
+ orderAddNote.mutate({
+ input: variables,
+ order: id
+ })
+ }
+ onBack={() => navigate(orderListUrl())}
+ order={order}
+ shippingMethods={maybe(
+ () =>
+ data.order.availableShippingMethods,
+ []
+ )}
+ onOrderCancel={() =>
+ navigate(orderCancelUrl(encodedId))
+ }
+ onOrderFulfill={() =>
+ navigate(orderFulfillUrl(encodedId))
+ }
+ onFulfillmentCancel={fulfillmentId =>
+ navigate(
+ orderFulfillmentCancelUrl(
+ encodedId,
+ encodeURIComponent(fulfillmentId)
+ )
)
- )
- }
- onFulfillmentTrackingNumberUpdate={fulfillmentId =>
- navigate(
- orderFulfillmentEditTrackingUrl(
- encodedId,
- encodeURIComponent(fulfillmentId)
+ }
+ onFulfillmentTrackingNumberUpdate={fulfillmentId =>
+ navigate(
+ orderFulfillmentEditTrackingUrl(
+ encodedId,
+ encodeURIComponent(fulfillmentId)
+ )
)
- )
- }
- onPaymentCapture={() =>
- navigate(
- orderPaymentCaptureUrl(encodedId)
- )
- }
- onPaymentVoid={() =>
- navigate(orderPaymentVoidUrl(encodedId))
- }
- onPaymentRefund={() =>
- navigate(orderPaymentRefundUrl(encodedId))
- }
- onProductClick={id => () =>
- navigate(
- productUrl(encodeURIComponent(id))
- )}
- onBillingAddressEdit={() =>
- navigate(
- orderBillingAddressEditUrl(encodedId)
- )
- }
- onShippingAddressEdit={() =>
- navigate(
- orderShippingAddressEditUrl(encodedId)
- )
- }
- onPaymentPaid={() =>
- navigate(orderMarkAsPaidUrl(encodedId))
- }
- />
- <Route
- path={orderCancelUrl(":id")}
- render={({ match }) => (
- <OrderCancelDialog
- number={maybe(() => order.number)}
- open={!!match}
- onClose={onModalClose}
- onSubmit={variables =>
- orderCancel.mutate({
- id,
- ...variables
- })
- }
- />
- )}
- />
- <Route
- path={orderMarkAsPaidUrl(":id")}
- render={({ match }) => (
- <OrderMarkAsPaidDialog
- onClose={onModalClose}
- onConfirm={() =>
- orderPaymentMarkAsPaid.mutate({ id })
- }
- open={!!match}
- />
- )}
- />
- <Route
- path={orderPaymentVoidUrl(":id")}
- render={({ match }) => (
- <OrderPaymentVoidDialog
- open={!!match}
- onClose={onModalClose}
- onConfirm={() =>
- orderVoid.mutate({ id })
- }
- />
- )}
- />
- <Route
- path={orderPaymentCaptureUrl(":id")}
- render={({ match }) => (
- <OrderPaymentDialog
- initial={maybe(
- () => order.total.gross.amount
- )}
- open={!!match}
- variant="capture"
- onClose={onModalClose}
- onSubmit={variables =>
- orderPaymentCapture.mutate({
- ...variables,
- id
- })
- }
- />
- )}
- />
- <Route
- path={orderPaymentRefundUrl(":id")}
- render={({ match }) => (
- <OrderPaymentDialog
- initial={maybe(
- () => order.total.gross.amount
- )}
- open={!!match}
- variant="refund"
- onClose={onModalClose}
- onSubmit={variables =>
- orderPaymentRefund.mutate({
- ...variables,
- id
- })
- }
- />
- )}
- />
- <Route
- path={orderFulfillUrl(":id")}
- render={({ match }) => (
- <OrderFulfillmentDialog
- open={!!match}
- lines={maybe(
- () => order.lines,
- []
- ).filter(
- line =>
- line.quantityFulfilled <
- line.quantity
+ }
+ onPaymentCapture={() =>
+ navigate(
+ orderPaymentCaptureUrl(encodedId)
+ )
+ }
+ onPaymentVoid={() =>
+ navigate(orderPaymentVoidUrl(encodedId))
+ }
+ onPaymentRefund={() =>
+ navigate(
+ orderPaymentRefundUrl(encodedId)
+ )
+ }
+ onProductClick={id => () =>
+ navigate(
+ productUrl(encodeURIComponent(id))
)}
- onClose={onModalClose}
- onSubmit={variables =>
- orderCreateFulfillment.mutate({
- input: {
+ onBillingAddressEdit={() =>
+ navigate(
+ orderBillingAddressEditUrl(encodedId)
+ )
+ }
+ onShippingAddressEdit={() =>
+ navigate(
+ orderShippingAddressEditUrl(encodedId)
+ )
+ }
+ onPaymentPaid={() =>
+ navigate(orderMarkAsPaidUrl(encodedId))
+ }
+ />
+ <Route
+ path={orderCancelUrl(":id")}
+ render={({ match }) => (
+ <OrderCancelDialog
+ number={maybe(() => order.number)}
+ open={!!match}
+ onClose={onModalClose}
+ onSubmit={variables =>
+ orderCancel.mutate({
+ id,
+ ...variables
+ })
+ }
+ />
+ )}
+ />
+ <Route
+ path={orderMarkAsPaidUrl(":id")}
+ render={({ match }) => (
+ <OrderMarkAsPaidDialog
+ onClose={onModalClose}
+ onConfirm={() =>
+ orderPaymentMarkAsPaid.mutate({
+ id
+ })
+ }
+ open={!!match}
+ />
+ )}
+ />
+ <Route
+ path={orderPaymentVoidUrl(":id")}
+ render={({ match }) => (
+ <OrderPaymentVoidDialog
+ open={!!match}
+ onClose={onModalClose}
+ onConfirm={() =>
+ orderVoid.mutate({ id })
+ }
+ />
+ )}
+ />
+ <Route
+ path={orderPaymentCaptureUrl(":id")}
+ render={({ match }) => (
+ <OrderPaymentDialog
+ initial={maybe(
+ () => order.total.gross.amount
+ )}
+ open={!!match}
+ variant="capture"
+ onClose={onModalClose}
+ onSubmit={variables =>
+ orderPaymentCapture.mutate({
...variables,
- lines: maybe(
- () => order.lines,
- []
- )
- .filter(
- line =>
- line.quantityFulfilled <
- line.quantity
- )
- .map((line, lineIndex) => ({
- orderLineId: line.id,
- quantity:
- variables.lines[lineIndex]
- }))
- .filter(
- line => line.quantity > 0
- )
- },
- order: order.id
- })
- }
- />
- )}
- />
- <Route
- path={orderFulfillmentCancelUrl(
- ":orderId",
- ":fulfillmentId"
- )}
- render={({ match }) => (
- <OrderFulfillmentCancelDialog
- open={!!match}
- onConfirm={variables =>
- orderFulfillmentCancel.mutate({
- id: decodeURIComponent(
- match.params.fulfillmentId
- ),
- input: variables
- })
- }
- onClose={onModalClose}
- />
- )}
- />
- <Route
- path={orderFulfillmentEditTrackingUrl(
- ":orderId",
- ":fulfillmentId"
- )}
- render={({ match }) => (
- <OrderFulfillmentTrackingDialog
- open={!!match}
- trackingNumber={maybe(
- () =>
- data.order.fulfillments.find(
- fulfillment =>
- fulfillment.id ===
- decodeURIComponent(
- match.params.fulfillmentId
+ id
+ })
+ }
+ />
+ )}
+ />
+ <Route
+ path={orderPaymentRefundUrl(":id")}
+ render={({ match }) => (
+ <OrderPaymentDialog
+ initial={maybe(
+ () => order.total.gross.amount
+ )}
+ open={!!match}
+ variant="refund"
+ onClose={onModalClose}
+ onSubmit={variables =>
+ orderPaymentRefund.mutate({
+ ...variables,
+ id
+ })
+ }
+ />
+ )}
+ />
+ <Route
+ path={orderFulfillUrl(":id")}
+ render={({ match }) => (
+ <OrderFulfillmentDialog
+ open={!!match}
+ lines={maybe(
+ () => order.lines,
+ []
+ ).filter(
+ line =>
+ line.quantityFulfilled <
+ line.quantity
+ )}
+ onClose={onModalClose}
+ onSubmit={variables =>
+ orderCreateFulfillment.mutate({
+ input: {
+ ...variables,
+ lines: maybe(
+ () => order.lines,
+ []
)
- ).trackingNumber
- )}
- onConfirm={variables =>
- orderFulfillmentUpdateTracking.mutate(
- {
+ .filter(
+ line =>
+ line.quantityFulfilled <
+ line.quantity
+ )
+ .map((line, lineIndex) => ({
+ orderLineId: line.id,
+ quantity:
+ variables.lines[lineIndex]
+ }))
+ .filter(
+ line => line.quantity > 0
+ )
+ },
+ order: order.id
+ })
+ }
+ />
+ )}
+ />
+ <Route
+ path={orderFulfillmentCancelUrl(
+ ":orderId",
+ ":fulfillmentId"
+ )}
+ render={({ match }) => (
+ <OrderFulfillmentCancelDialog
+ open={!!match}
+ onConfirm={variables =>
+ orderFulfillmentCancel.mutate({
id: decodeURIComponent(
match.params.fulfillmentId
),
- input: {
- ...variables,
- notifyCustomer: true
+ input: variables
+ })
+ }
+ onClose={onModalClose}
+ />
+ )}
+ />
+ <Route
+ path={orderFulfillmentEditTrackingUrl(
+ ":orderId",
+ ":fulfillmentId"
+ )}
+ render={({ match }) => (
+ <OrderFulfillmentTrackingDialog
+ open={!!match}
+ trackingNumber={maybe(
+ () =>
+ data.order.fulfillments.find(
+ fulfillment =>
+ fulfillment.id ===
+ decodeURIComponent(
+ match.params.fulfillmentId
+ )
+ ).trackingNumber
+ )}
+ onConfirm={variables =>
+ orderFulfillmentUpdateTracking.mutate(
+ {
+ id: decodeURIComponent(
+ match.params.fulfillmentId
+ ),
+ input: {
+ ...variables,
+ notifyCustomer: true
+ }
}
- }
+ )
+ }
+ onClose={onModalClose}
+ />
+ )}
+ />
+ </>
+ ) : (
+ <>
+ <WindowTitle
+ title={maybe(
+ () =>
+ "Draft order #" + data.order.number
+ )}
+ />
+ <OrderDraftPage
+ disabled={loading}
+ errors={errors}
+ onNoteAdd={variables =>
+ orderAddNote.mutate({
+ input: variables,
+ order: id
+ })
+ }
+ fetchVariants={variantSearch}
+ variants={maybe(() =>
+ variantSearchOpts.data.products.edges
+ .map(edge => edge.node)
+ .map(product =>
+ product.variants.map(variant => ({
+ ...variant,
+ name: `${product.name}(${
+ variant.name
+ })`
+ }))
)
- }
- onClose={onModalClose}
- />
- )}
- />
- </>
- ) : (
- <>
- <WindowTitle
- title={maybe(
- () => "Draft order #" + data.order.number
- )}
- />
- <OrderDraftPage
- disabled={loading}
- errors={errors}
- onNoteAdd={variables =>
- orderAddNote.mutate({
- input: variables,
- order: id
- })
- }
- fetchVariants={variantSearch}
- variants={maybe(() =>
- variantSearchOpts.data.products.edges
- .map(edge => edge.node)
- .map(product =>
- product.variants.map(variant => ({
- ...variant,
- name: `${product.name}(${
- variant.name
- })`
- }))
+ .reduce(
+ (prev, curr) => prev.concat(curr),
+ []
+ )
+ )}
+ users={maybe(
+ () =>
+ users.searchOpts.data.customers.edges.map(
+ edge => edge.node
+ ),
+ []
+ )}
+ variantsLoading={
+ variantSearchOpts.loading
+ }
+ fetchUsers={users.search}
+ usersLoading={users.searchOpts.loading}
+ onCustomerEdit={data =>
+ orderDraftUpdate.mutate({
+ id,
+ input: data
+ })
+ }
+ onDraftFinalize={() =>
+ navigate(
+ orderDraftFinalizeUrl(encodedId),
+ true
)
- .reduce(
- (prev, curr) => prev.concat(curr),
- []
+ }
+ onDraftRemove={() =>
+ navigate(orderCancelUrl(encodedId))
+ }
+ onOrderLineAdd={() =>
+ navigate(
+ orderDraftLineAddUrl(encodedId)
)
- )}
- users={maybe(
- () =>
- users.searchOpts.data.customers.edges.map(
- edge => edge.node
- ),
- []
- )}
- variantsLoading={variantSearchOpts.loading}
- fetchUsers={users.search}
- usersLoading={users.searchOpts.loading}
- onCustomerEdit={data =>
- orderDraftUpdate.mutate({
- id,
- input: data
- })
- }
- onDraftFinalize={() =>
- navigate(
- orderDraftFinalizeUrl(encodedId),
- true
- )
- }
- onDraftRemove={() =>
- navigate(orderCancelUrl(encodedId))
- }
- onOrderLineAdd={() =>
- navigate(orderDraftLineAddUrl(encodedId))
- }
- onBack={() => navigate(orderListUrl())}
- order={order}
- countries={maybe(
- () => data.shop.countries,
- []
- ).map(country => ({
- code: country.code,
- label: country.country
- }))}
- onProductClick={id => () =>
- navigate(
- productUrl(encodeURIComponent(id))
- )}
- onBillingAddressEdit={() =>
- navigate(
- orderBillingAddressEditUrl(encodedId)
- )
- }
- onShippingAddressEdit={() =>
- navigate(
- orderShippingAddressEditUrl(encodedId)
- )
- }
- onShippingMethodEdit={() =>
- navigate(
- orderDraftShippingMethodUrl(encodedId)
- )
- }
- onOrderLineRemove={id =>
- orderLineDelete.mutate({ id })
- }
- onOrderLineChange={(id, data) =>
- orderLineUpdate.mutate({
- id,
- input: data
- })
- }
- />
- </>
- )}
- <Route
- path={orderShippingAddressEditUrl(":id")}
- render={({ match }) => (
- <OrderAddressEditDialog
- address={transformAddressToForm(
- maybe(() => order.shippingAddress)
- )}
- countries={maybe(
- () => data.shop.countries,
- []
- ).map(country => ({
- code: country.code,
- label: country.country
- }))}
- errors={errors}
- open={!!match}
- variant="shipping"
- onClose={onModalClose}
- onConfirm={variables =>
- orderUpdate.mutate({
- id,
- input: {
- shippingAddress: variables
- }
- })
- }
- />
- )}
- />
- <Route
- path={orderBillingAddressEditUrl(":id")}
- render={({ match }) => (
- <OrderAddressEditDialog
- address={transformAddressToForm(
- maybe(() => order.billingAddress)
- )}
- countries={maybe(
- () => data.shop.countries,
- []
- ).map(country => ({
- code: country.code,
- label: country.country
- }))}
- errors={errors}
- open={!!match}
- variant="billing"
- onClose={onModalClose}
- onConfirm={variables =>
- orderUpdate.mutate({
- id,
- input: {
- billingAddress: variables
- }
- })
- }
- />
- )}
- />
- <Route
- path={orderDraftFinalizeUrl(":id")}
- render={({ match }) => (
- <OrderDraftFinalizeDialog
- onClose={onModalClose}
- onConfirm={() =>
- orderDraftFinalize.mutate({ id })
- }
- open={!!match}
- orderNumber={maybe(() => order.number)}
- />
- )}
- />
- <Route
- path={orderCancelUrl(":id")}
- render={({ match }) => (
- <OrderDraftCancelDialog
- onClose={onModalClose}
- onConfirm={() =>
- orderDraftCancel.mutate({ id })
- }
- open={!!match}
- orderNumber={maybe(() => order.number)}
- />
- )}
- />
- <Route
- path={orderDraftShippingMethodUrl(":id")}
- render={({ match }) => (
- <OrderShippingMethodEditDialog
- open={!!match}
- shippingMethod={maybe(
- () => order.shippingMethod.id,
- ""
- )}
- shippingMethods={maybe(
- () => order.availableShippingMethods
- )}
- onClose={onModalClose}
- onSubmit={variables =>
- orderShippingMethodUpdate.mutate({
- id,
- input: {
- shippingMethod:
- variables.shippingMethod
- }
- })
- }
- />
- )}
- />
- <Route
- path={orderDraftLineAddUrl(":id")}
- render={({ match }) => (
- <OrderProductAddDialog
- loading={variantSearchOpts.loading}
- open={!!match}
- variants={maybe(() =>
- variantSearchOpts.data.products.edges
- .map(edge => edge.node)
- .map(product =>
- product.variants.map(variant => ({
- ...variant,
- name: `${product.name}(${
- variant.name
- })`
- }))
+ }
+ onBack={() => navigate(orderListUrl())}
+ order={order}
+ countries={maybe(
+ () => data.shop.countries,
+ []
+ ).map(country => ({
+ code: country.code,
+ label: country.country
+ }))}
+ onProductClick={id => () =>
+ navigate(
+ productUrl(encodeURIComponent(id))
+ )}
+ onBillingAddressEdit={() =>
+ navigate(
+ orderBillingAddressEditUrl(encodedId)
)
- .reduce(
- (prev, curr) => prev.concat(curr),
- []
+ }
+ onShippingAddressEdit={() =>
+ navigate(
+ orderShippingAddressEditUrl(encodedId)
)
- )}
- fetchVariants={variantSearch}
- onClose={onModalClose}
- onSubmit={variables =>
- orderLineAdd.mutate({
- id,
- input: {
- quantity: variables.quantity,
- variantId: variables.variant.value
- }
- })
- }
- />
+ }
+ onShippingMethodEdit={() =>
+ navigate(
+ orderDraftShippingMethodUrl(encodedId)
+ )
+ }
+ onOrderLineRemove={id =>
+ orderLineDelete.mutate({ id })
+ }
+ onOrderLineChange={(id, data) =>
+ orderLineUpdate.mutate({
+ id,
+ input: data
+ })
+ }
+ saveButtonBarState="default"
+ />
+ </>
)}
- />
- </>
- )}
+ <Route
+ path={orderShippingAddressEditUrl(":id")}
+ render={({ match }) => (
+ <OrderAddressEditDialog
+ address={transformAddressToForm(
+ maybe(() => order.shippingAddress)
+ )}
+ countries={maybe(
+ () => data.shop.countries,
+ []
+ ).map(country => ({
+ code: country.code,
+ label: country.country
+ }))}
+ errors={errors}
+ open={!!match}
+ variant="shipping"
+ onClose={onModalClose}
+ onConfirm={variables =>
+ orderUpdate.mutate({
+ id,
+ input: {
+ shippingAddress: variables
+ }
+ })
+ }
+ />
+ )}
+ />
+ <Route
+ path={orderBillingAddressEditUrl(":id")}
+ render={({ match }) => (
+ <OrderAddressEditDialog
+ address={transformAddressToForm(
+ maybe(() => order.billingAddress)
+ )}
+ countries={maybe(
+ () => data.shop.countries,
+ []
+ ).map(country => ({
+ code: country.code,
+ label: country.country
+ }))}
+ errors={errors}
+ open={!!match}
+ variant="billing"
+ onClose={onModalClose}
+ onConfirm={variables =>
+ orderUpdate.mutate({
+ id,
+ input: {
+ billingAddress: variables
+ }
+ })
+ }
+ />
+ )}
+ />
+ <Route
+ path={orderDraftFinalizeUrl(":id")}
+ render={({ match }) => (
+ <OrderDraftFinalizeDialog
+ confirmButtonState={
+ finalizeTransitionState
+ }
+ onClose={onModalClose}
+ onConfirm={() =>
+ orderDraftFinalize.mutate({ id })
+ }
+ open={!!match}
+ orderNumber={maybe(() => order.number)}
+ />
+ )}
+ />
+ <Route
+ path={orderCancelUrl(":id")}
+ render={({ match }) => (
+ <OrderDraftCancelDialog
+ onClose={onModalClose}
+ onConfirm={() =>
+ orderDraftCancel.mutate({ id })
+ }
+ open={!!match}
+ orderNumber={maybe(() => order.number)}
+ />
+ )}
+ />
+ <Route
+ path={orderDraftShippingMethodUrl(":id")}
+ render={({ match }) => (
+ <OrderShippingMethodEditDialog
+ open={!!match}
+ shippingMethod={maybe(
+ () => order.shippingMethod.id,
+ ""
+ )}
+ shippingMethods={maybe(
+ () => order.availableShippingMethods
+ )}
+ onClose={onModalClose}
+ onSubmit={variables =>
+ orderShippingMethodUpdate.mutate({
+ id,
+ input: {
+ shippingMethod:
+ variables.shippingMethod
+ }
+ })
+ }
+ />
+ )}
+ />
+ <Route
+ path={orderDraftLineAddUrl(":id")}
+ render={({ match }) => (
+ <OrderProductAddDialog
+ loading={variantSearchOpts.loading}
+ open={!!match}
+ variants={maybe(() =>
+ variantSearchOpts.data.products.edges
+ .map(edge => edge.node)
+ .map(product => ({
+ ...product,
+ variants: product.variants.edges.map(
+ edge => edge.node
+ )
+ }))
+ .map(product =>
+ product.variants.map(variant => ({
+ ...variant,
+ name: `${product.name}(${
+ variant.name
+ })`
+ }))
+ )
+ .reduce(
+ (prev, curr) => prev.concat(curr),
+ []
+ )
+ )}
+ fetchVariants={variantSearch}
+ onClose={onModalClose}
+ onSubmit={variables =>
+ orderLineAdd.mutate({
+ id,
+ input: {
+ quantity: variables.quantity,
+ variantId: variables.variant.value
+ }
+ })
+ }
+ />
+ )}
+ />
+ </>
+ );
+ }}
</OrderOperations>
)}
</OrderDetailsMessages>
diff --git a/saleor/static/dashboard-next/pages/views/PageCreate.tsx b/saleor/static/dashboard-next/pages/views/PageCreate.tsx
index 7c02e8a741..679074aae7 100644
--- a/saleor/static/dashboard-next/pages/views/PageCreate.tsx
+++ b/saleor/static/dashboard-next/pages/views/PageCreate.tsx
@@ -4,6 +4,7 @@ import { Redirect } from "react-router";
import { NavigatorLink } from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
+import { getMutationState, maybe } from "../../misc";
import PageDetailsPage from "../../pages/components/PageDetailsPage";
import { TypedPageCreateMutation } from "../mutations";
import { pageListUrl } from "../urls";
@@ -14,6 +15,11 @@ export const PageCreateForm: React.StatelessComponent = () => (
if (called && !loading && !createResult.pageCreate.errors.length) {
return <Redirect to={pageListUrl} push={false} />;
}
+ const formTransitionState = getMutationState(
+ called,
+ loading,
+ maybe(() => createResult.pageCreate.errors)
+ );
return (
<NavigatorLink to={pageListUrl}>
{handleCancel => (
@@ -35,6 +41,7 @@ export const PageCreateForm: React.StatelessComponent = () => (
})
}
title={i18n.t("Add page", { context: "title" })}
+ saveButtonBarState={formTransitionState}
/>
</>
)}
diff --git a/saleor/static/dashboard-next/pages/views/PageDetails.tsx b/saleor/static/dashboard-next/pages/views/PageDetails.tsx
index d7b36cd504..954036f529 100644
--- a/saleor/static/dashboard-next/pages/views/PageDetails.tsx
+++ b/saleor/static/dashboard-next/pages/views/PageDetails.tsx
@@ -1,10 +1,8 @@
import * as React from "react";
import { Redirect } from "react-router";
-import ErrorMessageCard from "../../components/ErrorMessageCard";
import { NavigatorLink } from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
-import i18n from "../../i18n";
import { maybe } from "../../misc";
import PageDetailsPage from "../components/PageDetailsPage";
import { TypedPageDeleteMutation, TypedPageUpdateMutation } from "../mutations";
@@ -33,102 +31,88 @@ export class PageUpdateForm extends React.Component<
const { id } = this.props;
return (
<TypedPageDetailsQuery displayLoader variables={{ id }}>
- {({ data: detailsResult, error, loading }) => {
- if (error) {
- return (
- <ErrorMessageCard
- message={i18n.t("Unable to find matching page.")}
- />
- );
- }
- return (
- <TypedPageDeleteMutation>
- {(
- _,
- { called, data: deleteResult, error, loading: deleteInProgress }
- ) => {
- if (called && !deleteInProgress) {
- if (error) {
- console.error(error);
- return;
- }
- if (
- deleteResult.pageDelete.errors &&
- deleteResult.pageDelete.errors.length
- ) {
- console.error(deleteResult.pageDelete);
- return;
- }
- // FIXME: component is loaded with previous state (meaning that deleted page will still be there until table reload)
- this.handleRemoveButtonClick();
- return <Redirect to={pageListUrl} />;
+ {({ data, loading }) => (
+ <TypedPageDeleteMutation>
+ {(
+ _,
+ { called, data: deleteResult, error, loading: deleteInProgress }
+ ) => {
+ if (called && !deleteInProgress) {
+ if (error) {
+ console.error(error);
+ return;
}
- return (
- <TypedPageUpdateMutation>
- {(
- updatePage,
- {
- called,
- data: updateResult,
- error,
- loading: updateInProgress
- }
- ) => {
- if (
- called &&
- !updateInProgress &&
- updateResult &&
- updateResult.pageUpdate &&
- !updateResult.pageUpdate.errors.length
- ) {
- if (error) {
- console.error(error);
- return;
- }
- return <Redirect to={pageListUrl} />;
+ if (
+ deleteResult.pageDelete.errors &&
+ deleteResult.pageDelete.errors.length
+ ) {
+ console.error(deleteResult.pageDelete);
+ return;
+ }
+ // FIXME: component is loaded with previous state (meaning that deleted page will still be there until table reload)
+ this.handleRemoveButtonClick();
+ return <Redirect to={pageListUrl} />;
+ }
+ return (
+ <TypedPageUpdateMutation>
+ {(
+ updatePage,
+ {
+ called,
+ data: updateResult,
+ error,
+ loading: updateInProgress
+ }
+ ) => {
+ if (
+ called &&
+ !updateInProgress &&
+ updateResult &&
+ updateResult.pageUpdate &&
+ !updateResult.pageUpdate.errors.length
+ ) {
+ if (error) {
+ console.error(error);
+ return;
}
- return (
- <NavigatorLink to={pageListUrl}>
- {handleCancel => (
- <>
- <WindowTitle
- title={maybe(() => detailsResult.page.title)}
- />
- <PageDetailsPage
- onBack={handleCancel}
- page={loading ? undefined : detailsResult.page}
- onSubmit={data =>
- updatePage({
- variables: { id, ...data }
- })
- }
- errors={
- updateResult
- ? updateResult.pageUpdate.errors
- : []
- }
- title={
- detailsResult && detailsResult.page
- ? detailsResult.page.title
- : undefined
- }
- disabled={
- loading ||
- deleteInProgress ||
- updateInProgress
- }
- />
- </>
- )}
- </NavigatorLink>
- );
- }}
- </TypedPageUpdateMutation>
- );
- }}
- </TypedPageDeleteMutation>
- );
- }}
+ return <Redirect to={pageListUrl} />;
+ }
+ return (
+ <NavigatorLink to={pageListUrl}>
+ {handleCancel => (
+ <>
+ <WindowTitle title={maybe(() => data.page.title)} />
+ <PageDetailsPage
+ onBack={handleCancel}
+ page={loading ? undefined : data.page}
+ onSubmit={data =>
+ updatePage({
+ variables: { id, ...data }
+ })
+ }
+ errors={
+ updateResult
+ ? updateResult.pageUpdate.errors
+ : []
+ }
+ title={
+ data && data.page ? data.page.title : undefined
+ }
+ disabled={
+ loading || deleteInProgress || updateInProgress
+ }
+ saveButtonBarState="default"
+ />
+ </>
+ )}
+ </NavigatorLink>
+ );
+ }}
+ </TypedPageUpdateMutation>
+ );
+ }}
+ </TypedPageDeleteMutation>
+ )}
</TypedPageDetailsQuery>
);
}
diff --git a/saleor/static/dashboard-next/products/containers/ProductUpdate.tsx b/saleor/static/dashboard-next/products/containers/ProductUpdate.tsx
index bd9f1abc47..14867393c4 100644
--- a/saleor/static/dashboard-next/products/containers/ProductUpdate.tsx
+++ b/saleor/static/dashboard-next/products/containers/ProductUpdate.tsx
@@ -19,8 +19,9 @@ const ProductUpdateProvider: React.StatelessComponent<
ProductUpdateProviderProps
> = ({ children, onError, onSuccess }) => (
<TypedProductUpdateMutation onCompleted={onSuccess} onError={onError}>
- {(mutate, { data, error, loading }) =>
+ {(mutate, { called, data, error, loading }) =>
children({
+ called,
data,
error,
loading,
diff --git a/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx b/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx
index a97d5d7eba..562e3cb79b 100644
--- a/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx
+++ b/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx
@@ -203,6 +203,7 @@ const ProductUpdateOperations: React.StatelessComponent<
reorderProductImages.mutate({ variables })
},
updateProduct: {
+ called: updateProduct.called,
data: updateProduct.data,
loading: updateProduct.loading,
mutate: variables =>
diff --git a/saleor/static/dashboard-next/products/containers/ProductVariantOperations.tsx b/saleor/static/dashboard-next/products/containers/ProductVariantOperations.tsx
index a67def080a..75b249c775 100644
--- a/saleor/static/dashboard-next/products/containers/ProductVariantOperations.tsx
+++ b/saleor/static/dashboard-next/products/containers/ProductVariantOperations.tsx
@@ -85,6 +85,7 @@ const VariantUpdateOperations: React.StatelessComponent<
mutate: variables => unassignImage.mutate({ variables })
},
updateVariant: {
+ called: updateVariant.called,
data: updateVariant.data,
loading: updateVariant.loading,
mutate: variables => updateVariant.mutate({ variables })
diff --git a/saleor/static/dashboard-next/products/containers/ProductVariantUpdate.tsx b/saleor/static/dashboard-next/products/containers/ProductVariantUpdate.tsx
index 57188b239c..0e88a2e7df 100644
--- a/saleor/static/dashboard-next/products/containers/ProductVariantUpdate.tsx
+++ b/saleor/static/dashboard-next/products/containers/ProductVariantUpdate.tsx
@@ -19,8 +19,9 @@ const ProductVariantUpdateProvider: React.StatelessComponent<
ProductVariantUpdateProviderProps
> = ({ children, onError, onSuccess }) => (
<TypedVariantUpdateMutation onCompleted={onSuccess} onError={onError}>
- {(mutate, { data, error, loading }) => {
+ {(mutate, { called, data, error, loading }) => {
return children({
+ called,
data,
error,
loading,
diff --git a/saleor/static/dashboard-next/products/views/ProductCreate.tsx b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
index f81122f7d6..8fdc674aa8 100644
--- a/saleor/static/dashboard-next/products/views/ProductCreate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
@@ -1,12 +1,11 @@
import * as React from "react";
-import ErrorMessageCard from "../../components/ErrorMessageCard";
import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
import Shop from "../../components/Shop";
import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
-import { decimal, maybe } from "../../misc";
+import { decimal, getMutationState, maybe } from "../../misc";
import ProductCreatePage from "../components/ProductCreatePage";
import { TypedProductCreateMutation } from "../mutations";
import { TypedProductCreateQuery } from "../queries";
@@ -32,7 +31,7 @@ export const ProductUpdate: React.StatelessComponent<
return (
<TypedProductCreateQuery displayLoader>
- {({ data, error, loading }) => {
+ {({ data, loading }) => {
const handleSuccess = (data: ProductCreate) => {
if (data.productCreate.errors.length === 0) {
pushMessage({ text: i18n.t("Product created") });
@@ -44,19 +43,12 @@ export const ProductUpdate: React.StatelessComponent<
}
};
- if (error) {
- return (
- <ErrorMessageCard
- message={i18n.t("Something went wrong")}
- />
- );
- }
-
return (
<TypedProductCreateMutation onCompleted={handleSuccess}>
{(
productCreate,
{
+ called: productCreateCalled,
data: productCreateData,
loading: productCreateDataLoading
}
@@ -83,6 +75,14 @@ export const ProductUpdate: React.StatelessComponent<
const disabled =
loading || productCreateDataLoading;
+
+ const formTransitionState = getMutationState(
+ productCreateCalled,
+ productCreateDataLoading,
+ maybe(
+ () => productCreateData.productCreate.errors
+ )
+ );
return (
<>
<WindowTitle title={i18n.t("Create product")} />
@@ -121,6 +121,7 @@ export const ProductUpdate: React.StatelessComponent<
onAttributesEdit={handleAttributesEdit}
onBack={handleBack}
onSubmit={handleSubmit}
+ saveButtonBarState={formTransitionState}
/>
</>
);
diff --git a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx b/saleor/static/dashboard-next/products/views/ProductImage/index.tsx
index e5f262d22b..29a9971c26 100644
--- a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductImage/index.tsx
@@ -6,7 +6,7 @@ import ActionDialog from "../../../components/ActionDialog";
import Messages from "../../../components/messages";
import Navigator from "../../../components/Navigator";
import i18n from "../../../i18n";
-import { maybe } from "../../../misc";
+import { getMutationState, maybe } from "../../../misc";
import ProductImagePage from "../../components/ProductImagePage";
import {
TypedProductImageDeleteMutation,
@@ -53,7 +53,7 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
<TypedProductImageUpdateMutation
onCompleted={handleUpdateSuccess}
>
- {updateImage => (
+ {(updateImage, updateResult) => (
<TypedProductImageDeleteMutation onCompleted={handleBack}>
{deleteImage => {
const handleDelete = () =>
@@ -77,6 +77,14 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
};
const image =
data && data.product && data.product.mainImage;
+
+ const formTransitionState = getMutationState(
+ updateResult.called,
+ updateResult.loading,
+ maybe(
+ () => updateResult.data.productImageUpdate.errors
+ )
+ );
return (
<>
<ProductImagePage
@@ -94,6 +102,7 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
}
onRowClick={handleImageClick}
onSubmit={handleUpdate}
+ saveButtonBarState={formTransitionState}
/>
<Route
path={productImageRemoveUrl(
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
index 993b9cb905..f93cf8fb8d 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
@@ -10,7 +10,7 @@ import Messages from "../../../components/messages";
import Navigator from "../../../components/Navigator";
import { WindowTitle } from "../../../components/WindowTitle";
import i18n from "../../../i18n";
-import { decimal, maybe } from "../../../misc";
+import { decimal, getMutationState, maybe } from "../../../misc";
import { productTypeUrl } from "../../../productTypes/urls";
import ProductUpdatePage from "../../components/ProductUpdatePage";
import ProductUpdateOperations from "../../containers/ProductUpdateOperations";
@@ -120,9 +120,11 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
reorderProductImages.loading ||
updateProduct.loading ||
loading;
- const formSubmitState = disableFormSave
- ? "loading"
- : "idle";
+ const formTransitionState = getMutationState(
+ updateProduct.called,
+ updateProduct.loading,
+ maybe(() => updateProduct.data.productUpdate.errors)
+ );
return (
<>
<WindowTitle
@@ -133,7 +135,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
collections={allCollections}
disabled={disableFormSave}
errors={errors}
- saveButtonBarState={formSubmitState}
+ saveButtonBarState={formTransitionState}
images={maybe(() => data.product.images)}
header={maybe(() => product.name)}
placeholderImage={placeholderImg}
diff --git a/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx b/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx
index e2450722b3..6215c36ea6 100644
--- a/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx
@@ -7,7 +7,7 @@ import Messages from "../../../components/messages";
import Navigator from "../../../components/Navigator";
import { WindowTitle } from "../../../components/WindowTitle";
import i18n from "../../../i18n";
-import { decimal, maybe } from "../../../misc";
+import { decimal, maybe, getMutationState } from "../../../misc";
import ProductVariantDeleteDialog from "../../components/ProductVariantDeleteDialog";
import ProductVariantPage from "../../components/ProductVariantPage";
import ProductVariantOperations from "../../containers/ProductVariantOperations";
@@ -79,9 +79,13 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
updateVariant.loading ||
assignImage.loading ||
unassignImage.loading;
- const formSubmitState = disableFormSave
- ? "loading"
- : "idle";
+ const formTransitionState = getMutationState(
+ updateVariant.called,
+ updateVariant.loading,
+ maybe(
+ () => updateVariant.data.productVariantUpdate.errors
+ )
+ );
const handleImageSelect = (id: string) => () => {
if (variant) {
if (
@@ -109,7 +113,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
/>
<ProductVariantPage
errors={errors}
- saveButtonBarState={formSubmitState}
+ saveButtonBarState={formTransitionState}
loading={disableFormSave}
placeholderImage={placeholderImg}
variant={variant}
diff --git a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx
index 7b10fc9b01..d9ed358ff3 100644
--- a/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductVariantCreate.tsx
@@ -6,7 +6,7 @@ import Navigator from "../../components/Navigator";
import Shop from "../../components/Shop";
import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
-import { decimal, maybe } from "../../misc";
+import { decimal, getMutationState, maybe } from "../../misc";
import ProductVariantCreatePage from "../components/ProductVariantCreatePage";
import { TypedVariantCreateMutation } from "../mutations";
import { TypedProductVariantCreateQuery } from "../queries";
@@ -52,7 +52,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
const handleCreateSuccess = (data: VariantCreate) => {
if (
- data.productVariantCreate.errors &&
+ data.productVariantCreate.errors === null ||
data.productVariantCreate.errors.length === 0
) {
pushMessage({ text: i18n.t("Product created") });
@@ -102,8 +102,18 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
)
);
- const loading =
+ const disableForm =
productLoading || variantCreateResult.loading;
+
+ const formTransitionstate = getMutationState(
+ variantCreateResult.called,
+ variantCreateResult.loading,
+ maybe(
+ () =>
+ variantCreateResult.data.productVariantCreate
+ .errors
+ )
+ );
return (
<>
<WindowTitle title={i18n.t("Create variant")} />
@@ -116,11 +126,12 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
[]
)}
header={i18n.t("Add Variant")}
- loading={loading}
+ loading={disableForm}
product={maybe(() => data.product)}
onBack={handleBack}
onSubmit={handleSubmit}
onVariantClick={handleVariantClick}
+ saveButtonBarState={formTransitionstate}
/>
</>
);
diff --git a/saleor/static/dashboard-next/siteSettings/views/index.tsx b/saleor/static/dashboard-next/siteSettings/views/index.tsx
index f300c9eb18..a997c8a2d0 100644
--- a/saleor/static/dashboard-next/siteSettings/views/index.tsx
+++ b/saleor/static/dashboard-next/siteSettings/views/index.tsx
@@ -6,7 +6,7 @@ import Navigator from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
import { configurationMenuUrl } from "../../configuration";
import i18n from "../../i18n";
-import { maybe } from "../../misc";
+import { getMutationState, maybe } from "../../misc";
import { AuthorizationKeyType } from "../../types/globalTypes";
import SiteSettingsKeyDialog, {
SiteSettingsKeyDialogForm
@@ -131,6 +131,25 @@ export const SiteSettings: React.StatelessComponent<{}> = () => (
}
}
});
+
+ const formTransitionState = getMutationState(
+ updateShopSettingsOpts.called,
+ updateShopSettingsOpts.loading,
+ [
+ ...maybe(
+ () =>
+ updateShopSettingsOpts.data.shopDomainUpdate
+ .errors,
+ []
+ ),
+ ...maybe(
+ () =>
+ updateShopSettingsOpts.data
+ .shopSettingsUpdate.errors,
+ []
+ )
+ ]
+ );
return (
<>
<WindowTitle title={i18n.t("Site settings")} />
@@ -148,6 +167,7 @@ export const SiteSettings: React.StatelessComponent<{}> = () => (
})
}
onSubmit={handleUpdateShopSettings}
+ saveButtonBarState={formTransitionState}
/>
<Route
path={siteSettingsAddKeyUrl}
diff --git a/saleor/static/dashboard-next/staff/views/StaffDetails.tsx b/saleor/static/dashboard-next/staff/views/StaffDetails.tsx
index ce2fc82bc8..ef2ffeee52 100644
--- a/saleor/static/dashboard-next/staff/views/StaffDetails.tsx
+++ b/saleor/static/dashboard-next/staff/views/StaffDetails.tsx
@@ -7,7 +7,7 @@ import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
-import { maybe } from "../../misc";
+import { getMutationState, maybe } from "../../misc";
import StaffDetailsPage from "../components/StaffDetailsPage/StaffDetailsPage";
import {
TypedStaffMemberDeleteMutation,
@@ -54,57 +54,67 @@ export const StaffDetails: React.StatelessComponent<OrderListProps> = ({
<TypedStaffMemberUpdateMutation
onCompleted={handleStaffMemberUpdate}
>
- {updateStaffMember => (
+ {(updateStaffMember, updateResult) => (
<TypedStaffMemberDeleteMutation
variables={{ id }}
onCompleted={handleStaffMemberDelete}
>
- {deleteStaffMember => (
- <>
- <WindowTitle title={maybe(() => data.user.email)} />
- <StaffDetailsPage
- disabled={loading}
- onBack={() => navigate(staffListUrl)}
- onDelete={() => navigate(staffMemberRemoveUrl(id))}
- onSubmit={variables =>
- updateStaffMember({
- variables: {
- id,
- input: {
- isActive: variables.isActive,
- permissions: variables.permissions
+ {deleteStaffMember => {
+ const formTransitionState = getMutationState(
+ updateResult.called,
+ updateResult.loading,
+ maybe(() => updateResult.data.staffUpdate.errors)
+ );
+ return (
+ <>
+ <WindowTitle title={maybe(() => data.user.email)} />
+ <StaffDetailsPage
+ disabled={loading}
+ onBack={() => navigate(staffListUrl)}
+ onDelete={() =>
+ navigate(staffMemberRemoveUrl(id))
+ }
+ onSubmit={variables =>
+ updateStaffMember({
+ variables: {
+ id,
+ input: {
+ isActive: variables.isActive,
+ permissions: variables.permissions
+ }
}
- }
- })
- }
- permissions={maybe(() => data.shop.permissions)}
- staffMember={maybe(() => data.user)}
- />
- <Route
- path={staffMemberRemoveUrl(id)}
- render={({ match }) => (
- <ActionDialog
- open={!!match}
- title={i18n.t("Remove staff user")}
- variant="delete"
- onClose={() =>
- navigate(staffMemberDetailsUrl(id))
- }
- onConfirm={deleteStaffMember}
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to remove <strong>{{ email }}</strong> from staff members?",
- { email: maybe(() => data.user.email) }
- )
- }}
- />
- </ActionDialog>
- )}
- />
- </>
- )}
+ })
+ }
+ permissions={maybe(() => data.shop.permissions)}
+ staffMember={maybe(() => data.user)}
+ saveButtonBarState={formTransitionState}
+ />
+ <Route
+ path={staffMemberRemoveUrl(id)}
+ render={({ match }) => (
+ <ActionDialog
+ open={!!match}
+ title={i18n.t("Remove staff user")}
+ variant="delete"
+ onClose={() =>
+ navigate(staffMemberDetailsUrl(id))
+ }
+ onConfirm={deleteStaffMember}
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ email }}</strong> from staff members?",
+ { email: maybe(() => data.user.email) }
+ )
+ }}
+ />
+ </ActionDialog>
+ )}
+ />
+ </>
+ );
+ }}
</TypedStaffMemberDeleteMutation>
)}
</TypedStaffMemberUpdateMutation>
diff --git a/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftFinalizeDialog.tsx b/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftFinalizeDialog.tsx
index aca9152aa0..d280f8ce54 100644
--- a/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftFinalizeDialog.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftFinalizeDialog.tsx
@@ -7,6 +7,7 @@ import OrderDraftFinalize, {
import Decorator from "../../Decorator";
const props: OrderDraftFinalizeDialogProps = {
+ confirmButtonState: "default",
onClose: () => undefined,
onConfirm: () => undefined,
open: true,
diff --git a/saleor/static/dashboard-next/types.ts b/saleor/static/dashboard-next/types.ts
index 3334a0cdf2..3813e04f31 100644
--- a/saleor/static/dashboard-next/types.ts
+++ b/saleor/static/dashboard-next/types.ts
@@ -30,6 +30,7 @@ export interface PartialMutationProviderOutput<
TData extends {} = {},
TVariables extends {} = {}
> {
+ called?: boolean;
data: TData;
loading: boolean;
mutate: (variables: TVariables) => void;