Skip to content

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

Add lots of motions

dominik-zeglen4923e9a27f26
diff --git a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
index c851cb06dc..10e2b28466 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
@@ -10,9 +10,8 @@ import i18n from "../../../i18n";
import { UserError } from "../../../types";
import CategoryDetailsForm from "../../components/CategoryDetailsForm";
-import SaveButtonBar, {
- SaveButtonBarState
-} from "../../../components/SaveButtonBar/SaveButtonBar";
+import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton/ConfirmButton";
+import SaveButtonBar from "../../../components/SaveButtonBar/SaveButtonBar";
interface FormData {
description: string;
@@ -31,7 +30,7 @@ const initialData: FormData = {
export interface CategoryCreatePageProps {
errors: UserError[];
disabled: boolean;
- saveButtonBarState?: SaveButtonBarState;
+ saveButtonBarState: ConfirmButtonTransitionState;
onSubmit(data: FormData);
onBack();
}
diff --git a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx b/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
index df5bc5f828..41a567a45e 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryCreate.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 CategoryCreatePage from "../components/CategoryCreatePage";
import { TypedCategoryCreateMutation } from "../mutations";
import { CategoryCreate } from "../types/CategoryCreate";
@@ -31,33 +31,45 @@ export const CategoryCreateView: React.StatelessComponent<
};
return (
<TypedCategoryCreateMutation onCompleted={handleSuccess}>
- {(mutate, { data, loading }) => (
- <>
- <WindowTitle title={i18n.t("Create category")} />
- <CategoryCreatePage
- errors={maybe(() => data.categoryCreate.errors, [])}
- disabled={loading}
- onBack={() =>
- navigate(categoryUrl(encodeURIComponent(parentId)))
- }
- onSubmit={formData =>
- mutate({
- variables: {
- input: {
- description: formData.description,
- name: formData.name,
- seo: {
- description: formData.seoDescription,
- title: formData.seoTitle
- }
- },
- parent: parentId
- }
- })
- }
- />
- </>
- )}
+ {(createCategory, createCategoryResult) => {
+ const formTransitionState = getMutationState(
+ createCategoryResult.called,
+ createCategoryResult.loading,
+ maybe(() => createCategoryResult.data.categoryCreate.errors)
+ );
+
+ return (
+ <>
+ <WindowTitle title={i18n.t("Create category")} />
+ <CategoryCreatePage
+ saveButtonBarState={formTransitionState}
+ errors={maybe(
+ () => createCategoryResult.data.categoryCreate.errors,
+ []
+ )}
+ disabled={createCategoryResult.loading}
+ onBack={() =>
+ navigate(categoryUrl(encodeURIComponent(parentId)))
+ }
+ onSubmit={formData =>
+ createCategory({
+ variables: {
+ input: {
+ description: formData.description,
+ name: formData.name,
+ seo: {
+ description: formData.seoDescription,
+ title: formData.seoTitle
+ }
+ },
+ parent: parentId
+ }
+ })
+ }
+ />
+ </>
+ );
+ }}
</TypedCategoryCreateMutation>
);
}}
diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
index b89860bfbf..34f38ada0d 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
@@ -11,7 +11,7 @@ import {
} from "../../../components/Paginator";
import { WindowTitle } from "../../../components/WindowTitle";
import i18n from "../../../i18n";
-import { maybe } from "../../../misc";
+import { getMutationState, maybe } from "../../../misc";
import { productAddUrl, productUrl } from "../../../products/urls";
import { CategoryUpdatePage } from "../../components/CategoryUpdatePage/CategoryUpdatePage";
import {
@@ -70,13 +70,23 @@ export const CategoryDetails: React.StatelessComponent<
return (
<TypedCategoryDeleteMutation onCompleted={onCategoryDelete}>
- {deleteCategory => (
+ {(deleteCategory, deleteResult) => (
<TypedCategoryUpdateMutation onCompleted={onCategoryUpdate}>
{(updateCategory, updateResult) => {
const paginationState = createPaginationState(
PAGINATE_BY,
params
);
+ const formTransitionState = getMutationState(
+ updateResult.called,
+ updateResult.loading,
+ maybe(() => updateResult.data.categoryUpdate.errors)
+ );
+ const removeDialogTransitionState = getMutationState(
+ deleteResult.called,
+ deleteResult.loading,
+ maybe(() => deleteResult.data.categoryDelete.errors)
+ );
return (
<TypedCategoryDetailsQuery
displayLoader
@@ -165,9 +175,7 @@ export const CategoryDetails: React.StatelessComponent<
edge => edge.node
)
)}
- saveButtonBarState={
- loading ? "loading" : "default"
- }
+ saveButtonBarState={formTransitionState}
subcategories={maybe(() =>
data.category.children.edges.map(
edge => edge.node
@@ -180,6 +188,9 @@ export const CategoryDetails: React.StatelessComponent<
path={categoryDeleteUrl(encodeURIComponent(id))}
render={({ match }) => (
<ActionDialog
+ confirmButtonState={
+ removeDialogTransitionState
+ }
onClose={() =>
navigate(
categoryUrl(encodeURIComponent(id)),
diff --git a/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx b/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx
index ae7e57568f..e438f77037 100644
--- a/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx
+++ b/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx
@@ -8,8 +8,12 @@ import * as classNames from "classnames";
import * as React from "react";
import i18n from "../../i18n";
+import ConfirmButton, {
+ ConfirmButtonTransitionState
+} from "../ConfirmButton/ConfirmButton";
interface ActionDialogProps {
+ confirmButtonState: ConfirmButtonTransitionState;
open: boolean;
title: string;
variant?: string;
@@ -27,7 +31,16 @@ const decorate = withStyles(theme => ({
}
}));
const ActionDialog = decorate<ActionDialogProps>(
- ({ children, classes, open, title, variant, onConfirm, onClose }) => (
+ ({
+ children,
+ classes,
+ confirmButtonState,
+ open,
+ title,
+ variant,
+ onConfirm,
+ onClose
+ }) => (
<Dialog open={open}>
<DialogTitle>{title}</DialogTitle>
<DialogContent>{children}</DialogContent>
@@ -35,7 +48,8 @@ const ActionDialog = decorate<ActionDialogProps>(
<Button onClick={onClose}>
{i18n.t("Cancel", { context: "button" })}
</Button>
- <Button
+ <ConfirmButton
+ transitionState={confirmButtonState}
color="primary"
variant="raised"
onClick={onConfirm}
@@ -46,7 +60,7 @@ const ActionDialog = decorate<ActionDialogProps>(
{variant === "delete"
? i18n.t("Delete", { context: "button" })
: i18n.t("Confirm", { context: "button" })}
- </Button>
+ </ConfirmButton>
</DialogActions>
</Dialog>
)
diff --git a/saleor/static/dashboard-next/misc.ts b/saleor/static/dashboard-next/misc.ts
index ce78be1193..b97e7e8f2d 100644
--- a/saleor/static/dashboard-next/misc.ts
+++ b/saleor/static/dashboard-next/misc.ts
@@ -1,5 +1,7 @@
+import { ConfirmButtonTransitionState } from "./components/ConfirmButton/ConfirmButton";
import { AddressType } from "./customers/types";
import i18n from "./i18n";
+import { UserError } from "./types";
import {
AuthorizationKeyType,
OrderStatus,
@@ -132,3 +134,21 @@ export function only<T>(obj: T, key: keyof T): boolean {
export function empty(obj: object): boolean {
return Object.keys(obj).every(key => obj[key] === undefined);
}
+
+export function hasErrors(errorList: UserError[] | null): boolean {
+ return !(errorList === null || errorList.length === 0);
+}
+
+export function getMutationState(
+ called: boolean,
+ loading: boolean,
+ errorList: UserError[]
+): ConfirmButtonTransitionState {
+ return loading
+ ? "loading"
+ : called
+ ? hasErrors(errorList)
+ ? "error"
+ : "success"
+ : "default";
+}