UNPKG

@onereach/channel-transformer

Version:

Convert data model between different channels (Slack, Microsoft Teams, Generic...)

26 lines (21 loc) 806 B
import { IGenericRadio } from "../../../../generic/types"; import { IRWCAnswerComponent, IRWCOption } from '../../../types'; import { RWCAnswerComponent } from "../../../classes/v5"; import { removeBackticks } from "../../../utils"; export const transformRadioGroup = ({props}: IGenericRadio) : IRWCAnswerComponent => { const type = "rwc-radio-group"; const options: Array<IRWCOption> = props.options.map(op => ({ value: op.value, label: op.label, })); const result = { options, defaultValue: "No option" }; for (const radio in props.value) { if (props.value[radio]) result.defaultValue = removeBackticks( options.find(({ value }) => value === radio).label ); } return new RWCAnswerComponent(result, type); };