Use query hooks in category details view
This commit is contained in:
parent
419525f493
commit
ce2624bb9f
1 changed files with 186 additions and 195 deletions
|
@ -17,8 +17,7 @@ import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
import { PAGINATE_BY } from "../../config";
|
import { PAGINATE_BY } from "../../config";
|
||||||
import { maybe } from "../../misc";
|
import { maybe } from "../../misc";
|
||||||
import { TypedProductBulkDeleteMutation } from "../../products/mutations";
|
import { useProductBulkDeleteMutation } from "../../products/mutations";
|
||||||
import { productBulkDelete } from "../../products/types/productBulkDelete";
|
|
||||||
import { productAddUrl, productUrl } from "../../products/urls";
|
import { productAddUrl, productUrl } from "../../products/urls";
|
||||||
import { CategoryInput } from "../../types/globalTypes";
|
import { CategoryInput } from "../../types/globalTypes";
|
||||||
import {
|
import {
|
||||||
|
@ -129,6 +128,23 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
onCompleted: handleBulkCategoryDelete
|
onCompleted: handleBulkCategoryDelete
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [
|
||||||
|
productBulkDelete,
|
||||||
|
productBulkDeleteOpts
|
||||||
|
] = useProductBulkDeleteMutation({
|
||||||
|
onCompleted: data => {
|
||||||
|
if (data.productBulkDelete.errors.length === 0) {
|
||||||
|
closeModal();
|
||||||
|
notify({
|
||||||
|
status: "success",
|
||||||
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
|
});
|
||||||
|
refetch();
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const changeTab = (tabName: CategoryPageTab) => {
|
const changeTab = (tabName: CategoryPageTab) => {
|
||||||
reset();
|
reset();
|
||||||
navigate(
|
navigate(
|
||||||
|
@ -143,18 +159,6 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
CategoryUrlQueryParams
|
CategoryUrlQueryParams
|
||||||
>(navigate, params => categoryUrl(id, params), params);
|
>(navigate, params => categoryUrl(id, params), params);
|
||||||
|
|
||||||
const handleBulkProductDelete = (data: productBulkDelete) => {
|
|
||||||
if (data.productBulkDelete.errors.length === 0) {
|
|
||||||
closeModal();
|
|
||||||
notify({
|
|
||||||
status: "success",
|
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
|
||||||
});
|
|
||||||
refetch();
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
|
const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
|
||||||
params.activeTab === CategoryPageTab.categories
|
params.activeTab === CategoryPageTab.categories
|
||||||
? maybe(() => data.category.children.pageInfo)
|
? maybe(() => data.category.children.pageInfo)
|
||||||
|
@ -166,9 +170,6 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WindowTitle title={maybe(() => data.category.name)} />
|
<WindowTitle title={maybe(() => data.category.name)} />
|
||||||
<TypedProductBulkDeleteMutation onCompleted={handleBulkProductDelete}>
|
|
||||||
{(productBulkDelete, productBulkDeleteOpts) => (
|
|
||||||
<>
|
|
||||||
<CategoryUpdatePage
|
<CategoryUpdatePage
|
||||||
changeTab={changeTab}
|
changeTab={changeTab}
|
||||||
currentTab={params.activeTab}
|
currentTab={params.activeTab}
|
||||||
|
@ -179,10 +180,7 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
onAddProduct={() => navigate(productAddUrl)}
|
onAddProduct={() => navigate(productAddUrl)}
|
||||||
onBack={() =>
|
onBack={() =>
|
||||||
navigate(
|
navigate(
|
||||||
maybe(
|
maybe(() => categoryUrl(data.category.parent.id), categoryListUrl())
|
||||||
() => categoryUrl(data.category.parent.id),
|
|
||||||
categoryListUrl()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onCategoryClick={id => () => navigate(categoryUrl(id))}
|
onCategoryClick={id => () => navigate(categoryUrl(id))}
|
||||||
|
@ -311,9 +309,7 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
defaultMessage="{counter,plural,one{Are you sure you want to delete this category?} other{Are you sure you want to delete {displayQuantity} categories?}}"
|
defaultMessage="{counter,plural,one{Are you sure you want to delete this category?} other{Are you sure you want to delete {displayQuantity} categories?}}"
|
||||||
values={{
|
values={{
|
||||||
counter: maybe(() => params.ids.length),
|
counter: maybe(() => params.ids.length),
|
||||||
displayQuantity: (
|
displayQuantity: <strong>{maybe(() => params.ids.length)}</strong>
|
||||||
<strong>{maybe(() => params.ids.length)}</strong>
|
|
||||||
)
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</DialogContentText>
|
</DialogContentText>
|
||||||
|
@ -341,17 +337,12 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
||||||
defaultMessage="{counter,plural,one{Are you sure you want to delete this product?} other{Are you sure you want to delete {displayQuantity} products?}}"
|
defaultMessage="{counter,plural,one{Are you sure you want to delete this product?} other{Are you sure you want to delete {displayQuantity} products?}}"
|
||||||
values={{
|
values={{
|
||||||
counter: maybe(() => params.ids.length),
|
counter: maybe(() => params.ids.length),
|
||||||
displayQuantity: (
|
displayQuantity: <strong>{maybe(() => params.ids.length)}</strong>
|
||||||
<strong>{maybe(() => params.ids.length)}</strong>
|
|
||||||
)
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</DialogContentText>
|
</DialogContentText>
|
||||||
</ActionDialog>
|
</ActionDialog>
|
||||||
</>
|
</>
|
||||||
)}
|
|
||||||
</TypedProductBulkDeleteMutation>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default CategoryDetails;
|
export default CategoryDetails;
|
||||||
|
|
Loading…
Reference in a new issue