@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.object.assign.js");
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 = _interopRequireWildcard(require("react"));
11
- var _Autocomplete = _interopRequireDefault(require("@mui/lab/Autocomplete"));
10
+ var _react = require("react");
12
11
  var _material = require("@mui/material");
13
- var _lists = require("@aclymatepackages/lists");
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
- style,
28
- variant = "outlined",
29
- label,
30
- helperText,
31
- textFieldProps
18
+ fetchNaicsCodes,
19
+ questionText = "What does your company do?"
32
20
  } = _ref;
33
- const [inputValue, setInputValue] = (0, _react.useState)("");
34
- return /*#__PURE__*/_react.default.createElement("div", {
35
- onClick: e => e.stopPropagation(),
36
- onFocus: e => e.stopPropagation()
37
- }, /*#__PURE__*/_react.default.createElement(_Autocomplete.default, {
38
- id: "company-industry-autocomplete",
39
- options: _lists.threeDigitNaicsCodesIndustries,
40
- getOptionLabel: option => typeof option === "string" ? option : option.label,
41
- renderInput: params => /*#__PURE__*/_react.default.createElement(_material.TextField, _extends({}, params, {
42
- label: label || "Company Industry",
43
- fullWidth: true,
44
- size: "small",
45
- variant: variant,
46
- style: style,
47
- helperText: helperText
48
- }, textFieldProps)),
49
- inputValue: inputValue,
50
- onInputChange: (e, newInputValue) => setInputValue(newInputValue),
51
- onChange: (event, newValue) => setIndustry(newValue || null),
52
- value: industry !== null && industry !== void 0 ? industry : null,
53
- getOptionSelected: (option, value) => option.label === value.label,
54
- PopperComponent: CustomPopper
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@aclymatepackages/modules",
3
- "version": "4.3.4",
3
+ "version": "5.0.0",
4
4
  "description": "Aclymate modules",
5
5
  "author": "William Loopesko",
6
6
  "main": "dist/index.js",
@@ -1,56 +1,99 @@
1
- import React, { useState } from "react";
1
+ import { useState } from "react";
2
2
 
3
- import Autocomplete from "@mui/lab/Autocomplete";
4
- import { TextField, Popper } from "@mui/material";
3
+ import { Grid, Typography, Chip, Button } from "@mui/material";
5
4
 
6
- import { threeDigitNaicsCodesIndustries } from "@aclymatepackages/lists";
7
-
8
- const CustomPopper = (props) => (
9
- <Popper {...props} style={{ width: "fit-content" }} />
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
- style,
16
- variant = "outlined",
17
- label,
18
- helperText,
19
- textFieldProps,
14
+ fetchNaicsCodes,
15
+ questionText = "What does your company do?"
20
16
  }) => {
21
- const [inputValue, setInputValue] = useState("");
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
- <div
25
- onClick={(e) => e.stopPropagation()}
26
- onFocus={(e) => e.stopPropagation()}
27
- >
28
- <Autocomplete
29
- id="company-industry-autocomplete"
30
- options={threeDigitNaicsCodesIndustries}
31
- getOptionLabel={(option) =>
32
- typeof option === "string" ? option : option.label
33
- }
34
- renderInput={(params) => (
35
- <TextField
36
- {...params}
37
- label={label || "Company Industry"}
38
- fullWidth
39
- size="small"
40
- variant={variant}
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
- inputValue={inputValue}
47
- onInputChange={(e, newInputValue) => setInputValue(newInputValue)}
48
- onChange={(event, newValue) => setIndustry(newValue || null)}
49
- value={industry ?? null}
50
- getOptionSelected={(option, value) => option.label === value.label}
51
- PopperComponent={CustomPopper}
52
- />
53
- </div>
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&apos;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;