impact-chatbot 2.3.78 → 2.3.79

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
@@ -5487,7 +5487,7 @@ const useStyles$8 = makeStyles((theme) => ({
5487
5487
  }));
5488
5488
  const MAX_RETRY_COUNT_BUTTON = 1;
5489
5489
  const RETRY_COUNTDOWN_SECONDS_BUTTON = 15;
5490
- const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = false, isFormValid = true }) => {
5490
+ const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = false, isFormValid = true, formParamNames = [], messageIndex = 0 }) => {
5491
5491
  const classes = useStyles$8();
5492
5492
  const dispatch = useDispatch();
5493
5493
  const sourceRef = useRef(null);
@@ -5513,19 +5513,56 @@ const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = fa
5513
5513
  status: "",
5514
5514
  });
5515
5515
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
5516
+ const chatbotContextRef = useRef(chatbotContext);
5517
+ chatbotContextRef.current = chatbotContext;
5518
+ const persistedFormValues = useSelector((state) => state.smartBotReducer.persistedFormValues);
5519
+ const persistedFormValuesRef = useRef(persistedFormValues);
5520
+ persistedFormValuesRef.current = persistedFormValues;
5516
5521
  const thinkingContext = useSelector((state) => state.smartBotReducer.thinkingContext);
5517
5522
  const handleButtonClick = (button) => {
5518
5523
  if (isStepFormSubmit) {
5519
- // Build the user_input from chatbotContext
5524
+ // Read the latest chatbotContext from ref to avoid stale closures
5525
+ const currentContext = chatbotContextRef.current;
5526
+ const currentPersisted = persistedFormValuesRef.current;
5527
+ // Build the user_input ONLY from formParamNames (current form's fields)
5520
5528
  const userInput = {};
5521
- for (const key in chatbotContext) {
5522
- if (key.startsWith('__'))
5523
- continue;
5524
- if (chatbotContext[key]?.updated) {
5525
- let value = chatbotContext[key][key];
5526
- userInput[key] = isArray$2(value)
5527
- ? value
5528
- : typeof value === 'number' ? value : String(value);
5529
+ if (formParamNames.length > 0) {
5530
+ formParamNames.forEach((paramName) => {
5531
+ // Primary source: chatbotContext (set by handleChange in form components)
5532
+ if (currentContext[paramName]?.updated) {
5533
+ let value = currentContext[paramName][paramName];
5534
+ userInput[paramName] = isArray$2(value)
5535
+ ? value
5536
+ : typeof value === 'number' ? value : String(value);
5537
+ }
5538
+ else {
5539
+ // Fallback: persistedFormValues (covers edge case where chatbotContext
5540
+ // was cleared but the form still has a valid selection displayed)
5541
+ const persistedKey = `${messageIndex}_${paramName}`;
5542
+ const persistedValue = currentPersisted[persistedKey];
5543
+ if (persistedValue !== undefined && persistedValue !== null) {
5544
+ // For select components, persistedFormValues stores option objects
5545
+ if (isArray$2(persistedValue)) {
5546
+ userInput[paramName] = persistedValue.map((opt) => opt.value !== undefined ? opt.value : opt);
5547
+ }
5548
+ else {
5549
+ userInput[paramName] = typeof persistedValue === 'number' ? persistedValue : String(persistedValue);
5550
+ }
5551
+ }
5552
+ }
5553
+ });
5554
+ }
5555
+ else {
5556
+ // Legacy fallback: no formParamNames provided, iterate chatbotContext
5557
+ for (const key in currentContext) {
5558
+ if (key.startsWith('__'))
5559
+ continue;
5560
+ if (currentContext[key]?.updated) {
5561
+ let value = currentContext[key][key];
5562
+ userInput[key] = isArray$2(value)
5563
+ ? value
5564
+ : typeof value === 'number' ? value : String(value);
5565
+ }
5529
5566
  }
5530
5567
  }
5531
5568
  dispatch(setChatbotContext({}));
@@ -5863,6 +5900,8 @@ const TableContent = ({ bodyText }) => {
5863
5900
  const [isModalOpen, setIsModalOpen] = useState(false);
5864
5901
  const [downloadUrl, setDownloadUrl] = useState("");
5865
5902
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
5903
+ const chatbotContextRef = useRef(chatbotContext);
5904
+ chatbotContextRef.current = chatbotContext;
5866
5905
  const dispatch = useDispatch();
5867
5906
  useEffect(() => {
5868
5907
  let formattedColumns = getFormattedTableConfig(table_config);
@@ -5908,9 +5947,10 @@ const TableContent = ({ bodyText }) => {
5908
5947
  const onSelectionChanged = (event) => {
5909
5948
  try {
5910
5949
  const selectedList = event.api.getSelectedRows();
5950
+ const latestContext = chatbotContextRef.current;
5911
5951
  dispatch(setChatbotContext({
5912
- ...chatbotContext,
5913
- tables: { ...chatbotContext?.tables, [table_name]: selectedList },
5952
+ ...latestContext,
5953
+ tables: { ...latestContext?.tables, [table_name]: selectedList },
5914
5954
  }));
5915
5955
  }
5916
5956
  catch (error) {
@@ -6781,6 +6821,8 @@ const SliderContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
6781
6821
  const formKey = `${messageIndex}_${bodyText?.paramName}`;
6782
6822
  const { header, headerOrentiation, inputPosition, label, max, min, required, disabled, } = bodyText;
6783
6823
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
6824
+ const chatbotContextRef = useRef(chatbotContext);
6825
+ chatbotContextRef.current = chatbotContext;
6784
6826
  const persistedFormValues = useSelector((state) => state.smartBotReducer.persistedFormValues);
6785
6827
  const dispatch = useDispatch();
6786
6828
  const [sliderValue, setSliderValue] = useState(persistedFormValues[formKey] !== undefined ? persistedFormValues[formKey] : 0);
@@ -6788,16 +6830,18 @@ const SliderContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
6788
6830
  return null;
6789
6831
  const handleChange = (value) => {
6790
6832
  try {
6791
- setSliderValue(value?.target?.value);
6833
+ const newValue = value?.target?.value;
6834
+ setSliderValue(newValue);
6835
+ const latestContext = chatbotContextRef.current;
6792
6836
  dispatch(setChatbotContext({
6793
- ...chatbotContext,
6837
+ ...latestContext,
6794
6838
  [bodyText?.paramName]: {
6795
- ...chatbotContext?.[bodyText?.paramName],
6796
- [bodyText?.paramName]: value?.target?.value,
6839
+ ...latestContext?.[bodyText?.paramName],
6840
+ [bodyText?.paramName]: newValue,
6797
6841
  updated: true,
6798
6842
  },
6799
6843
  }));
6800
- dispatch(setPersistedFormValues({ [formKey]: value?.target?.value }));
6844
+ dispatch(setPersistedFormValues({ [formKey]: newValue }));
6801
6845
  }
6802
6846
  catch (error) {
6803
6847
  console.error("Error in slider handleChange", error);
@@ -6833,6 +6877,8 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
6833
6877
  const searchTermRef = useRef("");
6834
6878
  const selectAllCountRef = useRef(persistedFormValues?.[selectAllKey] || 0);
6835
6879
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
6880
+ const chatbotContextRef = useRef(chatbotContext);
6881
+ chatbotContextRef.current = chatbotContext;
6836
6882
  const heirarchyKeyValuePairs = useSelector((state) => state.smartBotReducer.heirarchyKeyValuePairs);
6837
6883
  const dispatch = useDispatch();
6838
6884
  // Cross-filter cascading context (optional — graceful fallback when not wrapped)
@@ -6850,10 +6896,11 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
6850
6896
  else {
6851
6897
  value = selectedOptions.value;
6852
6898
  }
6899
+ const latestContext = chatbotContextRef.current;
6853
6900
  const updatedContext = {
6854
- ...chatbotContext,
6901
+ ...latestContext,
6855
6902
  [bodyText?.paramName]: {
6856
- ...chatbotContext?.[bodyText?.paramName],
6903
+ ...latestContext?.[bodyText?.paramName],
6857
6904
  [bodyText?.paramName]: value,
6858
6905
  updated: true,
6859
6906
  },
@@ -6903,10 +6950,11 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
6903
6950
  setCurrentSelectedOptions([]);
6904
6951
  setIsAllSelected(false);
6905
6952
  // Also clear from chatbotContext and persistedFormValues
6953
+ const ctx = chatbotContextRef.current;
6906
6954
  dispatch(setChatbotContext({
6907
- ...chatbotContext,
6955
+ ...ctx,
6908
6956
  [bodyText?.paramName]: {
6909
- ...chatbotContext?.[bodyText?.paramName],
6957
+ ...ctx?.[bodyText?.paramName],
6910
6958
  [bodyText?.paramName]: [],
6911
6959
  updated: true,
6912
6960
  },
@@ -6964,10 +7012,11 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
6964
7012
  isRequired: isRequired, isDisabled: isDisabled || isFormDisabled, isClearable: !(isDisabled || isFormDisabled), onClearAll: () => {
6965
7013
  setCurrentSelectedOptions([]);
6966
7014
  setIsAllSelected(false);
7015
+ const ctx1 = chatbotContextRef.current;
6967
7016
  dispatch(setChatbotContext({
6968
- ...chatbotContext,
7017
+ ...ctx1,
6969
7018
  [bodyText?.paramName]: {
6970
- ...chatbotContext?.[bodyText?.paramName],
7019
+ ...ctx1?.[bodyText?.paramName],
6971
7020
  [bodyText?.paramName]: [],
6972
7021
  updated: true,
6973
7022
  },
@@ -7046,10 +7095,11 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7046
7095
  selectAllCountRef.current = allOptionsRef.current.length;
7047
7096
  }
7048
7097
  setIsAllSelected(true);
7098
+ const ctx2 = chatbotContextRef.current;
7049
7099
  dispatch(setChatbotContext({
7050
- ...chatbotContext,
7100
+ ...ctx2,
7051
7101
  [bodyText?.paramName]: {
7052
- ...chatbotContext?.[bodyText?.paramName],
7102
+ ...ctx2?.[bodyText?.paramName],
7053
7103
  [bodyText?.paramName]: valuesToDispatch,
7054
7104
  updated: true,
7055
7105
  },
@@ -7067,10 +7117,11 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7067
7117
  else {
7068
7118
  setCurrentSelectedOptions([]);
7069
7119
  setIsAllSelected(false);
7120
+ const ctx3 = chatbotContextRef.current;
7070
7121
  dispatch(setChatbotContext({
7071
- ...chatbotContext,
7122
+ ...ctx3,
7072
7123
  [bodyText?.paramName]: {
7073
- ...chatbotContext?.[bodyText?.paramName],
7124
+ ...ctx3?.[bodyText?.paramName],
7074
7125
  [bodyText?.paramName]: [],
7075
7126
  updated: true,
7076
7127
  },
@@ -7092,6 +7143,8 @@ const DatePickerContent = ({ bodyText, isFormDisabled = false, messageIndex }) =
7092
7143
  const formKey = `${messageIndex}_${bodyText?.paramName}`;
7093
7144
  const { displayFormat, label, isRequired, labelOrientation, placeholder, minDate, maxDate, isDisabled, minStartDate, } = bodyText;
7094
7145
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
7146
+ const chatbotContextRef = useRef(chatbotContext);
7147
+ chatbotContextRef.current = chatbotContext;
7095
7148
  const persistedFormValues = useSelector((state) => state.smartBotReducer.persistedFormValues);
7096
7149
  const dispatch = useDispatch();
7097
7150
  const [selectedDate, setSelectedDate] = useState(persistedFormValues[formKey] || null);
@@ -7100,10 +7153,11 @@ const DatePickerContent = ({ bodyText, isFormDisabled = false, messageIndex }) =
7100
7153
  const handleDateChange = (date) => {
7101
7154
  try {
7102
7155
  setSelectedDate(date);
7156
+ const latestContext = chatbotContextRef.current;
7103
7157
  dispatch(setChatbotContext({
7104
- ...chatbotContext,
7158
+ ...latestContext,
7105
7159
  [bodyText?.paramName]: {
7106
- ...chatbotContext?.[bodyText?.paramName],
7160
+ ...latestContext?.[bodyText?.paramName],
7107
7161
  [bodyText?.paramName]: moment(date).format(displayFormat),
7108
7162
  updated: true,
7109
7163
  },
@@ -7131,6 +7185,8 @@ const DateRangePickerContent = ({ bodyText, isFormDisabled = false, messageIndex
7131
7185
  const formKey = `${messageIndex}_${bodyText?.paramName}`;
7132
7186
  const { displayFormat, label, isRequired, labelOrientation, minDate, maxDate, isDisabled, showMonthYearSelect, minStartDate, } = bodyText;
7133
7187
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
7188
+ const chatbotContextRef = useRef(chatbotContext);
7189
+ chatbotContextRef.current = chatbotContext;
7134
7190
  const persistedFormValues = useSelector((state) => state.smartBotReducer.persistedFormValues);
7135
7191
  const dispatch = useDispatch();
7136
7192
  const [startDate, setStartDate] = useState(persistedFormValues[formKey]?.startDate || null);
@@ -7141,10 +7197,11 @@ const DateRangePickerContent = ({ bodyText, isFormDisabled = false, messageIndex
7141
7197
  try {
7142
7198
  setStartDate(start);
7143
7199
  setEndDate(end);
7200
+ const latestContext = chatbotContextRef.current;
7144
7201
  dispatch(setChatbotContext({
7145
- ...chatbotContext,
7202
+ ...latestContext,
7146
7203
  [bodyText?.paramName]: {
7147
- ...chatbotContext?.[bodyText?.paramName],
7204
+ ...latestContext?.[bodyText?.paramName],
7148
7205
  [bodyText?.paramName]: {
7149
7206
  startDate: start ? moment(start).format(displayFormat) : null,
7150
7207
  endDate: end ? moment(end).format(displayFormat) : null,
@@ -7179,6 +7236,8 @@ const CheckboxContent = ({ bodyText, isFormDisabled = false, messageIndex }) =>
7179
7236
  const formKey = `${messageIndex}_${bodyText?.paramName}`;
7180
7237
  const { label, checked: checkedValue, required, disabled, } = bodyText;
7181
7238
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
7239
+ const chatbotContextRef = useRef(chatbotContext);
7240
+ chatbotContextRef.current = chatbotContext;
7182
7241
  const persistedFormValues = useSelector((state) => state.smartBotReducer.persistedFormValues);
7183
7242
  const dispatch = useDispatch();
7184
7243
  const [checked, setChecked] = useState(persistedFormValues[formKey] !== undefined ? persistedFormValues[formKey] : checkedValue);
@@ -7187,15 +7246,11 @@ const CheckboxContent = ({ bodyText, isFormDisabled = false, messageIndex }) =>
7187
7246
  const handleChange = (isChecked) => {
7188
7247
  try {
7189
7248
  setChecked(isChecked?.currentTarget?.checked);
7190
- // chatbotContext.checkbox = {
7191
- // ...chatbotContext?.checkbox,
7192
- // [bodyText?.paramName]: isChecked?.currentTarget?.checked,
7193
- // updated: true
7194
- // };
7249
+ const latestContext = chatbotContextRef.current;
7195
7250
  dispatch(setChatbotContext({
7196
- ...chatbotContext,
7251
+ ...latestContext,
7197
7252
  [bodyText?.paramName]: {
7198
- ...chatbotContext?.[bodyText?.paramName],
7253
+ ...latestContext?.[bodyText?.paramName],
7199
7254
  [bodyText?.paramName]: isChecked?.currentTarget?.checked,
7200
7255
  updated: true,
7201
7256
  },
@@ -7214,6 +7269,8 @@ const RadioContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7214
7269
  const classes = useStyles$a();
7215
7270
  const { label, isDisabled, orientation, options } = bodyText;
7216
7271
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
7272
+ const chatbotContextRef = useRef(chatbotContext);
7273
+ chatbotContextRef.current = chatbotContext;
7217
7274
  const persistedFormValues = useSelector((state) => state.smartBotReducer.persistedFormValues);
7218
7275
  const dispatch = useDispatch();
7219
7276
  const [selectedOption, setSelectedOption] = useState(persistedFormValues[formKey] ?? null);
@@ -7228,10 +7285,11 @@ const RadioContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7228
7285
  // [bodyText?.paramName]: value,
7229
7286
  // updated: true,
7230
7287
  // };
7288
+ const latestContext = chatbotContextRef.current;
7231
7289
  dispatch(setChatbotContext({
7232
- ...chatbotContext,
7290
+ ...latestContext,
7233
7291
  [bodyText?.paramName]: {
7234
- ...chatbotContext?.[bodyText?.paramName],
7292
+ ...latestContext?.[bodyText?.paramName],
7235
7293
  [bodyText?.paramName]: value,
7236
7294
  updated: true,
7237
7295
  },
@@ -7249,6 +7307,8 @@ const InputContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7249
7307
  const formKey = `${messageIndex}_${bodyText?.paramName}`;
7250
7308
  const { label, placeholder, isRequired, isDisabled, inputType, labelOrientation, defaultValue, maxLength, minLength, } = bodyText;
7251
7309
  const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
7310
+ const chatbotContextRef = useRef(chatbotContext);
7311
+ chatbotContextRef.current = chatbotContext;
7252
7312
  const persistedFormValues = useSelector((state) => state.smartBotReducer.persistedFormValues);
7253
7313
  const dispatch = useDispatch();
7254
7314
  const [value, setValue] = useState(persistedFormValues[formKey] !== undefined ? persistedFormValues[formKey] : (defaultValue || ""));
@@ -7258,10 +7318,11 @@ const InputContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7258
7318
  try {
7259
7319
  const newValue = event?.target?.value || event?.currentTarget?.value || "";
7260
7320
  setValue(newValue);
7321
+ const latestContext = chatbotContextRef.current;
7261
7322
  dispatch(setChatbotContext({
7262
- ...chatbotContext,
7323
+ ...latestContext,
7263
7324
  [bodyText?.paramName]: {
7264
- ...chatbotContext?.[bodyText?.paramName],
7325
+ ...latestContext?.[bodyText?.paramName],
7265
7326
  [bodyText?.paramName]: replaceSpecialCharToCharCode(newValue),
7266
7327
  updated: true,
7267
7328
  type: inputType,
@@ -7557,6 +7618,15 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
7557
7618
  });
7558
7619
  return selections;
7559
7620
  }, [crossFilterConfigs, chatbotContext, persistedFormValues, messageIndex]);
7621
+ // Extract the param names of the current form's fields so ButtonContent
7622
+ // can restrict user_input to only these keys (avoids leaking stale context).
7623
+ const formParamNames = useMemo(() => {
7624
+ if (!formData || !Array.isArray(formData))
7625
+ return [];
7626
+ return formData
7627
+ .filter((item) => item?.type !== "button" && item?.data?.param_name)
7628
+ .map((item) => item.data.param_name);
7629
+ }, [formData]);
7560
7630
  if (!formData || !Array.isArray(formData) || formData.length === 0) {
7561
7631
  return null;
7562
7632
  }
@@ -7584,7 +7654,7 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
7584
7654
  case "radio":
7585
7655
  return jsx(RadioContent, { bodyText: parsedData.bodyText, isFormDisabled: formFieldsDisabled, messageIndex: messageIndex }, key);
7586
7656
  case "button":
7587
- return jsx(ButtonContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled || isFormSubmitted || isTimedOut, isStepFormSubmit: true, isFormValid: requiredFieldsFilled }, key);
7657
+ return jsx(ButtonContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled || isFormSubmitted || isTimedOut, isStepFormSubmit: true, isFormValid: requiredFieldsFilled, formParamNames: formParamNames, messageIndex: messageIndex }, key);
7588
7658
  case "input":
7589
7659
  return jsx(InputContent, { bodyText: parsedData.bodyText, isFormDisabled: formFieldsDisabled, messageIndex: messageIndex }, key);
7590
7660
  case "image":