Skip to content

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

Move voucher details dialog paths to qs

dominik-zeglen5a93f3f79a2d
diff --git a/saleor/static/dashboard-next/discounts/index.tsx b/saleor/static/dashboard-next/discounts/index.tsx
index f36b8347a8..39ce26909f 100644
--- a/saleor/static/dashboard-next/discounts/index.tsx
+++ b/saleor/static/dashboard-next/discounts/index.tsx
@@ -13,15 +13,14 @@ import {
SaleUrlQueryParams,
voucherAddPath,
voucherListPath,
- voucherPath
+ voucherPath,
+ VoucherUrlQueryParams
} from "./urls";
import SaleCreateView from "./views/SaleCreate";
import SaleDetailsViewComponent from "./views/SaleDetails";
import SaleListViewComponent, { SaleListQueryParams } from "./views/SaleList";
import VoucherCreateView from "./views/VoucherCreate";
-import VoucherDetailsViewComponent, {
- VoucherDetailsQueryParams
-} from "./views/VoucherDetails";
+import VoucherDetailsViewComponent from "./views/VoucherDetails";
import VoucherListViewComponent, {
VoucherListQueryParams
} from "./views/VoucherList";
@@ -67,11 +66,10 @@ const VoucherListView: React.StatelessComponent<RouteComponentProps<{}>> = ({
const VoucherDetailsView: React.StatelessComponent<
RouteComponentProps<{ id: string }>
> = ({ match, location }) => {
- const { after, before, tab } = parseQs(location.search.substr(1));
- const params: VoucherDetailsQueryParams = {
- after,
- before,
- tab: voucherDetailsPageTab(tab)
+ const { activeTab, ...qs } = parseQs(location.search.substr(1));
+ const params: VoucherUrlQueryParams = {
+ ...qs,
+ activeTab: voucherDetailsPageTab(activeTab)
};
return (
<VoucherDetailsViewComponent
diff --git a/saleor/static/dashboard-next/discounts/urls.ts b/saleor/static/dashboard-next/discounts/urls.ts
index 8391ff2822..353c86a5d8 100644
--- a/saleor/static/dashboard-next/discounts/urls.ts
+++ b/saleor/static/dashboard-next/discounts/urls.ts
@@ -3,6 +3,7 @@ import * as urlJoin from "url-join";
import { ActiveTab, Dialog, Pagination } from "../types";
import { SaleDetailsPageTab } from "./components/SaleDetailsPage";
+import { VoucherDetailsPageTab } from "./components/VoucherDetailsPage";
export const discountSection = "/discounts/";
@@ -27,6 +28,16 @@ export const voucherSection = urlJoin(discountSection, "vouchers");
export const voucherListPath = voucherSection;
export const voucherListUrl = voucherListPath;
export const voucherPath = (id: string) => urlJoin(voucherSection, id);
-export const voucherUrl = (id: string) => voucherPath(encodeURIComponent(id));
+export type VoucherUrlDialog =
+ | "assign-category"
+ | "assign-collection"
+ | "assign-country"
+ | "assign-product"
+ | "remove";
+export type VoucherUrlQueryParams = Pagination &
+ Dialog<VoucherUrlDialog> &
+ ActiveTab<VoucherDetailsPageTab>;
+export const voucherUrl = (id: string, params?: VoucherUrlQueryParams) =>
+ voucherPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
export const voucherAddPath = urlJoin(voucherSection, "add");
export const voucherAddUrl = voucherAddPath;
diff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
new file mode 100644
index 0000000000..ab80231878
--- /dev/null
+++ b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
@@ -0,0 +1,446 @@
+import DialogContentText from "@material-ui/core/DialogContentText";
+import * as React from "react";
+
+import { categoryUrl } from "../../categories/urls";
+import { collectionUrl } from "../../collections/urls";
+import ActionDialog from "../../components/ActionDialog";
+import AssignCategoriesDialog from "../../components/AssignCategoryDialog";
+import AssignCollectionDialog from "../../components/AssignCollectionDialog";
+import AssignProductDialog from "../../components/AssignProductDialog";
+import { createPaginationState } from "../../components/Paginator";
+import { WindowTitle } from "../../components/WindowTitle";
+import { SearchCategoriesProvider } from "../../containers/SearchCategories";
+import { SearchCollectionsProvider } from "../../containers/SearchCollections";
+import { SearchProductsProvider } from "../../containers/SearchProducts";
+import useNavigator from "../../hooks/useNavigator";
+import useNotifier from "../../hooks/useNotifier";
+import usePaginator from "../../hooks/usePaginator";
+import useShop from "../../hooks/useShop";
+import i18n from "../../i18n";
+import { decimal, getMutationState, maybe } from "../../misc";
+import { productUrl } from "../../products/urls";
+import {
+ DiscountValueTypeEnum,
+ VoucherDiscountValueType
+} from "../../types/globalTypes";
+import DiscountCountrySelectDialog from "../components/DiscountCountrySelectDialog";
+import VoucherDetailsPage, {
+ VoucherDetailsPageTab
+} from "../components/VoucherDetailsPage";
+import {
+ TypedVoucherCataloguesAdd,
+ TypedVoucherCataloguesRemove,
+ TypedVoucherDelete,
+ TypedVoucherUpdate
+} from "../mutations";
+import { TypedVoucherDetails } from "../queries";
+import { VoucherCataloguesAdd } from "../types/VoucherCataloguesAdd";
+import { VoucherDelete } from "../types/VoucherDelete";
+import { VoucherUpdate } from "../types/VoucherUpdate";
+import {
+ voucherListUrl,
+ voucherUrl,
+ VoucherUrlDialog,
+ VoucherUrlQueryParams
+} from "../urls";
+
+const PAGINATE_BY = 20;
+
+interface VoucherDetailsProps {
+ id: string;
+ params: VoucherUrlQueryParams;
+}
+
+function discountValueTypeEnum(
+ type: VoucherDiscountValueType
+): DiscountValueTypeEnum {
+ return type.toString() === DiscountValueTypeEnum.FIXED
+ ? DiscountValueTypeEnum.FIXED
+ : DiscountValueTypeEnum.PERCENTAGE;
+}
+
+export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
+ id,
+ params
+}) => {
+ const navigate = useNavigator();
+ const paginate = usePaginator();
+ const notify = useNotifier();
+ const shop = useShop();
+
+ const paginationState = createPaginationState(PAGINATE_BY, params);
+ const changeTab = (tab: VoucherDetailsPageTab) =>
+ navigate(
+ voucherUrl(id, {
+ activeTab: tab
+ })
+ );
+
+ const handleCatalogueAdd = (data: VoucherCataloguesAdd) => {
+ if (data.voucherCataloguesAdd.errors.length === 0) {
+ closeModal();
+ }
+ };
+
+ const handleVoucherDelete = (data: VoucherDelete) => {
+ if (data.voucherDelete.errors.length === 0) {
+ notify({
+ text: i18n.t("Removed voucher", {
+ context: "notification"
+ })
+ });
+ navigate(voucherListUrl, true);
+ }
+ };
+
+ const handleVoucherUpdate = (data: VoucherUpdate) => {
+ if (data.voucherUpdate.errors.length === 0) {
+ closeModal();
+ notify({
+ text: i18n.t("Updated voucher", {
+ context: "notification"
+ })
+ });
+ }
+ };
+
+ const closeModal = () =>
+ navigate(
+ voucherUrl(id, {
+ ...params,
+ action: undefined
+ }),
+ true
+ );
+
+ const openModal = (action: VoucherUrlDialog) =>
+ navigate(
+ voucherUrl(id, {
+ ...params,
+ action
+ })
+ );
+
+ return (
+ <TypedVoucherCataloguesRemove>
+ {(voucherCataloguesRemove, voucherCataloguesRemoveOpts) => (
+ <TypedVoucherCataloguesAdd onCompleted={handleCatalogueAdd}>
+ {(voucherCataloguesAdd, voucherCataloguesAddOpts) => (
+ <TypedVoucherUpdate onCompleted={handleVoucherUpdate}>
+ {(voucherUpdate, voucherUpdateOpts) => (
+ <TypedVoucherDelete onCompleted={handleVoucherDelete}>
+ {(voucherDelete, voucherDeleteOpts) => (
+ <TypedVoucherDetails
+ displayLoader
+ variables={{ id, ...paginationState }}
+ >
+ {({ data, loading }) => {
+ const tabPageInfo =
+ params.activeTab === VoucherDetailsPageTab.categories
+ ? maybe(() => data.voucher.categories.pageInfo)
+ : params.activeTab ===
+ VoucherDetailsPageTab.collections
+ ? maybe(() => data.voucher.collections.pageInfo)
+ : maybe(() => data.voucher.products.pageInfo);
+ const formTransitionState = getMutationState(
+ voucherUpdateOpts.called,
+ voucherUpdateOpts.loading,
+ maybe(
+ () => voucherUpdateOpts.data.voucherUpdate.errors
+ )
+ );
+ const assignTransitionState = getMutationState(
+ voucherCataloguesAddOpts.called,
+ voucherCataloguesAddOpts.loading,
+ maybe(
+ () =>
+ voucherCataloguesAddOpts.data.voucherCataloguesAdd
+ .errors
+ )
+ );
+ const removeTransitionState = getMutationState(
+ voucherDeleteOpts.called,
+ voucherDeleteOpts.loading,
+ maybe(
+ () => voucherDeleteOpts.data.voucherDelete.errors
+ )
+ );
+
+ const {
+ loadNextPage,
+ loadPreviousPage,
+ pageInfo
+ } = paginate(tabPageInfo, paginationState, params);
+
+ return (
+ <>
+ <WindowTitle title={i18n.t("Vouchers")} />
+ <VoucherDetailsPage
+ defaultCurrency={maybe(
+ () => shop.defaultCurrency
+ )}
+ voucher={maybe(() => data.voucher)}
+ disabled={
+ loading || voucherCataloguesRemoveOpts.loading
+ }
+ errors={maybe(
+ () =>
+ voucherUpdateOpts.data.voucherUpdate.errors
+ )}
+ pageInfo={pageInfo}
+ onNextPage={loadNextPage}
+ onPreviousPage={loadPreviousPage}
+ onCategoryAssign={() =>
+ openModal("assign-category")
+ }
+ onCategoryClick={id => () =>
+ navigate(categoryUrl(id))}
+ onCollectionAssign={() =>
+ openModal("assign-collection")
+ }
+ onCollectionUnassign={collectionId =>
+ voucherCataloguesRemove({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ collections: [collectionId]
+ }
+ }
+ })
+ }
+ onCountryAssign={() =>
+ openModal("assign-country")
+ }
+ onCountryUnassign={countryCode =>
+ voucherUpdate({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ countries: data.voucher.countries
+ .filter(
+ country =>
+ country.code !== countryCode
+ )
+ .map(country => country.code)
+ }
+ }
+ })
+ }
+ onCategoryUnassign={categoryId =>
+ voucherCataloguesRemove({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ categories: [categoryId]
+ }
+ }
+ })
+ }
+ onCollectionClick={id => () =>
+ navigate(collectionUrl(id))}
+ onProductAssign={() =>
+ openModal("assign-product")
+ }
+ onProductUnassign={productId =>
+ voucherCataloguesRemove({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ products: [productId]
+ }
+ }
+ })
+ }
+ onProductClick={id => () =>
+ navigate(productUrl(id))}
+ activeTab={params.activeTab}
+ onBack={() => navigate(voucherListUrl)}
+ onTabClick={changeTab}
+ onSubmit={formData =>
+ voucherUpdate({
+ variables: {
+ id,
+ input: {
+ discountValue: decimal(formData.value),
+ discountValueType: discountValueTypeEnum(
+ formData.discountType
+ ),
+ endDate:
+ formData.endDate === ""
+ ? null
+ : formData.endDate,
+ name: formData.name,
+ startDate:
+ formData.startDate === ""
+ ? null
+ : formData.startDate
+ }
+ }
+ })
+ }
+ onRemove={() => openModal("remove")}
+ saveButtonBarState={formTransitionState}
+ />
+ <SearchCategoriesProvider>
+ {(searchCategories, searchCategoriesOpts) => (
+ <AssignCategoriesDialog
+ categories={maybe(() =>
+ searchCategoriesOpts.data.categories.edges
+ .map(edge => edge.node)
+ .filter(
+ suggestedCategory =>
+ suggestedCategory.id
+ )
+ )}
+ confirmButtonState={assignTransitionState}
+ open={params.action === "assign-category"}
+ onFetch={searchCategories}
+ loading={searchCategoriesOpts.loading}
+ onClose={closeModal}
+ onSubmit={formData =>
+ voucherCataloguesAdd({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ categories: formData.categories.map(
+ product => product.id
+ )
+ }
+ }
+ })
+ }
+ />
+ )}
+ </SearchCategoriesProvider>
+ <SearchCollectionsProvider>
+ {(searchCollections, searchCollectionsOpts) => (
+ <AssignCollectionDialog
+ collections={maybe(() =>
+ searchCollectionsOpts.data.collections.edges
+ .map(edge => edge.node)
+ .filter(
+ suggestedCategory =>
+ suggestedCategory.id
+ )
+ )}
+ confirmButtonState={assignTransitionState}
+ open={params.action === "assign-collection"}
+ onFetch={searchCollections}
+ loading={searchCollectionsOpts.loading}
+ onClose={closeModal}
+ onSubmit={formData =>
+ voucherCataloguesAdd({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ collections: formData.collections.map(
+ product => product.id
+ )
+ }
+ }
+ })
+ }
+ />
+ )}
+ </SearchCollectionsProvider>
+ <DiscountCountrySelectDialog
+ confirmButtonState={formTransitionState}
+ countries={maybe(() => shop.countries, [])}
+ onClose={() => navigate(voucherUrl(id))}
+ onConfirm={formData =>
+ voucherUpdate({
+ variables: {
+ id,
+ input: {
+ countries: formData.countries
+ }
+ }
+ })
+ }
+ open={params.action === "assign-country"}
+ initial={maybe(
+ () =>
+ data.voucher.countries.map(
+ country => country.code
+ ),
+ []
+ )}
+ />
+ <SearchProductsProvider>
+ {(searchProducts, searchProductsOpts) => (
+ <AssignProductDialog
+ confirmButtonState={assignTransitionState}
+ open={params.action === "assign-product"}
+ onFetch={searchProducts}
+ loading={searchProductsOpts.loading}
+ onClose={closeModal}
+ onSubmit={formData =>
+ voucherCataloguesAdd({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ products: formData.products.map(
+ product => product.id
+ )
+ }
+ }
+ })
+ }
+ products={maybe(() =>
+ searchProductsOpts.data.products.edges
+ .map(edge => edge.node)
+ .filter(
+ suggestedProduct => suggestedProduct.id
+ )
+ )}
+ />
+ )}
+ </SearchProductsProvider>
+ <ActionDialog
+ open={params.action === "remove"}
+ title={i18n.t("Remove Voucher")}
+ confirmButtonState={removeTransitionState}
+ onClose={closeModal}
+ variant="delete"
+ onConfirm={() =>
+ voucherDelete({
+ variables: { id }
+ })
+ }
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ voucherName }}</strong>?",
+ {
+ voucherName: maybe(
+ () => data.voucher.name,
+ "..."
+ )
+ }
+ )
+ }}
+ />
+ </ActionDialog>
+ </>
+ );
+ }}
+ </TypedVoucherDetails>
+ )}
+ </TypedVoucherDelete>
+ )}
+ </TypedVoucherUpdate>
+ )}
+ </TypedVoucherCataloguesAdd>
+ )}
+ </TypedVoucherCataloguesRemove>
+ );
+};
+export default VoucherDetails;
diff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsx b/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsx
deleted file mode 100644
index 5876df18fb..0000000000
--- a/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsx
+++ /dev/null
@@ -1,632 +0,0 @@
-import DialogContentText from "@material-ui/core/DialogContentText";
-import { stringify as stringifyQs } from "qs";
-import * as React from "react";
-import { Route } from "react-router-dom";
-
-import { categoryUrl } from "../../../categories/urls";
-import { collectionUrl } from "../../../collections/urls";
-import ActionDialog from "../../../components/ActionDialog";
-import AssignCategoriesDialog from "../../../components/AssignCategoryDialog";
-import AssignCollectionDialog from "../../../components/AssignCollectionDialog";
-import AssignProductDialog from "../../../components/AssignProductDialog";
-import Messages from "../../../components/messages";
-import Navigator from "../../../components/Navigator";
-import {
- createPaginationState,
- Paginator
-} from "../../../components/Paginator";
-import Shop from "../../../components/Shop";
-import { WindowTitle } from "../../../components/WindowTitle";
-import { SearchCategoriesProvider } from "../../../containers/SearchCategories";
-import { SearchCollectionsProvider } from "../../../containers/SearchCollections";
-import { SearchProductsProvider } from "../../../containers/SearchProducts";
-import i18n from "../../../i18n";
-import { decimal, getMutationState, maybe } from "../../../misc";
-import { productUrl } from "../../../products/urls";
-import { Pagination } from "../../../types";
-import {
- DiscountValueTypeEnum,
- VoucherDiscountValueType
-} from "../../../types/globalTypes";
-import DiscountCountrySelectDialog from "../../components/DiscountCountrySelectDialog";
-import VoucherDetailsPage, {
- VoucherDetailsPageTab
-} from "../../components/VoucherDetailsPage";
-import {
- TypedVoucherCataloguesAdd,
- TypedVoucherCataloguesRemove,
- TypedVoucherDelete,
- TypedVoucherUpdate
-} from "../../mutations";
-import { TypedVoucherDetails } from "../../queries";
-import { VoucherCataloguesAdd } from "../../types/VoucherCataloguesAdd";
-import { VoucherDelete } from "../../types/VoucherDelete";
-import { VoucherUpdate } from "../../types/VoucherUpdate";
-import { voucherListUrl, voucherUrl } from "../../urls";
-import {
- voucherAssignCategoriesPath,
- voucherAssignCategoriesUrl,
- voucherAssignCollectionsPath,
- voucherAssignCollectionsUrl,
- voucherAssignCountriesPath,
- voucherAssignCountriesUrl,
- voucherAssignProductsPath,
- voucherAssignProductsUrl,
- voucherDeletePath,
- voucherDeleteUrl
-} from "./urls";
-
-const PAGINATE_BY = 20;
-
-export type VoucherDetailsQueryParams = Pagination &
- Partial<{
- tab: VoucherDetailsPageTab;
- }>;
-
-interface VoucherDetailsProps {
- id: string;
- params: VoucherDetailsQueryParams;
-}
-
-function discountValueTypeEnum(
- type: VoucherDiscountValueType
-): DiscountValueTypeEnum {
- return type.toString() === DiscountValueTypeEnum.FIXED
- ? DiscountValueTypeEnum.FIXED
- : DiscountValueTypeEnum.PERCENTAGE;
-}
-
-export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
- id,
- params
-}) => (
- <>
- <WindowTitle title={i18n.t("Vouchers")} />
- <Shop>
- {shop => (
- <Messages>
- {pushMessage => (
- <Navigator>
- {navigate => {
- const paginationState = createPaginationState(
- PAGINATE_BY,
- params
- );
- const changeTab = (tab: VoucherDetailsPageTab) =>
- navigate(
- "?" +
- stringifyQs({
- tab
- })
- );
-
- const handleCatalogueAdd = (data: VoucherCataloguesAdd) => {
- if (data.voucherCataloguesAdd.errors.length === 0) {
- navigate(voucherUrl(id), true, true);
- }
- };
-
- const handleVoucherDelete = (data: VoucherDelete) => {
- if (data.voucherDelete.errors.length === 0) {
- pushMessage({
- text: i18n.t("Removed voucher", {
- context: "notification"
- })
- });
- navigate(voucherListUrl, true);
- }
- };
-
- const handleVoucherUpdate = (data: VoucherUpdate) => {
- if (data.voucherUpdate.errors.length === 0) {
- navigate(voucherUrl(id), true, true);
- }
- pushMessage({
- text: i18n.t("Updated voucher", {
- context: "notification"
- })
- });
- };
-
- return (
- <TypedVoucherCataloguesRemove>
- {(voucherCataloguesRemove, voucherCataloguesRemoveOpts) => (
- <TypedVoucherCataloguesAdd
- onCompleted={handleCatalogueAdd}
- >
- {(voucherCataloguesAdd, voucherCataloguesAddOpts) => (
- <TypedVoucherUpdate onCompleted={handleVoucherUpdate}>
- {(voucherUpdate, voucherUpdateOpts) => (
- <TypedVoucherDelete
- onCompleted={handleVoucherDelete}
- >
- {(voucherDelete, voucherDeleteOpts) => (
- <TypedVoucherDetails
- displayLoader
- variables={{ id, ...paginationState }}
- >
- {({ data, loading }) => {
- const pageInfo =
- params.tab ===
- VoucherDetailsPageTab.categories
- ? maybe(
- () =>
- data.voucher.categories.pageInfo
- )
- : params.tab ===
- VoucherDetailsPageTab.collections
- ? maybe(
- () =>
- data.voucher.collections
- .pageInfo
- )
- : maybe(
- () =>
- data.voucher.products.pageInfo
- );
- const formTransitionState = getMutationState(
- voucherUpdateOpts.called,
- voucherUpdateOpts.loading,
- maybe(
- () =>
- voucherUpdateOpts.data.voucherUpdate
- .errors
- )
- );
- const assignTransitionState = getMutationState(
- voucherCataloguesAddOpts.called,
- voucherCataloguesAddOpts.loading,
- maybe(
- () =>
- voucherCataloguesAddOpts.data
- .voucherCataloguesAdd.errors
- )
- );
- const removeTransitionState = getMutationState(
- voucherDeleteOpts.called,
- voucherDeleteOpts.loading,
- maybe(
- () =>
- voucherDeleteOpts.data.voucherDelete
- .errors
- )
- );
-
- return (
- <Paginator
- pageInfo={pageInfo}
- paginationState={paginationState}
- queryString={params}
- >
- {({
- loadNextPage,
- loadPreviousPage,
- pageInfo
- }) => (
- <>
- <VoucherDetailsPage
- defaultCurrency={maybe(
- () => shop.defaultCurrency
- )}
- voucher={maybe(
- () => data.voucher
- )}
- disabled={
- loading ||
- voucherCataloguesRemoveOpts.loading
- }
- errors={maybe(
- () =>
- voucherUpdateOpts.data
- .voucherUpdate.errors
- )}
- pageInfo={pageInfo}
- onNextPage={loadNextPage}
- onPreviousPage={
- loadPreviousPage
- }
- onCategoryAssign={() =>
- navigate(
- voucherAssignCategoriesUrl(
- id
- ),
- false,
- true
- )
- }
- onCategoryClick={id => () =>
- navigate(categoryUrl(id))}
- onCollectionAssign={() =>
- navigate(
- voucherAssignCollectionsUrl(
- id
- ),
- false,
- true
- )
- }
- onCollectionUnassign={collectionId =>
- voucherCataloguesRemove({
- variables: {
- ...paginationState,
- id,
- input: {
- collections: [
- collectionId
- ]
- }
- }
- })
- }
- onCountryAssign={() =>
- navigate(
- voucherAssignCountriesUrl(
- id
- ),
- false,
- true
- )
- }
- onCountryUnassign={countryCode =>
- voucherUpdate({
- variables: {
- ...paginationState,
- id,
- input: {
- countries: data.voucher.countries
- .filter(
- country =>
- country.code !==
- countryCode
- )
- .map(
- country =>
- country.code
- )
- }
- }
- })
- }
- onCategoryUnassign={categoryId =>
- voucherCataloguesRemove({
- variables: {
- ...paginationState,
- id,
- input: {
- categories: [categoryId]
- }
- }
- })
- }
- onCollectionClick={id => () =>
- navigate(collectionUrl(id))}
- onProductAssign={() =>
- navigate(
- voucherAssignProductsUrl(
- id
- ),
- false,
- true
- )
- }
- onProductUnassign={productId =>
- voucherCataloguesRemove({
- variables: {
- ...paginationState,
- id,
- input: {
- products: [productId]
- }
- }
- })
- }
- onProductClick={id => () =>
- navigate(productUrl(id))}
- activeTab={params.tab}
- onBack={() =>
- navigate(voucherListUrl)
- }
- onTabClick={changeTab}
- onSubmit={formData =>
- voucherUpdate({
- variables: {
- id,
- input: {
- discountValue: decimal(
- formData.value
- ),
- discountValueType: discountValueTypeEnum(
- formData.discountType
- ),
- endDate:
- formData.endDate ===
- ""
- ? null
- : formData.endDate,
- name: formData.name,
- startDate:
- formData.startDate ===
- ""
- ? null
- : formData.startDate
- }
- }
- })
- }
- onRemove={() =>
- navigate(voucherDeleteUrl(id))
- }
- saveButtonBarState={
- formTransitionState
- }
- />
- <Route
- path={voucherAssignProductsPath(
- ":id"
- )}
- render={({ match }) => (
- <SearchProductsProvider>
- {(
- searchProducts,
- searchProductsOpts
- ) => (
- <AssignProductDialog
- confirmButtonState={
- assignTransitionState
- }
- open={!!match}
- onFetch={searchProducts}
- loading={
- searchProductsOpts.loading
- }
- onClose={() =>
- navigate(
- voucherUrl(id),
- true,
- true
- )
- }
- onSubmit={formData =>
- voucherCataloguesAdd({
- variables: {
- ...paginationState,
- id,
- input: {
- products: formData.products.map(
- product =>
- product.id
- )
- }
- }
- })
- }
- products={maybe(() =>
- searchProductsOpts.data.products.edges
- .map(
- edge => edge.node
- )
- .filter(
- suggestedProduct =>
- suggestedProduct.id
- )
- )}
- />
- )}
- </SearchProductsProvider>
- )}
- />
- <Route
- path={voucherAssignCategoriesPath(
- ":id"
- )}
- render={({ match }) => (
- <SearchCategoriesProvider>
- {(
- searchCategories,
- searchCategoriesOpts
- ) => (
- <AssignCategoriesDialog
- categories={maybe(() =>
- searchCategoriesOpts.data.categories.edges
- .map(
- edge => edge.node
- )
- .filter(
- suggestedCategory =>
- suggestedCategory.id
- )
- )}
- confirmButtonState={
- assignTransitionState
- }
- open={!!match}
- onFetch={
- searchCategories
- }
- loading={
- searchCategoriesOpts.loading
- }
- onClose={() =>
- navigate(
- voucherUrl(id),
- true,
- true
- )
- }
- onSubmit={formData =>
- voucherCataloguesAdd({
- variables: {
- ...paginationState,
- id,
- input: {
- categories: formData.categories.map(
- product =>
- product.id
- )
- }
- }
- })
- }
- />
- )}
- </SearchCategoriesProvider>
- )}
- />
- <Route
- path={voucherAssignCollectionsPath(
- ":id"
- )}
- render={({ match }) => (
- <SearchCollectionsProvider>
- {(
- searchCollections,
- searchCollectionsOpts
- ) => (
- <AssignCollectionDialog
- collections={maybe(() =>
- searchCollectionsOpts.data.collections.edges
- .map(
- edge => edge.node
- )
- .filter(
- suggestedCategory =>
- suggestedCategory.id
- )
- )}
- confirmButtonState={
- assignTransitionState
- }
- open={!!match}
- onFetch={
- searchCollections
- }
- loading={
- searchCollectionsOpts.loading
- }
- onClose={() =>
- navigate(
- voucherUrl(id),
- true,
- true
- )
- }
- onSubmit={formData =>
- voucherCataloguesAdd({
- variables: {
- ...paginationState,
- id,
- input: {
- collections: formData.collections.map(
- product =>
- product.id
- )
- }
- }
- })
- }
- />
- )}
- </SearchCollectionsProvider>
- )}
- />
- <Route
- path={voucherDeletePath(":id")}
- render={({ match }) => (
- <ActionDialog
- open={!!match}
- title={i18n.t(
- "Remove Voucher"
- )}
- confirmButtonState={
- removeTransitionState
- }
- onClose={() =>
- navigate(voucherUrl(id))
- }
- variant="delete"
- onConfirm={() =>
- voucherDelete({
- variables: { id }
- })
- }
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to remove <strong>{{ voucherName }}</strong>?",
- {
- voucherName: maybe(
- () =>
- data.voucher
- .name
- )
- }
- )
- }}
- />
- </ActionDialog>
- )}
- />
- <Route
- path={voucherAssignCountriesPath(
- ":id"
- )}
- render={({ match }) => (
- <DiscountCountrySelectDialog
- confirmButtonState={
- formTransitionState
- }
- countries={maybe(
- () => shop.countries,
- []
- )}
- onClose={() =>
- navigate(voucherUrl(id))
- }
- onConfirm={formData =>
- voucherUpdate({
- variables: {
- id,
- input: {
- countries:
- formData.countries
- }
- }
- })
- }
- open={!!match}
- initial={maybe(
- () =>
- data.voucher.countries.map(
- country =>
- country.code
- ),
- []
- )}
- />
- )}
- />
- </>
- )}
- </Paginator>
- );
- }}
- </TypedVoucherDetails>
- )}
- </TypedVoucherDelete>
- )}
- </TypedVoucherUpdate>
- )}
- </TypedVoucherCataloguesAdd>
- )}
- </TypedVoucherCataloguesRemove>
- );
- }}
- </Navigator>
- )}
- </Messages>
- )}
- </Shop>
- </>
-);
-export default VoucherDetails;
diff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails/urls.ts b/saleor/static/dashboard-next/discounts/views/VoucherDetails/urls.ts
deleted file mode 100644
index 668b7da87d..0000000000
--- a/saleor/static/dashboard-next/discounts/views/VoucherDetails/urls.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import * as urlJoin from "url-join";
-
-import { voucherPath } from "../../urls";
-
-export const voucherAssignProductsPath = (id: string) =>
- urlJoin(voucherPath(id), "assign-products");
-export const voucherAssignProductsUrl = (id: string) =>
- voucherAssignProductsPath(encodeURIComponent(id));
-
-export const voucherAssignCategoriesPath = (id: string) =>
- urlJoin(voucherPath(id), "assign-categories");
-export const voucherAssignCategoriesUrl = (id: string) =>
- voucherAssignCategoriesPath(encodeURIComponent(id));
-
-export const voucherAssignCollectionsPath = (id: string) =>
- urlJoin(voucherPath(id), "assign-collections");
-export const voucherAssignCollectionsUrl = (id: string) =>
- voucherAssignCollectionsPath(encodeURIComponent(id));
-
-export const voucherAssignCountriesPath = (id: string) =>
- urlJoin(voucherPath(id), "assign-countries");
-export const voucherAssignCountriesUrl = (id: string) =>
- voucherAssignCountriesPath(encodeURIComponent(id));
-
-export const voucherDeletePath = (id: string) =>
- urlJoin(voucherPath(id), "delete");
-export const voucherDeleteUrl = (id: string) =>
- voucherDeletePath(encodeURIComponent(id));