Skip to content

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

Extract onQueryChange as generic handler

dominik-zeglen8769cbc07730
diff --git a/saleor/static/dashboard-next/misc.ts b/saleor/static/dashboard-next/misc.ts
index c89827576f..36f9f33f59 100644
--- a/saleor/static/dashboard-next/misc.ts
+++ b/saleor/static/dashboard-next/misc.ts
@@ -1,9 +1,11 @@
import moment from "moment-timezone";
import { MutationFn, MutationResult } from "react-apollo";
import urlJoin from "url-join";
+
import { ConfirmButtonTransitionState } from "./components/ConfirmButton/ConfirmButton";
import { APP_MOUNT_URI } from "./config";
import { AddressType } from "./customers/types";
+import { ChangeEvent } from "./hooks/useForm";
import i18n from "./i18n";
import { PartialMutationProviderOutput, UserError } from "./types";
import {
@@ -271,3 +273,14 @@ export function generateCode(charNum: number) {
}
return result;
}
+
+export function onQueryChange(
+ event: ChangeEvent,
+ onFetch: (data: string) => void,
+ setQuery: (data: string) => void
+) {
+ const value = event.target.value;
+
+ onFetch(value);
+ setQuery(value);
+}
diff --git a/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
index 5a1f2574a4..f18884e234 100644
--- a/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
@@ -25,8 +25,8 @@ import ConfirmButton, {
import Money from "@saleor/components/Money";
import TableCellAvatar from "@saleor/components/TableCellAvatar";
import { ChangeEvent } from "@saleor/hooks/useForm";
-import i18n from "../../../i18n";
-import { maybe, renderCollection } from "../../../misc";
+import i18n from "@saleor/i18n";
+import { maybe, onQueryChange, renderCollection } from "@saleor/misc";
import {
SearchOrderVariant_products_edges_node,
SearchOrderVariant_products_edges_node_variants
@@ -150,17 +150,6 @@ const onVariantAdd = (
)
: setVariants([...variants, variant]);
-function onQueryChange(
- event: ChangeEvent,
- onFetch: (data: string) => void,
- setQuery: (data: string) => void
-) {
- const value = event.target.value;
-
- onFetch(value);
- setQuery(value);
-}
-
const OrderProductAddDialog = withStyles(styles, {
name: "OrderProductAddDialog"
})(