Merge pull request #296 from mirumee/ref/unify-modals
Unify dialog handling
This commit is contained in:
commit
42fa13b1f6
36 changed files with 419 additions and 638 deletions
|
@ -22,6 +22,7 @@ All notable, unreleased changes to this project will be documented in this file.
|
||||||
- Add ability to reset own password - #289 by @dominik-zeglen
|
- Add ability to reset own password - #289 by @dominik-zeglen
|
||||||
- Move mutation state to mutation - #297 by @dominik-zeglen
|
- Move mutation state to mutation - #297 by @dominik-zeglen
|
||||||
- Add table sorting - #292 by @dominik-zeglen
|
- Add table sorting - #292 by @dominik-zeglen
|
||||||
|
- Unify dialog handling - #296 by @dominik-zeglen
|
||||||
|
|
||||||
## 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {
|
||||||
remove,
|
remove,
|
||||||
updateAtIndex
|
updateAtIndex
|
||||||
} from "@saleor/utils/lists";
|
} from "@saleor/utils/lists";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import AttributePage from "../../components/AttributePage";
|
import AttributePage from "../../components/AttributePage";
|
||||||
import AttributeValueDeleteDialog from "../../components/AttributeValueDeleteDialog";
|
import AttributeValueDeleteDialog from "../../components/AttributeValueDeleteDialog";
|
||||||
import AttributeValueEditDialog, {
|
import AttributeValueEditDialog, {
|
||||||
|
@ -22,10 +23,10 @@ import { AttributeCreateMutation } from "../../mutations";
|
||||||
import { AttributeCreate } from "../../types/AttributeCreate";
|
import { AttributeCreate } from "../../types/AttributeCreate";
|
||||||
import {
|
import {
|
||||||
attributeAddUrl,
|
attributeAddUrl,
|
||||||
AttributeAddUrlDialog,
|
|
||||||
AttributeAddUrlQueryParams,
|
AttributeAddUrlQueryParams,
|
||||||
attributeListUrl,
|
attributeListUrl,
|
||||||
attributeUrl
|
attributeUrl,
|
||||||
|
AttributeAddUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
|
|
||||||
interface AttributeDetailsProps {
|
interface AttributeDetailsProps {
|
||||||
|
@ -51,24 +52,10 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {
|
||||||
|
|
||||||
const id = params.id ? parseInt(params.id, 0) : undefined;
|
const id = params.id ? parseInt(params.id, 0) : undefined;
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
AttributeAddUrlDialog,
|
||||||
attributeAddUrl({
|
AttributeAddUrlQueryParams
|
||||||
...params,
|
>(navigate, attributeAddUrl, params);
|
||||||
action: undefined,
|
|
||||||
id: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: AttributeAddUrlDialog, valueId?: string) =>
|
|
||||||
navigate(
|
|
||||||
attributeAddUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
id: valueId
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleValueDelete = () => {
|
const handleValueDelete = () => {
|
||||||
setValues(remove(values[params.id], values, areValuesEqual));
|
setValues(remove(values[params.id], values, areValuesEqual));
|
||||||
|
@ -159,9 +146,17 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
onValueAdd={() => openModal("add-value")}
|
onValueAdd={() => openModal("add-value")}
|
||||||
onValueDelete={id => openModal("remove-value", id)}
|
onValueDelete={id =>
|
||||||
|
openModal("remove-value", {
|
||||||
|
id
|
||||||
|
})
|
||||||
|
}
|
||||||
onValueReorder={handleValueReorder}
|
onValueReorder={handleValueReorder}
|
||||||
onValueUpdate={id => openModal("edit-value", id)}
|
onValueUpdate={id =>
|
||||||
|
openModal("edit-value", {
|
||||||
|
id
|
||||||
|
})
|
||||||
|
}
|
||||||
saveButtonBarState={attributeCreateOpts.status}
|
saveButtonBarState={attributeCreateOpts.status}
|
||||||
values={values.map((value, valueIndex) => ({
|
values={values.map((value, valueIndex) => ({
|
||||||
__typename: "AttributeValue" as "AttributeValue",
|
__typename: "AttributeValue" as "AttributeValue",
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { commonMessages } from "@saleor/intl";
|
||||||
import { maybe } from "@saleor/misc";
|
import { maybe } from "@saleor/misc";
|
||||||
import { ReorderEvent } from "@saleor/types";
|
import { ReorderEvent } from "@saleor/types";
|
||||||
import { move } from "@saleor/utils/lists";
|
import { move } from "@saleor/utils/lists";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import AttributeDeleteDialog from "../../components/AttributeDeleteDialog";
|
import AttributeDeleteDialog from "../../components/AttributeDeleteDialog";
|
||||||
import AttributePage from "../../components/AttributePage";
|
import AttributePage from "../../components/AttributePage";
|
||||||
import AttributeValueDeleteDialog from "../../components/AttributeValueDeleteDialog";
|
import AttributeValueDeleteDialog from "../../components/AttributeValueDeleteDialog";
|
||||||
|
@ -29,8 +30,8 @@ import { AttributeValueUpdate } from "../../types/AttributeValueUpdate";
|
||||||
import {
|
import {
|
||||||
attributeListUrl,
|
attributeListUrl,
|
||||||
attributeUrl,
|
attributeUrl,
|
||||||
AttributeUrlDialog,
|
AttributeUrlQueryParams,
|
||||||
AttributeUrlQueryParams
|
AttributeUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
|
|
||||||
interface AttributeDetailsProps {
|
interface AttributeDetailsProps {
|
||||||
|
@ -43,25 +44,10 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ id, params }) => {
|
||||||
const notify = useNotifier();
|
const notify = useNotifier();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
AttributeUrlDialog,
|
||||||
attributeUrl(id, {
|
AttributeUrlQueryParams
|
||||||
...params,
|
>(navigate, params => attributeUrl(id, params), params);
|
||||||
action: undefined,
|
|
||||||
id: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: AttributeUrlDialog, valueId?: string) =>
|
|
||||||
navigate(
|
|
||||||
attributeUrl(id, {
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
id: valueId
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleDelete = (data: AttributeDelete) => {
|
const handleDelete = (data: AttributeDelete) => {
|
||||||
if (data.attributeDelete.errors.length === 0) {
|
if (data.attributeDelete.errors.length === 0) {
|
||||||
|
@ -200,11 +186,15 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ id, params }) => {
|
||||||
}}
|
}}
|
||||||
onValueAdd={() => openModal("add-value")}
|
onValueAdd={() => openModal("add-value")}
|
||||||
onValueDelete={id =>
|
onValueDelete={id =>
|
||||||
openModal("remove-value", id)
|
openModal("remove-value", {
|
||||||
|
id
|
||||||
|
})
|
||||||
}
|
}
|
||||||
onValueReorder={handleValueReorder}
|
onValueReorder={handleValueReorder}
|
||||||
onValueUpdate={id =>
|
onValueUpdate={id =>
|
||||||
openModal("edit-value", id)
|
openModal("edit-value", {
|
||||||
|
id
|
||||||
|
})
|
||||||
}
|
}
|
||||||
saveButtonBarState={
|
saveButtonBarState={
|
||||||
attributeUpdateOpts.status
|
attributeUpdateOpts.status
|
||||||
|
|
|
@ -23,6 +23,7 @@ import usePaginator, {
|
||||||
} from "@saleor/hooks/usePaginator";
|
} from "@saleor/hooks/usePaginator";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { PAGINATE_BY } from "../../../config";
|
import { PAGINATE_BY } from "../../../config";
|
||||||
import useBulkActions from "../../../hooks/useBulkActions";
|
import useBulkActions from "../../../hooks/useBulkActions";
|
||||||
import { maybe } from "../../../misc";
|
import { maybe } from "../../../misc";
|
||||||
|
@ -34,10 +35,10 @@ import { AttributeBulkDelete } from "../../types/AttributeBulkDelete";
|
||||||
import {
|
import {
|
||||||
attributeAddUrl,
|
attributeAddUrl,
|
||||||
attributeListUrl,
|
attributeListUrl,
|
||||||
AttributeListUrlDialog,
|
|
||||||
AttributeListUrlFilters,
|
AttributeListUrlFilters,
|
||||||
AttributeListUrlQueryParams,
|
AttributeListUrlQueryParams,
|
||||||
attributeUrl
|
attributeUrl,
|
||||||
|
AttributeListUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import { getSortQueryVariables } from "./sort";
|
import { getSortQueryVariables } from "./sort";
|
||||||
|
|
||||||
|
@ -76,24 +77,10 @@ const AttributeList: React.FC<AttributeListProps> = ({ params }) => {
|
||||||
: 0
|
: 0
|
||||||
: parseInt(params.activeTab, 0);
|
: parseInt(params.activeTab, 0);
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
AttributeListUrlDialog,
|
||||||
attributeListUrl({
|
AttributeListUrlQueryParams
|
||||||
...params,
|
>(navigate, attributeListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: AttributeListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
attributeListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const changeFilterField = (filter: AttributeListUrlFilters) => {
|
const changeFilterField = (filter: AttributeListUrlFilters) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -181,7 +168,11 @@ const AttributeList: React.FC<AttributeListProps> = ({ params }) => {
|
||||||
toolbar={
|
toolbar={
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("remove", listElements)}
|
onClick={() =>
|
||||||
|
openModal("remove", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
|
@ -13,6 +13,7 @@ import usePaginator, {
|
||||||
createPaginationState
|
createPaginationState
|
||||||
} from "@saleor/hooks/usePaginator";
|
} from "@saleor/hooks/usePaginator";
|
||||||
import { commonMessages } from "@saleor/intl";
|
import { commonMessages } from "@saleor/intl";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { PAGINATE_BY } from "../../config";
|
import { PAGINATE_BY } from "../../config";
|
||||||
import { maybe } from "../../misc";
|
import { maybe } from "../../misc";
|
||||||
import { TypedProductBulkDeleteMutation } from "../../products/mutations";
|
import { TypedProductBulkDeleteMutation } from "../../products/mutations";
|
||||||
|
@ -36,8 +37,8 @@ import {
|
||||||
categoryAddUrl,
|
categoryAddUrl,
|
||||||
categoryListUrl,
|
categoryListUrl,
|
||||||
categoryUrl,
|
categoryUrl,
|
||||||
CategoryUrlDialog,
|
CategoryUrlQueryParams,
|
||||||
CategoryUrlQueryParams
|
CategoryUrlDialog
|
||||||
} from "../urls";
|
} from "../urls";
|
||||||
|
|
||||||
export interface CategoryDetailsProps {
|
export interface CategoryDetailsProps {
|
||||||
|
@ -128,24 +129,10 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
CategoryUrlDialog,
|
||||||
categoryUrl(id, {
|
CategoryUrlQueryParams
|
||||||
...params,
|
>(navigate, params => categoryUrl(id, params), params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: CategoryUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
categoryUrl(id, {
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleBulkProductDelete = (data: productBulkDelete) => {
|
const handleBulkProductDelete = (data: productBulkDelete) => {
|
||||||
if (data.productBulkDelete.errors.length === 0) {
|
if (data.productBulkDelete.errors.length === 0) {
|
||||||
|
@ -240,7 +227,11 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
subcategoryListToolbar={
|
subcategoryListToolbar={
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("delete-categories", listElements)}
|
onClick={() =>
|
||||||
|
openModal("delete-categories", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
@ -248,7 +239,11 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
productListToolbar={
|
productListToolbar={
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("delete-products", listElements)}
|
onClick={() =>
|
||||||
|
openModal("delete-products", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { CategoryListPage } from "../../components/CategoryListPage/CategoryListPage";
|
import { CategoryListPage } from "../../components/CategoryListPage/CategoryListPage";
|
||||||
import { useCategoryBulkDeleteMutation } from "../../mutations";
|
import { useCategoryBulkDeleteMutation } from "../../mutations";
|
||||||
import { useRootCategoriesQuery } from "../../queries";
|
import { useRootCategoriesQuery } from "../../queries";
|
||||||
|
@ -26,10 +27,10 @@ import { CategoryBulkDelete } from "../../types/CategoryBulkDelete";
|
||||||
import {
|
import {
|
||||||
categoryAddUrl,
|
categoryAddUrl,
|
||||||
categoryListUrl,
|
categoryListUrl,
|
||||||
CategoryListUrlDialog,
|
|
||||||
CategoryListUrlFilters,
|
CategoryListUrlFilters,
|
||||||
CategoryListUrlQueryParams,
|
CategoryListUrlQueryParams,
|
||||||
categoryUrl
|
categoryUrl,
|
||||||
|
CategoryListUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import {
|
import {
|
||||||
areFiltersApplied,
|
areFiltersApplied,
|
||||||
|
@ -91,24 +92,10 @@ export const CategoryList: React.FC<CategoryListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
CategoryListUrlDialog,
|
||||||
categoryListUrl({
|
CategoryListUrlQueryParams
|
||||||
...params,
|
>(navigate, categoryListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: CategoryListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
categoryListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -187,13 +174,9 @@ export const CategoryList: React.FC<CategoryListProps> = ({ params }) => {
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(
|
openModal("delete", {
|
||||||
categoryListUrl({
|
|
||||||
...params,
|
|
||||||
action: "delete",
|
|
||||||
ids: listElements
|
ids: listElements
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
|
|
@ -15,6 +15,7 @@ import usePaginator, {
|
||||||
} from "@saleor/hooks/usePaginator";
|
} from "@saleor/hooks/usePaginator";
|
||||||
import { commonMessages } from "@saleor/intl";
|
import { commonMessages } from "@saleor/intl";
|
||||||
import useProductSearch from "@saleor/searches/useProductSearch";
|
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { getMutationState, maybe } from "../../misc";
|
import { getMutationState, maybe } from "../../misc";
|
||||||
import { productUrl } from "../../products/urls";
|
import { productUrl } from "../../products/urls";
|
||||||
import { CollectionInput } from "../../types/globalTypes";
|
import { CollectionInput } from "../../types/globalTypes";
|
||||||
|
@ -30,8 +31,8 @@ import { UnassignCollectionProduct } from "../types/UnassignCollectionProduct";
|
||||||
import {
|
import {
|
||||||
collectionListUrl,
|
collectionListUrl,
|
||||||
collectionUrl,
|
collectionUrl,
|
||||||
CollectionUrlDialog,
|
CollectionUrlQueryParams,
|
||||||
CollectionUrlQueryParams
|
CollectionUrlDialog
|
||||||
} from "../urls";
|
} from "../urls";
|
||||||
|
|
||||||
interface CollectionDetailsProps {
|
interface CollectionDetailsProps {
|
||||||
|
@ -54,22 +55,10 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
CollectionUrlDialog,
|
||||||
collectionUrl(id, {
|
CollectionUrlQueryParams
|
||||||
...params,
|
>(navigate, params => collectionUrl(id, params), params);
|
||||||
action: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
const openModal = (action: CollectionUrlDialog) =>
|
|
||||||
navigate(
|
|
||||||
collectionUrl(id, {
|
|
||||||
...params,
|
|
||||||
action
|
|
||||||
}),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
const paginationState = createPaginationState(PAGINATE_BY, params);
|
const paginationState = createPaginationState(PAGINATE_BY, params);
|
||||||
|
|
||||||
|
@ -243,12 +232,9 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(
|
openModal("unassign", {
|
||||||
collectionUrl(id, {
|
|
||||||
action: "unassign",
|
|
||||||
ids: listElements
|
ids: listElements
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import CollectionListPage from "../../components/CollectionListPage/CollectionListPage";
|
import CollectionListPage from "../../components/CollectionListPage/CollectionListPage";
|
||||||
import {
|
import {
|
||||||
TypedCollectionBulkDelete,
|
TypedCollectionBulkDelete,
|
||||||
|
@ -33,10 +34,10 @@ import { CollectionBulkPublish } from "../../types/CollectionBulkPublish";
|
||||||
import {
|
import {
|
||||||
collectionAddUrl,
|
collectionAddUrl,
|
||||||
collectionListUrl,
|
collectionListUrl,
|
||||||
CollectionListUrlDialog,
|
|
||||||
CollectionListUrlFilters,
|
CollectionListUrlFilters,
|
||||||
CollectionListUrlQueryParams,
|
CollectionListUrlQueryParams,
|
||||||
collectionUrl
|
collectionUrl,
|
||||||
|
CollectionListUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import {
|
import {
|
||||||
areFiltersApplied,
|
areFiltersApplied,
|
||||||
|
@ -98,24 +99,10 @@ export const CollectionList: React.FC<CollectionListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
CollectionListUrlDialog,
|
||||||
collectionListUrl({
|
CollectionListUrlQueryParams
|
||||||
...params,
|
>(navigate, collectionListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: CollectionListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
collectionListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -200,7 +187,11 @@ export const CollectionList: React.FC<CollectionListProps> = ({ params }) => {
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("unpublish", listElements)}
|
onClick={() =>
|
||||||
|
openModal("unpublish", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Unpublish"
|
defaultMessage="Unpublish"
|
||||||
|
@ -209,7 +200,11 @@ export const CollectionList: React.FC<CollectionListProps> = ({ params }) => {
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("publish", listElements)}
|
onClick={() =>
|
||||||
|
openModal("publish", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Publish"
|
defaultMessage="Publish"
|
||||||
|
@ -218,7 +213,11 @@ export const CollectionList: React.FC<CollectionListProps> = ({ params }) => {
|
||||||
</Button>
|
</Button>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("remove", listElements)}
|
onClick={() =>
|
||||||
|
openModal("remove", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { siteSettingsUrl } from "@saleor/siteSettings/urls";
|
||||||
import { staffListUrl } from "@saleor/staff/urls";
|
import { staffListUrl } from "@saleor/staff/urls";
|
||||||
import { countryListUrl } from "@saleor/taxes/urls";
|
import { countryListUrl } from "@saleor/taxes/urls";
|
||||||
import { languageListUrl } from "@saleor/translations/urls";
|
import { languageListUrl } from "@saleor/translations/urls";
|
||||||
import { webhooksListUrl } from "@saleor/webhooks/urls";
|
import { webhookListUrl } from "@saleor/webhooks/urls";
|
||||||
import { QuickSearchActionInput } from "../../types";
|
import { QuickSearchActionInput } from "../../types";
|
||||||
|
|
||||||
interface View {
|
interface View {
|
||||||
|
@ -115,7 +115,7 @@ function searchInViews(
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: intl.formatMessage(sectionNames.webhooks),
|
label: intl.formatMessage(sectionNames.webhooks),
|
||||||
url: webhooksListUrl()
|
url: webhookListUrl()
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import { siteSettingsUrl } from "@saleor/siteSettings/urls";
|
||||||
import { staffListUrl } from "@saleor/staff/urls";
|
import { staffListUrl } from "@saleor/staff/urls";
|
||||||
import { taxSection } from "@saleor/taxes/urls";
|
import { taxSection } from "@saleor/taxes/urls";
|
||||||
import { PermissionEnum } from "@saleor/types/globalTypes";
|
import { PermissionEnum } from "@saleor/types/globalTypes";
|
||||||
import { webhooksListUrl } from "@saleor/webhooks/urls";
|
import { webhookListUrl } from "@saleor/webhooks/urls";
|
||||||
import ConfigurationPage, { MenuSection } from "./ConfigurationPage";
|
import ConfigurationPage, { MenuSection } from "./ConfigurationPage";
|
||||||
|
|
||||||
export function createConfigurationMenu(intl: IntlShape): MenuSection[] {
|
export function createConfigurationMenu(intl: IntlShape): MenuSection[] {
|
||||||
|
@ -171,7 +171,7 @@ export function createConfigurationMenu(intl: IntlShape): MenuSection[] {
|
||||||
icon: <Webhooks fontSize="inherit" viewBox="0 0 44 44" />,
|
icon: <Webhooks fontSize="inherit" viewBox="0 0 44 44" />,
|
||||||
permission: PermissionEnum.MANAGE_WEBHOOKS,
|
permission: PermissionEnum.MANAGE_WEBHOOKS,
|
||||||
title: intl.formatMessage(sectionNames.webhooks),
|
title: intl.formatMessage(sectionNames.webhooks),
|
||||||
url: webhooksListUrl()
|
url: webhookListUrl()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useNotifier from "@saleor/hooks/useNotifier";
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import useShop from "@saleor/hooks/useShop";
|
import useShop from "@saleor/hooks/useShop";
|
||||||
import { commonMessages } from "@saleor/intl";
|
import { commonMessages } from "@saleor/intl";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { maybe } from "../../misc";
|
import { maybe } from "../../misc";
|
||||||
import CustomerAddressDialog from "../components/CustomerAddressDialog";
|
import CustomerAddressDialog from "../components/CustomerAddressDialog";
|
||||||
import CustomerAddressListPage from "../components/CustomerAddressListPage";
|
import CustomerAddressListPage from "../components/CustomerAddressListPage";
|
||||||
|
@ -24,9 +25,9 @@ import { SetCustomerDefaultAddress } from "../types/SetCustomerDefaultAddress";
|
||||||
import { UpdateCustomerAddress } from "../types/UpdateCustomerAddress";
|
import { UpdateCustomerAddress } from "../types/UpdateCustomerAddress";
|
||||||
import {
|
import {
|
||||||
customerAddressesUrl,
|
customerAddressesUrl,
|
||||||
CustomerAddressesUrlDialog,
|
|
||||||
CustomerAddressesUrlQueryParams,
|
CustomerAddressesUrlQueryParams,
|
||||||
customerUrl
|
customerUrl,
|
||||||
|
CustomerAddressesUrlDialog
|
||||||
} from "../urls";
|
} from "../urls";
|
||||||
|
|
||||||
interface CustomerAddressesProps {
|
interface CustomerAddressesProps {
|
||||||
|
@ -43,9 +44,10 @@ const CustomerAddresses: React.FC<CustomerAddressesProps> = ({
|
||||||
const shop = useShop();
|
const shop = useShop();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
const closeModal = () => navigate(customerAddressesUrl(id), true);
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
const openModal = (action: CustomerAddressesUrlDialog, addressId?: string) =>
|
CustomerAddressesUrlDialog,
|
||||||
navigate(customerAddressesUrl(id, { action, id: addressId }));
|
CustomerAddressesUrlQueryParams
|
||||||
|
>(navigate, params => customerAddressesUrl(id, params), params);
|
||||||
|
|
||||||
const handleSetAddressAsDefault = (data: SetCustomerDefaultAddress) => {
|
const handleSetAddressAsDefault = (data: SetCustomerDefaultAddress) => {
|
||||||
if (data.addressSetDefault.errors.length === 0) {
|
if (data.addressSetDefault.errors.length === 0) {
|
||||||
|
@ -116,9 +118,15 @@ const CustomerAddresses: React.FC<CustomerAddressesProps> = ({
|
||||||
disabled={customerData.loading}
|
disabled={customerData.loading}
|
||||||
onAdd={() => openModal("add")}
|
onAdd={() => openModal("add")}
|
||||||
onBack={() => navigate(customerUrl(id))}
|
onBack={() => navigate(customerUrl(id))}
|
||||||
onEdit={addressId => openModal("edit", addressId)}
|
onEdit={id =>
|
||||||
onRemove={addressId =>
|
openModal("edit", {
|
||||||
openModal("remove", addressId)
|
id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
onRemove={id =>
|
||||||
|
openModal("remove", {
|
||||||
|
id
|
||||||
|
})
|
||||||
}
|
}
|
||||||
onSetAsDefault={(addressId, type) =>
|
onSetAsDefault={(addressId, type) =>
|
||||||
setCustomerDefaultAddress({
|
setCustomerDefaultAddress({
|
||||||
|
|
|
@ -21,6 +21,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import CustomerListPage from "../../components/CustomerListPage";
|
import CustomerListPage from "../../components/CustomerListPage";
|
||||||
import { TypedBulkRemoveCustomers } from "../../mutations";
|
import { TypedBulkRemoveCustomers } from "../../mutations";
|
||||||
import { useCustomerListQuery } from "../../queries";
|
import { useCustomerListQuery } from "../../queries";
|
||||||
|
@ -28,10 +29,10 @@ import { BulkRemoveCustomers } from "../../types/BulkRemoveCustomers";
|
||||||
import {
|
import {
|
||||||
customerAddUrl,
|
customerAddUrl,
|
||||||
customerListUrl,
|
customerListUrl,
|
||||||
CustomerListUrlDialog,
|
|
||||||
CustomerListUrlFilters,
|
CustomerListUrlFilters,
|
||||||
CustomerListUrlQueryParams,
|
CustomerListUrlQueryParams,
|
||||||
customerUrl
|
customerUrl,
|
||||||
|
CustomerListUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import {
|
import {
|
||||||
areFiltersApplied,
|
areFiltersApplied,
|
||||||
|
@ -93,24 +94,10 @@ export const CustomerList: React.FC<CustomerListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
CustomerListUrlDialog,
|
||||||
customerListUrl({
|
CustomerListUrlQueryParams
|
||||||
...params,
|
>(navigate, customerListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: CustomerListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
customerListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -179,12 +166,9 @@ export const CustomerList: React.FC<CustomerListProps> = ({ params }) => {
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(
|
openModal("remove", {
|
||||||
customerListUrl({
|
|
||||||
action: "remove",
|
|
||||||
ids: listElements
|
ids: listElements
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { commonMessages, sectionNames } from "@saleor/intl";
|
||||||
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 useProductSearch from "@saleor/searches/useProductSearch";
|
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { categoryUrl } from "../../categories/urls";
|
import { categoryUrl } from "../../categories/urls";
|
||||||
import { collectionUrl } from "../../collections/urls";
|
import { collectionUrl } from "../../collections/urls";
|
||||||
import { decimal, joinDateTime, maybe } from "../../misc";
|
import { decimal, joinDateTime, maybe } from "../../misc";
|
||||||
|
@ -42,8 +43,8 @@ import { SaleUpdate } from "../types/SaleUpdate";
|
||||||
import {
|
import {
|
||||||
saleListUrl,
|
saleListUrl,
|
||||||
saleUrl,
|
saleUrl,
|
||||||
SaleUrlDialog,
|
SaleUrlQueryParams,
|
||||||
SaleUrlQueryParams
|
SaleUrlDialog
|
||||||
} from "../urls";
|
} from "../urls";
|
||||||
|
|
||||||
interface SaleDetailsProps {
|
interface SaleDetailsProps {
|
||||||
|
@ -114,24 +115,10 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
SaleUrlDialog,
|
||||||
saleUrl(id, {
|
SaleUrlQueryParams
|
||||||
...params,
|
>(navigate, params => saleUrl(id, params), params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: SaleUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
saleUrl(id, {
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleCatalogueAdd = (data: SaleCataloguesAdd) => {
|
const handleCatalogueAdd = (data: SaleCataloguesAdd) => {
|
||||||
if (data.saleCataloguesAdd.errors.length === 0) {
|
if (data.saleCataloguesAdd.errors.length === 0) {
|
||||||
|
@ -285,7 +272,9 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openModal("unassign-category", listElements)
|
openModal("unassign-category", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
@ -299,10 +288,9 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openModal(
|
openModal("unassign-collection", {
|
||||||
"unassign-collection",
|
ids: listElements
|
||||||
listElements
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
@ -316,7 +304,9 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openModal("unassign-product", listElements)
|
openModal("unassign-product", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
|
|
@ -23,17 +23,18 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import SaleListPage from "../../components/SaleListPage";
|
import SaleListPage from "../../components/SaleListPage";
|
||||||
import { TypedSaleBulkDelete } from "../../mutations";
|
import { TypedSaleBulkDelete } from "../../mutations";
|
||||||
import { useSaleListQuery } from "../../queries";
|
import { useSaleListQuery } from "../../queries";
|
||||||
import { SaleBulkDelete } from "../../types/SaleBulkDelete";
|
import { SaleBulkDelete } from "../../types/SaleBulkDelete";
|
||||||
import {
|
import {
|
||||||
saleAddUrl,
|
saleAddUrl,
|
||||||
saleListUrl,
|
|
||||||
SaleListUrlDialog,
|
|
||||||
SaleListUrlFilters,
|
SaleListUrlFilters,
|
||||||
SaleListUrlQueryParams,
|
SaleListUrlQueryParams,
|
||||||
saleUrl
|
saleUrl,
|
||||||
|
saleListUrl,
|
||||||
|
SaleListUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import {
|
import {
|
||||||
areFiltersApplied,
|
areFiltersApplied,
|
||||||
|
@ -96,24 +97,10 @@ export const SaleList: React.FC<SaleListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
SaleListUrlDialog,
|
||||||
saleListUrl({
|
SaleListUrlQueryParams
|
||||||
...params,
|
>(navigate, saleListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: SaleListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
saleListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -199,12 +186,9 @@ export const SaleList: React.FC<SaleListProps> = ({ params }) => {
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(
|
openModal("remove", {
|
||||||
saleListUrl({
|
|
||||||
action: "remove",
|
|
||||||
ids: listElements
|
ids: listElements
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { commonMessages, sectionNames } from "@saleor/intl";
|
||||||
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 useProductSearch from "@saleor/searches/useProductSearch";
|
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { categoryUrl } from "../../categories/urls";
|
import { categoryUrl } from "../../categories/urls";
|
||||||
import { collectionUrl } from "../../collections/urls";
|
import { collectionUrl } from "../../collections/urls";
|
||||||
import { decimal, joinDateTime, maybe } from "../../misc";
|
import { decimal, joinDateTime, maybe } from "../../misc";
|
||||||
|
@ -47,8 +48,8 @@ import { VoucherUpdate } from "../types/VoucherUpdate";
|
||||||
import {
|
import {
|
||||||
voucherListUrl,
|
voucherListUrl,
|
||||||
voucherUrl,
|
voucherUrl,
|
||||||
VoucherUrlDialog,
|
VoucherUrlQueryParams,
|
||||||
VoucherUrlQueryParams
|
VoucherUrlDialog
|
||||||
} from "../urls";
|
} from "../urls";
|
||||||
|
|
||||||
interface VoucherDetailsProps {
|
interface VoucherDetailsProps {
|
||||||
|
@ -117,23 +118,10 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
VoucherUrlDialog,
|
||||||
voucherUrl(id, {
|
VoucherUrlQueryParams
|
||||||
...params,
|
>(navigate, params => voucherUrl(id, params), params);
|
||||||
action: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: VoucherUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
voucherUrl(id, {
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleCatalogueAdd = (data: VoucherCataloguesAdd) => {
|
const handleCatalogueAdd = (data: VoucherCataloguesAdd) => {
|
||||||
if (data.voucherCataloguesAdd.errors.length === 0) {
|
if (data.voucherCataloguesAdd.errors.length === 0) {
|
||||||
|
@ -360,7 +348,9 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openModal("unassign-category", listElements)
|
openModal("unassign-category", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
@ -374,10 +364,9 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openModal(
|
openModal("unassign-collection", {
|
||||||
"unassign-collection",
|
ids: listElements
|
||||||
listElements
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
@ -391,7 +380,9 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openModal("unassign-product", listElements)
|
openModal("unassign-product", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
|
|
@ -23,6 +23,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import VoucherListPage from "../../components/VoucherListPage";
|
import VoucherListPage from "../../components/VoucherListPage";
|
||||||
import { TypedVoucherBulkDelete } from "../../mutations";
|
import { TypedVoucherBulkDelete } from "../../mutations";
|
||||||
import { useVoucherListQuery } from "../../queries";
|
import { useVoucherListQuery } from "../../queries";
|
||||||
|
@ -30,10 +31,10 @@ import { VoucherBulkDelete } from "../../types/VoucherBulkDelete";
|
||||||
import {
|
import {
|
||||||
voucherAddUrl,
|
voucherAddUrl,
|
||||||
voucherListUrl,
|
voucherListUrl,
|
||||||
VoucherListUrlDialog,
|
|
||||||
VoucherListUrlFilters,
|
VoucherListUrlFilters,
|
||||||
VoucherListUrlQueryParams,
|
VoucherListUrlQueryParams,
|
||||||
voucherUrl
|
voucherUrl,
|
||||||
|
VoucherListUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import {
|
import {
|
||||||
areFiltersApplied,
|
areFiltersApplied,
|
||||||
|
@ -96,24 +97,10 @@ export const VoucherList: React.FC<VoucherListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
VoucherListUrlDialog,
|
||||||
voucherListUrl({
|
VoucherListUrlQueryParams
|
||||||
...params,
|
>(navigate, voucherListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: VoucherListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
voucherListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -199,12 +186,9 @@ export const VoucherList: React.FC<VoucherListProps> = ({ params }) => {
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(
|
openModal("remove", {
|
||||||
voucherListUrl({
|
|
||||||
action: "remove",
|
|
||||||
ids: listElements
|
ids: listElements
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { DEFAULT_INITIAL_SEARCH_DATA } from "@saleor/config";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useUser from "@saleor/hooks/useUser";
|
import useUser from "@saleor/hooks/useUser";
|
||||||
import useCustomerSearch from "@saleor/searches/useCustomerSearch";
|
import useCustomerSearch from "@saleor/searches/useCustomerSearch";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { customerUrl } from "../../../customers/urls";
|
import { customerUrl } from "../../../customers/urls";
|
||||||
import { getMutationState, maybe, transformAddressToForm } from "../../../misc";
|
import { getMutationState, maybe, transformAddressToForm } from "../../../misc";
|
||||||
import { productUrl } from "../../../products/urls";
|
import { productUrl } from "../../../products/urls";
|
||||||
|
@ -31,8 +32,8 @@ import { OrderDetails_order } from "../../types/OrderDetails";
|
||||||
import {
|
import {
|
||||||
orderListUrl,
|
orderListUrl,
|
||||||
orderUrl,
|
orderUrl,
|
||||||
OrderUrlDialog,
|
OrderUrlQueryParams,
|
||||||
OrderUrlQueryParams
|
OrderUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import { OrderDetailsMessages } from "./OrderDetailsMessages";
|
import { OrderDetailsMessages } from "./OrderDetailsMessages";
|
||||||
|
|
||||||
|
@ -97,13 +98,11 @@ export const OrderDetails: React.FC<OrderDetailsProps> = ({ id, params }) => {
|
||||||
>
|
>
|
||||||
{({ data, loading }) => {
|
{({ data, loading }) => {
|
||||||
const order = maybe(() => data.order);
|
const order = maybe(() => data.order);
|
||||||
const closeModal = () => navigate(orderUrl(id), true);
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
const openModal = (action: OrderUrlDialog) =>
|
OrderUrlDialog,
|
||||||
navigate(
|
OrderUrlQueryParams
|
||||||
orderUrl(id, {
|
>(navigate, params => orderUrl(id, params), params);
|
||||||
action
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<OrderDetailsMessages>
|
<OrderDetailsMessages>
|
||||||
{orderMessages => (
|
{orderMessages => (
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import OrderDraftListPage from "../../components/OrderDraftListPage";
|
import OrderDraftListPage from "../../components/OrderDraftListPage";
|
||||||
import {
|
import {
|
||||||
TypedOrderDraftBulkCancelMutation,
|
TypedOrderDraftBulkCancelMutation,
|
||||||
|
@ -30,10 +31,10 @@ import { OrderDraftBulkCancel } from "../../types/OrderDraftBulkCancel";
|
||||||
import { OrderDraftCreate } from "../../types/OrderDraftCreate";
|
import { OrderDraftCreate } from "../../types/OrderDraftCreate";
|
||||||
import {
|
import {
|
||||||
orderDraftListUrl,
|
orderDraftListUrl,
|
||||||
OrderDraftListUrlDialog,
|
|
||||||
OrderDraftListUrlFilters,
|
OrderDraftListUrlFilters,
|
||||||
OrderDraftListUrlQueryParams,
|
OrderDraftListUrlQueryParams,
|
||||||
orderUrl
|
orderUrl,
|
||||||
|
OrderDraftListUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import {
|
import {
|
||||||
areFiltersApplied,
|
areFiltersApplied,
|
||||||
|
@ -94,24 +95,10 @@ export const OrderDraftList: React.FC<OrderDraftListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
OrderDraftListUrlDialog,
|
||||||
orderDraftListUrl({
|
OrderDraftListUrlQueryParams
|
||||||
...params,
|
>(navigate, orderDraftListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: OrderDraftListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
orderDraftListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -211,12 +198,9 @@ export const OrderDraftList: React.FC<OrderDraftListProps> = ({ params }) => {
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(
|
openModal("remove", {
|
||||||
orderDraftListUrl({
|
|
||||||
action: "remove",
|
|
||||||
ids: listElements
|
ids: listElements
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import OrderBulkCancelDialog from "../../components/OrderBulkCancelDialog";
|
import OrderBulkCancelDialog from "../../components/OrderBulkCancelDialog";
|
||||||
import OrderListPage from "../../components/OrderListPage/OrderListPage";
|
import OrderListPage from "../../components/OrderListPage/OrderListPage";
|
||||||
import {
|
import {
|
||||||
|
@ -30,10 +31,10 @@ import { OrderBulkCancel } from "../../types/OrderBulkCancel";
|
||||||
import { OrderDraftCreate } from "../../types/OrderDraftCreate";
|
import { OrderDraftCreate } from "../../types/OrderDraftCreate";
|
||||||
import {
|
import {
|
||||||
orderListUrl,
|
orderListUrl,
|
||||||
OrderListUrlDialog,
|
|
||||||
OrderListUrlFilters,
|
OrderListUrlFilters,
|
||||||
OrderListUrlQueryParams,
|
OrderListUrlQueryParams,
|
||||||
orderUrl
|
orderUrl,
|
||||||
|
OrderListUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import {
|
import {
|
||||||
areFiltersApplied,
|
areFiltersApplied,
|
||||||
|
@ -87,16 +88,6 @@ export const OrderList: React.FC<OrderListProps> = ({ params }) => {
|
||||||
: 0
|
: 0
|
||||||
: parseInt(params.activeTab, 0);
|
: parseInt(params.activeTab, 0);
|
||||||
|
|
||||||
const closeModal = () =>
|
|
||||||
navigate(
|
|
||||||
orderListUrl({
|
|
||||||
...params,
|
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const changeFilters = (filters: OrderListUrlFilters) => {
|
const changeFilters = (filters: OrderListUrlFilters) => {
|
||||||
reset();
|
reset();
|
||||||
navigate(orderListUrl(filters));
|
navigate(orderListUrl(filters));
|
||||||
|
@ -113,14 +104,10 @@ export const OrderList: React.FC<OrderListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const openModal = (action: OrderListUrlDialog, ids?: string[]) =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
OrderListUrlDialog,
|
||||||
orderListUrl({
|
OrderListUrlQueryParams
|
||||||
...params,
|
>(navigate, orderListUrl, params);
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -222,7 +209,11 @@ export const OrderList: React.FC<OrderListProps> = ({ params }) => {
|
||||||
toolbar={
|
toolbar={
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("cancel", listElements)}
|
onClick={() =>
|
||||||
|
openModal("cancel", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Cancel"
|
defaultMessage="Cancel"
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import PageListPage from "../../components/PageListPage/PageListPage";
|
import PageListPage from "../../components/PageListPage/PageListPage";
|
||||||
import { TypedPageBulkPublish, TypedPageBulkRemove } from "../../mutations";
|
import { TypedPageBulkPublish, TypedPageBulkRemove } from "../../mutations";
|
||||||
import { usePageListQuery } from "../../queries";
|
import { usePageListQuery } from "../../queries";
|
||||||
|
@ -67,24 +68,10 @@ export const PageList: React.FC<PageListProps> = ({ params }) => {
|
||||||
params
|
params
|
||||||
);
|
);
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
PageListUrlDialog,
|
||||||
pageListUrl({
|
PageListUrlQueryParams
|
||||||
...params,
|
>(navigate, pageListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: PageListUrlDialog, ids: string[]) =>
|
|
||||||
navigate(
|
|
||||||
pageListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handlePageBulkPublish = (data: PageBulkPublish) => {
|
const handlePageBulkPublish = (data: PageBulkPublish) => {
|
||||||
if (data.pageBulkPublish.errors.length === 0) {
|
if (data.pageBulkPublish.errors.length === 0) {
|
||||||
|
@ -138,7 +125,11 @@ export const PageList: React.FC<PageListProps> = ({ params }) => {
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("unpublish", listElements)}
|
onClick={() =>
|
||||||
|
openModal("unpublish", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Unpublish"
|
defaultMessage="Unpublish"
|
||||||
|
@ -147,7 +138,11 @@ export const PageList: React.FC<PageListProps> = ({ params }) => {
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("publish", listElements)}
|
onClick={() =>
|
||||||
|
openModal("publish", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Publish"
|
defaultMessage="Publish"
|
||||||
|
@ -156,7 +151,11 @@ export const PageList: React.FC<PageListProps> = ({ params }) => {
|
||||||
</Button>
|
</Button>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => openModal("remove", listElements)}
|
onClick={() =>
|
||||||
|
openModal("remove", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
|
@ -19,8 +19,6 @@ export const pluginListUrl = (params?: PluginListUrlQueryParams) =>
|
||||||
|
|
||||||
export const pluginPath = (id: string) => urlJoin(pluginSection, id);
|
export const pluginPath = (id: string) => urlJoin(pluginSection, id);
|
||||||
export type PluginUrlDialog = "clear" | "edit";
|
export type PluginUrlDialog = "clear" | "edit";
|
||||||
export type PluginUrlQueryParams = Dialog<PluginUrlDialog> & {
|
export type PluginUrlQueryParams = Dialog<PluginUrlDialog> & SingleAction;
|
||||||
field?: string;
|
export const pluginUrl = (id: string, params?: PluginUrlQueryParams) =>
|
||||||
};
|
|
||||||
export const pluginsUrl = (id: string, params?: PluginUrlQueryParams) =>
|
|
||||||
pluginPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
pluginPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
||||||
|
|
|
@ -12,11 +12,7 @@ import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
import PluginsListPage from "../../components/PluginsListPage/PluginsListPage";
|
import PluginsListPage from "../../components/PluginsListPage/PluginsListPage";
|
||||||
import { usePluginsListQuery } from "../../queries";
|
import { usePluginsListQuery } from "../../queries";
|
||||||
import {
|
import { PluginListUrlQueryParams, pluginListUrl, pluginUrl } from "../../urls";
|
||||||
PluginListUrlQueryParams,
|
|
||||||
pluginListUrl,
|
|
||||||
pluginsUrl
|
|
||||||
} from "../../urls";
|
|
||||||
import { getSortQueryVariables } from "./sort";
|
import { getSortQueryVariables } from "./sort";
|
||||||
|
|
||||||
interface PluginsListProps {
|
interface PluginsListProps {
|
||||||
|
@ -65,7 +61,7 @@ export const PluginsList: React.FC<PluginsListProps> = ({ params }) => {
|
||||||
onPreviousPage={loadPreviousPage}
|
onPreviousPage={loadPreviousPage}
|
||||||
onSort={handleSort}
|
onSort={handleSort}
|
||||||
onUpdateListSettings={updateListSettings}
|
onUpdateListSettings={updateListSettings}
|
||||||
onRowClick={id => () => navigate(pluginsUrl(id))}
|
onRowClick={id => () => navigate(pluginUrl(id))}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -8,6 +8,7 @@ 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 { ConfigurationItemInput } from "@saleor/types/globalTypes";
|
import { ConfigurationItemInput } from "@saleor/types/globalTypes";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { maybe } from "../../misc";
|
import { maybe } from "../../misc";
|
||||||
import PluginsDetailsPage from "../components/PluginsDetailsPage";
|
import PluginsDetailsPage from "../components/PluginsDetailsPage";
|
||||||
import PluginSecretFieldDialog from "../components/PluginSecretFieldDialog";
|
import PluginSecretFieldDialog from "../components/PluginSecretFieldDialog";
|
||||||
|
@ -17,7 +18,7 @@ import { Plugin_plugin_configuration } from "../types/Plugin";
|
||||||
import { PluginUpdate } from "../types/PluginUpdate";
|
import { PluginUpdate } from "../types/PluginUpdate";
|
||||||
import {
|
import {
|
||||||
pluginListUrl,
|
pluginListUrl,
|
||||||
pluginsUrl,
|
pluginUrl,
|
||||||
PluginUrlQueryParams,
|
PluginUrlQueryParams,
|
||||||
PluginUrlDialog
|
PluginUrlDialog
|
||||||
} from "../urls";
|
} from "../urls";
|
||||||
|
@ -52,24 +53,10 @@ export const PluginsDetails: React.FC<PluginsDetailsProps> = ({
|
||||||
const notify = useNotifier();
|
const notify = useNotifier();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
PluginUrlDialog,
|
||||||
pluginsUrl(id, {
|
PluginUrlQueryParams
|
||||||
...params,
|
>(navigate, params => pluginUrl(id, params), params);
|
||||||
action: undefined,
|
|
||||||
field: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: PluginUrlDialog, field?: string) =>
|
|
||||||
navigate(
|
|
||||||
pluginsUrl(id, {
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
field
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleUpdate = (data: PluginUpdate) => {
|
const handleUpdate = (data: PluginUpdate) => {
|
||||||
if (data.pluginUpdate.errors.length === 0) {
|
if (data.pluginUpdate.errors.length === 0) {
|
||||||
|
@ -97,7 +84,7 @@ export const PluginsDetails: React.FC<PluginsDetailsProps> = ({
|
||||||
input: {
|
input: {
|
||||||
configuration: [
|
configuration: [
|
||||||
{
|
{
|
||||||
name: params.field,
|
name: params.id,
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -118,8 +105,16 @@ export const PluginsDetails: React.FC<PluginsDetailsProps> = ({
|
||||||
}
|
}
|
||||||
plugin={maybe(() => pluginDetails.data.plugin)}
|
plugin={maybe(() => pluginDetails.data.plugin)}
|
||||||
onBack={() => navigate(pluginListUrl())}
|
onBack={() => navigate(pluginListUrl())}
|
||||||
onClear={field => openModal("clear", field)}
|
onClear={id =>
|
||||||
onEdit={field => openModal("edit", field)}
|
openModal("clear", {
|
||||||
|
id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
onEdit={id =>
|
||||||
|
openModal("edit", {
|
||||||
|
id
|
||||||
|
})
|
||||||
|
}
|
||||||
onSubmit={formData =>
|
onSubmit={formData =>
|
||||||
pluginUpdate({
|
pluginUpdate({
|
||||||
variables: {
|
variables: {
|
||||||
|
@ -142,7 +137,7 @@ export const PluginsDetails: React.FC<PluginsDetailsProps> = ({
|
||||||
!!params.action ? pluginUpdateOpts.status : "default"
|
!!params.action ? pluginUpdateOpts.status : "default"
|
||||||
}
|
}
|
||||||
onClose={closeModal}
|
onClose={closeModal}
|
||||||
open={params.action === "clear" && !!params.field}
|
open={params.action === "clear" && !!params.id}
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
defaultMessage: "Authorization Field Delete",
|
defaultMessage: "Authorization Field Delete",
|
||||||
description: "header"
|
description: "header"
|
||||||
|
@ -159,12 +154,12 @@ export const PluginsDetails: React.FC<PluginsDetailsProps> = ({
|
||||||
}
|
}
|
||||||
field={maybe(() =>
|
field={maybe(() =>
|
||||||
pluginDetails.data.plugin.configuration.find(
|
pluginDetails.data.plugin.configuration.find(
|
||||||
field => field.name === params.field
|
field => field.name === params.id
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
onClose={closeModal}
|
onClose={closeModal}
|
||||||
onConfirm={formData => handleFieldUpdate(formData.value)}
|
onConfirm={formData => handleFieldUpdate(formData.value)}
|
||||||
open={params.action === "edit" && !!params.field}
|
open={params.action === "edit" && !!params.id}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { commonMessages } from "@saleor/intl";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { configurationMenuUrl } from "../../../configuration";
|
import { configurationMenuUrl } from "../../../configuration";
|
||||||
import { maybe } from "../../../misc";
|
import { maybe } from "../../../misc";
|
||||||
import ProductTypeListPage from "../../components/ProductTypeListPage";
|
import ProductTypeListPage from "../../components/ProductTypeListPage";
|
||||||
|
@ -92,24 +93,10 @@ export const ProductTypeList: React.FC<ProductTypeListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
ProductTypeListUrlDialog,
|
||||||
productTypeListUrl({
|
ProductTypeListUrlQueryParams
|
||||||
...params,
|
>(navigate, productTypeListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: ProductTypeListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
productTypeListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -200,12 +187,9 @@ export const ProductTypeList: React.FC<ProductTypeListProps> = ({ params }) => {
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(
|
openModal("remove", {
|
||||||
productTypeListUrl({
|
|
||||||
action: "remove",
|
|
||||||
ids: listElements
|
ids: listElements
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
|
|
@ -52,9 +52,8 @@ 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";
|
export type ProductUrlDialog = "create-variants" | "remove" | "remove-variants";
|
||||||
export type ProductUrlQueryParams = BulkAction &
|
export type ProductUrlQueryParams = BulkAction & Dialog<ProductUrlDialog>;
|
||||||
Dialog<"create-variants" | "remove" | "remove-variants">;
|
|
||||||
export const productUrl = (id: string, params?: ProductUrlQueryParams) =>
|
export const productUrl = (id: string, params?: ProductUrlQueryParams) =>
|
||||||
productPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
productPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ProductListVariables } from "@saleor/products/types/ProductList";
|
import { ProductListVariables } from "@saleor/products/types/ProductList";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortUrlVariables } from "@saleor/utils/sort";
|
import { getSortUrlVariables } from "@saleor/utils/sort";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import ProductListPage from "../../components/ProductListPage";
|
import ProductListPage from "../../components/ProductListPage";
|
||||||
import {
|
import {
|
||||||
TypedProductBulkDeleteMutation,
|
TypedProductBulkDeleteMutation,
|
||||||
|
@ -39,11 +40,11 @@ import { productBulkPublish } from "../../types/productBulkPublish";
|
||||||
import {
|
import {
|
||||||
productAddUrl,
|
productAddUrl,
|
||||||
productListUrl,
|
productListUrl,
|
||||||
ProductListUrlDialog,
|
|
||||||
ProductListUrlFilters,
|
ProductListUrlFilters,
|
||||||
ProductListUrlQueryParams,
|
ProductListUrlQueryParams,
|
||||||
ProductListUrlSortField,
|
ProductListUrlSortField,
|
||||||
productUrl
|
productUrl,
|
||||||
|
ProductListUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import {
|
import {
|
||||||
areFiltersApplied,
|
areFiltersApplied,
|
||||||
|
@ -97,15 +98,10 @@ export const ProductList: React.FC<ProductListProps> = ({ params }) => {
|
||||||
: 0
|
: 0
|
||||||
: parseInt(params.activeTab, 0);
|
: parseInt(params.activeTab, 0);
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
ProductListUrlDialog,
|
||||||
productListUrl({
|
ProductListUrlQueryParams
|
||||||
...params,
|
>(navigate, productListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const changeFilters = (filters: ProductListUrlFilters) => {
|
const changeFilters = (filters: ProductListUrlFilters) => {
|
||||||
reset();
|
reset();
|
||||||
|
@ -123,15 +119,6 @@ export const ProductList: React.FC<ProductListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const openModal = (action: ProductListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
productListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
reset();
|
reset();
|
||||||
navigate(
|
navigate(
|
||||||
|
@ -311,7 +298,9 @@ export const ProductList: React.FC<ProductListProps> = ({ params }) => {
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openModal("unpublish", listElements)
|
openModal("unpublish", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
@ -322,7 +311,9 @@ export const ProductList: React.FC<ProductListProps> = ({ params }) => {
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openModal("publish", listElements)
|
openModal("publish", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
@ -333,7 +324,9 @@ export const ProductList: React.FC<ProductListProps> = ({ params }) => {
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openModal("delete", listElements)
|
openModal("delete", {
|
||||||
|
ids: listElements
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
|
|
@ -17,6 +17,7 @@ import ProductVariantCreateDialog from "@saleor/products/components/ProductVaria
|
||||||
import { ProductVariantBulkCreate } from "@saleor/products/types/ProductVariantBulkCreate";
|
import { ProductVariantBulkCreate } from "@saleor/products/types/ProductVariantBulkCreate";
|
||||||
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 createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { getMutationState, maybe } from "../../../misc";
|
import { getMutationState, maybe } from "../../../misc";
|
||||||
import ProductUpdatePage from "../../components/ProductUpdatePage";
|
import ProductUpdatePage from "../../components/ProductUpdatePage";
|
||||||
import ProductUpdateOperations from "../../containers/ProductUpdateOperations";
|
import ProductUpdateOperations from "../../containers/ProductUpdateOperations";
|
||||||
|
@ -31,10 +32,10 @@ import {
|
||||||
productImageUrl,
|
productImageUrl,
|
||||||
productListUrl,
|
productListUrl,
|
||||||
productUrl,
|
productUrl,
|
||||||
ProductUrlDialog,
|
|
||||||
ProductUrlQueryParams,
|
ProductUrlQueryParams,
|
||||||
productVariantAddUrl,
|
productVariantAddUrl,
|
||||||
productVariantEditUrl
|
productVariantEditUrl,
|
||||||
|
ProductUrlDialog
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import {
|
import {
|
||||||
createImageReorderHandler,
|
createImageReorderHandler,
|
||||||
|
@ -70,12 +71,10 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
|
|
||||||
const openModal = (action: ProductUrlDialog) =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
ProductUrlDialog,
|
||||||
productUrl(id, {
|
ProductUrlQueryParams
|
||||||
action
|
>(navigate, params => productUrl(id, params), params);
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TypedProductDetailsQuery
|
<TypedProductDetailsQuery
|
||||||
|
@ -128,7 +127,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
data: ProductVariantBulkCreate
|
data: ProductVariantBulkCreate
|
||||||
) => {
|
) => {
|
||||||
if (data.productVariantBulkCreate.errors.length === 0) {
|
if (data.productVariantBulkCreate.errors.length === 0) {
|
||||||
navigate(productUrl(id), true);
|
closeModal();
|
||||||
refetch();
|
refetch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -137,20 +136,12 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
data: ProductVariantBulkDelete
|
data: ProductVariantBulkDelete
|
||||||
) => {
|
) => {
|
||||||
if (data.productVariantBulkDelete.errors.length === 0) {
|
if (data.productVariantBulkDelete.errors.length === 0) {
|
||||||
navigate(productUrl(id), true);
|
closeModal();
|
||||||
reset();
|
reset();
|
||||||
refetch();
|
refetch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleVariantCreatorOpen = () =>
|
|
||||||
navigate(
|
|
||||||
productUrl(id, {
|
|
||||||
...params,
|
|
||||||
action: "create-variants"
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const product = data ? data.product : undefined;
|
const product = data ? data.product : undefined;
|
||||||
return (
|
return (
|
||||||
<ProductUpdateOperations
|
<ProductUpdateOperations
|
||||||
|
@ -248,7 +239,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
onImageReorder={handleImageReorder}
|
onImageReorder={handleImageReorder}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
onVariantAdd={handleVariantAdd}
|
onVariantAdd={handleVariantAdd}
|
||||||
onVariantsAdd={handleVariantCreatorOpen}
|
onVariantsAdd={() => openModal("create-variants")}
|
||||||
onVariantShow={variantId => () =>
|
onVariantShow={variantId => () =>
|
||||||
navigate(productVariantEditUrl(product.id, variantId))}
|
navigate(productVariantEditUrl(product.id, variantId))}
|
||||||
onImageUpload={handleImageUpload}
|
onImageUpload={handleImageUpload}
|
||||||
|
@ -258,12 +249,9 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(
|
openModal("remove-variants", {
|
||||||
productUrl(id, {
|
|
||||||
action: "remove-variants",
|
|
||||||
ids: listElements
|
ids: listElements
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
@ -292,7 +280,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
/>
|
/>
|
||||||
<ActionDialog
|
<ActionDialog
|
||||||
open={params.action === "remove"}
|
open={params.action === "remove"}
|
||||||
onClose={() => navigate(productUrl(id), true)}
|
onClose={closeModal}
|
||||||
confirmButtonState={deleteProduct.opts.status}
|
confirmButtonState={deleteProduct.opts.status}
|
||||||
onConfirm={() => deleteProduct.mutate({ id })}
|
onConfirm={() => deleteProduct.mutate({ id })}
|
||||||
variant="delete"
|
variant="delete"
|
||||||
|
@ -313,7 +301,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
</ActionDialog>
|
</ActionDialog>
|
||||||
<ActionDialog
|
<ActionDialog
|
||||||
open={params.action === "remove-variants"}
|
open={params.action === "remove-variants"}
|
||||||
onClose={() => navigate(productUrl(id), true)}
|
onClose={closeModal}
|
||||||
confirmButtonState={bulkProductVariantDelete.opts.status}
|
confirmButtonState={bulkProductVariantDelete.opts.status}
|
||||||
onConfirm={() =>
|
onConfirm={() =>
|
||||||
bulkProductVariantDelete.mutate({
|
bulkProductVariantDelete.mutate({
|
||||||
|
@ -355,14 +343,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
[]
|
[]
|
||||||
)}
|
)}
|
||||||
currencySymbol={maybe(() => shop.defaultCurrency)}
|
currencySymbol={maybe(() => shop.defaultCurrency)}
|
||||||
onClose={() =>
|
onClose={closeModal}
|
||||||
navigate(
|
|
||||||
productUrl(id, {
|
|
||||||
...params,
|
|
||||||
action: undefined
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onSubmit={inputs =>
|
onSubmit={inputs =>
|
||||||
bulkProductVariantCreate.mutate({
|
bulkProductVariantCreate.mutate({
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -21,6 +21,7 @@ import { ServiceDelete } from "@saleor/services/types/ServiceDelete";
|
||||||
import { ServiceTokenCreate } from "@saleor/services/types/ServiceTokenCreate";
|
import { ServiceTokenCreate } from "@saleor/services/types/ServiceTokenCreate";
|
||||||
import { ServiceTokenDelete } from "@saleor/services/types/ServiceTokenDelete";
|
import { ServiceTokenDelete } from "@saleor/services/types/ServiceTokenDelete";
|
||||||
import { ServiceUpdate } from "@saleor/services/types/ServiceUpdate";
|
import { ServiceUpdate } from "@saleor/services/types/ServiceUpdate";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import ServiceDetailsPage, {
|
import ServiceDetailsPage, {
|
||||||
ServiceDetailsPageFormData
|
ServiceDetailsPageFormData
|
||||||
} from "../../components/ServiceDetailsPage";
|
} from "../../components/ServiceDetailsPage";
|
||||||
|
@ -52,24 +53,10 @@ export const ServiceDetails: React.FC<OrderListProps> = ({
|
||||||
|
|
||||||
React.useEffect(() => onTokenClose, []);
|
React.useEffect(() => onTokenClose, []);
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
ServiceUrlDialog,
|
||||||
serviceUrl(id, {
|
ServiceUrlQueryParams
|
||||||
...params,
|
>(navigate, params => serviceUrl(id, params), params);
|
||||||
action: undefined,
|
|
||||||
id: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: ServiceUrlDialog, tokenId?: string) =>
|
|
||||||
navigate(
|
|
||||||
serviceUrl(id, {
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
id: tokenId
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const onServiceUpdate = (data: ServiceUpdate) => {
|
const onServiceUpdate = (data: ServiceUpdate) => {
|
||||||
if (maybe(() => data.serviceAccountUpdate.errors.length === 0)) {
|
if (maybe(() => data.serviceAccountUpdate.errors.length === 0)) {
|
||||||
|
@ -170,7 +157,11 @@ export const ServiceDetails: React.FC<OrderListProps> = ({
|
||||||
<ServiceDetailsPage
|
<ServiceDetailsPage
|
||||||
apiUri={API_URI}
|
apiUri={API_URI}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
errors={[]}
|
errors={maybe(
|
||||||
|
() =>
|
||||||
|
updateServiceOpts.data.serviceAccountUpdate
|
||||||
|
.errors
|
||||||
|
)}
|
||||||
token={token}
|
token={token}
|
||||||
onApiUriClick={() => open(API_URI, "blank")}
|
onApiUriClick={() => open(API_URI, "blank")}
|
||||||
onBack={handleBack}
|
onBack={handleBack}
|
||||||
|
@ -179,7 +170,9 @@ export const ServiceDetails: React.FC<OrderListProps> = ({
|
||||||
onTokenClose={onTokenClose}
|
onTokenClose={onTokenClose}
|
||||||
onTokenCreate={() => openModal("create-token")}
|
onTokenCreate={() => openModal("create-token")}
|
||||||
onTokenDelete={id =>
|
onTokenDelete={id =>
|
||||||
openModal("remove-token", id)
|
openModal("remove-token", {
|
||||||
|
id
|
||||||
|
})
|
||||||
}
|
}
|
||||||
permissions={maybe(() => shop.permissions)}
|
permissions={maybe(() => shop.permissions)}
|
||||||
service={maybe(() => data.serviceAccount)}
|
service={maybe(() => data.serviceAccount)}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import useListSettings from "@saleor/hooks/useListSettings";
|
import useListSettings from "@saleor/hooks/useListSettings";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useNotifier from "@saleor/hooks/useNotifier";
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
|
@ -20,6 +19,7 @@ import { ServiceDelete } from "@saleor/services/types/ServiceDelete";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import ServiceDeleteDialog from "../../components/ServiceDeleteDialog";
|
import ServiceDeleteDialog from "../../components/ServiceDeleteDialog";
|
||||||
import ServiceListPage from "../../components/ServiceListPage";
|
import ServiceListPage from "../../components/ServiceListPage";
|
||||||
import { useServiceListQuery } from "../../queries";
|
import { useServiceListQuery } from "../../queries";
|
||||||
|
@ -86,24 +86,10 @@ export const ServiceList: React.FC<ServiceListProps> = ({ params }) => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
ServiceListUrlDialog,
|
||||||
serviceListUrl({
|
ServiceListUrlQueryParams
|
||||||
...params,
|
>(navigate, serviceListUrl, params);
|
||||||
action: undefined,
|
|
||||||
id: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: ServiceListUrlDialog, id?: string) =>
|
|
||||||
navigate(
|
|
||||||
serviceListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
id
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
navigate(
|
navigate(
|
||||||
|
@ -131,14 +117,7 @@ export const ServiceList: React.FC<ServiceListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCreate = () => navigate(serviceAddUrl);
|
const handleCreate = () => navigate(serviceAddUrl);
|
||||||
const handleRemove = (id: string) =>
|
|
||||||
navigate(
|
|
||||||
serviceListUrl({
|
|
||||||
...params,
|
|
||||||
action: "remove",
|
|
||||||
id
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const onRemove = (data: ServiceDelete) => {
|
const onRemove = (data: ServiceDelete) => {
|
||||||
if (data.serviceAccountDelete.errors.length === 0) {
|
if (data.serviceAccountDelete.errors.length === 0) {
|
||||||
notify({
|
notify({
|
||||||
|
@ -185,7 +164,11 @@ export const ServiceList: React.FC<ServiceListProps> = ({ params }) => {
|
||||||
onPreviousPage={loadPreviousPage}
|
onPreviousPage={loadPreviousPage}
|
||||||
onUpdateListSettings={updateListSettings}
|
onUpdateListSettings={updateListSettings}
|
||||||
onRowClick={id => () => navigate(serviceUrl(id))}
|
onRowClick={id => () => navigate(serviceUrl(id))}
|
||||||
onRemove={handleRemove}
|
onRemove={id =>
|
||||||
|
openModal("remove", {
|
||||||
|
id
|
||||||
|
})
|
||||||
|
}
|
||||||
onSort={handleSort}
|
onSort={handleSort}
|
||||||
/>
|
/>
|
||||||
<ServiceDeleteDialog
|
<ServiceDeleteDialog
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
import { getSortParams } from "@saleor/utils/sort";
|
import { getSortParams } from "@saleor/utils/sort";
|
||||||
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
import createSortHandler from "@saleor/utils/handlers/sortHandler";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import StaffAddMemberDialog, {
|
import StaffAddMemberDialog, {
|
||||||
FormData as AddStaffMemberForm
|
FormData as AddStaffMemberForm
|
||||||
} from "../../components/StaffAddMemberDialog";
|
} from "../../components/StaffAddMemberDialog";
|
||||||
|
@ -92,24 +93,10 @@ export const StaffList: React.FC<StaffListProps> = ({ params }) => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
StaffListUrlDialog,
|
||||||
staffListUrl({
|
StaffListUrlQueryParams
|
||||||
...params,
|
>(navigate, staffListUrl, params);
|
||||||
action: undefined,
|
|
||||||
ids: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: StaffListUrlDialog, ids?: string[]) =>
|
|
||||||
navigate(
|
|
||||||
staffListUrl({
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
ids
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
navigate(
|
navigate(
|
||||||
|
@ -188,13 +175,7 @@ export const StaffList: React.FC<StaffListProps> = ({ params }) => {
|
||||||
staffMembers={maybe(() =>
|
staffMembers={maybe(() =>
|
||||||
data.staffUsers.edges.map(edge => edge.node)
|
data.staffUsers.edges.map(edge => edge.node)
|
||||||
)}
|
)}
|
||||||
onAdd={() =>
|
onAdd={() => openModal("add")}
|
||||||
navigate(
|
|
||||||
staffListUrl({
|
|
||||||
action: "add"
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onBack={() => navigate(configurationMenuUrl)}
|
onBack={() => navigate(configurationMenuUrl)}
|
||||||
onNextPage={loadNextPage}
|
onNextPage={loadNextPage}
|
||||||
onPreviousPage={loadPreviousPage}
|
onPreviousPage={loadPreviousPage}
|
||||||
|
|
40
src/utils/handlers/dialogActionHandlers.ts
Normal file
40
src/utils/handlers/dialogActionHandlers.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import { UseNavigatorResult } from "@saleor/hooks/useNavigator";
|
||||||
|
import { Dialog, BulkAction, SingleAction } from "@saleor/types";
|
||||||
|
|
||||||
|
type Url<T extends Dialog<any>> = (params: T) => string;
|
||||||
|
type CreateCloseModal<
|
||||||
|
TAction extends string,
|
||||||
|
TParams extends Dialog<TAction>
|
||||||
|
> = [(action: TAction, newParams?: TParams) => void, () => void];
|
||||||
|
|
||||||
|
function createDialogActionHandlers<
|
||||||
|
TAction extends string,
|
||||||
|
TParams extends Dialog<TAction> & BulkAction & SingleAction
|
||||||
|
>(
|
||||||
|
navigate: UseNavigatorResult,
|
||||||
|
url: Url<TParams>,
|
||||||
|
params: TParams
|
||||||
|
): CreateCloseModal<TAction, TParams> {
|
||||||
|
const close = () =>
|
||||||
|
navigate(
|
||||||
|
url({
|
||||||
|
...params,
|
||||||
|
action: undefined,
|
||||||
|
id: undefined,
|
||||||
|
ids: undefined
|
||||||
|
}),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
const open = (action: TAction, newParams?: TParams) =>
|
||||||
|
navigate(
|
||||||
|
url({
|
||||||
|
...params,
|
||||||
|
...newParams,
|
||||||
|
action
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return [open, close];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createDialogActionHandlers;
|
|
@ -7,10 +7,11 @@ import { sectionNames } from "@saleor/intl";
|
||||||
import { asSortParams } from "@saleor/utils/sort";
|
import { asSortParams } from "@saleor/utils/sort";
|
||||||
import { WindowTitle } from "../components/WindowTitle";
|
import { WindowTitle } from "../components/WindowTitle";
|
||||||
import {
|
import {
|
||||||
webhooksAddUrl,
|
webhookAddUrl,
|
||||||
webhooksListPath,
|
webhookListPath,
|
||||||
WebhookListUrlQueryParams,
|
WebhookListUrlQueryParams,
|
||||||
webhooksPath,
|
webhookPath,
|
||||||
|
WebhookUrlQueryParams,
|
||||||
WebhookListUrlSortField
|
WebhookListUrlSortField
|
||||||
} from "./urls";
|
} from "./urls";
|
||||||
import WebhookCreate from "./views/WebhooksCreate";
|
import WebhookCreate from "./views/WebhooksCreate";
|
||||||
|
@ -29,7 +30,7 @@ const WebhookList: React.FC<RouteComponentProps<any>> = ({ location }) => {
|
||||||
|
|
||||||
const WebhookDetails: React.FC<RouteComponentProps<any>> = ({ match }) => {
|
const WebhookDetails: React.FC<RouteComponentProps<any>> = ({ match }) => {
|
||||||
const qs = parseQs(location.search.substr(1));
|
const qs = parseQs(location.search.substr(1));
|
||||||
const params: WebhookListUrlQueryParams = qs;
|
const params: WebhookUrlQueryParams = qs;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WebhooksDetails id={decodeURIComponent(match.params.id)} params={params} />
|
<WebhooksDetails id={decodeURIComponent(match.params.id)} params={params} />
|
||||||
|
@ -42,9 +43,9 @@ const Component = () => {
|
||||||
<>
|
<>
|
||||||
<WindowTitle title={intl.formatMessage(sectionNames.webhooks)} />
|
<WindowTitle title={intl.formatMessage(sectionNames.webhooks)} />
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path={webhooksListPath} component={WebhookList} />
|
<Route exact path={webhookListPath} component={WebhookList} />
|
||||||
<Route exact path={webhooksAddUrl} component={WebhookCreate} />
|
<Route exact path={webhookAddUrl} component={WebhookCreate} />
|
||||||
<Route path={webhooksPath(":id")} component={WebhookDetails} />
|
<Route path={webhookPath(":id")} component={WebhookDetails} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,9 +11,9 @@ import {
|
||||||
Sort
|
Sort
|
||||||
} from "../types";
|
} from "../types";
|
||||||
|
|
||||||
export const webhooksSection = "/webhooks/";
|
export const webhookSection = "/webhooks/";
|
||||||
|
|
||||||
export const webhooksListPath = webhooksSection;
|
export const webhookListPath = webhookSection;
|
||||||
export enum WebhookListUrlFiltersEnum {
|
export enum WebhookListUrlFiltersEnum {
|
||||||
query = "query"
|
query = "query"
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,14 @@ export type WebhookListUrlQueryParams = ActiveTab &
|
||||||
SingleAction &
|
SingleAction &
|
||||||
WebhookListUrlFilters &
|
WebhookListUrlFilters &
|
||||||
WebhookListUrlSort;
|
WebhookListUrlSort;
|
||||||
export const webhooksListUrl = (params?: WebhookListUrlQueryParams) =>
|
export const webhookListUrl = (params?: WebhookListUrlQueryParams) =>
|
||||||
webhooksListPath + "?" + stringifyQs(params);
|
webhookListPath + "?" + stringifyQs(params);
|
||||||
|
|
||||||
export const webhooksPath = (id: string) => urlJoin(webhooksSection, id);
|
export const webhookPath = (id: string) => urlJoin(webhookSection, id);
|
||||||
export type WebhookUrlDialog = "remove";
|
export type WebhookUrlDialog = "remove";
|
||||||
export type WebhooksUrlQueryParams = Dialog<WebhookUrlDialog> & SingleAction;
|
export type WebhookUrlQueryParams = Dialog<WebhookUrlDialog> & SingleAction;
|
||||||
export const webhooksUrl = (id: string, params?: WebhooksUrlQueryParams) =>
|
export const webhookUrl = (id: string, params?: WebhookUrlQueryParams) =>
|
||||||
webhooksPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
webhookPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
||||||
|
|
||||||
export const webhooksAddPath = urlJoin(webhooksSection, "add");
|
export const webhookAddPath = urlJoin(webhookSection, "add");
|
||||||
export const webhooksAddUrl = webhooksAddPath;
|
export const webhookAddUrl = webhookAddPath;
|
||||||
|
|
|
@ -25,10 +25,10 @@ import { useWebhooksListQuery } from "../../queries";
|
||||||
import {
|
import {
|
||||||
WebhookListUrlDialog,
|
WebhookListUrlDialog,
|
||||||
WebhookListUrlFilters,
|
WebhookListUrlFilters,
|
||||||
webhooksAddUrl,
|
webhookAddUrl,
|
||||||
webhooksListUrl,
|
webhookListUrl,
|
||||||
WebhookListUrlQueryParams,
|
WebhookListUrlQueryParams,
|
||||||
webhooksUrl
|
webhookUrl
|
||||||
} from "../../urls";
|
} from "../../urls";
|
||||||
import { getSortQueryVariables } from "./sort";
|
import { getSortQueryVariables } from "./sort";
|
||||||
import {
|
import {
|
||||||
|
@ -78,7 +78,7 @@ export const WebhooksList: React.FC<WebhooksListProps> = ({ params }) => {
|
||||||
|
|
||||||
const changeFilterField = (filter: WebhookListUrlFilters) =>
|
const changeFilterField = (filter: WebhookListUrlFilters) =>
|
||||||
navigate(
|
navigate(
|
||||||
webhooksListUrl({
|
webhookListUrl({
|
||||||
...getActiveFilters(params),
|
...getActiveFilters(params),
|
||||||
...filter,
|
...filter,
|
||||||
activeTab: undefined
|
activeTab: undefined
|
||||||
|
@ -86,7 +86,7 @@ export const WebhooksList: React.FC<WebhooksListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
const closeModal = () =>
|
const closeModal = () =>
|
||||||
navigate(
|
navigate(
|
||||||
webhooksListUrl({
|
webhookListUrl({
|
||||||
...params,
|
...params,
|
||||||
action: undefined,
|
action: undefined,
|
||||||
id: undefined
|
id: undefined
|
||||||
|
@ -96,7 +96,7 @@ export const WebhooksList: React.FC<WebhooksListProps> = ({ params }) => {
|
||||||
|
|
||||||
const openModal = (action: WebhookListUrlDialog, id?: string) =>
|
const openModal = (action: WebhookListUrlDialog, id?: string) =>
|
||||||
navigate(
|
navigate(
|
||||||
webhooksListUrl({
|
webhookListUrl({
|
||||||
...params,
|
...params,
|
||||||
action,
|
action,
|
||||||
id
|
id
|
||||||
|
@ -105,7 +105,7 @@ export const WebhooksList: React.FC<WebhooksListProps> = ({ params }) => {
|
||||||
|
|
||||||
const handleTabChange = (tab: number) => {
|
const handleTabChange = (tab: number) => {
|
||||||
navigate(
|
navigate(
|
||||||
webhooksListUrl({
|
webhookListUrl({
|
||||||
activeTab: tab.toString(),
|
activeTab: tab.toString(),
|
||||||
...getFilterTabs()[tab - 1].data
|
...getFilterTabs()[tab - 1].data
|
||||||
})
|
})
|
||||||
|
@ -114,7 +114,7 @@ export const WebhooksList: React.FC<WebhooksListProps> = ({ params }) => {
|
||||||
|
|
||||||
const handleTabDelete = () => {
|
const handleTabDelete = () => {
|
||||||
deleteFilterTab(currentTab);
|
deleteFilterTab(currentTab);
|
||||||
navigate(webhooksListUrl());
|
navigate(webhookListUrl());
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTabSave = (data: SaveFilterTabDialogFormData) => {
|
const handleTabSave = (data: SaveFilterTabDialogFormData) => {
|
||||||
|
@ -127,12 +127,12 @@ export const WebhooksList: React.FC<WebhooksListProps> = ({ params }) => {
|
||||||
notify({
|
notify({
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
});
|
});
|
||||||
navigate(webhooksListUrl());
|
navigate(webhookListUrl());
|
||||||
refetch();
|
refetch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSort = createSortHandler(navigate, webhooksListUrl, params);
|
const handleSort = createSortHandler(navigate, webhookListUrl, params);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TypedWebhookDelete onCompleted={onWebhookDelete}>
|
<TypedWebhookDelete onCompleted={onWebhookDelete}>
|
||||||
|
@ -144,7 +144,7 @@ export const WebhooksList: React.FC<WebhooksListProps> = ({ params }) => {
|
||||||
);
|
);
|
||||||
const handleRemove = (id: string) => {
|
const handleRemove = (id: string) => {
|
||||||
navigate(
|
navigate(
|
||||||
webhooksListUrl({
|
webhookListUrl({
|
||||||
...params,
|
...params,
|
||||||
action: "remove",
|
action: "remove",
|
||||||
id
|
id
|
||||||
|
@ -165,7 +165,7 @@ export const WebhooksList: React.FC<WebhooksListProps> = ({ params }) => {
|
||||||
currentTab={currentTab}
|
currentTab={currentTab}
|
||||||
initialSearch={params.query || ""}
|
initialSearch={params.query || ""}
|
||||||
onSearchChange={query => changeFilterField({ query })}
|
onSearchChange={query => changeFilterField({ query })}
|
||||||
onAll={() => navigate(webhooksListUrl())}
|
onAll={() => navigate(webhookListUrl())}
|
||||||
onTabChange={handleTabChange}
|
onTabChange={handleTabChange}
|
||||||
onTabDelete={() => openModal("delete-search")}
|
onTabDelete={() => openModal("delete-search")}
|
||||||
onTabSave={() => openModal("save-search")}
|
onTabSave={() => openModal("save-search")}
|
||||||
|
@ -175,14 +175,14 @@ export const WebhooksList: React.FC<WebhooksListProps> = ({ params }) => {
|
||||||
sort={getSortParams(params)}
|
sort={getSortParams(params)}
|
||||||
webhooks={maybe(() => data.webhooks.edges.map(edge => edge.node))}
|
webhooks={maybe(() => data.webhooks.edges.map(edge => edge.node))}
|
||||||
pageInfo={pageInfo}
|
pageInfo={pageInfo}
|
||||||
onAdd={() => navigate(webhooksAddUrl)}
|
onAdd={() => navigate(webhookAddUrl)}
|
||||||
onBack={() => navigate(configurationMenuUrl)}
|
onBack={() => navigate(configurationMenuUrl)}
|
||||||
onNextPage={loadNextPage}
|
onNextPage={loadNextPage}
|
||||||
onPreviousPage={loadPreviousPage}
|
onPreviousPage={loadPreviousPage}
|
||||||
onRemove={handleRemove}
|
onRemove={handleRemove}
|
||||||
onSort={handleSort}
|
onSort={handleSort}
|
||||||
onUpdateListSettings={updateListSettings}
|
onUpdateListSettings={updateListSettings}
|
||||||
onRowClick={id => () => navigate(webhooksUrl(id))}
|
onRowClick={id => () => navigate(webhookUrl(id))}
|
||||||
/>
|
/>
|
||||||
<WebhookDeleteDialog
|
<WebhookDeleteDialog
|
||||||
confirmButtonState={webhookDeleteOpts.status}
|
confirmButtonState={webhookDeleteOpts.status}
|
||||||
|
|
|
@ -11,11 +11,7 @@ import { useIntl } from "react-intl";
|
||||||
import { maybe } from "../../misc";
|
import { maybe } from "../../misc";
|
||||||
import WebhookCreatePage, { FormData } from "../components/WebhookCreatePage";
|
import WebhookCreatePage, { FormData } from "../components/WebhookCreatePage";
|
||||||
import { TypedWebhookCreate } from "../mutations";
|
import { TypedWebhookCreate } from "../mutations";
|
||||||
import {
|
import { webhookListUrl, WebhookListUrlQueryParams, webhookUrl } from "../urls";
|
||||||
webhooksListUrl,
|
|
||||||
WebhookListUrlQueryParams,
|
|
||||||
webhooksUrl
|
|
||||||
} from "../urls";
|
|
||||||
|
|
||||||
export interface WebhooksCreateProps {
|
export interface WebhooksCreateProps {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -38,11 +34,11 @@ export const WebhooksCreate: React.FC<WebhooksCreateProps> = () => {
|
||||||
notify({
|
notify({
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
});
|
});
|
||||||
navigate(webhooksUrl(data.webhookCreate.webhook.id));
|
navigate(webhookUrl(data.webhookCreate.webhook.id));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBack = () => navigate(webhooksListUrl());
|
const handleBack = () => navigate(webhookListUrl());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TypedWebhookCreate onCompleted={onSubmit}>
|
<TypedWebhookCreate onCompleted={onSubmit}>
|
||||||
|
|
|
@ -11,20 +11,21 @@ import { WebhookEventTypeEnum } from "@saleor/types/globalTypes";
|
||||||
import WebhookDeleteDialog from "@saleor/webhooks/components/WebhookDeleteDialog";
|
import WebhookDeleteDialog from "@saleor/webhooks/components/WebhookDeleteDialog";
|
||||||
import { WebhookDelete } from "@saleor/webhooks/types/WebhookDelete";
|
import { WebhookDelete } from "@saleor/webhooks/types/WebhookDelete";
|
||||||
import { WebhookUpdate } from "@saleor/webhooks/types/WebhookUpdate";
|
import { WebhookUpdate } from "@saleor/webhooks/types/WebhookUpdate";
|
||||||
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import { maybe } from "../../misc";
|
import { maybe } from "../../misc";
|
||||||
import WebhooksDetailsPage from "../components/WebhooksDetailsPage";
|
import WebhooksDetailsPage from "../components/WebhooksDetailsPage";
|
||||||
import { TypedWebhookDelete, TypedWebhookUpdate } from "../mutations";
|
import { TypedWebhookDelete, TypedWebhookUpdate } from "../mutations";
|
||||||
import { TypedWebhooksDetailsQuery } from "../queries";
|
import { TypedWebhooksDetailsQuery } from "../queries";
|
||||||
import {
|
import {
|
||||||
webhooksListUrl,
|
webhookListUrl,
|
||||||
WebhookListUrlQueryParams,
|
webhookUrl,
|
||||||
webhooksUrl,
|
WebhookUrlDialog,
|
||||||
WebhookUrlDialog
|
WebhookUrlQueryParams
|
||||||
} from "../urls";
|
} from "../urls";
|
||||||
|
|
||||||
export interface WebhooksDetailsProps {
|
export interface WebhooksDetailsProps {
|
||||||
id: string;
|
id: string;
|
||||||
params: WebhookListUrlQueryParams;
|
params: WebhookUrlQueryParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WebhooksDetails: React.FC<WebhooksDetailsProps> = ({
|
export const WebhooksDetails: React.FC<WebhooksDetailsProps> = ({
|
||||||
|
@ -41,31 +42,17 @@ export const WebhooksDetails: React.FC<WebhooksDetailsProps> = ({
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
});
|
});
|
||||||
|
|
||||||
const closeModal = () =>
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
navigate(
|
WebhookUrlDialog,
|
||||||
webhooksUrl(id, {
|
WebhookUrlQueryParams
|
||||||
...params,
|
>(navigate, params => webhookUrl(id, params), params);
|
||||||
action: undefined,
|
|
||||||
id: undefined
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = (action: WebhookUrlDialog, tokenId?: string) =>
|
|
||||||
navigate(
|
|
||||||
webhooksUrl(id, {
|
|
||||||
...params,
|
|
||||||
action,
|
|
||||||
id: tokenId
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const onWebhookDelete = (data: WebhookDelete) => {
|
const onWebhookDelete = (data: WebhookDelete) => {
|
||||||
if (data.webhookDelete.errors.length === 0) {
|
if (data.webhookDelete.errors.length === 0) {
|
||||||
notify({
|
notify({
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
});
|
});
|
||||||
navigate(webhooksListUrl());
|
navigate(webhookListUrl());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -74,7 +61,7 @@ export const WebhooksDetails: React.FC<WebhooksDetailsProps> = ({
|
||||||
notify({
|
notify({
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
});
|
});
|
||||||
navigate(webhooksUrl(data.webhookUpdate.webhook.id));
|
navigate(webhookUrl(data.webhookUpdate.webhook.id));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,7 +100,7 @@ export const WebhooksDetails: React.FC<WebhooksDetailsProps> = ({
|
||||||
edge => edge.node
|
edge => edge.node
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
onBack={() => navigate(webhooksListUrl())}
|
onBack={() => navigate(webhookListUrl())}
|
||||||
onDelete={() => openModal("remove")}
|
onDelete={() => openModal("remove")}
|
||||||
onSubmit={data => {
|
onSubmit={data => {
|
||||||
webhookUpdate({
|
webhookUpdate({
|
||||||
|
|
Loading…
Reference in a new issue