Skip to content

Commit

Permalink
botonic-react: add whatsapp product list component
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertGom committed Dec 24, 2024
1 parent 4f5a25a commit 6e85d3e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/botonic-react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ export {
WhatsappCTAUrlButtonProps,
} from './whatsapp-cta-url-button'
export { WhatsappProduct } from './whatsapp-product'
export {
ProductItem,
WhatsappProductList,
WhatsappProductListProps,
WhatsappProductListSection,
} from './whatsapp-product-list'
export { WhatsappTemplate } from './whatsapp-template'
55 changes: 55 additions & 0 deletions packages/botonic-react/src/components/whatsapp-product-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { INPUT } from '@botonic/core'
import React from 'react'

import { renderComponent } from '../util/react'
import { Message } from './message'

export interface ProductItem {
product_retailer_id: string
}

export interface WhatsappProductListSection {
title: string
product_items: ProductItem[]
}

export interface WhatsappProductListProps {
body: string
header: string
catalogId: string
sections: WhatsappProductListSection[]
footer?: string
}

const serialize = (message: string) => {
return { text: message }

Check warning on line 25 in packages/botonic-react/src/components/whatsapp-product-list.tsx

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/components/whatsapp-product-list.tsx#L25

Added line #L25 was not covered by tests
}

export const WhatsappProductList = (props: WhatsappProductListProps) => {
const renderBrowser = () => {

Check warning on line 29 in packages/botonic-react/src/components/whatsapp-product-list.tsx

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/components/whatsapp-product-list.tsx#L29

Added line #L29 was not covered by tests
// Return a dummy message for browser
const message = `WhatsApp Product List would be sent to the user.`
return (

Check warning on line 32 in packages/botonic-react/src/components/whatsapp-product-list.tsx

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/components/whatsapp-product-list.tsx#L31-L32

Added lines #L31 - L32 were not covered by tests
<Message json={serialize(message)} {...props} type={INPUT.TEXT}>
{message}
</Message>
)
}

const renderNode = () => {
return (

Check warning on line 40 in packages/botonic-react/src/components/whatsapp-product-list.tsx

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/components/whatsapp-product-list.tsx#L39-L40

Added lines #L39 - L40 were not covered by tests
// @ts-ignore Property 'message' does not exist on type 'JSX.IntrinsicElements'.
<message
{...props}
body={props.body}
footer={props.footer}
header={props.header}
sections={JSON.stringify(props.sections)}
catalogId={props.catalogId}
type={INPUT.WHATSAPP_PRODUCT_LIST}
/>
)
}

return renderComponent({ renderBrowser, renderNode })

Check warning on line 54 in packages/botonic-react/src/components/whatsapp-product-list.tsx

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/components/whatsapp-product-list.tsx#L54

Added line #L54 was not covered by tests
}

0 comments on commit 6e85d3e

Please sign in to comment.