I am unable to change the checkbox value when I click on it. But when I save it and re-call the API I am getting the expected value.
{state?.skuModifierList?.map((item) => {
return (
<Panel
header={item?.name}
key={item.id}
className="panel-styles"
extra={<DeleteOutlined onClick={() => deleteModifier(item.id)} className="delete-modifier-icon"/>}
>
<div>
<Row gutter={[8, 8]}>
{item?.options?.map((option) => {
return(
<Col {...({ sm: 24, md: 12 })} key={option?.modifier_option_id}>
<div className='modifier-checkbox-wrapper'>
<Row gutter={[8, 8]}>
<Col {...({ sm: 24, md: 20 })}>
{option?.name}
</Col>
<Col {...({ sm: 24, md: 4 })}>
<Checkbox
checked = {option?.suppressed == true ? false : true}
onChange={(e) => handleChange({
value:e.target.checked,
modifierId:item.id,
optionId:option?.modifier_option_id,
})}
/>
</Col>
</Row>
</div>
</Col>
)
})}
</Row>
<div className='save-modifier-options-btn-wrapper'>
<Button type="primary" onClick={updateModifierOptions} className="save-modifier-options-btn">
Save
</Button>
</div>
</div>
</Panel>
)
})}
If I change the attribute from checked to defaultChecked then in the UI the checkbox is updating but I am not getting the updated data. Without a page refresh.
This is my handle change function
const handleChange = ({value, modifierId, optionId}) => {
if(selectedModifierId !== modifierId){
optionList = []
}
selectedModifierId = modifierId
const tempList = [...state?.skuModifierList];
tempList?.map((i) => {
if(i?.id == modifierId){
i?.options?.map((op) => {
if(op?.modifier_option_id == optionId){
if(value == false) {
optionList?.push(op?.modifier_option_id)
}
if(value == true){
if(optionList?.includes(op?.modifier_option_id)){
const index = optionList?.indexOf(op?.modifier_option_id);
optionList?.splice(index, 1);
}
}
}
})
}
})
}