in this editChannelWidget effector method I need to make a check that if…
- User
in this editChannelWidget effector method I need to make a check that if data.prechats.skillGroup.label is undefined then it should also assign empty string to it. .on(editChannelWidget, (store, data) => ({ ...store, channelSettings: { ...store.channelSettings, prechats: { ...store.channelSettings?.prechats, ...data.prechats, fullName: { ...store.channelSettings?.prechats?.fullName, ...data.prechats?.fullName, }, phone: { ...store.channelSettings?.prechats?.phone, ...data.prechats?.phone, }, skillGroup: { ...store.channelSettings?.prechats?.skillGroup, ...data.prechats?.skillGroup, }, }, bar: { ...store.channelSettings?.bar, ...data.bar, text: { ...store.channelSettings?.bar?.text, ...data.bar?.text, }, triggerMessage: { ...store.channelSettings?.bar?.triggerMessage, ...data.bar?.triggerMessage, }, }, behaviour: { ...store.channelSettings?.behaviour, ...data.behaviour, }, }, }))
- Assistant
To add a check for
data.prechats.skillGroup.labelto assign an empty string if it isundefined, you can modify theskillGroupassignment within theeditChannelWidgetmethod as follows:- Use optional chaining to safely access the existing
skillGroup. - Check if
data.prechats.skillGroup.labelis undefined, and if so, assign an empty string to it.
Here's how you can adjust the code:
.on(editChannelWidget, (store, data) => ({ ...store, channelSettings: { ...store.channelSettings, prechats: { ...store.channelSettings?.prechats, ...data.prechats, fullName: { ...store.channelSettings?.prechats?.fullName, ...data.prechats?.fullName, }, phone: { ...store.channelSettings?.prechats?.phone, ...data.prechats?.phone, }, skillGroup: { ...store.channelSettings?.prechats?.skillGroup, ...data.prechats?.skillGroup, label: data.prechats?.skillGroup?.label === undefined ? '' : data.prechats?.skillGroup?.label, }, }, bar: { ...store.channelSettings?.bar, ...data.bar, text: { ...store.channelSettings?.bar?.text, ...data.bar?.text, }, triggerMessage: { ...store.channelSettings?.bar?.triggerMessage, ...data.bar?.triggerMessage, }, }, behaviour: { ...store.channelSettings?.behaviour, ...data.behaviour, }, }, })) - Use optional chaining to safely access the existing
- User
This code results in a bug where once I input something inside of my input of fullName and then switch to the input skillGroup, the value of fullName will disappear and change to an empty string.
- Assistant
- User
what about the revious logic of undefined value in lable of fullName though, it now won't work too
- Assistant