@aclymatepackages/modules 4.3.4 → 5.0.0
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.
|
@@ -1,57 +1,109 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.weak-map.js");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
|
-
require("core-js/modules/es.
|
|
7
|
+
require("core-js/modules/es.symbol.description.js");
|
|
8
|
+
require("core-js/modules/es.promise.js");
|
|
9
9
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
10
|
-
var _react =
|
|
11
|
-
var _Autocomplete = _interopRequireDefault(require("@mui/lab/Autocomplete"));
|
|
10
|
+
var _react = require("react");
|
|
12
11
|
var _material = require("@mui/material");
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
16
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
18
|
-
const CustomPopper = props => /*#__PURE__*/_react.default.createElement(_material.Popper, _extends({}, props, {
|
|
19
|
-
style: {
|
|
20
|
-
width: "fit-content"
|
|
21
|
-
}
|
|
22
|
-
}));
|
|
12
|
+
var _atoms = require("@aclymatepackages/atoms");
|
|
13
|
+
var _otherHelpers = require("@aclymatepackages/other-helpers");
|
|
23
14
|
const IndustryAutocomplete = _ref => {
|
|
24
15
|
let {
|
|
25
16
|
industry,
|
|
26
17
|
setIndustry,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
label,
|
|
30
|
-
helperText,
|
|
31
|
-
textFieldProps
|
|
18
|
+
fetchNaicsCodes,
|
|
19
|
+
questionText = "What does your company do?"
|
|
32
20
|
} = _ref;
|
|
33
|
-
const [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
options
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
21
|
+
const [loading, setLoading] = (0, _react.useState)(false);
|
|
22
|
+
const [naicsCodesOptions, setNaicsCodesOptions] = (0, _react.useState)([]);
|
|
23
|
+
const [companyDescription, setCompanyDescription] = (0, _react.useState)("");
|
|
24
|
+
const industryTitle = (industry === null || industry === void 0 ? void 0 : industry.naicsTitle) || (industry === null || industry === void 0 ? void 0 : industry.label) || null;
|
|
25
|
+
const onSearch = async () => {
|
|
26
|
+
setLoading(true);
|
|
27
|
+
const options = await fetchNaicsCodes(companyDescription);
|
|
28
|
+
setNaicsCodesOptions(options || []);
|
|
29
|
+
setLoading(false);
|
|
30
|
+
};
|
|
31
|
+
const onSelectOption = _ref2 => {
|
|
32
|
+
let {
|
|
33
|
+
code,
|
|
34
|
+
description,
|
|
35
|
+
tonsCo2ePerDollar
|
|
36
|
+
} = _ref2;
|
|
37
|
+
setIndustry({
|
|
38
|
+
naicsCode: code,
|
|
39
|
+
naicsTitle: description,
|
|
40
|
+
tonsCo2ePerDollar
|
|
41
|
+
});
|
|
42
|
+
setNaicsCodesOptions([]);
|
|
43
|
+
};
|
|
44
|
+
const onDeleteCurrentIndustry = () => {
|
|
45
|
+
setIndustry(null);
|
|
46
|
+
setNaicsCodesOptions([]);
|
|
47
|
+
};
|
|
48
|
+
const showCurrentChip = !!industryTitle && !naicsCodesOptions.length;
|
|
49
|
+
const showOptions = !!naicsCodesOptions.length;
|
|
50
|
+
const showSearchInput = !showCurrentChip && !showOptions;
|
|
51
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, showSearchInput && /*#__PURE__*/React.createElement(_material.Grid, {
|
|
52
|
+
item: true
|
|
53
|
+
}, /*#__PURE__*/React.createElement(_atoms.SearchActionInput, {
|
|
54
|
+
label: questionText,
|
|
55
|
+
value: companyDescription,
|
|
56
|
+
setValue: setCompanyDescription,
|
|
57
|
+
searchLoading: loading,
|
|
58
|
+
searchFunction: onSearch
|
|
59
|
+
})), showCurrentChip && /*#__PURE__*/React.createElement(_material.Grid, {
|
|
60
|
+
item: true,
|
|
61
|
+
alignSelf: "center"
|
|
62
|
+
}, /*#__PURE__*/React.createElement(_material.Chip, {
|
|
63
|
+
label: (0, _otherHelpers.truncateText)(industryTitle, 50),
|
|
64
|
+
onDelete: onDeleteCurrentIndustry
|
|
65
|
+
})), showOptions && /*#__PURE__*/React.createElement(_material.Grid, {
|
|
66
|
+
item: true,
|
|
67
|
+
container: true,
|
|
68
|
+
spacing: 2
|
|
69
|
+
}, /*#__PURE__*/React.createElement(_material.Grid, {
|
|
70
|
+
item: true,
|
|
71
|
+
xs: 12
|
|
72
|
+
}, /*#__PURE__*/React.createElement(_material.Typography, {
|
|
73
|
+
variant: "h6",
|
|
74
|
+
align: "center"
|
|
75
|
+
}, "Select your company's industry")), /*#__PURE__*/React.createElement(_material.Grid, {
|
|
76
|
+
item: true,
|
|
77
|
+
container: true,
|
|
78
|
+
justifyContent: "center",
|
|
79
|
+
spacing: 2
|
|
80
|
+
}, naicsCodesOptions.map((_ref3, idx) => {
|
|
81
|
+
let {
|
|
82
|
+
code,
|
|
83
|
+
description,
|
|
84
|
+
tonsCo2ePerDollar
|
|
85
|
+
} = _ref3;
|
|
86
|
+
return /*#__PURE__*/React.createElement(_material.Grid, {
|
|
87
|
+
item: true,
|
|
88
|
+
key: "naics-chip-".concat(idx)
|
|
89
|
+
}, /*#__PURE__*/React.createElement(_atoms.DefaultSelectableChip, {
|
|
90
|
+
label: (0, _otherHelpers.truncateText)(description, 50),
|
|
91
|
+
onClick: () => onSelectOption({
|
|
92
|
+
code,
|
|
93
|
+
description,
|
|
94
|
+
tonsCo2ePerDollar
|
|
95
|
+
}),
|
|
96
|
+
isSelected: (industry === null || industry === void 0 ? void 0 : industry.naicsCode) === code
|
|
97
|
+
}));
|
|
98
|
+
})), /*#__PURE__*/React.createElement(_material.Grid, {
|
|
99
|
+
item: true,
|
|
100
|
+
container: true,
|
|
101
|
+
justifyContent: "center"
|
|
102
|
+
}, /*#__PURE__*/React.createElement(_material.Grid, {
|
|
103
|
+
item: true
|
|
104
|
+
}, /*#__PURE__*/React.createElement(_material.Button, {
|
|
105
|
+
color: "primary",
|
|
106
|
+
onClick: () => setNaicsCodesOptions([])
|
|
107
|
+
}, "Choose Different Categories")))));
|
|
56
108
|
};
|
|
57
109
|
var _default = exports.default = IndustryAutocomplete;
|
package/package.json
CHANGED
|
@@ -1,56 +1,99 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useState } from "react";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { TextField, Popper } from "@mui/material";
|
|
3
|
+
import { Grid, Typography, Chip, Button } from "@mui/material";
|
|
5
4
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import {
|
|
6
|
+
DefaultSelectableChip,
|
|
7
|
+
SearchActionInput
|
|
8
|
+
} from "@aclymatepackages/atoms";
|
|
9
|
+
import { truncateText } from "@aclymatepackages/other-helpers";
|
|
11
10
|
|
|
12
11
|
const IndustryAutocomplete = ({
|
|
13
12
|
industry,
|
|
14
13
|
setIndustry,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
label,
|
|
18
|
-
helperText,
|
|
19
|
-
textFieldProps,
|
|
14
|
+
fetchNaicsCodes,
|
|
15
|
+
questionText = "What does your company do?"
|
|
20
16
|
}) => {
|
|
21
|
-
const [
|
|
17
|
+
const [loading, setLoading] = useState(false);
|
|
18
|
+
const [naicsCodesOptions, setNaicsCodesOptions] = useState([]);
|
|
19
|
+
const [companyDescription, setCompanyDescription] = useState("");
|
|
20
|
+
|
|
21
|
+
const industryTitle = industry?.naicsTitle || industry?.label || null;
|
|
22
|
+
|
|
23
|
+
const onSearch = async () => {
|
|
24
|
+
setLoading(true);
|
|
25
|
+
const options = await fetchNaicsCodes(companyDescription);
|
|
26
|
+
setNaicsCodesOptions(options || []);
|
|
27
|
+
setLoading(false);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const onSelectOption = ({ code, description, tonsCo2ePerDollar }) => {
|
|
31
|
+
setIndustry({ naicsCode: code, naicsTitle: description, tonsCo2ePerDollar });
|
|
32
|
+
setNaicsCodesOptions([]);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const onDeleteCurrentIndustry = () => {
|
|
36
|
+
setIndustry(null);
|
|
37
|
+
setNaicsCodesOptions([]);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const showCurrentChip = !!industryTitle && !naicsCodesOptions.length;
|
|
41
|
+
const showOptions = !!naicsCodesOptions.length;
|
|
42
|
+
const showSearchInput = !showCurrentChip && !showOptions;
|
|
22
43
|
|
|
23
44
|
return (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
style={style}
|
|
42
|
-
helperText={helperText}
|
|
43
|
-
{...textFieldProps}
|
|
45
|
+
<>
|
|
46
|
+
{showSearchInput && (
|
|
47
|
+
<Grid item>
|
|
48
|
+
<SearchActionInput
|
|
49
|
+
label={questionText}
|
|
50
|
+
value={companyDescription}
|
|
51
|
+
setValue={setCompanyDescription}
|
|
52
|
+
searchLoading={loading}
|
|
53
|
+
searchFunction={onSearch}
|
|
54
|
+
/>
|
|
55
|
+
</Grid>
|
|
56
|
+
)}
|
|
57
|
+
{showCurrentChip && (
|
|
58
|
+
<Grid item alignSelf="center">
|
|
59
|
+
<Chip
|
|
60
|
+
label={truncateText(industryTitle, 50)}
|
|
61
|
+
onDelete={onDeleteCurrentIndustry}
|
|
44
62
|
/>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
</Grid>
|
|
64
|
+
)}
|
|
65
|
+
{showOptions && (
|
|
66
|
+
<Grid item container spacing={2}>
|
|
67
|
+
<Grid item xs={12}>
|
|
68
|
+
<Typography variant="h6" align="center">
|
|
69
|
+
Select your company's industry
|
|
70
|
+
</Typography>
|
|
71
|
+
</Grid>
|
|
72
|
+
<Grid item container justifyContent="center" spacing={2}>
|
|
73
|
+
{naicsCodesOptions.map(
|
|
74
|
+
({ code, description, tonsCo2ePerDollar }, idx) => (
|
|
75
|
+
<Grid item key={`naics-chip-${idx}`}>
|
|
76
|
+
<DefaultSelectableChip
|
|
77
|
+
label={truncateText(description, 50)}
|
|
78
|
+
onClick={() =>
|
|
79
|
+
onSelectOption({ code, description, tonsCo2ePerDollar })
|
|
80
|
+
}
|
|
81
|
+
isSelected={industry?.naicsCode === code}
|
|
82
|
+
/>
|
|
83
|
+
</Grid>
|
|
84
|
+
)
|
|
85
|
+
)}
|
|
86
|
+
</Grid>
|
|
87
|
+
<Grid item container justifyContent="center">
|
|
88
|
+
<Grid item>
|
|
89
|
+
<Button color="primary" onClick={() => setNaicsCodesOptions([])}>
|
|
90
|
+
Choose Different Categories
|
|
91
|
+
</Button>
|
|
92
|
+
</Grid>
|
|
93
|
+
</Grid>
|
|
94
|
+
</Grid>
|
|
95
|
+
)}
|
|
96
|
+
</>
|
|
54
97
|
);
|
|
55
98
|
};
|
|
56
99
|
export default IndustryAutocomplete;
|