@soppiya/app-bridge 1.1.6 → 1.1.8
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.
- package/dist/components/collections-pciker/api/query.d.ts +5 -2
- package/dist/components/collections-pciker/api/query.js +8 -8
- package/dist/components/collections-pciker/model/useCollections.d.ts +1 -1
- package/dist/components/collections-pciker/model/useCollections.js +3 -4
- package/dist/components/country-picker/api/query.d.ts +8 -0
- package/dist/components/country-picker/api/query.js +19 -0
- package/dist/components/country-picker/index.d.ts +1 -0
- package/dist/components/country-picker/index.js +2 -0
- package/dist/components/country-picker/model/useContry.d.ts +26 -0
- package/dist/components/country-picker/model/useContry.js +48 -0
- package/dist/components/country-picker/ui/CountryPicker.d.ts +9 -0
- package/dist/components/country-picker/ui/CountryPicker.js +114 -0
- package/dist/components/country-picker/ui/CountryPicker.stories.d.ts +12 -0
- package/dist/components/country-picker/ui/CountryPicker.stories.js +11 -0
- package/dist/components/customers-picker/api/query.d.ts +8 -0
- package/dist/components/customers-picker/api/query.js +22 -0
- package/dist/components/customers-picker/index.d.ts +1 -0
- package/dist/components/customers-picker/index.js +2 -0
- package/dist/components/customers-picker/model/useCustomers.d.ts +30 -0
- package/dist/components/customers-picker/model/useCustomers.js +48 -0
- package/dist/components/customers-picker/ui/CustomersPicker.d.ts +9 -0
- package/dist/components/customers-picker/ui/CustomersPicker.js +113 -0
- package/dist/components/customers-picker/ui/CustomersPicker.stories.d.ts +12 -0
- package/dist/components/customers-picker/ui/CustomersPicker.stories.js +11 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +3 -0
- package/dist/components/media/Media.js +1 -1
- package/dist/components/meta-data/api/query.js +3 -0
- package/dist/components/meta-data/model/meta.types.js +3 -1
- package/dist/components/meta-data/model/useGetMetaFields.d.ts +4 -0
- package/dist/components/meta-data/ui/MetaData.stories.d.ts +1 -0
- package/dist/components/meta-data/ui/MetaData.stories.js +22 -1
- package/dist/components/meta-data/ui/MetaDataItem.js +22 -0
- package/dist/components/meta-data/ui/MetaobjectRefMetaField.d.ts +3 -0
- package/dist/components/meta-data/ui/MetaobjectRefMetaField.js +30 -0
- package/dist/components/meta-data/ui/SingleLineTextMetaField.js +10 -9
- package/dist/components/segments-picker/api/query.d.ts +8 -0
- package/dist/components/segments-picker/api/query.js +18 -0
- package/dist/components/segments-picker/index.d.ts +1 -0
- package/dist/components/segments-picker/index.js +2 -0
- package/dist/components/segments-picker/model/useSegments.d.ts +25 -0
- package/dist/components/segments-picker/model/useSegments.js +48 -0
- package/dist/components/segments-picker/ui/SegmentsPicker.d.ts +9 -0
- package/dist/components/segments-picker/ui/SegmentsPicker.js +105 -0
- package/dist/components/segments-picker/ui/SegmentsPicker.stories.d.ts +12 -0
- package/dist/components/segments-picker/ui/SegmentsPicker.stories.js +11 -0
- package/dist/shared/graphql/gql.d.ts +19 -4
- package/dist/shared/graphql/gql.js +6 -3
- package/dist/shared/graphql/graphql.d.ts +190 -55
- package/dist/shared/graphql/graphql.js +1309 -271
- package/dist/styles.css +12 -0
- package/package.json +2 -2
|
@@ -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
|
-
|
|
3
|
-
|
|
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($
|
|
3
|
-
collections(
|
|
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 };
|
|
@@ -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
|
};
|
|
@@ -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,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,9 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
title?: string;
|
|
3
|
+
initialIds?: string[];
|
|
4
|
+
limit?: number;
|
|
5
|
+
onClose?: () => void;
|
|
6
|
+
onOk?: (countries: string[]) => void;
|
|
7
|
+
};
|
|
8
|
+
declare const CountryPicker: ({ title, initialIds, limit, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default CountryPicker;
|
|
@@ -0,0 +1,114 @@
|
|
|
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, 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
|
+
disabled: lodash.isEmpty(selectedCustomer) || isDisabled,
|
|
34
|
+
onClick: handleOk,
|
|
35
|
+
children: "Add"
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
return /*#__PURE__*/ jsx(Modal, {
|
|
39
|
+
open: true,
|
|
40
|
+
title: title,
|
|
41
|
+
bodyPadding: 0,
|
|
42
|
+
buttons: buttonsJSX,
|
|
43
|
+
onClose: onClose,
|
|
44
|
+
children: /*#__PURE__*/ jsxs(BlockStack, {
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ jsx(Box, {
|
|
47
|
+
padding: 60,
|
|
48
|
+
children: /*#__PURE__*/ jsx(Input, {
|
|
49
|
+
size: "sm",
|
|
50
|
+
type: "search",
|
|
51
|
+
value: query ?? "",
|
|
52
|
+
onChange: (event)=>onChangeQuery(event.target.value)
|
|
53
|
+
})
|
|
54
|
+
}),
|
|
55
|
+
isLoadingCountry ? /*#__PURE__*/ jsx(InlineStack, {
|
|
56
|
+
justifyContent: "center",
|
|
57
|
+
padding: 80,
|
|
58
|
+
children: /*#__PURE__*/ jsx(Spinner, {
|
|
59
|
+
size: "md"
|
|
60
|
+
})
|
|
61
|
+
}) : /*#__PURE__*/ jsxs(BlockStack, {
|
|
62
|
+
children: [
|
|
63
|
+
countries.map((country)=>/*#__PURE__*/ jsx(InlineStack, {
|
|
64
|
+
stack: "full",
|
|
65
|
+
className: classnames('lg:cursor-pointer border-t border-t-[#ebebeb]!', {
|
|
66
|
+
'bg-[#f1f1f1ab] cursor-default!': !selectedCustomer.includes(country._id) && isReached
|
|
67
|
+
}),
|
|
68
|
+
gapX: 60,
|
|
69
|
+
padding: 60,
|
|
70
|
+
onClick: ()=>handleSelectCustomer(String(country._id)),
|
|
71
|
+
children: /*#__PURE__*/ jsx(BlockStack, {
|
|
72
|
+
children: /*#__PURE__*/ jsxs(InlineStack, {
|
|
73
|
+
alignItems: "center",
|
|
74
|
+
gapX: 70,
|
|
75
|
+
children: [
|
|
76
|
+
/*#__PURE__*/ jsx(Box, {
|
|
77
|
+
children: /*#__PURE__*/ jsx(Checkbox, {
|
|
78
|
+
disabled: !selectedCustomer.includes(country._id) && isReached,
|
|
79
|
+
checked: selectedCustomer.includes(String(country._id)),
|
|
80
|
+
onChange: ()=>{}
|
|
81
|
+
})
|
|
82
|
+
}),
|
|
83
|
+
/*#__PURE__*/ jsxs(InlineStack, {
|
|
84
|
+
gapX: 50,
|
|
85
|
+
children: [
|
|
86
|
+
/*#__PURE__*/ jsx(Box, {
|
|
87
|
+
children: /*#__PURE__*/ jsx(Image, {
|
|
88
|
+
url: country.flag || "",
|
|
89
|
+
className: "w-[30px]! h-5!"
|
|
90
|
+
})
|
|
91
|
+
}),
|
|
92
|
+
/*#__PURE__*/ jsx(Text, {
|
|
93
|
+
size: "md",
|
|
94
|
+
weight: "medium",
|
|
95
|
+
className: "capitalize!",
|
|
96
|
+
children: country.name
|
|
97
|
+
})
|
|
98
|
+
]
|
|
99
|
+
})
|
|
100
|
+
]
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})),
|
|
104
|
+
pageInfo?.hasNextPage && /*#__PURE__*/ jsx(InfinityScroll, {
|
|
105
|
+
onFetch: fetchMoreCountries
|
|
106
|
+
})
|
|
107
|
+
]
|
|
108
|
+
})
|
|
109
|
+
]
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
const ui_CountryPicker = CountryPicker;
|
|
114
|
+
export { ui_CountryPicker as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const meta: {
|
|
2
|
+
title: string;
|
|
3
|
+
component: ({ title, initialIds, limit, onClose, onOk }: {
|
|
4
|
+
title?: string;
|
|
5
|
+
initialIds?: string[];
|
|
6
|
+
limit?: number;
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
onOk?: (countries: string[]) => void;
|
|
9
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
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,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,9 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
title?: string;
|
|
3
|
+
initialIds?: string[];
|
|
4
|
+
limit?: number;
|
|
5
|
+
onClose?: () => void;
|
|
6
|
+
onOk?: (customers: string[]) => void;
|
|
7
|
+
};
|
|
8
|
+
declare const CustomersPicker: ({ title, initialIds, limit, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default CustomersPicker;
|
|
@@ -0,0 +1,113 @@
|
|
|
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, 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 { useCustomers } from "../model/useCustomers.js";
|
|
9
|
+
const CustomersPicker = ({ title = "Customers", initialIds = [], limit = 1 / 0, onClose, onOk })=>{
|
|
10
|
+
const [selectedCustomer, setSelectedCustomer] = useState(initialIds);
|
|
11
|
+
const { query, debounceQuery, onChangeQuery } = useFilterQuery();
|
|
12
|
+
const { customers, pageInfo, isLoadingCustomers, fetchMoreCustomers } = useCustomers({
|
|
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
|
+
disabled: lodash.isEmpty(selectedCustomer) || isDisabled,
|
|
34
|
+
onClick: handleOk,
|
|
35
|
+
children: "Add"
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
return /*#__PURE__*/ jsx(Modal, {
|
|
39
|
+
open: true,
|
|
40
|
+
title: title,
|
|
41
|
+
bodyPadding: 0,
|
|
42
|
+
buttons: buttonsJSX,
|
|
43
|
+
onClose: onClose,
|
|
44
|
+
children: /*#__PURE__*/ jsxs(BlockStack, {
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ jsx(Box, {
|
|
47
|
+
padding: 60,
|
|
48
|
+
children: /*#__PURE__*/ jsx(Input, {
|
|
49
|
+
size: "sm",
|
|
50
|
+
type: "search",
|
|
51
|
+
value: query ?? "",
|
|
52
|
+
onChange: (event)=>onChangeQuery(event.target.value)
|
|
53
|
+
})
|
|
54
|
+
}),
|
|
55
|
+
isLoadingCustomers ? /*#__PURE__*/ jsx(InlineStack, {
|
|
56
|
+
justifyContent: "center",
|
|
57
|
+
padding: 80,
|
|
58
|
+
children: /*#__PURE__*/ jsx(Spinner, {
|
|
59
|
+
size: "md"
|
|
60
|
+
})
|
|
61
|
+
}) : /*#__PURE__*/ jsxs(BlockStack, {
|
|
62
|
+
children: [
|
|
63
|
+
customers.map((customer)=>/*#__PURE__*/ jsx(InlineStack, {
|
|
64
|
+
stack: "full",
|
|
65
|
+
className: classnames('lg:cursor-pointer border-t border-t-[#ebebeb]!', {
|
|
66
|
+
'bg-[#f1f1f1ab] cursor-default!': !selectedCustomer.includes(customer._id) && isReached
|
|
67
|
+
}),
|
|
68
|
+
gapX: 60,
|
|
69
|
+
padding: 60,
|
|
70
|
+
onClick: ()=>handleSelectCustomer(String(customer._id)),
|
|
71
|
+
children: /*#__PURE__*/ jsx(BlockStack, {
|
|
72
|
+
children: /*#__PURE__*/ jsxs(InlineStack, {
|
|
73
|
+
alignItems: "center",
|
|
74
|
+
gapX: 70,
|
|
75
|
+
children: [
|
|
76
|
+
/*#__PURE__*/ jsx(Box, {
|
|
77
|
+
children: /*#__PURE__*/ jsx(Checkbox, {
|
|
78
|
+
disabled: !selectedCustomer.includes(customer._id) && isReached,
|
|
79
|
+
checked: selectedCustomer.includes(String(customer._id)),
|
|
80
|
+
onChange: ()=>{}
|
|
81
|
+
})
|
|
82
|
+
}),
|
|
83
|
+
/*#__PURE__*/ jsxs(BlockStack, {
|
|
84
|
+
children: [
|
|
85
|
+
/*#__PURE__*/ jsx(Text, {
|
|
86
|
+
size: "md",
|
|
87
|
+
weight: "medium",
|
|
88
|
+
className: "capitalize!",
|
|
89
|
+
children: customer.first_name + " " + customer.last_name
|
|
90
|
+
}),
|
|
91
|
+
/*#__PURE__*/ jsx(Text, {
|
|
92
|
+
size: "sm",
|
|
93
|
+
color: "secondary",
|
|
94
|
+
truncate: "truncate-1",
|
|
95
|
+
children: customer.email?.address
|
|
96
|
+
})
|
|
97
|
+
]
|
|
98
|
+
})
|
|
99
|
+
]
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
})),
|
|
103
|
+
pageInfo?.hasNextPage && /*#__PURE__*/ jsx(InfinityScroll, {
|
|
104
|
+
onFetch: fetchMoreCustomers
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
})
|
|
108
|
+
]
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const ui_CustomersPicker = CustomersPicker;
|
|
113
|
+
export { ui_CustomersPicker as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const meta: {
|
|
2
|
+
title: string;
|
|
3
|
+
component: ({ title, initialIds, limit, onClose, onOk }: {
|
|
4
|
+
title?: string;
|
|
5
|
+
initialIds?: string[];
|
|
6
|
+
limit?: number;
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
onOk?: (customers: string[]) => void;
|
|
9
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
export declare const Default: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import CustomersPicker from "./CustomersPicker.js";
|
|
3
|
+
const meta = {
|
|
4
|
+
title: "Example/CustomersPicker",
|
|
5
|
+
component: CustomersPicker
|
|
6
|
+
};
|
|
7
|
+
const CustomersPicker_stories = meta;
|
|
8
|
+
const Default = ()=>/*#__PURE__*/ jsx(CustomersPicker, {
|
|
9
|
+
title: "Select Customer"
|
|
10
|
+
});
|
|
11
|
+
export { Default, CustomersPicker_stories as default };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./articles-picker";
|
|
2
2
|
export * from "./blogs-picker";
|
|
3
3
|
export * from "./collections-pciker";
|
|
4
|
+
export * from "./country-picker";
|
|
5
|
+
export * from "./customers-picker";
|
|
4
6
|
export * from "./link-list-picker";
|
|
5
7
|
export * from "./media";
|
|
6
8
|
export * from "./meta-data";
|
|
@@ -9,4 +11,5 @@ export * from "./metaobjects-picker";
|
|
|
9
11
|
export * from "./pages-picker";
|
|
10
12
|
export * from "./products-picker";
|
|
11
13
|
export * from "./savebar";
|
|
14
|
+
export * from "./segments-picker";
|
|
12
15
|
export * from "./variants-picker";
|
package/dist/components/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./articles-picker/index.js";
|
|
2
2
|
export * from "./blogs-picker/index.js";
|
|
3
3
|
export * from "./collections-pciker/index.js";
|
|
4
|
+
export * from "./country-picker/index.js";
|
|
5
|
+
export * from "./customers-picker/index.js";
|
|
4
6
|
export * from "./link-list-picker/index.js";
|
|
5
7
|
export * from "./media/index.js";
|
|
6
8
|
export * from "./meta-data/index.js";
|
|
@@ -9,4 +11,5 @@ export * from "./metaobjects-picker/index.js";
|
|
|
9
11
|
export * from "./pages-picker/index.js";
|
|
10
12
|
export * from "./products-picker/index.js";
|
|
11
13
|
export * from "./savebar/index.js";
|
|
14
|
+
export * from "./segments-picker/index.js";
|
|
12
15
|
export * from "./variants-picker/index.js";
|
|
@@ -262,7 +262,7 @@ const Media_Media = ({ title = "Media", types = [
|
|
|
262
262
|
children: /*#__PURE__*/ jsx(Button, {
|
|
263
263
|
variant: "outline",
|
|
264
264
|
color: "secondary",
|
|
265
|
-
className: "
|
|
265
|
+
className: "px-2!",
|
|
266
266
|
disabled: !isMediaSelected,
|
|
267
267
|
loading: isDeletingMedias,
|
|
268
268
|
onClick: handleDeleteMedias,
|