beem-component 2.0.17 → 2.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,8 @@ import styled from 'styled-components';
8
8
  import Avatar from 'react-avatar';
9
9
  import ListIcon from '@mui/icons-material/List';
10
10
  import ShoppingCartOutlinedIcon from '@mui/icons-material/ShoppingCartOutlined';
11
+ import { isUndefined } from 'lodash';
12
+ import { Document, pdfjs, Page } from 'react-pdf';
11
13
  import BmAvatar from '../../Avatars/avatars';
12
14
  import { BmIcons } from '../../iconStyles';
13
15
  import { SessionDetails } from './sessionDetails';
@@ -24,6 +26,8 @@ import {
24
26
  } from '../../colors';
25
27
  import { BmFeedPostComments } from './FeedPostComments';
26
28
 
29
+ pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
30
+
27
31
  const BmChat = styled.div`
28
32
  display: flex;
29
33
  flex-direction: column;
@@ -75,13 +79,13 @@ const MessageDetails = styled.div`
75
79
  const Messages = styled.div`
76
80
  display: flex;
77
81
  flex-direction: ${({ type, isInteractive }) => {
78
- if (type === 'interactive' || isInteractive) {
82
+ if (type === 'interactive' || type === 'order' || isInteractive) {
79
83
  return 'column';
80
84
  }
81
85
  return 'row';
82
86
  }};
83
- align-items: ${({ type }) => {
84
- if (type === 'interactive') {
87
+ align-items: ${({ type, isInteractive }) => {
88
+ if (type === 'interactive' || type === 'order' || isInteractive) {
85
89
  return ' start';
86
90
  }
87
91
  return 'center';
@@ -159,6 +163,48 @@ const IntButton = styled.button`
159
163
  }};
160
164
  border-radius: 0.3rem;
161
165
  `;
166
+ const OrderBody = styled.button`
167
+ padding: 1rem;
168
+ margin: 0.1rem;
169
+ display: flex;
170
+ flex-direction: column;
171
+ align-items: start;
172
+ justify-content: center;
173
+ width: 100%;
174
+ background-color: rgba(217, 217, 217, 0.3);
175
+ border: none;
176
+ color: ${({ state }) => {
177
+ if (state) {
178
+ if (state === 'inbound') return `${BmPrimaryBlack}`;
179
+ if (state === 'outbound') return `${BmPrimaryWhite}`;
180
+ }
181
+ return `${BmPrimaryWhite}`;
182
+ }};
183
+ border-radius: 0.3rem;
184
+ > * {
185
+ color: ${({ state }) => {
186
+ if (state) {
187
+ if (state === 'inbound') return `${BmPrimaryBlack}`;
188
+ if (state === 'outbound') return `${BmPrimaryWhite}`;
189
+ }
190
+ return `${BmPrimaryWhite}`;
191
+ }};
192
+ }
193
+ `;
194
+ const CartContent = styled.div`
195
+ margin-bottom: 0.5rem;
196
+ display: flex;
197
+ flex-direction: row;
198
+ align-items: center;
199
+ justify-content: center;
200
+ color: ${({ state }) => {
201
+ if (state) {
202
+ if (state === 'inbound') return `${BmPrimaryBlack}`;
203
+ if (state === 'outbound') return `${BmPrimaryWhite}`;
204
+ }
205
+ return `${BmPrimaryWhite}`;
206
+ }};
207
+ `;
162
208
 
163
209
  const MessagesSubDetails = styled.div`
164
210
  display: flex;
@@ -364,6 +410,87 @@ export const RepliedTextWrapper = styled.div`
364
410
  }};
365
411
  `;
366
412
 
413
+ const QuickReplyRender = ({
414
+ content,
415
+ options,
416
+ type,
417
+ state,
418
+ rest,
419
+ isInteractive,
420
+ }) => {
421
+ return (
422
+ <Messages type={type} state={state} isInteractive={isInteractive} isImg>
423
+ {content?.url && (
424
+ <BmImageChat state={state} src={content?.url} {...rest} />
425
+ )}
426
+
427
+ <strong>{content?.header}</strong>
428
+ <p>{content?.text}</p>
429
+ <small>{content?.caption}</small>
430
+ {options?.map((button) => (
431
+ // eslint-disable-next-line react/jsx-key
432
+ <IntButton state={state}>{button?.title}</IntButton>
433
+ ))}
434
+ </Messages>
435
+ );
436
+ };
437
+ const ProductDetailRender = ({ type, state, header, body, isInteractive }) => {
438
+ console.log(type, state, header, body);
439
+ return (
440
+ <>
441
+ <Messages type={type} state={state} isInteractive={isInteractive}>
442
+ <strong>{header?.text}</strong>
443
+ <p>{body?.text}</p>
444
+ <IntButton state={state}>
445
+ <ShoppingCartOutlinedIcon />
446
+ Catalog
447
+ </IntButton>
448
+ </Messages>
449
+ </>
450
+ );
451
+ };
452
+ const ListReplyRender = ({
453
+ title,
454
+ body,
455
+ globalButtons,
456
+ isInteractive,
457
+ type,
458
+ state,
459
+ }) => {
460
+ return (
461
+ <>
462
+ <Messages type={type} state={state} isInteractive={isInteractive}>
463
+ <strong>{title}</strong>
464
+ <p>{body}</p>
465
+ <IntButton state={state}>
466
+ <ListIcon />
467
+ {globalButtons[0]?.title}
468
+ </IntButton>
469
+ </Messages>
470
+ </>
471
+ );
472
+ };
473
+
474
+ const OrderRender = ({ count, amount, type, state }) => {
475
+ return (
476
+ <>
477
+ <Messages type={type} state={state}>
478
+ <OrderBody state={state}>
479
+ <CartContent state={state}>
480
+ <ShoppingCartOutlinedIcon fontSize="small" />
481
+ <h5>
482
+ <strong>{count} items</strong>
483
+ </h5>
484
+ </CartContent>
485
+ <div>{amount} (estimated total)</div>
486
+ </OrderBody>
487
+
488
+ <IntButton state={state}>view sent cart</IntButton>
489
+ </Messages>
490
+ </>
491
+ );
492
+ };
493
+
367
494
  BmChat.Details = ({
368
495
  children,
369
496
  state,
@@ -382,6 +509,7 @@ BmChat.Details = ({
382
509
  type,
383
510
  ...rest
384
511
  }) => {
512
+ console.log(src);
385
513
  return (
386
514
  <>
387
515
  <Details state={state} {...rest}>
@@ -393,7 +521,7 @@ BmChat.Details = ({
393
521
  </MessageState>
394
522
  <MessageDetails feedPostComments={feedPostComments}>
395
523
  {/* For Images */}
396
- {src && (
524
+ {src && !isUndefined(src) && (
397
525
  <BmImageChat
398
526
  state={state}
399
527
  src={src}
@@ -407,99 +535,75 @@ BmChat.Details = ({
407
535
  {metadata ? (
408
536
  <RepliedTextWrapper state={state}>
409
537
  {metadata.type === 'quick_reply' ? (
410
- <Messages
411
- isInteractive={isInteractive}
538
+ <QuickReplyRender
539
+ isInteractive
540
+ rest={rest}
541
+ {...metadata}
412
542
  type={type}
413
543
  state={state}
414
- isImg
415
- >
416
- {metadata?.content?.url && (
417
- <BmImageChat
418
- state={state}
419
- src={metadata?.content?.url}
420
- {...rest}
421
- />
422
- )}
423
-
424
- <strong>{metadata?.content?.header}</strong>
425
- <p>{metadata?.content?.text}</p>
426
- <small>{metadata?.content?.caption}</small>
427
- {metadata?.options?.map((button) => (
428
- // eslint-disable-next-line react/jsx-key
429
- <IntButton state={state}>{button?.title}</IntButton>
430
- ))}
431
- </Messages>
432
- ) : metadata.type === 'quick_reply' ? (
433
- <Messages
434
- isInteractive={isInteractive}
544
+ />
545
+ ) : metadata.type === 'list' ? (
546
+ <ListReplyRender
547
+ isInteractive
548
+ {...metadata}
549
+ type={type}
550
+ state={state}
551
+ />
552
+ ) : metadata.type === 'product_details' ? (
553
+ <ProductDetailRender
554
+ isInteractive
555
+ {...metadata}
435
556
  type={type}
436
557
  state={state}
437
- >
438
- <strong>{metadata?.title}</strong>
439
- <p>{metadata?.body}</p>
440
- <IntButton state={state}>
441
- <ListIcon />
442
- {metadata?.globalButtons[0]?.title}
443
- </IntButton>
444
- </Messages>
558
+ />
559
+ ) : metadata.type === 'order' ? (
560
+ <OrderRender {...metadata} type={type} state={state} />
445
561
  ) : (
446
- <Messages metadata={metadata} state={state}>
447
- {metadata}
448
- </Messages>
562
+ <Messages metadata={metadata} state={state} />
449
563
  )}
450
564
 
451
565
  {children}
452
566
  </RepliedTextWrapper>
453
567
  ) : (
454
568
  <>
455
- {type && type === 'interactive' ? (
569
+ {type && (type === 'interactive' || type === 'order') ? (
456
570
  <>
457
- {children.type === 'quick_reply' ? (
458
- <Messages type={type} state={state} isImg>
459
- {children?.content?.url && (
460
- <BmImageChat
461
- state={state}
462
- src={children?.content?.url}
463
- {...rest}
464
- />
465
- )}
466
-
467
- <strong>{children?.content?.header}</strong>
468
- <p>{children?.content?.text}</p>
469
- <small>{children?.content?.caption}</small>
470
- {children?.options?.map((button) => (
471
- // eslint-disable-next-line react/jsx-key
472
- <IntButton state={state}>{button?.title}</IntButton>
473
- ))}
474
- </Messages>
475
- ) : (
476
- <>
477
- {children.type === 'product_details' ? (
478
- <>
479
- <Messages type={type} state={state}>
480
- <strong>{children?.header?.text}</strong>
481
- <p>{children?.body?.text}</p>
482
- <IntButton state={state}>
483
- <ShoppingCartOutlinedIcon />
484
- Catalog
485
- </IntButton>
486
- </Messages>
487
- </>
488
- ) : (
489
- <>
490
- <Messages type={type} state={state}>
491
- <strong>{children?.title}</strong>
492
- <p>{children?.body}</p>
493
- <IntButton state={state}>
494
- <ListIcon />
495
- {children?.globalButtons[0]?.title}
496
- </IntButton>
497
- </Messages>
498
- </>
499
- )}
500
- </>
571
+ {children.type === 'quick_reply' && (
572
+ <QuickReplyRender
573
+ rest={rest}
574
+ {...children}
575
+ type={type}
576
+ state={state}
577
+ />
578
+ )}
579
+ {children.type === 'list' && (
580
+ <ListReplyRender
581
+ {...children}
582
+ type={type}
583
+ state={state}
584
+ />
585
+ )}
586
+ {children.type === 'product_details' && (
587
+ <ProductDetailRender
588
+ {...children}
589
+ type={type}
590
+ state={state}
591
+ />
592
+ )}
593
+ {children.type === 'order' && (
594
+ <OrderRender {...children} type={type} state={state} />
501
595
  )}
502
596
  </>
597
+ ) : type === 'pdf' ? (
598
+ <>
599
+ <Document
600
+ file={{
601
+ url: `${file}`,
602
+ }}
603
+ >
604
+ <Page pageNumber={1} height="250" width="200" />
605
+ </Document>
606
+ </>
503
607
  ) : (
504
608
  <Messages state={state}>{children}</Messages>
505
609
  )}