Saleor 1659 use query params in channels picker (#886)
* use Query params in channels picker * update urls
This commit is contained in:
parent
bdb7837ccc
commit
2f9eddd9ee
27 changed files with 210 additions and 71 deletions
|
@ -219,7 +219,7 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
errors={updateResult.data?.categoryUpdate.errors || []}
|
errors={updateResult.data?.categoryUpdate.errors || []}
|
||||||
onAddCategory={() => navigate(categoryAddUrl(id))}
|
onAddCategory={() => navigate(categoryAddUrl(id))}
|
||||||
onAddProduct={() => navigate(productAddUrl)}
|
onAddProduct={() => navigate(productAddUrl())}
|
||||||
onBack={() =>
|
onBack={() =>
|
||||||
navigate(
|
navigate(
|
||||||
maybe(() => categoryUrl(data.category.parent.id), categoryListUrl())
|
maybe(() => categoryUrl(data.category.parent.id), categoryListUrl())
|
||||||
|
|
|
@ -17,6 +17,8 @@ export type ChannelsListUrlQueryParams = Dialog<ChannelsListUrlDialog> &
|
||||||
ChannelsListUrlSort &
|
ChannelsListUrlSort &
|
||||||
SingleAction;
|
SingleAction;
|
||||||
|
|
||||||
|
export type ChannelsAction = "open-channels-picker";
|
||||||
|
|
||||||
export const channelsSection = "/channels/";
|
export const channelsSection = "/channels/";
|
||||||
|
|
||||||
export const channelsListPath = channelsSection;
|
export const channelsListPath = channelsSection;
|
||||||
|
|
|
@ -8,13 +8,14 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
||||||
import { WindowTitle } from "../components/WindowTitle";
|
import { WindowTitle } from "../components/WindowTitle";
|
||||||
import {
|
import {
|
||||||
collectionAddPath,
|
collectionAddPath,
|
||||||
|
CollectionCreateUrlQueryParams,
|
||||||
collectionListPath,
|
collectionListPath,
|
||||||
CollectionListUrlQueryParams,
|
CollectionListUrlQueryParams,
|
||||||
CollectionListUrlSortField,
|
CollectionListUrlSortField,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
CollectionUrlQueryParams
|
CollectionUrlQueryParams
|
||||||
} from "./urls";
|
} from "./urls";
|
||||||
import CollectionCreate from "./views/CollectionCreate";
|
import CollectionCreateView from "./views/CollectionCreate";
|
||||||
import CollectionDetailsView from "./views/CollectionDetails";
|
import CollectionDetailsView from "./views/CollectionDetails";
|
||||||
import CollectionListView from "./views/CollectionList";
|
import CollectionListView from "./views/CollectionList";
|
||||||
|
|
||||||
|
@ -43,6 +44,12 @@ const CollectionDetails: React.FC<RouteComponentProps<
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CollectionCreate: React.FC<RouteComponentProps> = ({ location }) => {
|
||||||
|
const qs = parseQs(location.search.substr(1));
|
||||||
|
const params: CollectionCreateUrlQueryParams = qs;
|
||||||
|
return <CollectionCreateView params={params} />;
|
||||||
|
};
|
||||||
|
|
||||||
const Component = () => {
|
const Component = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ChannelsAction } from "@saleor/channels/urls";
|
||||||
import { stringify as stringifyQs } from "qs";
|
import { stringify as stringifyQs } from "qs";
|
||||||
import urlJoin from "url-join";
|
import urlJoin from "url-join";
|
||||||
|
|
||||||
|
@ -40,12 +41,15 @@ export type CollectionUrlDialog =
|
||||||
| "remove"
|
| "remove"
|
||||||
| "removeImage"
|
| "removeImage"
|
||||||
| "assign"
|
| "assign"
|
||||||
| "unassign";
|
| "unassign"
|
||||||
|
| ChannelsAction;
|
||||||
export type CollectionUrlQueryParams = BulkAction &
|
export type CollectionUrlQueryParams = BulkAction &
|
||||||
Pagination &
|
Pagination &
|
||||||
Dialog<CollectionUrlDialog>;
|
Dialog<CollectionUrlDialog>;
|
||||||
|
export type CollectionCreateUrlQueryParams = Dialog<ChannelsAction>;
|
||||||
export const collectionUrl = (id: string, params?: CollectionUrlQueryParams) =>
|
export const collectionUrl = (id: string, params?: CollectionUrlQueryParams) =>
|
||||||
collectionPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
collectionPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
||||||
|
|
||||||
export const collectionAddPath = urlJoin(collectionSectionUrl, "add");
|
export const collectionAddPath = urlJoin(collectionSectionUrl, "add");
|
||||||
export const collectionAddUrl = collectionAddPath;
|
export const collectionAddUrl = (params?: CollectionCreateUrlQueryParams) =>
|
||||||
|
collectionAddPath + "?" + stringifyQs(params);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useChannelsList } from "@saleor/channels/queries";
|
import { useChannelsList } from "@saleor/channels/queries";
|
||||||
|
import { ChannelsAction } from "@saleor/channels/urls";
|
||||||
import { createCollectionChannels } from "@saleor/channels/utils";
|
import { createCollectionChannels } from "@saleor/channels/utils";
|
||||||
import ChannelsAvailabilityDialog from "@saleor/components/ChannelsAvailabilityDialog";
|
import ChannelsAvailabilityDialog from "@saleor/components/ChannelsAvailabilityDialog";
|
||||||
import { WindowTitle } from "@saleor/components/WindowTitle";
|
import { WindowTitle } from "@saleor/components/WindowTitle";
|
||||||
|
@ -6,6 +7,7 @@ import useChannels from "@saleor/hooks/useChannels";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useNotifier from "@saleor/hooks/useNotifier";
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import { commonMessages } from "@saleor/intl";
|
import { commonMessages } from "@saleor/intl";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
||||||
import {
|
import {
|
||||||
useMetadataUpdate,
|
useMetadataUpdate,
|
||||||
|
@ -21,15 +23,31 @@ import {
|
||||||
useCollectionChannelListingUpdate,
|
useCollectionChannelListingUpdate,
|
||||||
useCollectionCreateMutation
|
useCollectionCreateMutation
|
||||||
} from "../mutations";
|
} from "../mutations";
|
||||||
import { collectionListUrl, collectionUrl } from "../urls";
|
import {
|
||||||
|
collectionAddUrl,
|
||||||
|
CollectionCreateUrlQueryParams,
|
||||||
|
collectionListUrl,
|
||||||
|
collectionUrl
|
||||||
|
} from "../urls";
|
||||||
|
|
||||||
export const CollectionCreate: React.FC = () => {
|
interface CollectionCreateProps {
|
||||||
|
params: CollectionCreateUrlQueryParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CollectionCreate: React.FC<CollectionCreateProps> = ({
|
||||||
|
params
|
||||||
|
}) => {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
const notify = useNotifier();
|
const notify = useNotifier();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [updateMetadata] = useMetadataUpdate({});
|
const [updateMetadata] = useMetadataUpdate({});
|
||||||
const [updatePrivateMetadata] = usePrivateMetadataUpdate({});
|
const [updatePrivateMetadata] = usePrivateMetadataUpdate({});
|
||||||
|
|
||||||
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
|
ChannelsAction,
|
||||||
|
CollectionCreateUrlQueryParams
|
||||||
|
>(navigate, params => collectionAddUrl(params), params);
|
||||||
|
|
||||||
const [
|
const [
|
||||||
updateChannels,
|
updateChannels,
|
||||||
updateChannelsOpts
|
updateChannelsOpts
|
||||||
|
@ -53,7 +71,7 @@ export const CollectionCreate: React.FC = () => {
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(allChannels);
|
} = useChannels(allChannels, params?.action, { closeModal, openModal });
|
||||||
|
|
||||||
const [createCollection, createCollectionOpts] = useCollectionCreateMutation({
|
const [createCollection, createCollectionOpts] = useCollectionCreateMutation({
|
||||||
onCompleted: data => {
|
onCompleted: data => {
|
||||||
|
|
|
@ -71,6 +71,11 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
|
||||||
const { search, loadMore, result } = useProductSearch({
|
const { search, loadMore, result } = useProductSearch({
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
|
CollectionUrlDialog,
|
||||||
|
CollectionUrlQueryParams
|
||||||
|
>(navigate, params => collectionUrl(id, params), params);
|
||||||
|
|
||||||
const [updateMetadata] = useMetadataUpdate({});
|
const [updateMetadata] = useMetadataUpdate({});
|
||||||
const [updatePrivateMetadata] = usePrivateMetadataUpdate({});
|
const [updatePrivateMetadata] = usePrivateMetadataUpdate({});
|
||||||
|
|
||||||
|
@ -151,11 +156,6 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const [openModal, closeModal] = createDialogActionHandlers<
|
|
||||||
CollectionUrlDialog,
|
|
||||||
CollectionUrlQueryParams
|
|
||||||
>(navigate, params => collectionUrl(id, params), params);
|
|
||||||
|
|
||||||
const paginationState = createPaginationState(PAGINATE_BY, params);
|
const paginationState = createPaginationState(PAGINATE_BY, params);
|
||||||
const handleBack = () => navigate(collectionListUrl());
|
const handleBack = () => navigate(collectionListUrl());
|
||||||
|
|
||||||
|
@ -190,7 +190,10 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(collectionChannelsChoices);
|
} = useChannels(collectionChannelsChoices, params?.action, {
|
||||||
|
closeModal,
|
||||||
|
openModal
|
||||||
|
});
|
||||||
|
|
||||||
const handleUpdate = async (formData: CollectionUpdateData) => {
|
const handleUpdate = async (formData: CollectionUpdateData) => {
|
||||||
const input: CollectionInput = {
|
const input: CollectionInput = {
|
||||||
|
|
|
@ -151,7 +151,7 @@ export const CollectionList: React.FC<CollectionListProps> = ({ params }) => {
|
||||||
currentTab={currentTab}
|
currentTab={currentTab}
|
||||||
initialSearch={params.query || ""}
|
initialSearch={params.query || ""}
|
||||||
onSearchChange={handleSearchChange}
|
onSearchChange={handleSearchChange}
|
||||||
onAdd={() => navigate(collectionAddUrl)}
|
onAdd={() => navigate(collectionAddUrl())}
|
||||||
onAll={() => navigate(collectionListUrl())}
|
onAll={() => navigate(collectionListUrl())}
|
||||||
onTabChange={handleTabChange}
|
onTabChange={handleTabChange}
|
||||||
onTabDelete={() => openModal("delete-search")}
|
onTabDelete={() => openModal("delete-search")}
|
||||||
|
|
|
@ -39,14 +39,14 @@ export function searchInCommands(
|
||||||
{
|
{
|
||||||
label: intl.formatMessage(messages.createCollection),
|
label: intl.formatMessage(messages.createCollection),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
navigate(collectionAddUrl);
|
navigate(collectionAddUrl());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: intl.formatMessage(messages.createProduct),
|
label: intl.formatMessage(messages.createProduct),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
navigate(productAddUrl);
|
navigate(productAddUrl());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -67,7 +67,7 @@ export function searchInCommands(
|
||||||
{
|
{
|
||||||
label: intl.formatMessage(messages.createVoucher),
|
label: intl.formatMessage(messages.createVoucher),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
navigate(voucherAddUrl);
|
navigate(voucherAddUrl());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,22 +10,24 @@ import { saleDetailsPageTab } from "./components/SaleDetailsPage";
|
||||||
import { voucherDetailsPageTab } from "./components/VoucherDetailsPage";
|
import { voucherDetailsPageTab } from "./components/VoucherDetailsPage";
|
||||||
import {
|
import {
|
||||||
saleAddPath,
|
saleAddPath,
|
||||||
|
SaleCreateUrlQueryParams,
|
||||||
saleListPath,
|
saleListPath,
|
||||||
SaleListUrlQueryParams,
|
SaleListUrlQueryParams,
|
||||||
SaleListUrlSortField,
|
SaleListUrlSortField,
|
||||||
salePath,
|
salePath,
|
||||||
SaleUrlQueryParams,
|
SaleUrlQueryParams,
|
||||||
voucherAddPath,
|
voucherAddPath,
|
||||||
|
VoucherCreateUrlQueryParams,
|
||||||
voucherListPath,
|
voucherListPath,
|
||||||
VoucherListUrlQueryParams,
|
VoucherListUrlQueryParams,
|
||||||
VoucherListUrlSortField,
|
VoucherListUrlSortField,
|
||||||
voucherPath,
|
voucherPath,
|
||||||
VoucherUrlQueryParams
|
VoucherUrlQueryParams
|
||||||
} from "./urls";
|
} from "./urls";
|
||||||
import SaleCreateView from "./views/SaleCreate/SaleCreate";
|
import SaleCreateViewComponent from "./views/SaleCreate/SaleCreate";
|
||||||
import SaleDetailsViewComponent from "./views/SaleDetails";
|
import SaleDetailsViewComponent from "./views/SaleDetails";
|
||||||
import SaleListViewComponent from "./views/SaleList";
|
import SaleListViewComponent from "./views/SaleList";
|
||||||
import VoucherCreateView from "./views/VoucherCreate";
|
import VoucherCreateViewComponent from "./views/VoucherCreate";
|
||||||
import VoucherDetailsViewComponent from "./views/VoucherDetails";
|
import VoucherDetailsViewComponent from "./views/VoucherDetails";
|
||||||
import VoucherListViewComponent from "./views/VoucherList";
|
import VoucherListViewComponent from "./views/VoucherList";
|
||||||
|
|
||||||
|
@ -53,6 +55,13 @@ const SaleDetailsView: React.FC<RouteComponentProps<{ id: string }>> = ({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const SaleCreateView: React.FC<RouteComponentProps> = ({ location }) => {
|
||||||
|
const qs = parseQs(location.search.substr(1));
|
||||||
|
const params: SaleCreateUrlQueryParams = qs;
|
||||||
|
|
||||||
|
return <SaleCreateViewComponent params={params} />;
|
||||||
|
};
|
||||||
|
|
||||||
const VoucherListView: React.FC<RouteComponentProps<{}>> = ({ location }) => {
|
const VoucherListView: React.FC<RouteComponentProps<{}>> = ({ location }) => {
|
||||||
const qs = parseQs(location.search.substr(1));
|
const qs = parseQs(location.search.substr(1));
|
||||||
const params: VoucherListUrlQueryParams = asSortParams(
|
const params: VoucherListUrlQueryParams = asSortParams(
|
||||||
|
@ -80,6 +89,13 @@ const VoucherDetailsView: React.FC<RouteComponentProps<{ id: string }>> = ({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const VoucherCreateView: React.FC<RouteComponentProps> = ({ location }) => {
|
||||||
|
const qs = parseQs(location.search.substr(1));
|
||||||
|
const params: VoucherCreateUrlQueryParams = qs;
|
||||||
|
|
||||||
|
return <VoucherCreateViewComponent params={params} />;
|
||||||
|
};
|
||||||
|
|
||||||
export const DiscountSection: React.FC<{}> = () => {
|
export const DiscountSection: React.FC<{}> = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ChannelsAction } from "@saleor/channels/urls";
|
||||||
import { stringify as stringifyQs } from "qs";
|
import { stringify as stringifyQs } from "qs";
|
||||||
import urlJoin from "url-join";
|
import urlJoin from "url-join";
|
||||||
|
|
||||||
|
@ -54,15 +55,18 @@ export type SaleUrlDialog =
|
||||||
| "unassign-category"
|
| "unassign-category"
|
||||||
| "unassign-collection"
|
| "unassign-collection"
|
||||||
| "unassign-product"
|
| "unassign-product"
|
||||||
| "remove";
|
| "remove"
|
||||||
|
| ChannelsAction;
|
||||||
export type SaleUrlQueryParams = Pagination &
|
export type SaleUrlQueryParams = Pagination &
|
||||||
BulkAction &
|
BulkAction &
|
||||||
Dialog<SaleUrlDialog> &
|
Dialog<SaleUrlDialog> &
|
||||||
ActiveTab<SaleDetailsPageTab>;
|
ActiveTab<SaleDetailsPageTab>;
|
||||||
|
export type SaleCreateUrlQueryParams = Dialog<ChannelsAction>;
|
||||||
export const saleUrl = (id: string, params?: SaleUrlQueryParams) =>
|
export const saleUrl = (id: string, params?: SaleUrlQueryParams) =>
|
||||||
salePath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
salePath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
||||||
export const saleAddPath = urlJoin(saleSection, "add");
|
export const saleAddPath = urlJoin(saleSection, "add");
|
||||||
export const saleAddUrl = saleAddPath;
|
export const saleAddUrl = (params?: SaleCreateUrlQueryParams) =>
|
||||||
|
saleAddPath + "?" + stringifyQs(params);
|
||||||
|
|
||||||
export const voucherSection = urlJoin(discountSection, "vouchers");
|
export const voucherSection = urlJoin(discountSection, "vouchers");
|
||||||
export const voucherListPath = voucherSection;
|
export const voucherListPath = voucherSection;
|
||||||
|
@ -107,12 +111,15 @@ export type VoucherUrlDialog =
|
||||||
| "unassign-category"
|
| "unassign-category"
|
||||||
| "unassign-collection"
|
| "unassign-collection"
|
||||||
| "unassign-product"
|
| "unassign-product"
|
||||||
| "remove";
|
| "remove"
|
||||||
|
| ChannelsAction;
|
||||||
export type VoucherUrlQueryParams = Pagination &
|
export type VoucherUrlQueryParams = Pagination &
|
||||||
BulkAction &
|
BulkAction &
|
||||||
Dialog<VoucherUrlDialog> &
|
Dialog<VoucherUrlDialog> &
|
||||||
ActiveTab<VoucherDetailsPageTab>;
|
ActiveTab<VoucherDetailsPageTab>;
|
||||||
|
export type VoucherCreateUrlQueryParams = Dialog<ChannelsAction>;
|
||||||
export const voucherUrl = (id: string, params?: VoucherUrlQueryParams) =>
|
export const voucherUrl = (id: string, params?: VoucherUrlQueryParams) =>
|
||||||
voucherPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
voucherPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
||||||
export const voucherAddPath = urlJoin(voucherSection, "add");
|
export const voucherAddPath = urlJoin(voucherSection, "add");
|
||||||
export const voucherAddUrl = voucherAddPath;
|
export const voucherAddUrl = (params?: VoucherCreateUrlQueryParams) =>
|
||||||
|
voucherAddPath + "?" + stringifyQs(params);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useChannelsList } from "@saleor/channels/queries";
|
import { useChannelsList } from "@saleor/channels/queries";
|
||||||
|
import { ChannelsAction } from "@saleor/channels/urls";
|
||||||
import { ChannelSaleData, createSortedSaleData } from "@saleor/channels/utils";
|
import { ChannelSaleData, createSortedSaleData } from "@saleor/channels/utils";
|
||||||
import ChannelsAvailabilityDialog from "@saleor/components/ChannelsAvailabilityDialog";
|
import ChannelsAvailabilityDialog from "@saleor/components/ChannelsAvailabilityDialog";
|
||||||
import { WindowTitle } from "@saleor/components/WindowTitle";
|
import { WindowTitle } from "@saleor/components/WindowTitle";
|
||||||
|
@ -8,21 +9,36 @@ import {
|
||||||
useSaleChannelListingUpdate
|
useSaleChannelListingUpdate
|
||||||
} from "@saleor/discounts/mutations";
|
} from "@saleor/discounts/mutations";
|
||||||
import { SaleCreate } from "@saleor/discounts/types/SaleCreate";
|
import { SaleCreate } from "@saleor/discounts/types/SaleCreate";
|
||||||
import { saleListUrl, saleUrl } from "@saleor/discounts/urls";
|
import {
|
||||||
|
saleAddUrl,
|
||||||
|
SaleCreateUrlQueryParams,
|
||||||
|
saleListUrl,
|
||||||
|
saleUrl
|
||||||
|
} from "@saleor/discounts/urls";
|
||||||
import useChannels from "@saleor/hooks/useChannels";
|
import useChannels from "@saleor/hooks/useChannels";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useNotifier from "@saleor/hooks/useNotifier";
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { createHandler } from "./handlers";
|
import { createHandler } from "./handlers";
|
||||||
|
|
||||||
export const SaleDetails: React.FC = () => {
|
interface SaleCreateProps {
|
||||||
|
params: SaleCreateUrlQueryParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SaleCreateView: React.FC<SaleCreateProps> = ({ params }) => {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
const pushMessage = useNotifier();
|
const pushMessage = useNotifier();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
|
ChannelsAction,
|
||||||
|
SaleCreateUrlQueryParams
|
||||||
|
>(navigate, params => saleAddUrl(params), params);
|
||||||
|
|
||||||
const { data: channelsData } = useChannelsList({});
|
const { data: channelsData } = useChannelsList({});
|
||||||
const allChannels: ChannelSaleData[] = createSortedSaleData(
|
const allChannels: ChannelSaleData[] = createSortedSaleData(
|
||||||
channelsData?.channels
|
channelsData?.channels
|
||||||
|
@ -39,7 +55,7 @@ export const SaleDetails: React.FC = () => {
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(allChannels);
|
} = useChannels(allChannels, params?.action, { closeModal, openModal });
|
||||||
|
|
||||||
const [updateChannels, updateChannelsOpts] = useSaleChannelListingUpdate({});
|
const [updateChannels, updateChannelsOpts] = useSaleChannelListingUpdate({});
|
||||||
|
|
||||||
|
@ -105,4 +121,4 @@ export const SaleDetails: React.FC = () => {
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default SaleDetails;
|
export default SaleCreateView;
|
||||||
|
|
|
@ -111,6 +111,11 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
|
SaleUrlDialog,
|
||||||
|
SaleUrlQueryParams
|
||||||
|
>(navigate, params => saleUrl(id, params), params);
|
||||||
|
|
||||||
const allChannels: ChannelSaleData[] = createChannelsDataWithSaleDiscountPrice(
|
const allChannels: ChannelSaleData[] = createChannelsDataWithSaleDiscountPrice(
|
||||||
data?.sale,
|
data?.sale,
|
||||||
channelsData?.channels
|
channelsData?.channels
|
||||||
|
@ -130,7 +135,10 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(saleChannelsChoices);
|
} = useChannels(saleChannelsChoices, params?.action, {
|
||||||
|
closeModal,
|
||||||
|
openModal
|
||||||
|
});
|
||||||
|
|
||||||
const [updateChannels, updateChannelsOpts] = useSaleChannelListingUpdate({});
|
const [updateChannels, updateChannelsOpts] = useSaleChannelListingUpdate({});
|
||||||
|
|
||||||
|
@ -157,11 +165,6 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [openModal, closeModal] = createDialogActionHandlers<
|
|
||||||
SaleUrlDialog,
|
|
||||||
SaleUrlQueryParams
|
|
||||||
>(navigate, params => saleUrl(id, params), params);
|
|
||||||
|
|
||||||
const handleCatalogueAdd = (data: SaleCataloguesAdd) => {
|
const handleCatalogueAdd = (data: SaleCataloguesAdd) => {
|
||||||
if (data.saleCataloguesAdd.errors.length === 0) {
|
if (data.saleCataloguesAdd.errors.length === 0) {
|
||||||
closeModal();
|
closeModal();
|
||||||
|
|
|
@ -176,7 +176,7 @@ export const SaleList: React.FC<SaleListProps> = ({ params }) => {
|
||||||
settings={settings}
|
settings={settings}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
pageInfo={pageInfo}
|
pageInfo={pageInfo}
|
||||||
onAdd={() => navigate(saleAddUrl)}
|
onAdd={() => navigate(saleAddUrl())}
|
||||||
onNextPage={loadNextPage}
|
onNextPage={loadNextPage}
|
||||||
onPreviousPage={loadPreviousPage}
|
onPreviousPage={loadPreviousPage}
|
||||||
onSort={handleSort}
|
onSort={handleSort}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useChannelsList } from "@saleor/channels/queries";
|
import { useChannelsList } from "@saleor/channels/queries";
|
||||||
|
import { ChannelsAction } from "@saleor/channels/urls";
|
||||||
import {
|
import {
|
||||||
ChannelVoucherData,
|
ChannelVoucherData,
|
||||||
createSortedVoucherData
|
createSortedVoucherData
|
||||||
|
@ -9,6 +10,7 @@ import useChannels from "@saleor/hooks/useChannels";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useNotifier from "@saleor/hooks/useNotifier";
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
|
@ -18,14 +20,28 @@ import {
|
||||||
useVoucherChannelListingUpdate
|
useVoucherChannelListingUpdate
|
||||||
} from "../../mutations";
|
} from "../../mutations";
|
||||||
import { VoucherCreate } from "../../types/VoucherCreate";
|
import { VoucherCreate } from "../../types/VoucherCreate";
|
||||||
import { voucherListUrl, voucherUrl } from "../../urls";
|
import {
|
||||||
|
voucherAddUrl,
|
||||||
|
VoucherCreateUrlQueryParams,
|
||||||
|
voucherListUrl,
|
||||||
|
voucherUrl
|
||||||
|
} from "../../urls";
|
||||||
import { createHandler } from "./handlers";
|
import { createHandler } from "./handlers";
|
||||||
|
|
||||||
export const VoucherDetails: React.FC = () => {
|
interface VoucherCreateProps {
|
||||||
|
params: VoucherCreateUrlQueryParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const VoucherCreateView: React.FC<VoucherCreateProps> = ({ params }) => {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
const notify = useNotifier();
|
const notify = useNotifier();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
|
ChannelsAction,
|
||||||
|
VoucherCreateUrlQueryParams
|
||||||
|
>(navigate, params => voucherAddUrl(params), params);
|
||||||
|
|
||||||
const { data: channelsData } = useChannelsList({});
|
const { data: channelsData } = useChannelsList({});
|
||||||
const allChannels: ChannelVoucherData[] = createSortedVoucherData(
|
const allChannels: ChannelVoucherData[] = createSortedVoucherData(
|
||||||
channelsData?.channels
|
channelsData?.channels
|
||||||
|
@ -42,7 +58,7 @@ export const VoucherDetails: React.FC = () => {
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(allChannels);
|
} = useChannels(allChannels, params?.action, { closeModal, openModal });
|
||||||
|
|
||||||
const [updateChannels, updateChannelsOpts] = useVoucherChannelListingUpdate(
|
const [updateChannels, updateChannelsOpts] = useVoucherChannelListingUpdate(
|
||||||
{}
|
{}
|
||||||
|
@ -111,4 +127,4 @@ export const VoucherDetails: React.FC = () => {
|
||||||
</TypedVoucherCreate>
|
</TypedVoucherCreate>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default VoucherDetails;
|
export default VoucherCreateView;
|
||||||
|
|
|
@ -114,6 +114,12 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
||||||
...paginationState
|
...paginationState
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
|
VoucherUrlDialog,
|
||||||
|
VoucherUrlQueryParams
|
||||||
|
>(navigate, params => voucherUrl(id, params), params);
|
||||||
|
|
||||||
const { data: channelsData } = useChannelsList({});
|
const { data: channelsData } = useChannelsList({});
|
||||||
|
|
||||||
const allChannels: ChannelVoucherData[] = createChannelsDataWithDiscountPrice(
|
const allChannels: ChannelVoucherData[] = createChannelsDataWithDiscountPrice(
|
||||||
|
@ -134,7 +140,10 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(voucherChannelsChoices);
|
} = useChannels(voucherChannelsChoices, params?.action, {
|
||||||
|
closeModal,
|
||||||
|
openModal
|
||||||
|
});
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!currentChannels.length && voucherChannelsChoices.length) {
|
if (!currentChannels.length && voucherChannelsChoices.length) {
|
||||||
|
@ -169,11 +178,6 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [openModal, closeModal] = createDialogActionHandlers<
|
|
||||||
VoucherUrlDialog,
|
|
||||||
VoucherUrlQueryParams
|
|
||||||
>(navigate, params => voucherUrl(id, params), params);
|
|
||||||
|
|
||||||
const handleCatalogueAdd = (data: VoucherCataloguesAdd) => {
|
const handleCatalogueAdd = (data: VoucherCataloguesAdd) => {
|
||||||
if (data.voucherCataloguesAdd.errors.length === 0) {
|
if (data.voucherCataloguesAdd.errors.length === 0) {
|
||||||
closeModal();
|
closeModal();
|
||||||
|
|
|
@ -177,7 +177,7 @@ export const VoucherList: React.FC<VoucherListProps> = ({ params }) => {
|
||||||
vouchers={maybe(() => data.vouchers.edges.map(edge => edge.node))}
|
vouchers={maybe(() => data.vouchers.edges.map(edge => edge.node))}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
pageInfo={pageInfo}
|
pageInfo={pageInfo}
|
||||||
onAdd={() => navigate(voucherAddUrl)}
|
onAdd={() => navigate(voucherAddUrl())}
|
||||||
onNextPage={loadNextPage}
|
onNextPage={loadNextPage}
|
||||||
onPreviousPage={loadPreviousPage}
|
onPreviousPage={loadPreviousPage}
|
||||||
onUpdateListSettings={updateListSettings}
|
onUpdateListSettings={updateListSettings}
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
|
import { ChannelsAction } from "@saleor/channels/urls";
|
||||||
import { Channel } from "@saleor/channels/utils";
|
import { Channel } from "@saleor/channels/utils";
|
||||||
import useListActions from "@saleor/hooks/useListActions";
|
import useListActions from "@saleor/hooks/useListActions";
|
||||||
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
||||||
import { useState } from "react";
|
|
||||||
|
|
||||||
function useChannels<T extends Channel>(channels: T[]) {
|
interface Modal {
|
||||||
const [isChannelsModalOpen, setChannelsModalOpen] = useState(false);
|
openModal: (action: ChannelsAction) => void;
|
||||||
|
closeModal: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function useChannels<T extends Channel, A>(
|
||||||
|
channels: T[],
|
||||||
|
action: A | ChannelsAction,
|
||||||
|
{ closeModal, openModal }: Modal
|
||||||
|
) {
|
||||||
const [currentChannels, setCurrentChannels] = useStateFromProps(channels);
|
const [currentChannels, setCurrentChannels] = useStateFromProps(channels);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -16,18 +23,18 @@ function useChannels<T extends Channel>(channels: T[]) {
|
||||||
} = useListActions<T>(currentChannels, (a, b) => a.id === b.id);
|
} = useListActions<T>(currentChannels, (a, b) => a.id === b.id);
|
||||||
|
|
||||||
const handleChannelsModalClose = () => {
|
const handleChannelsModalClose = () => {
|
||||||
setChannelsModalOpen(false);
|
closeModal();
|
||||||
setChannels(currentChannels);
|
setChannels(currentChannels);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChannelsModalOpen = () => setChannelsModalOpen(true);
|
const handleChannelsModalOpen = () => openModal("open-channels-picker");
|
||||||
|
|
||||||
const handleChannelsConfirm = () => {
|
const handleChannelsConfirm = () => {
|
||||||
const sortedChannelListElements = channelListElements.sort(
|
const sortedChannelListElements = channelListElements.sort(
|
||||||
(channel, nextChannel) => channel.name.localeCompare(nextChannel.name)
|
(channel, nextChannel) => channel.name.localeCompare(nextChannel.name)
|
||||||
);
|
);
|
||||||
setCurrentChannels(sortedChannelListElements);
|
setCurrentChannels(sortedChannelListElements);
|
||||||
setChannelsModalOpen(false);
|
closeModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleAllChannels = (items: T[], selected: number) => {
|
const toggleAllChannels = (items: T[], selected: number) => {
|
||||||
|
@ -46,7 +53,7 @@ function useChannels<T extends Channel>(channels: T[]) {
|
||||||
handleChannelsModalClose,
|
handleChannelsModalClose,
|
||||||
handleChannelsModalOpen,
|
handleChannelsModalOpen,
|
||||||
isChannelSelected,
|
isChannelSelected,
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen: action === "open-channels-picker",
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
||||||
import { WindowTitle } from "../components/WindowTitle";
|
import { WindowTitle } from "../components/WindowTitle";
|
||||||
import {
|
import {
|
||||||
productAddPath,
|
productAddPath,
|
||||||
|
ProductCreateUrlQueryParams,
|
||||||
productImagePath,
|
productImagePath,
|
||||||
ProductImageUrlQueryParams,
|
ProductImageUrlQueryParams,
|
||||||
productListPath,
|
productListPath,
|
||||||
|
@ -21,7 +22,7 @@ import {
|
||||||
productVariantEditPath,
|
productVariantEditPath,
|
||||||
ProductVariantEditUrlQueryParams
|
ProductVariantEditUrlQueryParams
|
||||||
} from "./urls";
|
} from "./urls";
|
||||||
import ProductCreate from "./views/ProductCreate";
|
import ProductCreateComponent from "./views/ProductCreate";
|
||||||
import ProductImageComponent from "./views/ProductImage";
|
import ProductImageComponent from "./views/ProductImage";
|
||||||
import ProductListComponent from "./views/ProductList";
|
import ProductListComponent from "./views/ProductList";
|
||||||
import ProductUpdateComponent from "./views/ProductUpdate";
|
import ProductUpdateComponent from "./views/ProductUpdate";
|
||||||
|
@ -60,6 +61,13 @@ const ProductUpdate: React.FC<RouteComponentProps<any>> = ({ match }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ProductCreate: React.FC<RouteComponentProps<any>> = () => {
|
||||||
|
const qs = parseQs(location.search.substr(1));
|
||||||
|
const params: ProductCreateUrlQueryParams = qs;
|
||||||
|
|
||||||
|
return <ProductCreateComponent params={params} />;
|
||||||
|
};
|
||||||
|
|
||||||
const ProductVariant: React.FC<RouteComponentProps<any>> = ({ match }) => {
|
const ProductVariant: React.FC<RouteComponentProps<any>> = ({ match }) => {
|
||||||
const qs = parseQs(location.search.substr(1));
|
const qs = parseQs(location.search.substr(1));
|
||||||
const params: ProductVariantEditUrlQueryParams = qs;
|
const params: ProductVariantEditUrlQueryParams = qs;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ChannelsAction } from "@saleor/channels/urls";
|
||||||
import urlJoin from "url-join";
|
import urlJoin from "url-join";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -16,7 +17,8 @@ import { stringifyQs } from "../utils/urls";
|
||||||
const productSection = "/products/";
|
const productSection = "/products/";
|
||||||
|
|
||||||
export const productAddPath = urlJoin(productSection, "add");
|
export const productAddPath = urlJoin(productSection, "add");
|
||||||
export const productAddUrl = productAddPath;
|
export const productAddUrl = (params?: ProductCreateUrlQueryParams) =>
|
||||||
|
productAddPath + "?" + stringifyQs(params);
|
||||||
|
|
||||||
export const productListPath = productSection;
|
export const productListPath = productSection;
|
||||||
export type ProductListUrlDialog = "delete" | "export" | TabActionDialog;
|
export type ProductListUrlDialog = "delete" | "export" | TabActionDialog;
|
||||||
|
@ -61,8 +63,9 @@ export const productListUrl = (params?: ProductListUrlQueryParams): string =>
|
||||||
productListPath + "?" + stringifyQs(params);
|
productListPath + "?" + stringifyQs(params);
|
||||||
|
|
||||||
export const productPath = (id: string) => urlJoin(productSection + id);
|
export const productPath = (id: string) => urlJoin(productSection + id);
|
||||||
export type ProductUrlDialog = "remove" | "remove-variants";
|
export type ProductUrlDialog = "remove" | "remove-variants" | ChannelsAction;
|
||||||
export type ProductUrlQueryParams = BulkAction & Dialog<ProductUrlDialog>;
|
export type ProductUrlQueryParams = BulkAction & Dialog<ProductUrlDialog>;
|
||||||
|
export type ProductCreateUrlQueryParams = Dialog<ChannelsAction>;
|
||||||
export const productUrl = (id: string, params?: ProductUrlQueryParams) =>
|
export const productUrl = (id: string, params?: ProductUrlQueryParams) =>
|
||||||
productPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
productPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useChannelsList } from "@saleor/channels/queries";
|
import { useChannelsList } from "@saleor/channels/queries";
|
||||||
|
import { ChannelsAction } from "@saleor/channels/urls";
|
||||||
import { ChannelData, createSortedChannelsData } from "@saleor/channels/utils";
|
import { ChannelData, createSortedChannelsData } from "@saleor/channels/utils";
|
||||||
import ChannelsAvailabilityDialog from "@saleor/components/ChannelsAvailabilityDialog";
|
import ChannelsAvailabilityDialog from "@saleor/components/ChannelsAvailabilityDialog";
|
||||||
import { WindowTitle } from "@saleor/components/WindowTitle";
|
import { WindowTitle } from "@saleor/components/WindowTitle";
|
||||||
|
@ -15,12 +16,18 @@ import {
|
||||||
useVariantCreateMutation
|
useVariantCreateMutation
|
||||||
} from "@saleor/products/mutations";
|
} from "@saleor/products/mutations";
|
||||||
import { useProductCreateMutation } from "@saleor/products/mutations";
|
import { useProductCreateMutation } from "@saleor/products/mutations";
|
||||||
import { productListUrl, productUrl } from "@saleor/products/urls";
|
import {
|
||||||
|
productAddUrl,
|
||||||
|
ProductCreateUrlQueryParams,
|
||||||
|
productListUrl,
|
||||||
|
productUrl
|
||||||
|
} from "@saleor/products/urls";
|
||||||
import useCategorySearch from "@saleor/searches/useCategorySearch";
|
import useCategorySearch from "@saleor/searches/useCategorySearch";
|
||||||
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
||||||
import useProductTypeSearch from "@saleor/searches/useProductTypeSearch";
|
import useProductTypeSearch from "@saleor/searches/useProductTypeSearch";
|
||||||
import { useTaxTypeList } from "@saleor/taxes/queries";
|
import { useTaxTypeList } from "@saleor/taxes/queries";
|
||||||
import { getProductErrorMessage } from "@saleor/utils/errors";
|
import { getProductErrorMessage } from "@saleor/utils/errors";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler";
|
||||||
import {
|
import {
|
||||||
useMetadataUpdate,
|
useMetadataUpdate,
|
||||||
|
@ -33,7 +40,11 @@ import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { createHandler } from "./handlers";
|
import { createHandler } from "./handlers";
|
||||||
|
|
||||||
export const ProductCreateView: React.FC = () => {
|
interface ProductCreateProps {
|
||||||
|
params: ProductCreateUrlQueryParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ProductCreateView: React.FC<ProductCreateProps> = ({ params }) => {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
const notify = useNotifier();
|
const notify = useNotifier();
|
||||||
const shop = useShop();
|
const shop = useShop();
|
||||||
|
@ -41,6 +52,12 @@ export const ProductCreateView: React.FC = () => {
|
||||||
const [productCreateComplete, setProductCreateComplete] = React.useState(
|
const [productCreateComplete, setProductCreateComplete] = React.useState(
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
|
ChannelsAction,
|
||||||
|
ProductCreateUrlQueryParams
|
||||||
|
>(navigate, params => productAddUrl(params), params);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreCategories,
|
loadMore: loadMoreCategories,
|
||||||
search: searchCategory,
|
search: searchCategory,
|
||||||
|
@ -92,7 +109,10 @@ export const ProductCreateView: React.FC = () => {
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(allChannels);
|
} = useChannels(allChannels, params?.action, {
|
||||||
|
closeModal,
|
||||||
|
openModal
|
||||||
|
});
|
||||||
|
|
||||||
const handleSuccess = (productId: string) => {
|
const handleSuccess = (productId: string) => {
|
||||||
notify({
|
notify({
|
||||||
|
|
|
@ -320,7 +320,7 @@ export const ProductList: React.FC<ProductListProps> = ({ params }) => {
|
||||||
() => attributes.data.availableInGrid.pageInfo.hasNextPage,
|
() => attributes.data.availableInGrid.pageInfo.hasNextPage,
|
||||||
false
|
false
|
||||||
)}
|
)}
|
||||||
onAdd={() => navigate(productAddUrl)}
|
onAdd={() => navigate(productAddUrl())}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
products={maybe(() => data.products.edges.map(edge => edge.node))}
|
products={maybe(() => data.products.edges.map(edge => edge.node))}
|
||||||
onFetchMore={() =>
|
onFetchMore={() =>
|
||||||
|
|
|
@ -190,6 +190,11 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
|
ProductUrlDialog,
|
||||||
|
ProductUrlQueryParams
|
||||||
|
>(navigate, params => productUrl(id, params), params);
|
||||||
|
|
||||||
const product = data?.product;
|
const product = data?.product;
|
||||||
|
|
||||||
const allChannels: ChannelData[] = createChannelsDataWithPrice(
|
const allChannels: ChannelData[] = createChannelsDataWithPrice(
|
||||||
|
@ -213,7 +218,10 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(productChannelsChoices);
|
} = useChannels(productChannelsChoices, params?.action, {
|
||||||
|
closeModal,
|
||||||
|
openModal
|
||||||
|
});
|
||||||
|
|
||||||
const [updateChannels, updateChannelsOpts] = useProductChannelListingUpdate({
|
const [updateChannels, updateChannelsOpts] = useProductChannelListingUpdate({
|
||||||
onCompleted: data => {
|
onCompleted: data => {
|
||||||
|
@ -235,11 +243,6 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
value: listing.channel.id
|
value: listing.channel.id
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const [openModal, closeModal] = createDialogActionHandlers<
|
|
||||||
ProductUrlDialog,
|
|
||||||
ProductUrlQueryParams
|
|
||||||
>(navigate, params => productUrl(id, params), params);
|
|
||||||
|
|
||||||
const handleBack = () => navigate(productListUrl());
|
const handleBack = () => navigate(productListUrl());
|
||||||
|
|
||||||
if (product === null) {
|
if (product === null) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ChannelsAction } from "@saleor/channels/urls";
|
||||||
import { stringify as stringifyQs } from "qs";
|
import { stringify as stringifyQs } from "qs";
|
||||||
import urlJoin from "url-join";
|
import urlJoin from "url-join";
|
||||||
|
|
||||||
|
@ -44,13 +45,14 @@ type ZipCodeRangeActions = "add-range" | "remove-range";
|
||||||
export type ShippingRateUrlDialog =
|
export type ShippingRateUrlDialog =
|
||||||
| ZipCodeRangeActions
|
| ZipCodeRangeActions
|
||||||
| "remove"
|
| "remove"
|
||||||
| ShippingMethodActions;
|
| ShippingMethodActions
|
||||||
|
| ChannelsAction;
|
||||||
|
|
||||||
export type ShippingRateUrlQueryParams = Dialog<ShippingRateUrlDialog> &
|
export type ShippingRateUrlQueryParams = Dialog<ShippingRateUrlDialog> &
|
||||||
SingleAction &
|
SingleAction &
|
||||||
BulkAction &
|
BulkAction &
|
||||||
Pagination;
|
Pagination;
|
||||||
export type ShippingRateCreateUrlDialog = ZipCodeRangeActions;
|
export type ShippingRateCreateUrlDialog = ZipCodeRangeActions | ChannelsAction;
|
||||||
export type ShippingRateCreateUrlQueryParams = Dialog<
|
export type ShippingRateCreateUrlQueryParams = Dialog<
|
||||||
ShippingRateCreateUrlDialog
|
ShippingRateCreateUrlDialog
|
||||||
> &
|
> &
|
||||||
|
|
|
@ -59,7 +59,7 @@ export const PriceRatesCreate: React.FC<PriceRatesCreateProps> = ({
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(allChannels);
|
} = useChannels(allChannels, params?.action, { closeModal, openModal });
|
||||||
|
|
||||||
const {
|
const {
|
||||||
channelErrors,
|
channelErrors,
|
||||||
|
|
|
@ -180,7 +180,7 @@ export const PriceRatesUpdate: React.FC<PriceRatesUpdateProps> = ({
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(shippingChannels);
|
} = useChannels(shippingChannels, params?.action, { closeModal, openModal });
|
||||||
|
|
||||||
const [updateShippingRate, updateShippingRateOpts] = useShippingRateUpdate(
|
const [updateShippingRate, updateShippingRateOpts] = useShippingRateUpdate(
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -63,7 +63,7 @@ export const WeightRatesCreate: React.FC<WeightRatesCreateProps> = ({
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(shippingChannels);
|
} = useChannels(shippingChannels, params?.action, { closeModal, openModal });
|
||||||
|
|
||||||
const {
|
const {
|
||||||
channelErrors,
|
channelErrors,
|
||||||
|
|
|
@ -144,7 +144,7 @@ export const WeightRatesUpdate: React.FC<WeightRatesUpdateProps> = ({
|
||||||
isChannelsModalOpen,
|
isChannelsModalOpen,
|
||||||
setCurrentChannels,
|
setCurrentChannels,
|
||||||
toggleAllChannels
|
toggleAllChannels
|
||||||
} = useChannels(shippingChannels);
|
} = useChannels(shippingChannels, params?.action, { closeModal, openModal });
|
||||||
|
|
||||||
const [updateShippingRate, updateShippingRateOpts] = useShippingRateUpdate(
|
const [updateShippingRate, updateShippingRateOpts] = useShippingRateUpdate(
|
||||||
{}
|
{}
|
||||||
|
|
Loading…
Reference in a new issue