@open-tender/store 1.1.171 → 1.1.173
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/cjs/components/Switch.d.ts +15 -0
- package/dist/cjs/components/Switch.js +23 -0
- package/dist/cjs/components/TagsFilter.d.ts +7 -0
- package/dist/cjs/components/TagsFilter.js +47 -0
- package/dist/esm/components/Switch.d.ts +15 -0
- package/dist/esm/components/Switch.js +21 -0
- package/dist/esm/components/TagsFilter.d.ts +7 -0
- package/dist/esm/components/TagsFilter.js +45 -0
- package/package.json +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SwitchProps } from '@open-tender/ui';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
declare const Switch: ({ id, label, on, isRequired, disabled, falseTrackColor, thumbColor, trueTrackColor, onChange, children }: {
|
|
4
|
+
id: number | string;
|
|
5
|
+
label: string;
|
|
6
|
+
on: boolean;
|
|
7
|
+
falseTrackColor?: string;
|
|
8
|
+
trueTrackColor?: string;
|
|
9
|
+
thumbColor?: string;
|
|
10
|
+
isRequired: boolean;
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
onChange: (value: boolean) => void;
|
|
13
|
+
children: (props: SwitchProps) => ReactNode;
|
|
14
|
+
}) => ReactNode;
|
|
15
|
+
export default Switch;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var hooks_1 = require("../app/hooks");
|
|
4
|
+
var slices_1 = require("../slices");
|
|
5
|
+
var Switch = function (_a) {
|
|
6
|
+
var id = _a.id, label = _a.label, on = _a.on, isRequired = _a.isRequired, disabled = _a.disabled, falseTrackColor = _a.falseTrackColor, thumbColor = _a.thumbColor, trueTrackColor = _a.trueTrackColor, onChange = _a.onChange, children = _a.children;
|
|
7
|
+
var config = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig).switch;
|
|
8
|
+
if (!config)
|
|
9
|
+
return null;
|
|
10
|
+
return children({
|
|
11
|
+
id: id,
|
|
12
|
+
config: config,
|
|
13
|
+
label: label,
|
|
14
|
+
value: on,
|
|
15
|
+
onTagSwitch: onChange,
|
|
16
|
+
isRequired: isRequired,
|
|
17
|
+
disabled: disabled,
|
|
18
|
+
falseTrackColor: falseTrackColor,
|
|
19
|
+
thumbColor: thumbColor,
|
|
20
|
+
trueTrackColor: trueTrackColor
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
exports.default = Switch;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SwitchProps, TagsFilterProps } from '@open-tender/ui';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
declare const TagsFilter: ({ children, SwitchView }: {
|
|
4
|
+
children: (props: TagsFilterProps) => ReactNode;
|
|
5
|
+
SwitchView: (props: SwitchProps) => ReactNode;
|
|
6
|
+
}) => React.ReactNode;
|
|
7
|
+
export default TagsFilter;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
var hooks_1 = require("../app/hooks");
|
|
6
|
+
var slices_1 = require("../slices");
|
|
7
|
+
var Switch_1 = tslib_1.__importDefault(require("./Switch"));
|
|
8
|
+
var TagsFilter = function (_a) {
|
|
9
|
+
var children = _a.children, SwitchView = _a.SwitchView;
|
|
10
|
+
var config = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig).tags;
|
|
11
|
+
var dispatch = (0, hooks_1.useAppDispatch)();
|
|
12
|
+
var _b = (0, hooks_1.useAppSelector)(slices_1.selectTags), tags = _b.entities, selectedTags = _b.selectedTags, loading = _b.loading, error = _b.error;
|
|
13
|
+
var _c = (0, react_1.useState)([]), localSelectedTags = _c[0], setLocalSelectedTags = _c[1];
|
|
14
|
+
var isLoading = loading === 'pending';
|
|
15
|
+
(0, react_1.useEffect)(function () {
|
|
16
|
+
setLocalSelectedTags(selectedTags.map(function (tag) { return tag.tag_id; }));
|
|
17
|
+
}, [selectedTags]);
|
|
18
|
+
var onTagSwitch = function (tag) {
|
|
19
|
+
setLocalSelectedTags(function (prevSelectedTags) {
|
|
20
|
+
if (prevSelectedTags.includes(tag.tag_id)) {
|
|
21
|
+
return prevSelectedTags.filter(function (id) { return id !== tag.tag_id; });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return tslib_1.__spreadArray(tslib_1.__spreadArray([], prevSelectedTags, true), [tag.tag_id], false);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var handleSubmit = function () {
|
|
29
|
+
var newSelectedTags = tags.filter(function (tag) {
|
|
30
|
+
return localSelectedTags.includes(tag.tag_id);
|
|
31
|
+
});
|
|
32
|
+
dispatch((0, slices_1.setSelectedTags)(newSelectedTags));
|
|
33
|
+
};
|
|
34
|
+
var handlers = { onTagSwitch: onTagSwitch, handleSubmit: handleSubmit };
|
|
35
|
+
var renderSwitch = (0, react_1.useCallback)(function (props) {
|
|
36
|
+
return (react_1.default.createElement(Switch_1.default, { key: props.id, id: props.id, children: SwitchView, label: props.label, on: props.value, onChange: props.onTagSwitch, disabled: false, isRequired: true }));
|
|
37
|
+
}, [SwitchView]);
|
|
38
|
+
return children({
|
|
39
|
+
config: config,
|
|
40
|
+
handlers: handlers,
|
|
41
|
+
isLoading: isLoading,
|
|
42
|
+
renderSwitch: renderSwitch,
|
|
43
|
+
tags: tags,
|
|
44
|
+
error: error === null || error === void 0 ? void 0 : error.detail
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
exports.default = TagsFilter;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SwitchProps } from '@open-tender/ui';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
declare const Switch: ({ id, label, on, isRequired, disabled, falseTrackColor, thumbColor, trueTrackColor, onChange, children }: {
|
|
4
|
+
id: number | string;
|
|
5
|
+
label: string;
|
|
6
|
+
on: boolean;
|
|
7
|
+
falseTrackColor?: string;
|
|
8
|
+
trueTrackColor?: string;
|
|
9
|
+
thumbColor?: string;
|
|
10
|
+
isRequired: boolean;
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
onChange: (value: boolean) => void;
|
|
13
|
+
children: (props: SwitchProps) => ReactNode;
|
|
14
|
+
}) => ReactNode;
|
|
15
|
+
export default Switch;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useAppSelector } from '../app/hooks';
|
|
2
|
+
import { selectKioskConfig } from '../slices';
|
|
3
|
+
var Switch = function (_a) {
|
|
4
|
+
var id = _a.id, label = _a.label, on = _a.on, isRequired = _a.isRequired, disabled = _a.disabled, falseTrackColor = _a.falseTrackColor, thumbColor = _a.thumbColor, trueTrackColor = _a.trueTrackColor, onChange = _a.onChange, children = _a.children;
|
|
5
|
+
var config = useAppSelector(selectKioskConfig).switch;
|
|
6
|
+
if (!config)
|
|
7
|
+
return null;
|
|
8
|
+
return children({
|
|
9
|
+
id: id,
|
|
10
|
+
config: config,
|
|
11
|
+
label: label,
|
|
12
|
+
value: on,
|
|
13
|
+
onTagSwitch: onChange,
|
|
14
|
+
isRequired: isRequired,
|
|
15
|
+
disabled: disabled,
|
|
16
|
+
falseTrackColor: falseTrackColor,
|
|
17
|
+
thumbColor: thumbColor,
|
|
18
|
+
trueTrackColor: trueTrackColor
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export default Switch;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SwitchProps, TagsFilterProps } from '@open-tender/ui';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
declare const TagsFilter: ({ children, SwitchView }: {
|
|
4
|
+
children: (props: TagsFilterProps) => ReactNode;
|
|
5
|
+
SwitchView: (props: SwitchProps) => ReactNode;
|
|
6
|
+
}) => React.ReactNode;
|
|
7
|
+
export default TagsFilter;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import { useAppDispatch, useAppSelector } from '../app/hooks';
|
|
4
|
+
import { selectKioskConfig, selectTags, setSelectedTags } from '../slices';
|
|
5
|
+
import { default as SwitchContainer } from './Switch';
|
|
6
|
+
var TagsFilter = function (_a) {
|
|
7
|
+
var children = _a.children, SwitchView = _a.SwitchView;
|
|
8
|
+
var config = useAppSelector(selectKioskConfig).tags;
|
|
9
|
+
var dispatch = useAppDispatch();
|
|
10
|
+
var _b = useAppSelector(selectTags), tags = _b.entities, selectedTags = _b.selectedTags, loading = _b.loading, error = _b.error;
|
|
11
|
+
var _c = useState([]), localSelectedTags = _c[0], setLocalSelectedTags = _c[1];
|
|
12
|
+
var isLoading = loading === 'pending';
|
|
13
|
+
useEffect(function () {
|
|
14
|
+
setLocalSelectedTags(selectedTags.map(function (tag) { return tag.tag_id; }));
|
|
15
|
+
}, [selectedTags]);
|
|
16
|
+
var onTagSwitch = function (tag) {
|
|
17
|
+
setLocalSelectedTags(function (prevSelectedTags) {
|
|
18
|
+
if (prevSelectedTags.includes(tag.tag_id)) {
|
|
19
|
+
return prevSelectedTags.filter(function (id) { return id !== tag.tag_id; });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return __spreadArray(__spreadArray([], prevSelectedTags, true), [tag.tag_id], false);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var handleSubmit = function () {
|
|
27
|
+
var newSelectedTags = tags.filter(function (tag) {
|
|
28
|
+
return localSelectedTags.includes(tag.tag_id);
|
|
29
|
+
});
|
|
30
|
+
dispatch(setSelectedTags(newSelectedTags));
|
|
31
|
+
};
|
|
32
|
+
var handlers = { onTagSwitch: onTagSwitch, handleSubmit: handleSubmit };
|
|
33
|
+
var renderSwitch = useCallback(function (props) {
|
|
34
|
+
return (React.createElement(SwitchContainer, { key: props.id, id: props.id, children: SwitchView, label: props.label, on: props.value, onChange: props.onTagSwitch, disabled: false, isRequired: true }));
|
|
35
|
+
}, [SwitchView]);
|
|
36
|
+
return children({
|
|
37
|
+
config: config,
|
|
38
|
+
handlers: handlers,
|
|
39
|
+
isLoading: isLoading,
|
|
40
|
+
renderSwitch: renderSwitch,
|
|
41
|
+
tags: tags,
|
|
42
|
+
error: error === null || error === void 0 ? void 0 : error.detail
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export default TagsFilter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/store",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.173",
|
|
4
4
|
"description": "A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@emotion/react": "^11.11.1",
|
|
64
64
|
"@open-tender/types": "^0.4.77",
|
|
65
|
-
"@open-tender/ui": "^0.4.
|
|
65
|
+
"@open-tender/ui": "^0.4.8",
|
|
66
66
|
"@open-tender/utils": "^0.4.52",
|
|
67
67
|
"@reduxjs/toolkit": "^2.0.1",
|
|
68
68
|
"date-fns": "2.30.0",
|