Use product search hook
This commit is contained in:
parent
bd7130d196
commit
fff2a8caea
6 changed files with 89 additions and 96 deletions
|
@ -13,8 +13,8 @@ import usePaginator, {
|
|||
createPaginationState
|
||||
} from "@saleor/hooks/usePaginator";
|
||||
import { commonMessages } from "@saleor/intl";
|
||||
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||
import { DEFAULT_INITIAL_SEARCH_DATA, PAGINATE_BY } from "../../config";
|
||||
import SearchProducts from "../../containers/SearchProducts";
|
||||
import { getMutationState, maybe } from "../../misc";
|
||||
import { productUrl } from "../../products/urls";
|
||||
import { CollectionInput } from "../../types/globalTypes";
|
||||
|
@ -50,6 +50,9 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
|
|||
);
|
||||
const paginate = usePaginator();
|
||||
const intl = useIntl();
|
||||
const { search, result } = useProductSearch({
|
||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||
});
|
||||
|
||||
const closeModal = () =>
|
||||
navigate(
|
||||
|
@ -284,8 +287,6 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
|
|||
toggle={toggle}
|
||||
toggleAll={toggleAll}
|
||||
/>
|
||||
<SearchProducts variables={DEFAULT_INITIAL_SEARCH_DATA}>
|
||||
{({ search, result }) => (
|
||||
<AssignProductDialog
|
||||
confirmButtonState={assignTransitionState}
|
||||
open={params.action === "assign"}
|
||||
|
@ -305,8 +306,6 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
|
|||
.filter(suggestedProduct => suggestedProduct.id)
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</SearchProducts>
|
||||
<ActionDialog
|
||||
confirmButtonState={removeTransitionState}
|
||||
onClose={closeModal}
|
||||
|
|
|
@ -21,7 +21,7 @@ import TableCellAvatar from "@saleor/components/TableCellAvatar";
|
|||
import useSearchQuery from "@saleor/hooks/useSearchQuery";
|
||||
import { buttonMessages } from "@saleor/intl";
|
||||
import { maybe } from "@saleor/misc";
|
||||
import { SearchProducts_search_edges_node } from "../../containers/SearchProducts/types/SearchProducts";
|
||||
import { SearchProducts_search_edges_node } from "@saleor/searches/types/SearchProducts";
|
||||
import Checkbox from "../Checkbox";
|
||||
|
||||
export interface FormData {
|
||||
|
|
|
@ -18,10 +18,10 @@ import useShop from "@saleor/hooks/useShop";
|
|||
import { commonMessages, sectionNames } from "@saleor/intl";
|
||||
import useCategorySearch from "@saleor/searches/useCategorySearch";
|
||||
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
||||
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||
import { categoryUrl } from "../../categories/urls";
|
||||
import { collectionUrl } from "../../collections/urls";
|
||||
import { DEFAULT_INITIAL_SEARCH_DATA, PAGINATE_BY } from "../../config";
|
||||
import SearchProducts from "../../containers/SearchProducts";
|
||||
import { decimal, getMutationState, joinDateTime, maybe } from "../../misc";
|
||||
import { productUrl } from "../../products/urls";
|
||||
import { DiscountValueTypeEnum, SaleType } from "../../types/globalTypes";
|
||||
|
@ -78,6 +78,12 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
|||
} = useCollectionSearch({
|
||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||
});
|
||||
const {
|
||||
search: searchProducts,
|
||||
result: searchProductsOpts
|
||||
} = useProductSearch({
|
||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||
});
|
||||
|
||||
const paginationState = createPaginationState(PAGINATE_BY, params);
|
||||
const changeTab = (tab: SaleDetailsPageTab) => {
|
||||
|
@ -353,13 +359,6 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
|||
toggle={toggle}
|
||||
toggleAll={toggleAll}
|
||||
/>
|
||||
<SearchProducts
|
||||
variables={DEFAULT_INITIAL_SEARCH_DATA}
|
||||
>
|
||||
{({
|
||||
search: searchProducts,
|
||||
result: searchProductsOpts
|
||||
}) => (
|
||||
<AssignProductDialog
|
||||
confirmButtonState={assignTransitionState}
|
||||
open={params.action === "assign-product"}
|
||||
|
@ -387,8 +386,6 @@ export const SaleDetails: React.FC<SaleDetailsProps> = ({ id, params }) => {
|
|||
)
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</SearchProducts>
|
||||
<AssignCategoriesDialog
|
||||
categories={maybe(() =>
|
||||
searchCategoriesOpts.data.search.edges
|
||||
|
|
|
@ -18,10 +18,10 @@ import useShop from "@saleor/hooks/useShop";
|
|||
import { commonMessages, sectionNames } from "@saleor/intl";
|
||||
import useCategorySearch from "@saleor/searches/useCategorySearch";
|
||||
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
||||
import useProductSearch from "@saleor/searches/useProductSearch";
|
||||
import { categoryUrl } from "../../categories/urls";
|
||||
import { collectionUrl } from "../../collections/urls";
|
||||
import { DEFAULT_INITIAL_SEARCH_DATA, PAGINATE_BY } from "../../config";
|
||||
import SearchProducts from "../../containers/SearchProducts";
|
||||
import { decimal, getMutationState, joinDateTime, maybe } from "../../misc";
|
||||
import { productUrl } from "../../products/urls";
|
||||
import {
|
||||
|
@ -80,6 +80,12 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
|||
} = useCollectionSearch({
|
||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||
});
|
||||
const {
|
||||
search: searchProducts,
|
||||
result: searchProductsOpts
|
||||
} = useProductSearch({
|
||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||
});
|
||||
|
||||
const paginationState = createPaginationState(PAGINATE_BY, params);
|
||||
const changeTab = (tab: VoucherDetailsPageTab) => {
|
||||
|
@ -509,13 +515,6 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
|||
[]
|
||||
)}
|
||||
/>
|
||||
<SearchProducts
|
||||
variables={DEFAULT_INITIAL_SEARCH_DATA}
|
||||
>
|
||||
{({
|
||||
search: searchProducts,
|
||||
result: searchProductsOpts
|
||||
}) => (
|
||||
<AssignProductDialog
|
||||
confirmButtonState={assignTransitionState}
|
||||
open={params.action === "assign-product"}
|
||||
|
@ -543,8 +542,6 @@ export const VoucherDetails: React.FC<VoucherDetailsProps> = ({
|
|||
)
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</SearchProducts>
|
||||
<ActionDialog
|
||||
open={
|
||||
params.action === "unassign-category" &&
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import gql from "graphql-tag";
|
||||
|
||||
import makeTopLevelSearch from "@saleor/hooks/makeTopLevelSearch";
|
||||
import { pageInfoFragment } from "@saleor/queries";
|
||||
import TopLevelSearch from "../TopLevelSearch";
|
||||
import {
|
||||
SearchProducts,
|
||||
SearchProductsVariables
|
||||
|
@ -27,6 +27,6 @@ export const searchProducts = gql`
|
|||
}
|
||||
`;
|
||||
|
||||
export default TopLevelSearch<SearchProducts, SearchProductsVariables>(
|
||||
export default makeTopLevelSearch<SearchProducts, SearchProductsVariables>(
|
||||
searchProducts
|
||||
);
|
Loading…
Reference in a new issue