verdnatura-chat/app/containers/message/Blocks.ts

33 lines
670 B
TypeScript
Raw Normal View History

2020-02-11 14:01:35 +00:00
import React from 'react';
2020-02-11 14:01:35 +00:00
import { messageBlockWithContext } from '../UIKit/MessageBlock';
import { IMessageBlocks } from './interfaces';
2020-02-11 14:01:35 +00:00
const Blocks = React.memo(({ blocks, id: mid, rid, blockAction }: IMessageBlocks) => {
2020-02-11 14:01:35 +00:00
if (blocks && blocks.length > 0) {
const appId = blocks[0]?.appId || '';
2020-02-11 14:01:35 +00:00
return React.createElement(
messageBlockWithContext({
action: async ({ actionId, value, blockId }: any) => {
2020-02-11 14:01:35 +00:00
await blockAction({
actionId,
appId,
value,
blockId,
rid,
mid
});
},
appId,
rid
}),
{ blocks }
2020-02-11 14:01:35 +00:00
);
}
return null;
});
Blocks.displayName = 'MessageBlocks';
export default Blocks;