-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
botonic-react: add whatsapp product list component
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/botonic-react/src/components/whatsapp-product-list.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
|
||
export const WhatsappProductList = (props: WhatsappProductListProps) => { | ||
const renderBrowser = () => { | ||
// Return a dummy message for browser | ||
const message = `WhatsApp Product List would be sent to the user.` | ||
return ( | ||
<Message json={serialize(message)} {...props} type={INPUT.TEXT}> | ||
{message} | ||
</Message> | ||
) | ||
} | ||
|
||
const renderNode = () => { | ||
return ( | ||
// @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 }) | ||
} |