UNPKG

@onereach/channel-transformer

Version:

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

28 lines (22 loc) 863 B
import { IGenericCheckbox } from '../../../../generic/types'; import { IRWCOption, IRWCMessage, IRWCAnswerComponent } from '../../../types'; import { getAnswerComponent } from '../../../helpers/answer-types'; export const transformCheckbox = ({ props }: IGenericCheckbox): IRWCMessage => { const options: Array<IRWCOption> = props?.options?.map(op => ({ label: op.label || op.value, value: op.value || op.label })) || []; const selected = props.value && options?.filter(op => props.value[op.value as string] === true); const defaultValue = selected?.map(o => o.label); const answerComponent: IRWCAnswerComponent = getAnswerComponent('rwc-checkbox-group'); answerComponent.vBind = { ...props.rwc, options, defaultValue }; const result: IRWCMessage = { message: props.label, answerComponent }; return result; };