impact-chatbot 2.3.17 → 2.3.19

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/index.esm.js CHANGED
@@ -23,7 +23,7 @@ import RefreshIcon from '@mui/icons-material/Refresh';
23
23
  import styled from 'styled-components';
24
24
  import { CircularProgress, Typography, Grid } from '@mui/material';
25
25
  import { fetchBaseUrl, replaceSpecialCharacter as replaceSpecialCharacter$1, fetchLegacyAgentScreen } from 'core/Utils/functions/utils';
26
- import { Button, Modal, AccordionModern, Tabs, Slider, Select, DatePicker, Checkbox, RadioButtonGroup, Input, Loader, ChatBotComponent } from 'impact-ui-v3';
26
+ import { Button, Modal, AccordionModern, Tabs, Slider, Select, DatePicker, DateRangePicker, Checkbox, RadioButtonGroup, Input, Loader, ChatBotComponent } from 'impact-ui-v3';
27
27
  import AgGridComponent from 'core/Utils/agGrid';
28
28
  import agGridColumnFormatter from 'core/Utils/agGrid/column-formatter';
29
29
  import CoreChart from 'core/Utils/core-charts';
@@ -434,6 +434,26 @@ const parseResponse = (data, type, agentId = "", currentMode = "", disableTimeAn
434
434
  paramName: data?.data?.param_name
435
435
  }
436
436
  };
437
+ case "dateRangePicker":
438
+ return {
439
+ ...data,
440
+ timeStamp: timeString,
441
+ userType: "bot",
442
+ userName: userName,
443
+ headerTitle: data?.data?.label || "",
444
+ bodyType: "dateRangePicker",
445
+ bodyText: {
446
+ displayFormat: data?.data?.displayFormat,
447
+ label: data?.data?.label,
448
+ isRequired: data?.data?.isRequired,
449
+ labelOrientation: data?.data?.labelOrientation,
450
+ minDate: data?.data?.minDate,
451
+ maxDate: data?.data?.maxDate,
452
+ isDisabled: data?.data?.isDisabled,
453
+ showMonthYearSelect: data?.data?.showMonthYearSelect,
454
+ paramName: data?.data?.param_name
455
+ }
456
+ };
437
457
  case "checkbox":
438
458
  return {
439
459
  ...data,
@@ -4847,7 +4867,7 @@ const useStyles$4 = makeStyles((theme) => ({
4847
4867
  marginTop: pxToRem(16),
4848
4868
  }
4849
4869
  }));
4850
- const ButtonContent = ({ bodyText }) => {
4870
+ const ButtonContent = ({ bodyText, isFormDisabled = false }) => {
4851
4871
  const classes = useStyles$4();
4852
4872
  const handleButtonClick = (button) => {
4853
4873
  // if (button.onClick) {
@@ -4864,7 +4884,7 @@ const ButtonContent = ({ bodyText }) => {
4864
4884
  if (!Array.isArray(bodyText.buttons)) {
4865
4885
  return null;
4866
4886
  }
4867
- return bodyText.buttons.map((button, index) => (jsx(Button, { variant: button.variant || "primary", size: button.size || "medium", onClick: () => handleButtonClick(), disabled: button.disabled, className: button.className, icon: button.icon, iconPlacement: button.iconPlacement || "left", children: button.label }, index)));
4887
+ return bodyText.buttons.map((button, index) => (jsx(Button, { variant: button.variant || "primary", size: button.size || "medium", onClick: () => handleButtonClick(), disabled: button.disabled || isFormDisabled, className: button.className, icon: button.icon, iconPlacement: button.iconPlacement || "left", children: button.label }, index)));
4868
4888
  };
4869
4889
  return (jsxs("div", { className: classes.buttonContainer, children: [bodyText.message && (jsx("div", { className: classes.message, children: bodyText.message })), jsx("div", { className: classes.buttonRow, children: renderButtons() })] }));
4870
4890
  };
@@ -6615,7 +6635,7 @@ const StreamedContent = ({ botData }) => {
6615
6635
  return renderContent();
6616
6636
  };
6617
6637
 
6618
- const SliderContent = ({ bodyText }) => {
6638
+ const SliderContent = ({ bodyText, isFormDisabled = false }) => {
6619
6639
  const { header, headerOrentiation, inputPosition, label, max, min, required, disabled, } = bodyText;
6620
6640
  const [sliderValue, setSliderValue] = useState(0);
6621
6641
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
@@ -6636,10 +6656,10 @@ const SliderContent = ({ bodyText }) => {
6636
6656
  console.error("Error in slider handleChange", error);
6637
6657
  }
6638
6658
  };
6639
- return (jsx("div", { style: { width: "100%", marginTop: "10px" }, children: jsx(Slider, { header: header, headerOrientation: headerOrentiation, inputPosition: inputPosition, label: label, max: max, min: min, required: required, disabled: disabled, onChange: (e) => handleChange(e), value: sliderValue }) }));
6659
+ return (jsx("div", { style: { width: "100%", marginTop: "10px" }, children: jsx(Slider, { header: header, headerOrientation: headerOrentiation, inputPosition: inputPosition, label: label, max: max, min: min, required: required, disabled: disabled || isFormDisabled, onChange: (e) => handleChange(e), value: sliderValue }) }));
6640
6660
  };
6641
6661
 
6642
- const SelectContent = ({ bodyText }) => {
6662
+ const SelectContent = ({ bodyText, isFormDisabled = false }) => {
6643
6663
  const { header, inputPosition, labelOrientation, label, options, isRequired, isDisabled, isMulti, paramName } = bodyText;
6644
6664
  const [isOpen, setIsOpen] = useState(false);
6645
6665
  const [currentOptions, setCurrentOptions] = useState([]);
@@ -6689,10 +6709,10 @@ const SelectContent = ({ bodyText }) => {
6689
6709
  return (jsx("div", { style: { width: "100%", marginTop: "10px" }, children: jsx(Select, { currentOptions: currentOptions, setCurrentOptions: setCurrentOptions, label: heirarchyKeyValuePairs[paramName] || label, labelOrientation: labelOrientation,
6690
6710
  // inputPosition={inputPosition}
6691
6711
  // header={header}
6692
- isRequired: isRequired, isDisabled: isDisabled, handleChange: (selected) => onChange(selected), isCloseWhenClickOutside: true, setIsOpen: setIsOpen, isOpen: isOpen, selectedOptions: currentSelectedOptions, setSelectedOptions: setCurrentSelectedOptions, initialOptions: initialOptions, isMulti: isMulti, isSelectAll: isAllSelected, setIsSelectAll: setIsAllSelected, toggleSelectAll: true, isWithSearch: isMulti ? true : false }) }));
6712
+ isRequired: isRequired, isDisabled: isDisabled || isFormDisabled, handleChange: (selected) => onChange(selected), isCloseWhenClickOutside: true, setIsOpen: setIsOpen, isOpen: isOpen, selectedOptions: currentSelectedOptions, setSelectedOptions: setCurrentSelectedOptions, initialOptions: initialOptions, isMulti: isMulti, isSelectAll: isAllSelected, setIsSelectAll: setIsAllSelected, toggleSelectAll: true, isWithSearch: isMulti ? true : false }) }));
6693
6713
  };
6694
6714
 
6695
- const DatePickerContent = ({ bodyText }) => {
6715
+ const DatePickerContent = ({ bodyText, isFormDisabled = false }) => {
6696
6716
  const { displayFormat, label, isRequired, labelOrientation, placeholder, minDate, maxDate, isDisabled, } = bodyText;
6697
6717
  const [selectedDate, setSelectedDate] = useState(null);
6698
6718
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
@@ -6716,13 +6736,49 @@ const DatePickerContent = ({ bodyText }) => {
6716
6736
  return (jsx("div", { style: { width: "100%", marginTop: "10px" }, children: jsx(DatePicker, { displayFormat: displayFormat, label: label, required: isRequired, labelOrientation: labelOrientation, placeholder: placeholder,
6717
6737
  // minDate={minDate}
6718
6738
  // maxDate={maxDate}
6719
- disabled: isDisabled, setSelectedDate: (date) => handleDateChange(date),
6739
+ isDisabled: isDisabled || isFormDisabled, setSelectedDate: (date) => handleDateChange(date),
6720
6740
  // showMonthYearSelect
6721
6741
  // showWeekNumbers
6722
6742
  selectedDate: selectedDate }) }));
6723
6743
  };
6724
6744
 
6725
- const CheckboxContent = ({ bodyText }) => {
6745
+ const DateRangePickerContent = ({ bodyText, isFormDisabled = false }) => {
6746
+ const { displayFormat, label, isRequired, labelOrientation, minDate, maxDate, isDisabled, showMonthYearSelect, } = bodyText;
6747
+ const [startDate, setStartDate] = useState(null);
6748
+ const [endDate, setEndDate] = useState(null);
6749
+ const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
6750
+ const dispatch = useDispatch();
6751
+ if (isEmpty$1(bodyText))
6752
+ return null;
6753
+ const handleDatesChange = (start, end) => {
6754
+ try {
6755
+ setStartDate(start);
6756
+ setEndDate(end);
6757
+ chatbotContext[bodyText?.paramName] = {
6758
+ ...chatbotContext?.[bodyText?.paramName],
6759
+ [bodyText?.paramName]: {
6760
+ startDate: start ? moment(start).format(displayFormat) : null,
6761
+ endDate: end ? moment(end).format(displayFormat) : null,
6762
+ },
6763
+ updated: true,
6764
+ };
6765
+ dispatch(setChatbotContext(chatbotContext));
6766
+ }
6767
+ catch (error) {
6768
+ console.error("Error in dateRangePicker handleDatesChange", error);
6769
+ }
6770
+ };
6771
+ return (jsx("div", { style: { width: "100%", marginTop: "10px" }, children: jsx(DateRangePicker, { displayFormat: displayFormat, label: label, isRequired: isRequired, labelOrientation: labelOrientation || "top", minDate: minDate, maxDate: maxDate, isDisabled: isDisabled || isFormDisabled, startDate: startDate, setStartDate: setStartDate, endDate: endDate, setEndDate: setEndDate, showMonthYearSelect: showMonthYearSelect, handleDatesChange: handleDatesChange, onPrimaryButtonClick: () => handleDatesChange(startDate, endDate), onSecondaryButtonClick: () => {
6772
+ setStartDate(null);
6773
+ setEndDate(null);
6774
+ }, onResetClick: () => {
6775
+ setStartDate(null);
6776
+ setEndDate(null);
6777
+ handleDatesChange(null, null);
6778
+ } }) }));
6779
+ };
6780
+
6781
+ const CheckboxContent = ({ bodyText, isFormDisabled = false }) => {
6726
6782
  const { label, checked: checkedValue, required, disabled, } = bodyText;
6727
6783
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
6728
6784
  const dispatch = useDispatch();
@@ -6748,10 +6804,10 @@ const CheckboxContent = ({ bodyText }) => {
6748
6804
  console.error("Error in checkbox handleChange", error);
6749
6805
  }
6750
6806
  };
6751
- return (jsx("div", { style: { width: '100%', marginTop: '10px' }, children: jsx(Checkbox, { label: label, checked: checked, required: required, disabled: disabled, onChange: (e) => handleChange(e), variant: "default" }) }));
6807
+ return (jsx("div", { style: { width: '100%', marginTop: '10px' }, children: jsx(Checkbox, { label: label, checked: checked, required: required, disabled: disabled || isFormDisabled, onChange: (e) => handleChange(e), variant: "default" }) }));
6752
6808
  };
6753
6809
 
6754
- const RadioContent = ({ bodyText }) => {
6810
+ const RadioContent = ({ bodyText, isFormDisabled = false }) => {
6755
6811
  const classes = useStyles$6();
6756
6812
  const { label, isDisabled, orientation, options } = bodyText;
6757
6813
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
@@ -6779,10 +6835,10 @@ const RadioContent = ({ bodyText }) => {
6779
6835
  console.error("Error in radio handleChange", error);
6780
6836
  }
6781
6837
  };
6782
- return (jsxs("div", { style: { width: "100%", marginTop: "10px" }, children: [bodyText?.label && jsx("p", { className: classes.radioGrpLabel, children: bodyText.label }), jsx(RadioButtonGroup, { name: "radio-group", options: options, onChange: (e) => handleChange(e), orientation: orientation, disabled: isDisabled, selectedOption: selectedOption })] }));
6838
+ return (jsxs("div", { style: { width: "100%", marginTop: "10px" }, children: [bodyText?.label && jsx("p", { className: classes.radioGrpLabel, children: bodyText.label }), jsx(RadioButtonGroup, { name: "radio-group", options: options, onChange: (e) => handleChange(e), orientation: orientation, isDisabled: isDisabled || isFormDisabled, selectedOption: selectedOption })] }));
6783
6839
  };
6784
6840
 
6785
- const InputContent = ({ bodyText }) => {
6841
+ const InputContent = ({ bodyText, isFormDisabled = false }) => {
6786
6842
  const { label, placeholder, isRequired, isDisabled, inputType, labelOrientation, defaultValue, maxLength, minLength, } = bodyText;
6787
6843
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
6788
6844
  const dispatch = useDispatch();
@@ -6805,7 +6861,7 @@ const InputContent = ({ bodyText }) => {
6805
6861
  console.error("Error in input handleChange", error);
6806
6862
  }
6807
6863
  };
6808
- return (jsx("div", { style: { width: '100%', marginTop: '10px' }, children: jsx(Input, { label: label, placeholder: placeholder, value: value, onChange: handleChange, required: isRequired, disabled: isDisabled, type: inputType || "text", labelOrientation: labelOrientation, maxLength: maxLength, minLength: minLength }) }));
6864
+ return (jsx("div", { style: { width: '100%', marginTop: '10px' }, children: jsx(Input, { label: label, placeholder: placeholder, value: value, onChange: handleChange, required: isRequired, isDisabled: isDisabled || isFormDisabled, type: inputType || "text", labelOrientation: labelOrientation, maxLength: maxLength, minLength: minLength }) }));
6809
6865
  };
6810
6866
 
6811
6867
  const ImageContent = ({ bodyText }) => {
@@ -7030,6 +7086,7 @@ const TabularContent = ({ steps, currentTabValue, children, questions = [], ques
7030
7086
  };
7031
7087
 
7032
7088
  const CombinedContent = ({ botData, props }) => {
7089
+ const isFormDisabled = botData?.isFormDisabled || false;
7033
7090
  const isTabEnabled = botData?.utilityData?.isTabEnabled;
7034
7091
  // Get the array of content items from bodyText
7035
7092
  const contentItems = Array.isArray(botData.bodyText) ? botData.bodyText : [];
@@ -7053,19 +7110,21 @@ const CombinedContent = ({ botData, props }) => {
7053
7110
  case "graph":
7054
7111
  return jsx(GraphContent, { bodyText: parsedData.bodyText }, key);
7055
7112
  case "slider":
7056
- return jsx(SliderContent, { bodyText: parsedData.bodyText }, key);
7113
+ return jsx(SliderContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
7057
7114
  case "select":
7058
- return jsx(SelectContent, { bodyText: parsedData.bodyText }, key);
7115
+ return jsx(SelectContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
7059
7116
  case "datePicker":
7060
- return jsx(DatePickerContent, { bodyText: parsedData.bodyText }, key);
7117
+ return jsx(DatePickerContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
7118
+ case "dateRangePicker":
7119
+ return jsx(DateRangePickerContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
7061
7120
  case "checkbox":
7062
- return jsx(CheckboxContent, { bodyText: parsedData.bodyText }, key);
7121
+ return jsx(CheckboxContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
7063
7122
  case "radio":
7064
- return jsx(RadioContent, { bodyText: parsedData.bodyText }, key);
7123
+ return jsx(RadioContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
7065
7124
  case "button":
7066
- return jsx(ButtonContent, { bodyText: parsedData.bodyText }, key);
7125
+ return jsx(ButtonContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
7067
7126
  case "input":
7068
- return jsx(InputContent, { bodyText: parsedData.bodyText }, key);
7127
+ return jsx(InputContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
7069
7128
  case "image":
7070
7129
  return jsx(ImageContent, { bodyText: parsedData.bodyText }, key);
7071
7130
  default:
@@ -7147,19 +7206,21 @@ const BotMessage = ({ botData, state, handleLikeDislike, props }) => {
7147
7206
  case "graph":
7148
7207
  return jsx(GraphContent, { bodyText: botData.bodyText });
7149
7208
  case "slider":
7150
- return jsx(SliderContent, { bodyText: botData.bodyText });
7209
+ return jsx(SliderContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled });
7151
7210
  case "select":
7152
- return jsx(SelectContent, { bodyText: botData.bodyText });
7211
+ return jsx(SelectContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled });
7153
7212
  case "datePicker":
7154
- return jsx(DatePickerContent, { bodyText: botData.bodyText });
7213
+ return jsx(DatePickerContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled });
7214
+ case "dateRangePicker":
7215
+ return jsx(DateRangePickerContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled });
7155
7216
  case "checkbox":
7156
- return jsx(CheckboxContent, { bodyText: botData.bodyText });
7217
+ return jsx(CheckboxContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled });
7157
7218
  case "radio":
7158
- return jsx(RadioContent, { bodyText: botData.bodyText });
7219
+ return jsx(RadioContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled });
7159
7220
  case "button":
7160
- return jsx(ButtonContent, { bodyText: botData.bodyText });
7221
+ return jsx(ButtonContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled });
7161
7222
  case "input":
7162
- return jsx(InputContent, { bodyText: botData.bodyText });
7223
+ return jsx(InputContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled });
7163
7224
  case "image":
7164
7225
  return jsx(ImageContent, { bodyText: botData.bodyText });
7165
7226
  case "combined":
@@ -10134,7 +10195,9 @@ const SmartBot = (props) => {
10134
10195
  customChatConfig: customChatConfig,
10135
10196
  loader: loader,
10136
10197
  };
10137
- chatDataInfoRef?.current[currentMode]?.conversations?.[1]?.messages.forEach((message, index) => {
10198
+ const allMessages = chatDataInfoRef?.current[currentMode]?.conversations?.[1]?.messages || [];
10199
+ const lastBotMessageIndex = allMessages.reduce((lastIdx, msg, idx) => msg.userType === "bot" ? idx : lastIdx, -1);
10200
+ allMessages.forEach((message, index) => {
10138
10201
  if (message.userType === "bot") {
10139
10202
  // let BotMessageJsx =
10140
10203
  // <BotMessage
@@ -10144,6 +10207,7 @@ const SmartBot = (props) => {
10144
10207
  // props={properties}
10145
10208
  // />
10146
10209
  // ;
10210
+ message.isFormDisabled = index !== lastBotMessageIndex;
10147
10211
  message.jsx = (jsx(BotMessage, { botData: message, state: loadingState, handleLikeDislike: handleLikeDislike, props: properties }));
10148
10212
  message.firstMessage = true;
10149
10213
  // message.enableLikes = true;