UNPKG

@onereach/channel-transformer

Version:

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

41 lines (33 loc) 1.26 kB
import { IGenericRadio } from '../../../generic/types'; import { ISlackInput, ISlackRadioButton, ISlackTextObject } from '../../types'; import { convertGenericOptions } from '../helpers/convert-options'; import { getElementWithSectionWrapper } from '../helpers/section-wrapper'; import { transformConfirm } from './confirm'; import { transformTextObject } from './text'; export const transformRadioButtons = ({ props }: IGenericRadio): ISlackRadioButton|ISlackInput => { const element: ISlackRadioButton = { type: 'radio_buttons', action_id: props.slack?.action_id || props.variableName || props.web?.variableName, options: convertGenericOptions(props.options) }; if (props.slack?.confirm) { element.confirm = transformConfirm(props.slack?.confirm); } if (props.value) { const initial_option = element.options?.find(op => props.value[op.value] === true); if (initial_option) { element.initial_option = initial_option; } } if (props.label) { const label: ISlackTextObject = transformTextObject({ value: props.label, type: 'plain' }); const dispatch_action = props.web?.interactive; return getElementWithSectionWrapper(element, label, dispatch_action); } return element; };