UNPKG

@onereach/channel-transformer

Version:

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

30 lines (27 loc) 1.02 kB
import { IGenericCard } from "../../../../generic/types"; import { getMethods } from "../methods"; export const transformCard = ( { props, children }: IGenericCard) => { const initCard: any = {...props.rwc, submitButtons: []}; return children.reduce((card, child) => { switch(child.type) { case 'video': card[child.type] = { ...child.props.rwc }; break; case 'image': card[child.type] = { ...child.props.rwc }; break; case 'additionalContentLink': card[child.type] = { ...child.props.rwc }; break; case 'header': card.title = getMethods(child.type)(child, true); break; case 'text': card.description = child.props.value; break; case 'button': card.submitButtons.push(getMethods(child.type)(child)); } return card; }, initCard); };