@soppiya/app-bridge 1.1.7 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/components/articles-picker/ui/ArticlesPicker.d.ts +2 -1
  2. package/dist/components/articles-picker/ui/ArticlesPicker.js +2 -1
  3. package/dist/components/articles-picker/ui/ProductPicker.stories.d.ts +2 -1
  4. package/dist/components/blogs-picker/ui/BlogsPicker.d.ts +2 -1
  5. package/dist/components/blogs-picker/ui/BlogsPicker.js +2 -1
  6. package/dist/components/blogs-picker/ui/BlogsPicker.stories.d.ts +2 -1
  7. package/dist/components/collections-pciker/api/query.d.ts +5 -2
  8. package/dist/components/collections-pciker/api/query.js +8 -8
  9. package/dist/components/collections-pciker/model/useCollections.d.ts +1 -1
  10. package/dist/components/collections-pciker/model/useCollections.js +3 -4
  11. package/dist/components/collections-pciker/ui/CollectionPicker.d.ts +2 -1
  12. package/dist/components/collections-pciker/ui/CollectionPicker.js +2 -1
  13. package/dist/components/collections-pciker/ui/CollectionPicker.stories.d.ts +2 -1
  14. package/dist/components/country-picker/api/query.d.ts +8 -0
  15. package/dist/components/country-picker/api/query.js +19 -0
  16. package/dist/components/country-picker/index.d.ts +1 -0
  17. package/dist/components/country-picker/index.js +2 -0
  18. package/dist/components/country-picker/model/useContry.d.ts +26 -0
  19. package/dist/components/country-picker/model/useContry.js +48 -0
  20. package/dist/components/country-picker/ui/CountryPicker.d.ts +10 -0
  21. package/dist/components/country-picker/ui/CountryPicker.js +115 -0
  22. package/dist/components/country-picker/ui/CountryPicker.stories.d.ts +13 -0
  23. package/dist/components/country-picker/ui/CountryPicker.stories.js +11 -0
  24. package/dist/components/customers-picker/api/query.d.ts +8 -0
  25. package/dist/components/customers-picker/api/query.js +22 -0
  26. package/dist/components/customers-picker/index.d.ts +1 -0
  27. package/dist/components/customers-picker/index.js +2 -0
  28. package/dist/components/customers-picker/model/useCustomers.d.ts +30 -0
  29. package/dist/components/customers-picker/model/useCustomers.js +48 -0
  30. package/dist/components/customers-picker/ui/CustomersPicker.d.ts +10 -0
  31. package/dist/components/customers-picker/ui/CustomersPicker.js +114 -0
  32. package/dist/components/customers-picker/ui/CustomersPicker.stories.d.ts +13 -0
  33. package/dist/components/customers-picker/ui/CustomersPicker.stories.js +11 -0
  34. package/dist/components/index.d.ts +3 -0
  35. package/dist/components/index.js +3 -0
  36. package/dist/components/link-list-picker/ui/LinkListPicker.d.ts +2 -1
  37. package/dist/components/link-list-picker/ui/LinkListPicker.js +2 -1
  38. package/dist/components/link-list-picker/ui/LinkListPicker.stories.d.ts +2 -1
  39. package/dist/components/media/Media.d.ts +2 -1
  40. package/dist/components/media/Media.js +2 -1
  41. package/dist/components/media/Media.stories.d.ts +2 -1
  42. package/dist/components/metaobjects-entries-picker/ui/MetaobjectEntriesPicker.d.ts +2 -1
  43. package/dist/components/metaobjects-entries-picker/ui/MetaobjectEntriesPicker.js +2 -1
  44. package/dist/components/metaobjects-entries-picker/ui/MetaobjectEntriesPicker.stories.d.ts +2 -1
  45. package/dist/components/metaobjects-picker/ui/MetaobjectsPicker.d.ts +2 -1
  46. package/dist/components/metaobjects-picker/ui/MetaobjectsPicker.js +2 -1
  47. package/dist/components/metaobjects-picker/ui/MetaobjectsPicker.stories.d.ts +2 -1
  48. package/dist/components/pages-picker/ui/PagesPicker.d.ts +2 -1
  49. package/dist/components/pages-picker/ui/PagesPicker.js +2 -1
  50. package/dist/components/pages-picker/ui/PagesPicker.stories.d.ts +2 -1
  51. package/dist/components/products-picker/ui/ProductPicker.d.ts +2 -1
  52. package/dist/components/products-picker/ui/ProductPicker.js +2 -1
  53. package/dist/components/products-picker/ui/ProductsPicker.stories.d.ts +2 -1
  54. package/dist/components/segments-picker/api/query.d.ts +8 -0
  55. package/dist/components/segments-picker/api/query.js +18 -0
  56. package/dist/components/segments-picker/index.d.ts +1 -0
  57. package/dist/components/segments-picker/index.js +2 -0
  58. package/dist/components/segments-picker/model/useSegments.d.ts +25 -0
  59. package/dist/components/segments-picker/model/useSegments.js +48 -0
  60. package/dist/components/segments-picker/ui/SegmentsPicker.d.ts +10 -0
  61. package/dist/components/segments-picker/ui/SegmentsPicker.js +106 -0
  62. package/dist/components/segments-picker/ui/SegmentsPicker.stories.d.ts +13 -0
  63. package/dist/components/segments-picker/ui/SegmentsPicker.stories.js +11 -0
  64. package/dist/components/variants-picker/ui/VariantsPicker.d.ts +2 -1
  65. package/dist/components/variants-picker/ui/VariantsPicker.js +2 -1
  66. package/dist/components/variants-picker/ui/VariantsPicker.stories.d.ts +2 -1
  67. package/dist/shared/graphql/gql.d.ts +17 -2
  68. package/dist/shared/graphql/gql.js +5 -2
  69. package/dist/shared/graphql/graphql.d.ts +150 -38
  70. package/dist/shared/graphql/graphql.js +1303 -284
  71. package/dist/styles.css +12 -0
  72. package/package.json +2 -2
@@ -2,8 +2,9 @@ type Props = {
2
2
  title?: string;
3
3
  initialIds?: string[];
4
4
  limit?: number;
5
+ okButtonLoading?: boolean;
5
6
  onClose?: () => void;
6
7
  onOk?: (articles: string[]) => void;
7
8
  };
8
- declare const ArticlesPicker: ({ title, initialIds, limit, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
9
+ declare const ArticlesPicker: ({ title, initialIds, limit, okButtonLoading, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
9
10
  export default ArticlesPicker;
@@ -6,7 +6,7 @@ import classnames from "classnames";
6
6
  import lodash from "lodash";
7
7
  import { useState } from "react";
8
8
  import { userArticles } from "../model/useArticles.js";
9
- const ArticlesPicker = ({ title = "Articles", initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
+ const ArticlesPicker = ({ title = "Articles", initialIds = [], limit = 1 / 0, okButtonLoading, onClose, onOk })=>{
10
10
  const [selectedVariant, setSelectedVariant] = useState(initialIds);
11
11
  const { query, debounceQuery, onChangeQuery } = useFilterQuery();
12
12
  const { articles, pageInfo, isLoadingArticles, fetchMoreArticles } = userArticles({
@@ -30,6 +30,7 @@ const ArticlesPicker = ({ title = "Articles", initialIds = [], limit = 1 / 0, on
30
30
  gap: 50,
31
31
  justifyContent: "end",
32
32
  children: /*#__PURE__*/ jsx(Button, {
33
+ loading: okButtonLoading,
33
34
  disabled: lodash.isEmpty(selectedVariant) || isDisabled,
34
35
  onClick: handleOk,
35
36
  children: "Add"
@@ -1,9 +1,10 @@
1
1
  declare const meta: {
2
2
  title: string;
3
- component: ({ title, initialIds, limit, onClose, onOk }: {
3
+ component: ({ title, initialIds, limit, okButtonLoading, onClose, onOk }: {
4
4
  title?: string;
5
5
  initialIds?: string[];
6
6
  limit?: number;
7
+ okButtonLoading?: boolean;
7
8
  onClose?: () => void;
8
9
  onOk?: (articles: string[]) => void;
9
10
  }) => import("react/jsx-runtime").JSX.Element;
@@ -2,8 +2,9 @@ type Props = {
2
2
  title?: string;
3
3
  initialIds?: string[];
4
4
  limit?: number;
5
+ okButtonLoading?: boolean;
5
6
  onClose?: () => void;
6
7
  onOk?: (products: string[]) => void;
7
8
  };
8
- declare const BlogsPicker: ({ title, initialIds, limit, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
9
+ declare const BlogsPicker: ({ title, initialIds, limit, okButtonLoading, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
9
10
  export default BlogsPicker;
@@ -6,7 +6,7 @@ import classnames from "classnames";
6
6
  import lodash from "lodash";
7
7
  import { useState } from "react";
8
8
  import { useBlogs } from "../model/useBlogs.js";
9
- const BlogsPicker = ({ title = "Blogs", initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
+ const BlogsPicker = ({ title = "Blogs", initialIds = [], limit = 1 / 0, okButtonLoading, onClose, onOk })=>{
10
10
  const [selectedBlog, setSelectedBlog] = useState(initialIds);
11
11
  const { query, debounceQuery, onChangeQuery } = useFilterQuery();
12
12
  const { blogs, isLoadingBlogs, fetchMoreBlogs, pageInfo } = useBlogs({
@@ -29,6 +29,7 @@ const BlogsPicker = ({ title = "Blogs", initialIds = [], limit = 1 / 0, onClose,
29
29
  const ButtonJSX = /*#__PURE__*/ jsx(InlineStack, {
30
30
  justifyContent: "end",
31
31
  children: /*#__PURE__*/ jsx(Button, {
32
+ loading: okButtonLoading,
32
33
  onClick: handleOk,
33
34
  disabled: lodash.isEmpty(selectedBlog) || isDisabled,
34
35
  children: "Add"
@@ -1,9 +1,10 @@
1
1
  declare const meta: {
2
2
  title: string;
3
- component: ({ title, initialIds, limit, onClose, onOk }: {
3
+ component: ({ title, initialIds, limit, okButtonLoading, onClose, onOk }: {
4
4
  title?: string;
5
5
  initialIds?: string[];
6
6
  limit?: number;
7
+ okButtonLoading?: boolean;
7
8
  onClose?: () => void;
8
9
  onOk?: (products: string[]) => void;
9
10
  }) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,8 @@
1
1
  export declare const collectionQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../../shared/graphql/graphql").CollectionsQuery, import("../../../shared/graphql/graphql").Exact<{
2
- skip?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
3
- filterKeys?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").CollectionFilterKeys>;
2
+ after?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
3
+ before?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
4
+ first?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
5
+ last?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
4
6
  query?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["String"]["input"]>;
7
+ filterKeys?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").CollectionFilterKeys>;
5
8
  }>>;
@@ -1,6 +1,12 @@
1
1
  import { graphql } from "../../../shared/graphql/index.js";
2
- const collectionQuery = graphql(`query Collections($skip: Int, $filterKeys: CollectionFilterKeys, $query: String) {
3
- collections(skip: $skip, filterKeys: $filterKeys, query: $query) {
2
+ const collectionQuery = graphql(`query Collections($after: ID, $before: ID, $first: Int, $last: Int, $query: String, $filterKeys: CollectionFilterKeys) {
3
+ collections(after: $after, before: $before, first: $first, last: $last, query: $query, filterKeys: $filterKeys) {
4
+ pageInfo {
5
+ endCursor
6
+ hasNextPage
7
+ hasPreviousPage
8
+ startCursor
9
+ }
4
10
  edges {
5
11
  node {
6
12
  _id
@@ -11,12 +17,6 @@ const collectionQuery = graphql(`query Collections($skip: Int, $filterKeys: Coll
11
17
  }
12
18
  }
13
19
  }
14
- pageInfo {
15
- endCursor
16
- hasNextPage
17
- hasPreviousPage
18
- startCursor
19
- }
20
20
  }
21
21
  }`);
22
22
  export { collectionQuery };
@@ -1,6 +1,6 @@
1
1
  import { CollectionFilterKeys } from "../../../shared/graphql/graphql";
2
2
  type Props = {
3
- skip?: number;
3
+ skip?: boolean;
4
4
  query?: string | null;
5
5
  filterKeys?: CollectionFilterKeys;
6
6
  };
@@ -3,10 +3,10 @@ import { collectionQuery } from "../api/query.js";
3
3
  const useCollections = (props = {})=>{
4
4
  const { skip, query, filterKeys } = props;
5
5
  const { data, loading: isLoadingCollections, error, fetchMore } = useQuery(collectionQuery, {
6
+ skip,
6
7
  variables: {
7
8
  filterKeys,
8
- query,
9
- skip
9
+ query
10
10
  }
11
11
  });
12
12
  const collections = data?.collections?.edges?.map((edge)=>edge?.node)?.filter((node)=>null != node);
@@ -16,8 +16,7 @@ const useCollections = (props = {})=>{
16
16
  fetchMore({
17
17
  variables: {
18
18
  filterKeys,
19
- query,
20
- skip
19
+ query
21
20
  }
22
21
  });
23
22
  };
@@ -2,8 +2,9 @@ type Props = {
2
2
  title?: string;
3
3
  initialIds?: string[];
4
4
  limit?: number;
5
+ okButtonLoading?: boolean;
5
6
  onClose?: () => void;
6
7
  onOk?: (collections: string[]) => void;
7
8
  };
8
- declare const CollectionPicker: ({ title, initialIds, limit, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
9
+ declare const CollectionPicker: ({ title, initialIds, limit, okButtonLoading, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
9
10
  export default CollectionPicker;
@@ -6,7 +6,7 @@ import classnames from "classnames";
6
6
  import lodash from "lodash";
7
7
  import { useState } from "react";
8
8
  import { useCollections } from "../model/useCollections.js";
9
- const CollectionPicker = ({ title = "Collections", initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
+ const CollectionPicker = ({ title = "Collections", initialIds = [], limit = 1 / 0, okButtonLoading, onClose, onOk })=>{
10
10
  const [selectedCollection, setSelectedCollection] = useState(initialIds);
11
11
  const { query, debounceQuery, onChangeQuery } = useFilterQuery();
12
12
  const { collections, isLoadingCollections, fetchMoreCollections, pageInfo } = useCollections({
@@ -28,6 +28,7 @@ const CollectionPicker = ({ title = "Collections", initialIds = [], limit = 1 /
28
28
  const ButtonJSX = /*#__PURE__*/ jsx(InlineStack, {
29
29
  justifyContent: "end",
30
30
  children: /*#__PURE__*/ jsx(Button, {
31
+ loading: okButtonLoading,
31
32
  disabled: lodash.isEmpty(selectedCollection) || isDisabled,
32
33
  onClick: handleOk,
33
34
  children: "Add"
@@ -1,9 +1,10 @@
1
1
  declare const meta: {
2
2
  title: string;
3
- component: ({ title, initialIds, limit, onClose, onOk }: {
3
+ component: ({ title, initialIds, limit, okButtonLoading, onClose, onOk }: {
4
4
  title?: string;
5
5
  initialIds?: string[];
6
6
  limit?: number;
7
+ okButtonLoading?: boolean;
7
8
  onClose?: () => void;
8
9
  onOk?: (collections: string[]) => void;
9
10
  }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ export declare const countryQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../../shared/graphql/graphql")._CountriesQuery, import("../../../shared/graphql/graphql").Exact<{
2
+ after?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
3
+ before?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
4
+ first?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
5
+ last?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
6
+ query?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["String"]["input"]>;
7
+ filterKeys?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql")._CountryFilterKeys>;
8
+ }>>;
@@ -0,0 +1,19 @@
1
+ import { graphql } from "../../../shared/graphql/index.js";
2
+ const countryQuery = graphql(`query _countries($after: ID, $before: ID, $first: Int, $last: Int, $query: String, $filterKeys: _CountryFilterKeys) {
3
+ _countries(after: $after, before: $before, first: $first, last: $last, query: $query, filterKeys: $filterKeys) {
4
+ pageInfo {
5
+ endCursor
6
+ hasNextPage
7
+ hasPreviousPage
8
+ startCursor
9
+ }
10
+ edges {
11
+ node {
12
+ _id
13
+ name
14
+ flag
15
+ }
16
+ }
17
+ }
18
+ }`);
19
+ export { countryQuery };
@@ -0,0 +1 @@
1
+ export { default as CountryPicker } from "./ui/CountryPicker";
@@ -0,0 +1,2 @@
1
+ import CountryPicker from "./ui/CountryPicker.js";
2
+ export { CountryPicker };
@@ -0,0 +1,26 @@
1
+ import { _CountryFilterKeys } from "../../../shared/graphql/graphql";
2
+ type Props = {
3
+ skip?: boolean;
4
+ first?: number;
5
+ query?: string | null;
6
+ filterKeys?: _CountryFilterKeys | null;
7
+ };
8
+ export declare const useCountry: (props?: Props) => {
9
+ countries: {
10
+ __typename: "_Country";
11
+ _id?: string | null;
12
+ name?: string | null;
13
+ flag?: string | null;
14
+ }[];
15
+ pageInfo: {
16
+ __typename: "PageInfo";
17
+ endCursor?: string | null;
18
+ hasNextPage?: boolean | null;
19
+ hasPreviousPage?: boolean | null;
20
+ startCursor?: string | null;
21
+ } | null | undefined;
22
+ isLoadingCountry: boolean;
23
+ error: import("@apollo/client").ErrorLike | undefined;
24
+ fetchMoreCountries: () => void;
25
+ };
26
+ export {};
@@ -0,0 +1,48 @@
1
+ import { useQuery } from "@apollo/client/react";
2
+ import { useRef } from "react";
3
+ import { countryQuery } from "../api/query.js";
4
+ const useCountry = (props = {})=>{
5
+ const { skip, first, query, filterKeys } = props;
6
+ const refArray = useRef([]);
7
+ const { data, loading: isLoadingCountry, error, fetchMore } = useQuery(countryQuery, {
8
+ skip,
9
+ variables: {
10
+ first,
11
+ query,
12
+ filterKeys
13
+ }
14
+ });
15
+ const countries = data?._countries?.edges?.map((edge)=>edge?.node).filter((node)=>null != node) ?? refArray.current;
16
+ const pageInfo = data?._countries?.pageInfo;
17
+ const fetchMoreCountries = ()=>{
18
+ if (!pageInfo?.hasNextPage) return;
19
+ fetchMore({
20
+ variables: {
21
+ first,
22
+ query,
23
+ after: pageInfo.endCursor,
24
+ filterKeys
25
+ },
26
+ updateQuery (prev, { fetchMoreResult }) {
27
+ if (!fetchMoreResult._countries?.edges || !prev._countries?.edges) return prev;
28
+ return {
29
+ _countries: {
30
+ ...fetchMoreResult._countries,
31
+ edges: [
32
+ ...prev._countries.edges,
33
+ ...fetchMoreResult._countries.edges
34
+ ]
35
+ }
36
+ };
37
+ }
38
+ });
39
+ };
40
+ return {
41
+ countries,
42
+ pageInfo,
43
+ isLoadingCountry,
44
+ error,
45
+ fetchMoreCountries
46
+ };
47
+ };
48
+ export { useCountry };
@@ -0,0 +1,10 @@
1
+ type Props = {
2
+ title?: string;
3
+ initialIds?: string[];
4
+ limit?: number;
5
+ okButtonLoading?: boolean;
6
+ onClose?: () => void;
7
+ onOk?: (countries: string[]) => void;
8
+ };
9
+ declare const CountryPicker: ({ title, initialIds, limit, okButtonLoading, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
10
+ export default CountryPicker;
@@ -0,0 +1,115 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { InfinityScroll } from "../../infinity-scroll/index.js";
3
+ import { useFilterQuery } from "../../../shared/lib/index.js";
4
+ import { BlockStack, Box, Button, Checkbox, Image, InlineStack, Input, Modal, Spinner, Text } from "@soppiya/elementus";
5
+ import classnames from "classnames";
6
+ import lodash from "lodash";
7
+ import { useState } from "react";
8
+ import { useCountry } from "../model/useContry.js";
9
+ const CountryPicker = ({ title = "Countries", initialIds = [], limit = 1 / 0, okButtonLoading, onClose, onOk })=>{
10
+ const [selectedCustomer, setSelectedCustomer] = useState(initialIds);
11
+ const { query, debounceQuery, onChangeQuery } = useFilterQuery();
12
+ const { countries, pageInfo, isLoadingCountry, fetchMoreCountries } = useCountry({
13
+ first: 20,
14
+ query: debounceQuery
15
+ });
16
+ const isReached = limit !== 1 / 0 && selectedCustomer.length >= limit;
17
+ const isDisabled = limit !== 1 / 0 && selectedCustomer.length > limit;
18
+ const handleSelectCustomer = (customerId)=>{
19
+ if (selectedCustomer.includes(customerId)) return void setSelectedCustomer((prev)=>prev.filter((id)=>customerId !== id));
20
+ if (isReached) return;
21
+ setSelectedCustomer((prev)=>[
22
+ ...prev,
23
+ customerId
24
+ ]);
25
+ };
26
+ const handleOk = ()=>{
27
+ if (lodash.isFunction(onOk)) onOk(selectedCustomer);
28
+ };
29
+ const buttonsJSX = /*#__PURE__*/ jsx(InlineStack, {
30
+ gap: 50,
31
+ justifyContent: "end",
32
+ children: /*#__PURE__*/ jsx(Button, {
33
+ loading: okButtonLoading,
34
+ disabled: lodash.isEmpty(selectedCustomer) || isDisabled,
35
+ onClick: handleOk,
36
+ children: "Add"
37
+ })
38
+ });
39
+ return /*#__PURE__*/ jsx(Modal, {
40
+ open: true,
41
+ title: title,
42
+ bodyPadding: 0,
43
+ buttons: buttonsJSX,
44
+ onClose: onClose,
45
+ children: /*#__PURE__*/ jsxs(BlockStack, {
46
+ children: [
47
+ /*#__PURE__*/ jsx(Box, {
48
+ padding: 60,
49
+ children: /*#__PURE__*/ jsx(Input, {
50
+ size: "sm",
51
+ type: "search",
52
+ value: query ?? "",
53
+ onChange: (event)=>onChangeQuery(event.target.value)
54
+ })
55
+ }),
56
+ isLoadingCountry ? /*#__PURE__*/ jsx(InlineStack, {
57
+ justifyContent: "center",
58
+ padding: 80,
59
+ children: /*#__PURE__*/ jsx(Spinner, {
60
+ size: "md"
61
+ })
62
+ }) : /*#__PURE__*/ jsxs(BlockStack, {
63
+ children: [
64
+ countries.map((country)=>/*#__PURE__*/ jsx(InlineStack, {
65
+ stack: "full",
66
+ className: classnames('lg:cursor-pointer border-t border-t-[#ebebeb]!', {
67
+ 'bg-[#f1f1f1ab] cursor-default!': !selectedCustomer.includes(country._id) && isReached
68
+ }),
69
+ gapX: 60,
70
+ padding: 60,
71
+ onClick: ()=>handleSelectCustomer(String(country._id)),
72
+ children: /*#__PURE__*/ jsx(BlockStack, {
73
+ children: /*#__PURE__*/ jsxs(InlineStack, {
74
+ alignItems: "center",
75
+ gapX: 70,
76
+ children: [
77
+ /*#__PURE__*/ jsx(Box, {
78
+ children: /*#__PURE__*/ jsx(Checkbox, {
79
+ disabled: !selectedCustomer.includes(country._id) && isReached,
80
+ checked: selectedCustomer.includes(String(country._id)),
81
+ onChange: ()=>{}
82
+ })
83
+ }),
84
+ /*#__PURE__*/ jsxs(InlineStack, {
85
+ gapX: 50,
86
+ children: [
87
+ /*#__PURE__*/ jsx(Box, {
88
+ children: /*#__PURE__*/ jsx(Image, {
89
+ url: country.flag || "",
90
+ className: "w-[30px]! h-5!"
91
+ })
92
+ }),
93
+ /*#__PURE__*/ jsx(Text, {
94
+ size: "md",
95
+ weight: "medium",
96
+ className: "capitalize!",
97
+ children: country.name
98
+ })
99
+ ]
100
+ })
101
+ ]
102
+ })
103
+ })
104
+ })),
105
+ pageInfo?.hasNextPage && /*#__PURE__*/ jsx(InfinityScroll, {
106
+ onFetch: fetchMoreCountries
107
+ })
108
+ ]
109
+ })
110
+ ]
111
+ })
112
+ });
113
+ };
114
+ const ui_CountryPicker = CountryPicker;
115
+ export { ui_CountryPicker as default };
@@ -0,0 +1,13 @@
1
+ declare const meta: {
2
+ title: string;
3
+ component: ({ title, initialIds, limit, okButtonLoading, onClose, onOk }: {
4
+ title?: string;
5
+ initialIds?: string[];
6
+ limit?: number;
7
+ okButtonLoading?: boolean;
8
+ onClose?: () => void;
9
+ onOk?: (countries: string[]) => void;
10
+ }) => import("react/jsx-runtime").JSX.Element;
11
+ };
12
+ export default meta;
13
+ export declare const Default: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import CountryPicker from "./CountryPicker.js";
3
+ const meta = {
4
+ title: "Example/CountryPicker",
5
+ component: CountryPicker
6
+ };
7
+ const CountryPicker_stories = meta;
8
+ const Default = ()=>/*#__PURE__*/ jsx(CountryPicker, {
9
+ title: "Select Countries"
10
+ });
11
+ export { Default, CountryPicker_stories as default };
@@ -0,0 +1,8 @@
1
+ export declare const customersQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../../shared/graphql/graphql").CustomersQuery, import("../../../shared/graphql/graphql").Exact<{
2
+ after?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
3
+ before?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
4
+ first?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
5
+ last?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
6
+ query?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["String"]["input"]>;
7
+ filterKeys?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").CustomerFilterKeys>;
8
+ }>>;
@@ -0,0 +1,22 @@
1
+ import { graphql } from "../../../shared/graphql/index.js";
2
+ const customersQuery = graphql(`query Customers($after: ID, $before: ID, $first: Int, $last: Int, $query: String, $filterKeys: CustomerFilterKeys) {
3
+ customers(after: $after, before: $before, first: $first, last: $last, query: $query, filterKeys: $filterKeys) {
4
+ pageInfo {
5
+ endCursor
6
+ hasNextPage
7
+ hasPreviousPage
8
+ startCursor
9
+ }
10
+ edges {
11
+ node {
12
+ _id
13
+ first_name
14
+ last_name
15
+ email {
16
+ address
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }`);
22
+ export { customersQuery };
@@ -0,0 +1 @@
1
+ export { default as CustomersPicker } from "./ui/CustomersPicker";
@@ -0,0 +1,2 @@
1
+ import CustomersPicker from "./ui/CustomersPicker.js";
2
+ export { CustomersPicker };
@@ -0,0 +1,30 @@
1
+ import { CustomerFilterKeys } from "../../../shared/graphql/graphql";
2
+ type Props = {
3
+ skip?: boolean;
4
+ first?: number;
5
+ query?: string | null;
6
+ filterKeys?: CustomerFilterKeys | null;
7
+ };
8
+ export declare const useCustomers: (props?: Props) => {
9
+ customers: {
10
+ __typename: "Customer";
11
+ _id?: string | null;
12
+ first_name?: string | null;
13
+ last_name?: string | null;
14
+ email?: {
15
+ __typename: "CustomerEmail";
16
+ address?: string | null;
17
+ } | null;
18
+ }[];
19
+ pageInfo: {
20
+ __typename: "PageInfo";
21
+ endCursor?: string | null;
22
+ hasNextPage?: boolean | null;
23
+ hasPreviousPage?: boolean | null;
24
+ startCursor?: string | null;
25
+ } | null | undefined;
26
+ isLoadingCustomers: boolean;
27
+ error: import("@apollo/client").ErrorLike | undefined;
28
+ fetchMoreCustomers: () => void;
29
+ };
30
+ export {};
@@ -0,0 +1,48 @@
1
+ import { useQuery } from "@apollo/client/react";
2
+ import { useRef } from "react";
3
+ import { customersQuery } from "../api/query.js";
4
+ const useCustomers = (props = {})=>{
5
+ const { skip, first, query, filterKeys } = props;
6
+ const refArray = useRef([]);
7
+ const { data, loading: isLoadingCustomers, error, fetchMore } = useQuery(customersQuery, {
8
+ skip,
9
+ variables: {
10
+ first,
11
+ query,
12
+ filterKeys
13
+ }
14
+ });
15
+ const pageInfo = data?.customers?.pageInfo;
16
+ const customers = data?.customers?.edges?.map((edge)=>edge?.node).filter((node)=>null != node) ?? refArray.current;
17
+ const fetchMoreCustomers = ()=>{
18
+ if (!pageInfo?.hasNextPage) return;
19
+ fetchMore({
20
+ variables: {
21
+ first,
22
+ query,
23
+ after: pageInfo.endCursor,
24
+ filterKeys
25
+ },
26
+ updateQuery (prev, { fetchMoreResult }) {
27
+ if (!fetchMoreResult.customers?.edges || !prev.customers?.edges) return prev;
28
+ return {
29
+ customers: {
30
+ ...fetchMoreResult.customers,
31
+ edges: [
32
+ ...prev.customers.edges,
33
+ ...fetchMoreResult.customers.edges
34
+ ]
35
+ }
36
+ };
37
+ }
38
+ });
39
+ };
40
+ return {
41
+ customers,
42
+ pageInfo,
43
+ isLoadingCustomers,
44
+ error,
45
+ fetchMoreCustomers
46
+ };
47
+ };
48
+ export { useCustomers };
@@ -0,0 +1,10 @@
1
+ type Props = {
2
+ title?: string;
3
+ initialIds?: string[];
4
+ limit?: number;
5
+ okButtonLoading?: boolean;
6
+ onClose?: () => void;
7
+ onOk?: (customers: string[]) => void;
8
+ };
9
+ declare const CustomersPicker: ({ title, initialIds, limit, okButtonLoading, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
10
+ export default CustomersPicker;