Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move product dialog paths to qs
dominik-zeglen187d72c55aee
diff --git a/saleor/static/dashboard-next/products/index.tsx b/saleor/static/dashboard-next/products/index.tsxindex f6112ca90d..bcfe1a3465 100644--- a/saleor/static/dashboard-next/products/index.tsx+++ b/saleor/static/dashboard-next/products/index.tsx@@ -7,10 +7,13 @@ import i18n from "../i18n";import {productAddPath,productImagePath,+ ProductImageUrlQueryParams,productListPath,productPath,+ ProductUrlQueryParams,productVariantAddPath,- productVariantEditPath+ productVariantEditPath,+ ProductVariantEditUrlQueryParams} from "./urls";import ProductCreate from "./views/ProductCreate";import ProductImageComponent from "./views/ProductImage";@@ -36,27 +39,44 @@ const ProductList: React.StatelessComponent<RouteComponentProps<any>> = ({const ProductUpdate: React.StatelessComponent<RouteComponentProps<any>> = ({match}) => {- return <ProductUpdateComponent id={decodeURIComponent(match.params.id)} />;+ const qs = parseQs(location.search.substr(1));+ const params: ProductUrlQueryParams = qs;++ return (+ <ProductUpdateComponent+ id={decodeURIComponent(match.params.id)}+ params={params}+ />+ );};const ProductVariant: React.StatelessComponent<RouteComponentProps<any>> = ({match}) => {+ const qs = parseQs(location.search.substr(1));+ const params: ProductVariantEditUrlQueryParams = qs;+return (<ProductVariantComponentvariantId={decodeURIComponent(match.params.variantId)}productId={decodeURIComponent(match.params.productId)}+ params={params}/>);};const ProductImage: React.StatelessComponent<RouteComponentProps<any>> = ({+ location,match}) => {+ const qs = parseQs(location.search.substr(1));+ const params: ProductImageUrlQueryParams = qs;+return (<ProductImageComponentimageId={decodeURIComponent(match.params.imageId)}productId={decodeURIComponent(match.params.productId)}+ params={params}/>);};diff --git a/saleor/static/dashboard-next/products/urls.ts b/saleor/static/dashboard-next/products/urls.tsindex c76ec7256f..d565197b36 100644--- a/saleor/static/dashboard-next/products/urls.ts+++ b/saleor/static/dashboard-next/products/urls.ts@@ -1,5 +1,7 @@import { stringify as stringifyQs } from "qs";import * as urlJoin from "url-join";++import { Dialog } from "../types";import { ProductListQueryParams } from "./views/ProductList";const productSection = "/products/";@@ -17,15 +19,26 @@ export const productListUrl = (params?: ProductListQueryParams): string => {};export const productPath = (id: string) => urlJoin(productSection, id);-export const productUrl = (id: string) => productPath(encodeURIComponent(id));+export type ProductUrlDialog = "remove";+export type ProductUrlQueryParams = Dialog<"remove">;+export const productUrl = (id: string, params?: ProductUrlQueryParams) =>+ productPath(encodeURIComponent(id)) + "?" + stringifyQs(params);export const productVariantEditPath = (productId: string, variantId: string) =>urlJoin(productSection, productId, "variant", variantId);-export const productVariantEditUrl = (productId: string, variantId: string) =>+export type ProductVariantEditUrlDialog = "remove";+export type ProductVariantEditUrlQueryParams = Dialog<"remove">;+export const productVariantEditUrl = (+ productId: string,+ variantId: string,+ params?: ProductVariantEditUrlQueryParams+) =>productVariantEditPath(encodeURIComponent(productId),encodeURIComponent(variantId)- );+ ) ++ "?" ++ stringifyQs(params);export const productVariantAddPath = (productId: string) =>urlJoin(productSection, productId, "variant/add");@@ -34,5 +47,13 @@ export const productVariantAddUrl = (productId: string) =>export const productImagePath = (productId: string, imageId: string) =>urlJoin(productSection, productId, "image", imageId);-export const productImageUrl = (productId: string, imageId: string) =>- productImagePath(encodeURIComponent(productId), encodeURIComponent(imageId));+export type ProductImageUrlDialog = "remove";+export type ProductImageUrlQueryParams = Dialog<"remove">;+export const productImageUrl = (+ productId: string,+ imageId: string,+ params?: ProductImageUrlQueryParams+) =>+ productImagePath(encodeURIComponent(productId), encodeURIComponent(imageId)) ++ "?" ++ stringifyQs(params);diff --git a/saleor/static/dashboard-next/products/views/ProductImage.tsx b/saleor/static/dashboard-next/products/views/ProductImage.tsxnew file mode 100644index 0000000000..c4c61c755d--- /dev/null+++ b/saleor/static/dashboard-next/products/views/ProductImage.tsx@@ -0,0 +1,132 @@+import DialogContentText from "@material-ui/core/DialogContentText";+import * as React from "react";++import ActionDialog from "../../components/ActionDialog";+import useNavigator from "../../hooks/useNavigator";+import useNotifier from "../../hooks/useNotifier";+import i18n from "../../i18n";+import { getMutationState, maybe } from "../../misc";+import ProductImagePage from "../components/ProductImagePage";+import {+ TypedProductImageDeleteMutation,+ TypedProductImageUpdateMutation+} from "../mutations";+import { TypedProductImageQuery } from "../queries";+import { ProductImageUpdate } from "../types/ProductImageUpdate";+import {+ productImageUrl,+ ProductImageUrlQueryParams,+ productUrl+} from "../urls";++interface ProductImageProps {+ imageId: string;+ productId: string;+ params: ProductImageUrlQueryParams;+}++export const ProductImage: React.StatelessComponent<ProductImageProps> = ({+ imageId,+ productId,+ params+}) => {+ const navigate = useNavigator();+ const notify = useNotifier();++ const handleBack = () => navigate(productUrl(productId));+ const handleUpdateSuccess = (data: ProductImageUpdate) => {+ if (data.productImageUpdate.errors.length === 0) {+ notify({ text: "Saved changes" });+ }+ };+ return (+ <TypedProductImageQuery+ displayLoader+ variables={{+ imageId,+ productId+ }}+ require={["product"]}+ >+ {({ data, loading }) => {+ return (+ <TypedProductImageUpdateMutation onCompleted={handleUpdateSuccess}>+ {(updateImage, updateResult) => (+ <TypedProductImageDeleteMutation onCompleted={handleBack}>+ {(deleteImage, deleteResult) => {+ const handleDelete = () =>+ deleteImage({ variables: { id: imageId } });+ const handleImageClick = (id: string) => () =>+ navigate(productImageUrl(productId, id));+ const handleUpdate = (formData: { description: string }) => {+ updateImage({+ variables: {+ alt: formData.description,+ id: imageId+ }+ });+ };+ const image = data && data.product && data.product.mainImage;++ const formTransitionState = getMutationState(+ updateResult.called,+ updateResult.loading,+ maybe(() => updateResult.data.productImageUpdate.errors)+ );+ const deleteTransitionState = getMutationState(+ deleteResult.called,+ deleteResult.loading,+ []+ );+ return (+ <>+ <ProductImagePage+ disabled={loading}+ product={maybe(() => data.product.name)}+ image={image || null}+ images={maybe(() => data.product.images)}+ onBack={handleBack}+ onDelete={() =>+ navigate(+ productImageUrl(productId, imageId, {+ action: "remove"+ })+ )+ }+ onRowClick={handleImageClick}+ onSubmit={handleUpdate}+ saveButtonBarState={formTransitionState}+ />+ <ActionDialog+ onClose={() =>+ navigate(productImageUrl(productId, imageId), true)+ }+ onConfirm={handleDelete}+ open={params.action === "remove"}+ title={i18n.t("Remove image", {+ context: "modal title"+ })}+ variant="delete"+ confirmButtonState={deleteTransitionState}+ >+ <DialogContentText>+ {i18n.t(+ "Are you sure you want to remove this image?",+ {+ context: "modal content"+ }+ )}+ </DialogContentText>+ </ActionDialog>+ </>+ );+ }}+ </TypedProductImageDeleteMutation>+ )}+ </TypedProductImageUpdateMutation>+ );+ }}+ </TypedProductImageQuery>+ );+};+export default ProductImage;diff --git a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx b/saleor/static/dashboard-next/products/views/ProductImage/index.tsxdeleted file mode 100644index 1825a763be..0000000000--- a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx+++ /dev/null@@ -1,148 +0,0 @@-import DialogContentText from "@material-ui/core/DialogContentText";-import * as React from "react";-import { Route } from "react-router-dom";--import ActionDialog from "../../../components/ActionDialog";-import Messages from "../../../components/messages";-import Navigator from "../../../components/Navigator";-import i18n from "../../../i18n";-import { getMutationState, maybe } from "../../../misc";-import ProductImagePage from "../../components/ProductImagePage";-import {- TypedProductImageDeleteMutation,- TypedProductImageUpdateMutation-} from "../../mutations";-import { TypedProductImageQuery } from "../../queries";-import { ProductImageUpdate } from "../../types/ProductImageUpdate";-import { productImageUrl, productUrl } from "../../urls";-import { productImageRemovePath, productImageRemoveUrl } from "./urls";--interface ProductImageProps {- imageId: string;- productId: string;-}--export const ProductImage: React.StatelessComponent<ProductImageProps> = ({- imageId,- productId-}) => (- <Messages>- {pushMessage => (- <Navigator>- {navigate => {- const handleBack = () => navigate(productUrl(productId));- const handleUpdateSuccess = (data: ProductImageUpdate) => {- if (data.productImageUpdate.errors.length === 0) {- pushMessage({ text: "Saved changes" });- }- };- return (- <TypedProductImageQuery- displayLoader- variables={{- imageId,- productId- }}- require={["product"]}- >- {({ data, loading }) => {- return (- <TypedProductImageUpdateMutation- onCompleted={handleUpdateSuccess}- >- {(updateImage, updateResult) => (- <TypedProductImageDeleteMutation onCompleted={handleBack}>- {(deleteImage, deleteResult) => {- const handleDelete = () =>- deleteImage({ variables: { id: imageId } });- const handleImageClick = (id: string) => () =>- navigate(productImageUrl(productId, id));- const handleUpdate = (formData: {- description: string;- }) => {- updateImage({- variables: {- alt: formData.description,- id: imageId- }- });- };- const image =- data && data.product && data.product.mainImage;-- const formTransitionState = getMutationState(- updateResult.called,- updateResult.loading,- maybe(- () => updateResult.data.productImageUpdate.errors- )- );- const deleteTransitionState = getMutationState(- deleteResult.called,- deleteResult.loading,- []- );- return (- <>- <ProductImagePage- disabled={loading}- product={maybe(() => data.product.name)}- image={image || null}- images={maybe(() => data.product.images)}- onBack={handleBack}- onDelete={() =>- navigate(- productImageRemoveUrl(productId, imageId)- )- }- onRowClick={handleImageClick}- onSubmit={handleUpdate}- saveButtonBarState={formTransitionState}- />- <Route- path={productImageRemovePath(- ":productId",- ":imageId"- )}- render={({ match }) => (- <ActionDialog- onClose={() =>- navigate(- productImageUrl(productId, imageId)- )- }- onConfirm={handleDelete}- open={!!match}- title={i18n.t("Remove image", {- context: "modal title"- })}- variant="delete"- confirmButtonState={deleteTransitionState}- >- <DialogContentText>- {i18n.t(- "Are you sure you want to remove this image?",- {- context: "modal content"- }- )}- </DialogContentText>- </ActionDialog>- )}- />- </>- );- }}- </TypedProductImageDeleteMutation>- )}- </TypedProductImageUpdateMutation>- );- }}- </TypedProductImageQuery>- );- }}- </Navigator>- )}- </Messages>-);-export default ProductImage;diff --git a/saleor/static/dashboard-next/products/views/ProductImage/urls.ts b/saleor/static/dashboard-next/products/views/ProductImage/urls.tsdeleted file mode 100644index 2a18f034e5..0000000000--- a/saleor/static/dashboard-next/products/views/ProductImage/urls.ts+++ /dev/null@@ -1,11 +0,0 @@-import * as urlJoin from "url-join";--import { productImagePath } from "../../urls";--export const productImageRemovePath = (productId: string, imageId: string) =>- urlJoin(productImagePath(productId, imageId), "remove");-export const productImageRemoveUrl = (productId: string, imageId: string) =>- productImageRemovePath(- encodeURIComponent(productId),- encodeURIComponent(imageId)- );diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsxnew file mode 100644index 0000000000..692c0acafa--- /dev/null+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx@@ -0,0 +1,291 @@+import DialogContentText from "@material-ui/core/DialogContentText";+import * as React from "react";+import { arrayMove } from "react-sortable-hoc";++import * as placeholderImg from "../../../images/placeholder255x255.png";+import ActionDialog from "../../components/ActionDialog";+import { WindowTitle } from "../../components/WindowTitle";+import useNavigator from "../../hooks/useNavigator";+import useNotifier from "../../hooks/useNotifier";+import i18n from "../../i18n";+import { decimal, getMutationState, maybe } from "../../misc";+import { productTypeUrl } from "../../productTypes/urls";+import ProductUpdatePage, { FormData } from "../components/ProductUpdatePage";+import { CategorySearchProvider } from "../containers/CategorySearch";+import { CollectionSearchProvider } from "../containers/CollectionSearch";+import ProductUpdateOperations from "../containers/ProductUpdateOperations";+import { TypedProductDetailsQuery } from "../queries";+import {+ ProductImageCreate,+ ProductImageCreateVariables+} from "../types/ProductImageCreate";+import {+ productImageUrl,+ productListUrl,+ productUrl,+ ProductUrlQueryParams,+ productVariantAddUrl,+ productVariantEditUrl+} from "../urls";++interface ProductUpdateProps {+ id: string;+ params: ProductUrlQueryParams;+}++export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({+ id,+ params+}) => {+ const navigate = useNavigator();+ const pushMessage = useNotifier();++ return (+ <CategorySearchProvider>+ {({ search: searchCategories, searchOpts: searchCategoriesOpts }) => (+ <CollectionSearchProvider>+ {({+ search: searchCollections,+ searchOpts: searchCollectionsOpts+ }) => (+ <TypedProductDetailsQuery+ displayLoader+ require={["product"]}+ variables={{ id }}+ >+ {({ data, loading }) => {+ const handleDelete = () => {+ pushMessage({ text: i18n.t("Product removed") });+ navigate(productListUrl());+ };+ const handleUpdate = () =>+ pushMessage({ text: i18n.t("Saved changes") });+ const handleImageCreate = (data: ProductImageCreate) => {+ const imageError = data.productImageCreate.errors.find(+ error =>+ error.field ===+ ("image" as keyof ProductImageCreateVariables)+ );+ if (imageError) {+ pushMessage({+ text: imageError.message+ });+ }+ };+ const handleImageDeleteSuccess = () =>+ pushMessage({+ text: i18n.t("Image successfully deleted")+ });+ const handleVariantAdd = () =>+ navigate(productVariantAddUrl(id));++ const product = data ? data.product : undefined;+ return (+ <ProductUpdateOperations+ product={product}+ onDelete={handleDelete}+ onImageCreate={handleImageCreate}+ onImageDelete={handleImageDeleteSuccess}+ onUpdate={handleUpdate}+ >+ {({+ createProductImage,+ deleteProduct,+ deleteProductImage,+ reorderProductImages,+ updateProduct,+ updateSimpleProduct+ }) => {+ const handleImageDelete = (id: string) => () =>+ deleteProductImage.mutate({ id });+ const handleImageEdit = (imageId: string) => () =>+ navigate(productImageUrl(id, imageId));+ const handleSubmit = (data: FormData) => {+ if (product) {+ if (product.productType.hasVariants) {+ updateProduct.mutate({+ attributes: data.attributes,+ category: data.category.value,+ chargeTaxes: data.chargeTaxes,+ collections: data.collections.map(+ collection => collection.value+ ),+ descriptionJson: JSON.stringify(data.description),+ id: product.id,+ isPublished: data.available,+ name: data.name,+ price: decimal(data.price),+ publicationDate:+ data.publicationDate !== ""+ ? data.publicationDate+ : null+ });+ } else {+ updateSimpleProduct.mutate({+ attributes: data.attributes,+ category: data.category.value,+ chargeTaxes: data.chargeTaxes,+ collections: data.collections.map(+ collection => collection.value+ ),+ descriptionJson: JSON.stringify(data.description),+ id: product.id,+ isPublished: data.available,+ name: data.name,+ price: decimal(data.price),+ productVariantId: product.variants[0].id,+ productVariantInput: {+ quantity: data.stockQuantity,+ sku: data.sku+ },+ publicationDate:+ data.publicationDate !== ""+ ? data.publicationDate+ : null+ });+ }+ }+ };++ const disableFormSave =+ createProductImage.opts.loading ||+ deleteProduct.opts.loading ||+ reorderProductImages.opts.loading ||+ updateProduct.opts.loading ||+ loading;+ const formTransitionState = getMutationState(+ updateProduct.opts.called ||+ updateSimpleProduct.opts.called,+ updateProduct.opts.loading ||+ updateSimpleProduct.opts.loading,+ maybe(+ () => updateProduct.opts.data.productUpdate.errors+ ),+ maybe(+ () =>+ updateSimpleProduct.opts.data.productUpdate.errors+ ),+ maybe(+ () =>+ updateSimpleProduct.opts.data.productVariantUpdate+ .errors+ )+ );+ const deleteTransitionState = getMutationState(+ deleteProduct.opts.called,+ deleteProduct.opts.loading,+ maybe(+ () => deleteProduct.opts.data.productDelete.errors+ )+ );+ return (+ <>+ <WindowTitle title={maybe(() => data.product.name)} />+ <ProductUpdatePage+ categories={maybe(+ () => searchCategoriesOpts.data.categories.edges,+ []+ ).map(edge => edge.node)}+ collections={maybe(+ () =>+ searchCollectionsOpts.data.collections.edges,+ []+ ).map(edge => edge.node)}+ disabled={disableFormSave}+ errors={maybe(+ () =>+ updateProduct.opts.data.productUpdate.errors,+ []+ )}+ fetchCategories={searchCategories}+ fetchCollections={searchCollections}+ saveButtonBarState={formTransitionState}+ images={maybe(() => data.product.images)}+ header={maybe(() => product.name)}+ placeholderImage={placeholderImg}+ product={product}+ productCollections={maybe(+ () => product.collections+ )}+ variants={maybe(() => product.variants)}+ onAttributesEdit={() =>+ navigate(+ productTypeUrl(data.product.productType.id)+ )+ }+ onBack={() => {+ navigate(productListUrl());+ }}+ onDelete={() =>+ navigate(+ productUrl(id, {+ action: "remove"+ })+ )+ }+ onProductShow={() => {+ if (product) {+ window.open(product.url);+ }+ }}+ onImageReorder={({ newIndex, oldIndex }) => {+ if (product) {+ let ids = product.images.map(image => image.id);+ ids = arrayMove(ids, oldIndex, newIndex);+ reorderProductImages.mutate({+ imagesIds: ids,+ productId: product.id+ });+ }+ }}+ onSubmit={handleSubmit}+ onVariantAdd={handleVariantAdd}+ onVariantShow={variantId => () =>+ navigate(+ productVariantEditUrl(product.id, variantId)+ )}+ onImageUpload={file => {+ if (product) {+ createProductImage.mutate({+ alt: "",+ image: file,+ product: product.id+ });+ }+ }}+ onImageEdit={handleImageEdit}+ onImageDelete={handleImageDelete}+ />+ <ActionDialog+ open={params.action === "remove"}+ onClose={() => navigate(productUrl(id))}+ confirmButtonState={deleteTransitionState}+ onConfirm={() => deleteProduct.mutate({ id })}+ variant="delete"+ title={i18n.t("Remove product")}+ >+ <DialogContentText+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "Are you sure you want to remove <strong>{{ name }}</strong>?",+ {+ name: product ? product.name : undefined+ }+ )+ }}+ />+ </ActionDialog>+ </>+ );+ }}+ </ProductUpdateOperations>+ );+ }}+ </TypedProductDetailsQuery>+ )}+ </CollectionSearchProvider>+ )}+ </CategorySearchProvider>+ );+};+export default ProductUpdate;diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsxdeleted file mode 100644index a3db550f7f..0000000000--- a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx+++ /dev/null@@ -1,345 +0,0 @@-import DialogContentText from "@material-ui/core/DialogContentText";-import * as React from "react";-import { Route } from "react-router-dom";-import { arrayMove } from "react-sortable-hoc";--import * as placeholderImg from "../../../../images/placeholder255x255.png";-import ActionDialog from "../../../components/ActionDialog";-import Messages from "../../../components/messages";-import Navigator from "../../../components/Navigator";-import { WindowTitle } from "../../../components/WindowTitle";-import i18n from "../../../i18n";-import { decimal, getMutationState, maybe } from "../../../misc";-import { productTypeUrl } from "../../../productTypes/urls";-import ProductUpdatePage, {- FormData-} from "../../components/ProductUpdatePage";-import { CategorySearchProvider } from "../../containers/CategorySearch";-import { CollectionSearchProvider } from "../../containers/CollectionSearch";-import ProductUpdateOperations from "../../containers/ProductUpdateOperations";-import { TypedProductDetailsQuery } from "../../queries";-import {- ProductImageCreate,- ProductImageCreateVariables-} from "../../types/ProductImageCreate";-import {- productImageUrl,- productListUrl,- productUrl,- productVariantAddUrl,- productVariantEditUrl-} from "../../urls";-import { productRemovePath, productRemoveUrl } from "./urls";--interface ProductUpdateProps {- id: string;-}--export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({- id-}) => (- <Messages>- {pushMessage => {- return (- <Navigator>- {navigate => {- return (- <CategorySearchProvider>- {({- search: searchCategories,- searchOpts: searchCategoriesOpts- }) => (- <CollectionSearchProvider>- {({- search: searchCollections,- searchOpts: searchCollectionsOpts- }) => (- <TypedProductDetailsQuery- displayLoader- require={["product"]}- variables={{ id }}- >- {({ data, loading }) => {- const handleDelete = () => {- pushMessage({ text: i18n.t("Product removed") });- navigate(productListUrl());- };- const handleUpdate = () =>- pushMessage({ text: i18n.t("Saved changes") });- const handleImageCreate = (- data: ProductImageCreate- ) => {- const imageError = data.productImageCreate.errors.find(- error =>- error.field ===- ("image" as keyof ProductImageCreateVariables)- );- if (imageError) {- pushMessage({- text: imageError.message- });- }- };- const handleImageDeleteSuccess = () =>- pushMessage({- text: i18n.t("Image successfully deleted")- });- const handleVariantAdd = () =>- navigate(productVariantAddUrl(id));-- const product = data ? data.product : undefined;- return (- <ProductUpdateOperations- product={product}- onDelete={handleDelete}- onImageCreate={handleImageCreate}- onImageDelete={handleImageDeleteSuccess}- onUpdate={handleUpdate}- >- {({- createProductImage,- deleteProduct,- deleteProductImage,- reorderProductImages,- updateProduct,- updateSimpleProduct- }) => {- const handleImageDelete = (id: string) => () =>- deleteProductImage.mutate({ id });- const handleImageEdit = (- imageId: string- ) => () =>- navigate(productImageUrl(id, imageId));- const handleSubmit = (data: FormData) => {- if (product) {- if (product.productType.hasVariants) {- updateProduct.mutate({- attributes: data.attributes,- category: data.category.value,- chargeTaxes: data.chargeTaxes,- collections: data.collections.map(- collection => collection.value- ),- descriptionJson: JSON.stringify(- data.description- ),- id: product.id,- isPublished: data.available,- name: data.name,- price: decimal(data.price),- publicationDate:- data.publicationDate !== ""- ? data.publicationDate- : null- });- } else {- updateSimpleProduct.mutate({- attributes: data.attributes,- category: data.category.value,- chargeTaxes: data.chargeTaxes,- collections: data.collections.map(- collection => collection.value- ),- descriptionJson: JSON.stringify(- data.description- ),- id: product.id,- isPublished: data.available,- name: data.name,- price: decimal(data.price),- productVariantId:- product.variants[0].id,- productVariantInput: {- quantity: data.stockQuantity,- sku: data.sku- },- publicationDate:- data.publicationDate !== ""- ? data.publicationDate- : null- });- }- }- };-- const disableFormSave =- createProductImage.opts.loading ||- deleteProduct.opts.loading ||- reorderProductImages.opts.loading ||- updateProduct.opts.loading ||- loading;- const formTransitionState = getMutationState(- updateProduct.opts.called ||- updateSimpleProduct.opts.called,- updateProduct.opts.loading ||- updateSimpleProduct.opts.loading,- maybe(- () =>- updateProduct.opts.data.productUpdate- .errors- ),- maybe(- () =>- updateSimpleProduct.opts.data- .productUpdate.errors- ),- maybe(- () =>- updateSimpleProduct.opts.data- .productVariantUpdate.errors- )- );- const deleteTransitionState = getMutationState(- deleteProduct.opts.called,- deleteProduct.opts.loading,- maybe(- () =>- deleteProduct.opts.data.productDelete- .errors- )- );- return (- <>- <WindowTitle- title={maybe(() => data.product.name)}- />- <ProductUpdatePage- categories={maybe(- () =>- searchCategoriesOpts.data.categories- .edges,- []- ).map(edge => edge.node)}- collections={maybe(- () =>- searchCollectionsOpts.data.collections- .edges,- []- ).map(edge => edge.node)}- disabled={disableFormSave}- errors={maybe(- () =>- updateProduct.opts.data.productUpdate- .errors,- []- )}- fetchCategories={searchCategories}- fetchCollections={searchCollections}- saveButtonBarState={formTransitionState}- images={maybe(() => data.product.images)}- header={maybe(() => product.name)}- placeholderImage={placeholderImg}- product={product}- productCollections={maybe(- () => product.collections- )}- variants={maybe(() => product.variants)}- onAttributesEdit={() =>- navigate(- productTypeUrl(- data.product.productType.id- )- )- }- onBack={() => {- navigate(productListUrl());- }}- onDelete={() =>- navigate(productRemoveUrl(id))- }- onProductShow={() => {- if (product) {- window.open(product.url);- }- }}- onImageReorder={({- newIndex,- oldIndex- }) => {- if (product) {- let ids = product.images.map(- image => image.id- );- ids = arrayMove(- ids,- oldIndex,- newIndex- );- reorderProductImages.mutate({- imagesIds: ids,- productId: product.id- });- }- }}- onSubmit={handleSubmit}- onVariantAdd={handleVariantAdd}- onVariantShow={variantId => () =>- navigate(- productVariantEditUrl(- product.id,- variantId- )- )}- onImageUpload={file => {- if (product) {- createProductImage.mutate({- alt: "",- image: file,- product: product.id- });- }- }}- onImageEdit={handleImageEdit}- onImageDelete={handleImageDelete}- />- <Route- path={productRemovePath(":id")}- render={({ match }) => (- <ActionDialog- open={!!match}- onClose={() =>- navigate(productUrl(id))- }- confirmButtonState={- deleteTransitionState- }- onConfirm={() =>- deleteProduct.mutate({ id })- }- variant="delete"- title={i18n.t("Remove product")}- >- <DialogContentText- dangerouslySetInnerHTML={{- __html: i18n.t(- "Are you sure you want to remove <strong>{{ name }}</strong>?",- {- name: product- ? product.name- : undefined- }- )- }}- />- </ActionDialog>- )}- />- </>- );- }}- </ProductUpdateOperations>- );- }}- </TypedProductDetailsQuery>- )}- </CollectionSearchProvider>- )}- </CategorySearchProvider>- );- }}- </Navigator>- );- }}- </Messages>-);-export default ProductUpdate;diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/urls.ts b/saleor/static/dashboard-next/products/views/ProductUpdate/urls.tsdeleted file mode 100644index 323f096555..0000000000--- a/saleor/static/dashboard-next/products/views/ProductUpdate/urls.ts+++ /dev/null@@ -1,7 +0,0 @@-import * as urlJoin from "url-join";-import { productPath } from "../../urls";--export const productRemovePath = (id: string) =>- urlJoin(productPath(id), "remove");-export const productRemoveUrl = (id: string) =>- productRemovePath(encodeURIComponent(id));diff --git a/saleor/static/dashboard-next/products/views/ProductVariant.tsx b/saleor/static/dashboard-next/products/views/ProductVariant.tsxnew file mode 100644index 0000000000..0cd04a6c69--- /dev/null+++ b/saleor/static/dashboard-next/products/views/ProductVariant.tsx@@ -0,0 +1,169 @@+import * as React from "react";++import * as placeholderImg from "../../../images/placeholder255x255.png";+import { WindowTitle } from "../../components/WindowTitle";+import useNavigator from "../../hooks/useNavigator";+import useNotifier from "../../hooks/useNotifier";+import i18n from "../../i18n";+import { decimal, getMutationState, maybe } from "../../misc";+import ProductVariantDeleteDialog from "../components/ProductVariantDeleteDialog";+import ProductVariantPage from "../components/ProductVariantPage";+import ProductVariantOperations from "../containers/ProductVariantOperations";+import { TypedProductVariantQuery } from "../queries";+import { VariantUpdate } from "../types/VariantUpdate";+import {+ productUrl,+ productVariantAddUrl,+ productVariantEditUrl,+ ProductVariantEditUrlQueryParams+} from "../urls";++interface ProductUpdateProps {+ variantId: string;+ productId: string;+ params: ProductVariantEditUrlQueryParams;+}++interface FormData {+ id: string;+ attributes?: Array<{+ slug: string;+ value: string;+ }>;+ costPrice?: string;+ priceOverride?: string;+ quantity: number;+ sku: string;+}++export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({+ variantId,+ productId,+ params+}) => {+ const navigate = useNavigator();+ const notify = useNotifier();++ return (+ <TypedProductVariantQuery+ displayLoader+ variables={{ id: variantId }}+ require={["productVariant"]}+ >+ {({ data, loading }) => {+ const variant = data ? data.productVariant : undefined;+ const handleBack = () => navigate(productUrl(productId));+ const handleDelete = () => {+ notify({ text: i18n.t("Variant removed") });+ navigate(productUrl(productId));+ };+ const handleUpdate = (data: VariantUpdate) => {+ if (!maybe(() => data.productVariantUpdate.errors.length)) {+ notify({ text: i18n.t("Changes saved") });+ }+ };++ return (+ <ProductVariantOperations+ onDelete={handleDelete}+ onUpdate={handleUpdate}+ >+ {({ assignImage, deleteVariant, updateVariant, unassignImage }) => {+ const disableFormSave =+ loading ||+ deleteVariant.opts.loading ||+ updateVariant.opts.loading ||+ assignImage.opts.loading ||+ unassignImage.opts.loading;+ const formTransitionState = getMutationState(+ updateVariant.opts.called,+ updateVariant.opts.loading,+ maybe(() => updateVariant.opts.data.productVariantUpdate.errors)+ );+ const removeTransitionState = getMutationState(+ deleteVariant.opts.called,+ deleteVariant.opts.loading,+ maybe(() => deleteVariant.opts.data.productVariantDelete.errors)+ );+ const handleImageSelect = (id: string) => () => {+ if (variant) {+ if (+ variant.images &&+ variant.images.map(image => image.id).indexOf(id) !== -1+ ) {+ unassignImage.mutate({+ imageId: id,+ variantId: variant.id+ });+ } else {+ assignImage.mutate({+ imageId: id,+ variantId: variant.id+ });+ }+ }+ };++ return (+ <>+ <WindowTitle title={maybe(() => data.productVariant.name)} />+ <ProductVariantPage+ errors={maybe(+ () => updateVariant.opts.data.productVariantUpdate.errors,+ []+ )}+ saveButtonBarState={formTransitionState}+ loading={disableFormSave}+ placeholderImage={placeholderImg}+ variant={variant}+ header={variant ? variant.name || variant.sku : undefined}+ onAdd={() => navigate(productVariantAddUrl(productId))}+ onBack={handleBack}+ onDelete={() =>+ navigate(+ productVariantEditUrl(productId, variantId, {+ action: "remove"+ })+ )+ }+ onImageSelect={handleImageSelect}+ onSubmit={(data: FormData) => {+ if (variant) {+ updateVariant.mutate({+ attributes: data.attributes ? data.attributes : null,+ costPrice: decimal(data.costPrice),+ id: variantId,+ priceOverride: decimal(data.priceOverride),+ quantity: data.quantity || null,+ sku: data.sku,+ trackInventory: true // FIXME: missing in UI+ });+ }+ }}+ onVariantClick={variantId => {+ navigate(productVariantEditUrl(productId, variantId));+ }}+ />+ <ProductVariantDeleteDialog+ confirmButtonState={removeTransitionState}+ onClose={() =>+ navigate(productVariantEditUrl(productId, variantId))+ }+ onConfirm={() =>+ deleteVariant.mutate({+ id: variantId+ })+ }+ open={params.action === "remove"}+ name={maybe(() => data.productVariant.name)}+ />+ </>+ );+ }}+ </ProductVariantOperations>+ );+ }}+ </TypedProductVariantQuery>+ );+};+export default ProductVariant;diff --git a/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx b/saleor/static/dashboard-next/products/views/ProductVariant/index.tsxdeleted file mode 100644index 17e1787f61..0000000000--- a/saleor/static/dashboard-next/products/views/ProductVariant/index.tsx+++ /dev/null@@ -1,203 +0,0 @@-import * as React from "react";-import { Route } from "react-router-dom";--import * as placeholderImg from "../../../../images/placeholder255x255.png";-import Messages from "../../../components/messages";-import Navigator from "../../../components/Navigator";-import { WindowTitle } from "../../../components/WindowTitle";-import i18n from "../../../i18n";-import { decimal, getMutationState, maybe } from "../../../misc";-import ProductVariantDeleteDialog from "../../components/ProductVariantDeleteDialog";-import ProductVariantPage from "../../components/ProductVariantPage";-import ProductVariantOperations from "../../containers/ProductVariantOperations";-import { TypedProductVariantQuery } from "../../queries";-import { VariantUpdate } from "../../types/VariantUpdate";-import {- productUrl,- productVariantAddUrl,- productVariantEditUrl-} from "../../urls";-import { productVariantRemovePath, productVariantRemoveUrl } from "./urls";--interface ProductUpdateProps {- variantId: string;- productId: string;-}--interface FormData {- id: string;- attributes?: Array<{- slug: string;- value: string;- }>;- costPrice?: string;- priceOverride?: string;- quantity: number;- sku: string;-}--export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({- variantId,- productId-}) => (- <Navigator>- {navigate => (- <Messages>- {pushMessage => (- <TypedProductVariantQuery- displayLoader- variables={{ id: variantId }}- require={["productVariant"]}- >- {({ data, loading }) => {- const variant = data ? data.productVariant : undefined;- const handleBack = () => navigate(productUrl(productId));- const handleDelete = () => {- pushMessage({ text: i18n.t("Variant removed") });- navigate(productUrl(productId));- };- const handleUpdate = (data: VariantUpdate) => {- if (!maybe(() => data.productVariantUpdate.errors.length)) {- pushMessage({ text: i18n.t("Changes saved") });- }- };-- return (- <ProductVariantOperations- onDelete={handleDelete}- onUpdate={handleUpdate}- >- {({- assignImage,- deleteVariant,- updateVariant,- unassignImage- }) => {- const disableFormSave =- loading ||- deleteVariant.opts.loading ||- updateVariant.opts.loading ||- assignImage.opts.loading ||- unassignImage.opts.loading;- const formTransitionState = getMutationState(- updateVariant.opts.called,- updateVariant.opts.loading,- maybe(- () =>- updateVariant.opts.data.productVariantUpdate.errors- )- );- const removeTransitionState = getMutationState(- deleteVariant.opts.called,- deleteVariant.opts.loading,- maybe(- () =>- deleteVariant.opts.data.productVariantDelete.errors- )- );- const handleImageSelect = (id: string) => () => {- if (variant) {- if (- variant.images &&- variant.images.map(image => image.id).indexOf(id) !==- -1- ) {- unassignImage.mutate({- imageId: id,- variantId: variant.id- });- } else {- assignImage.mutate({- imageId: id,- variantId: variant.id- });- }- }- };-- return (- <>- <WindowTitle- title={maybe(() => data.productVariant.name)}- />- <ProductVariantPage- errors={maybe(- () =>- updateVariant.opts.data.productVariantUpdate- .errors,- []- )}- saveButtonBarState={formTransitionState}- loading={disableFormSave}- placeholderImage={placeholderImg}- variant={variant}- header={- variant ? variant.name || variant.sku : undefined- }- onAdd={() =>- navigate(productVariantAddUrl(productId))- }- onBack={handleBack}- onDelete={() =>- navigate(- productVariantRemoveUrl(productId, variantId)- )- }- onImageSelect={handleImageSelect}- onSubmit={(data: FormData) => {- if (variant) {- updateVariant.mutate({- attributes: data.attributes- ? data.attributes- : null,- costPrice: decimal(data.costPrice),- id: variantId,- priceOverride: decimal(data.priceOverride),- quantity: data.quantity || null,- sku: data.sku,- trackInventory: true // FIXME: missing in UI- });- }- }}- onVariantClick={variantId => {- navigate(- productVariantEditUrl(productId, variantId)- );- }}- />- <Route- path={productVariantRemovePath(- ":productId",- ":variantId"- )}- render={({ match }) => (- <ProductVariantDeleteDialog- confirmButtonState={removeTransitionState}- onClose={() =>- navigate(- productVariantEditUrl(productId, variantId)- )- }- onConfirm={() =>- deleteVariant.mutate({- id: variantId- })- }- open={!!match}- name={maybe(() => data.productVariant.name)}- />- )}- />- </>- );- }}- </ProductVariantOperations>- );- }}- </TypedProductVariantQuery>- )}- </Messages>- )}- </Navigator>-);-export default ProductVariant;diff --git a/saleor/static/dashboard-next/products/views/ProductVariant/urls.ts b/saleor/static/dashboard-next/products/views/ProductVariant/urls.tsdeleted file mode 100644index 5ba178ac2e..0000000000--- a/saleor/static/dashboard-next/products/views/ProductVariant/urls.ts+++ /dev/null@@ -1,12 +0,0 @@-import * as urlJoin from "url-join";-import { productVariantEditPath } from "../../urls";--export const productVariantRemovePath = (- productId: string,- variantId: string-) => urlJoin(productVariantEditPath(productId, variantId), "remove");-export const productVariantRemoveUrl = (productId: string, variantId: string) =>- productVariantRemovePath(- encodeURIComponent(productId),- encodeURIComponent(variantId)- );