UNPKG

@onereach/channel-transformer

Version:

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

28 lines (22 loc) 852 B
import { IGenericRadio } from '../../../../generic/types'; import { IRWCOption, IRWCMessage, IRWCAnswerComponent } from '../../../types'; import { getAnswerComponent } from '../../../helpers/answer-types'; export const transformRadio = ({ props }: IGenericRadio): IRWCMessage => { const options: Array<IRWCOption> = props?.options?.map(op => ({ label: op.label || op.value, value: op.value || op.label })) || []; const selected = props.value && options?.find(op => props.value[op.value as string] === true); const defaultValue = selected?.label || "No option"; const answerComponent: IRWCAnswerComponent = getAnswerComponent('rwc-radio-group'); answerComponent.vBind = { ...props.rwc, options, defaultValue }; const result: IRWCMessage = { message: props.label, answerComponent }; return result; };