@onereach/channel-transformer
Version:
Convert data model between different channels (Slack, Microsoft Teams, Generic...)
32 lines (26 loc) • 746 B
text/typescript
import { IGenericOptions, IGenericRadio } from "../../../generic/types";
import { IRWCAnswerComponent } from "../../types";
import { removeBackticks } from "../../utils";
export const transformRadioGroup = (msg: IRWCAnswerComponent): IGenericRadio => {
const options: Array<IGenericOptions> = msg.vBind?.options.map(({ label, value } )=> {
return {
label,
value,
name: value,
key: value
};
});
const result: IGenericRadio = {
type: 'radio',
props: {
value: {},
options
}
};
if (msg.vBind.defaultValue) {
options.forEach(op => {
result.props.value[op.name] = removeBackticks(msg.vBind.defaultValue) === removeBackticks(op.label);
});
}
return result;
};