beem-component 2.1.18 → 2.1.20
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.
- package/dist/components/ChatComponents/ChatBody/chatBody.js +177 -69
- package/dist/components/Modals/modal.js +19 -11
- package/dist/components/Modals/modals.stories.js +13 -6
- package/package.json +1 -1
- package/src/App.js +446 -1759
- package/src/lib/components/ChatComponents/ChatBody/chatBody.js +257 -56
- package/src/lib/components/Modals/modal.js +11 -3
- package/src/lib/components/Modals/modals.stories.js +10 -6
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable react/no-array-index-key */
|
|
1
2
|
/* eslint-disable no-nested-ternary */
|
|
2
3
|
/* eslint-disable react/display-name */
|
|
3
4
|
import React, { useState } from 'react';
|
|
@@ -61,7 +62,7 @@ const Details = styled.div`
|
|
|
61
62
|
}
|
|
62
63
|
overflow-wrap: break-word !important;
|
|
63
64
|
word-wrap: break-word !important;
|
|
64
|
-
margin: 0rem;
|
|
65
|
+
margin: 0rem;
|
|
65
66
|
|
|
66
67
|
flex-grow: 1;
|
|
67
68
|
${'' /* border: 1px solid red; */}
|
|
@@ -433,30 +434,90 @@ const QuickReplyRender = ({
|
|
|
433
434
|
state,
|
|
434
435
|
rest,
|
|
435
436
|
isInteractive,
|
|
437
|
+
connector,
|
|
438
|
+
body,
|
|
439
|
+
action,
|
|
440
|
+
header,
|
|
441
|
+
footer,
|
|
436
442
|
}) => {
|
|
437
|
-
|
|
438
|
-
|
|
443
|
+
const MEDIA_TYPES = ['document', 'image', 'video'];
|
|
444
|
+
const renderers = {
|
|
445
|
+
dotgo_v3: () => (
|
|
446
|
+
<>
|
|
447
|
+
{header && (
|
|
448
|
+
<>
|
|
449
|
+
{MEDIA_TYPES.includes(header?.type) ? (
|
|
450
|
+
<BmImageChat
|
|
451
|
+
state={state}
|
|
452
|
+
src={header[header.type]?.link}
|
|
453
|
+
{...rest}
|
|
454
|
+
/>
|
|
455
|
+
) : (
|
|
456
|
+
<h5>{header[header.type]?.text}</h5>
|
|
457
|
+
)}
|
|
458
|
+
</>
|
|
459
|
+
)}
|
|
460
|
+
|
|
461
|
+
{body && (
|
|
462
|
+
<>
|
|
463
|
+
{body?.text?.split('\n').map((line, idx) => (
|
|
464
|
+
<p key={`body-line-${idx}`}>
|
|
465
|
+
{line}
|
|
466
|
+
<br />
|
|
467
|
+
</p>
|
|
468
|
+
))}
|
|
469
|
+
</>
|
|
470
|
+
)}
|
|
471
|
+
|
|
472
|
+
{footer && <small>{footer?.text}</small>}
|
|
473
|
+
|
|
474
|
+
{action?.buttons?.length > 0 &&
|
|
475
|
+
action.buttons.map((button, idx) => (
|
|
476
|
+
<IntButton state={state} key={`action-btn-${idx}`}>
|
|
477
|
+
{button[button.type]?.title}
|
|
478
|
+
</IntButton>
|
|
479
|
+
))}
|
|
480
|
+
</>
|
|
481
|
+
),
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
const FallbackRenderer = () => (
|
|
485
|
+
<>
|
|
439
486
|
{content?.url && (
|
|
440
|
-
<
|
|
487
|
+
<div>
|
|
488
|
+
<BmImageChat state={state} src={content?.url} {...rest} />
|
|
489
|
+
</div>
|
|
441
490
|
)}
|
|
442
491
|
|
|
443
|
-
<strong>{content
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
<
|
|
448
|
-
|
|
492
|
+
{content?.header && <strong>{content.header}</strong>}
|
|
493
|
+
|
|
494
|
+
{content?.text?.split('\n').map((line, idx) => (
|
|
495
|
+
<div>
|
|
496
|
+
<p key={`content-line-${idx}`}>
|
|
497
|
+
{line}
|
|
498
|
+
<br />
|
|
499
|
+
</p>
|
|
500
|
+
</div>
|
|
449
501
|
))}
|
|
450
|
-
|
|
451
|
-
{
|
|
452
|
-
|
|
453
|
-
|
|
502
|
+
|
|
503
|
+
{content?.caption && <small>{content.caption}</small>}
|
|
504
|
+
|
|
505
|
+
{options?.map((button, idx) => (
|
|
506
|
+
<IntButton state={state} key={`opt-btn-${idx}`}>
|
|
507
|
+
{button?.title}
|
|
508
|
+
</IntButton>
|
|
454
509
|
))}
|
|
510
|
+
</>
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
const ConnectorRenderer = renderers[connector] || FallbackRenderer;
|
|
514
|
+
return (
|
|
515
|
+
<Messages type={type} state={state} isInteractive={isInteractive} isImg>
|
|
516
|
+
<ConnectorRenderer />
|
|
455
517
|
</Messages>
|
|
456
518
|
);
|
|
457
519
|
};
|
|
458
520
|
const ProductDetailRender = ({ type, state, header, body, isInteractive }) => {
|
|
459
|
-
console.log(type, state, header, body);
|
|
460
521
|
return (
|
|
461
522
|
<>
|
|
462
523
|
<Messages type={type} state={state} isInteractive={isInteractive}>
|
|
@@ -477,43 +538,88 @@ const ListReplyRender = ({
|
|
|
477
538
|
isInteractive,
|
|
478
539
|
type,
|
|
479
540
|
state,
|
|
541
|
+
connector,
|
|
542
|
+
header,
|
|
543
|
+
action,
|
|
544
|
+
footer,
|
|
480
545
|
}) => {
|
|
546
|
+
const renderers = {
|
|
547
|
+
dotgo_v3: () => (
|
|
548
|
+
<>
|
|
549
|
+
{header && (
|
|
550
|
+
<>
|
|
551
|
+
<h6>{header[header.type]?.text}</h6>
|
|
552
|
+
</>
|
|
553
|
+
)}
|
|
554
|
+
|
|
555
|
+
{body && (
|
|
556
|
+
<>
|
|
557
|
+
{body?.text?.split('\n').map((line, idx) => (
|
|
558
|
+
<p key={`body-line-${idx}`}>
|
|
559
|
+
{line}
|
|
560
|
+
<br />
|
|
561
|
+
</p>
|
|
562
|
+
))}
|
|
563
|
+
</>
|
|
564
|
+
)}
|
|
565
|
+
|
|
566
|
+
{footer && <small>{footer?.text}</small>}
|
|
567
|
+
|
|
568
|
+
{action.button && (
|
|
569
|
+
<IntButton state={state}>
|
|
570
|
+
<ListIcon />
|
|
571
|
+
{action.button}
|
|
572
|
+
</IntButton>
|
|
573
|
+
)}
|
|
574
|
+
</>
|
|
575
|
+
),
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
const FallbackRenderer = () => (
|
|
579
|
+
<>
|
|
580
|
+
<strong>{title}</strong>
|
|
581
|
+
{body.split('\n').map((line) => (
|
|
582
|
+
<p>
|
|
583
|
+
{line}
|
|
584
|
+
<br />
|
|
585
|
+
</p>
|
|
586
|
+
))}
|
|
587
|
+
<IntButton state={state}>
|
|
588
|
+
<ListIcon />
|
|
589
|
+
{globalButtons[0]?.title}
|
|
590
|
+
</IntButton>
|
|
591
|
+
</>
|
|
592
|
+
);
|
|
593
|
+
|
|
594
|
+
const ConnectorRenderer = renderers[connector] || FallbackRenderer;
|
|
481
595
|
return (
|
|
482
596
|
<>
|
|
483
597
|
<Messages type={type} state={state} isInteractive={isInteractive}>
|
|
484
|
-
<
|
|
485
|
-
{body.split('\n').map((line) => (
|
|
486
|
-
<p>
|
|
487
|
-
{line}
|
|
488
|
-
<br />
|
|
489
|
-
</p>
|
|
490
|
-
))}
|
|
491
|
-
<IntButton state={state}>
|
|
492
|
-
<ListIcon />
|
|
493
|
-
{globalButtons[0]?.title}
|
|
494
|
-
</IntButton>
|
|
598
|
+
<ConnectorRenderer />
|
|
495
599
|
</Messages>
|
|
496
600
|
</>
|
|
497
601
|
);
|
|
498
602
|
};
|
|
499
603
|
|
|
500
|
-
const OrderRender = ({
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
604
|
+
const OrderRender = ({
|
|
605
|
+
amount,
|
|
606
|
+
type,
|
|
607
|
+
state,
|
|
608
|
+
items,
|
|
609
|
+
product_items,
|
|
610
|
+
connector,
|
|
611
|
+
isInteractive,
|
|
612
|
+
}) => {
|
|
613
|
+
const renderers = {
|
|
614
|
+
dotgo_v3: ({ displayItems, sumQuantities, setDisplayItems }) => (
|
|
615
|
+
<>
|
|
511
616
|
<OrderBody state={state}>
|
|
512
617
|
<CartContent state={state}>
|
|
513
618
|
<ShoppingCartOutlinedIcon fontSize="small" />
|
|
514
619
|
<h5>
|
|
515
620
|
<strong>
|
|
516
|
-
{sumQuantities()}
|
|
621
|
+
{sumQuantities(product_items)}{' '}
|
|
622
|
+
{sumQuantities(product_items) > 1 ? 'items' : 'item'}
|
|
517
623
|
</strong>
|
|
518
624
|
</h5>
|
|
519
625
|
</CartContent>
|
|
@@ -521,7 +627,7 @@ const OrderRender = ({ amount, type, state, items }) => {
|
|
|
521
627
|
|
|
522
628
|
{displayItems ? (
|
|
523
629
|
<OrderBody state={state}>
|
|
524
|
-
{
|
|
630
|
+
{product_items.map((data, index) => (
|
|
525
631
|
<>
|
|
526
632
|
<CartContent state={state}>
|
|
527
633
|
<p>{index + 1}. </p>
|
|
@@ -555,6 +661,84 @@ const OrderRender = ({ amount, type, state, items }) => {
|
|
|
555
661
|
>
|
|
556
662
|
<p>{displayItems ? 'HIDE' : 'SHOW'} CART ITEMS</p>
|
|
557
663
|
</IntButton>
|
|
664
|
+
</>
|
|
665
|
+
),
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
const FallbackRenderer = ({
|
|
669
|
+
sumQuantities,
|
|
670
|
+
displayItems,
|
|
671
|
+
setDisplayItems,
|
|
672
|
+
}) => (
|
|
673
|
+
<>
|
|
674
|
+
<OrderBody state={state}>
|
|
675
|
+
<CartContent state={state}>
|
|
676
|
+
<ShoppingCartOutlinedIcon fontSize="small" />
|
|
677
|
+
<h5>
|
|
678
|
+
<strong>
|
|
679
|
+
{sumQuantities(items)}{' '}
|
|
680
|
+
{sumQuantities(items) > 1 ? 'items' : 'item'}
|
|
681
|
+
</strong>
|
|
682
|
+
</h5>
|
|
683
|
+
</CartContent>
|
|
684
|
+
</OrderBody>
|
|
685
|
+
|
|
686
|
+
{displayItems ? (
|
|
687
|
+
<OrderBody state={state}>
|
|
688
|
+
{items.map((data, index) => (
|
|
689
|
+
<>
|
|
690
|
+
<CartContent state={state}>
|
|
691
|
+
<p>{index + 1}. </p>
|
|
692
|
+
<ProductImage src={data.imgURL} alt="product" />
|
|
693
|
+
|
|
694
|
+
<p>
|
|
695
|
+
{data.quantity} X {data.description} @ {data.currency}{' '}
|
|
696
|
+
{data.amount}
|
|
697
|
+
</p>
|
|
698
|
+
</CartContent>
|
|
699
|
+
<hr style={{ width: '100%' }} />
|
|
700
|
+
</>
|
|
701
|
+
))}
|
|
702
|
+
</OrderBody>
|
|
703
|
+
) : (
|
|
704
|
+
<></>
|
|
705
|
+
)}
|
|
706
|
+
<OrderBody state={state}>
|
|
707
|
+
<CartContent state={state}>
|
|
708
|
+
<p>
|
|
709
|
+
{' '}
|
|
710
|
+
Estimated Total: <strong>{amount}</strong>
|
|
711
|
+
</p>
|
|
712
|
+
</CartContent>
|
|
713
|
+
</OrderBody>
|
|
714
|
+
<IntButton
|
|
715
|
+
state={state}
|
|
716
|
+
onClick={() => {
|
|
717
|
+
setDisplayItems(!displayItems);
|
|
718
|
+
}}
|
|
719
|
+
>
|
|
720
|
+
<p>{displayItems ? 'HIDE' : 'SHOW'} CART ITEMS</p>
|
|
721
|
+
</IntButton>
|
|
722
|
+
</>
|
|
723
|
+
);
|
|
724
|
+
|
|
725
|
+
const ConnectorRenderer = renderers[connector] || FallbackRenderer;
|
|
726
|
+
const [displayItems, setDisplayItems] = useState(false);
|
|
727
|
+
|
|
728
|
+
const sumQuantities = (data) => {
|
|
729
|
+
return data?.reduce((total, item) => {
|
|
730
|
+
return total + parseInt(item.quantity, 10);
|
|
731
|
+
}, 0);
|
|
732
|
+
};
|
|
733
|
+
return (
|
|
734
|
+
<>
|
|
735
|
+
<Messages type={type} state={state} isInteractive={isInteractive}>
|
|
736
|
+
<ConnectorRenderer
|
|
737
|
+
sumQuantities={sumQuantities}
|
|
738
|
+
setDisplayItems={setDisplayItems}
|
|
739
|
+
displayItems={displayItems}
|
|
740
|
+
items={items}
|
|
741
|
+
/>
|
|
558
742
|
</Messages>
|
|
559
743
|
</>
|
|
560
744
|
);
|
|
@@ -603,33 +787,42 @@ BmChat.Details = ({
|
|
|
603
787
|
<>
|
|
604
788
|
{metadata ? (
|
|
605
789
|
<RepliedTextWrapper state={state}>
|
|
606
|
-
{metadata.type === 'quick_reply'
|
|
790
|
+
{metadata.message.type === 'quick_reply' ||
|
|
791
|
+
metadata.message.type === 'button' ? (
|
|
607
792
|
<QuickReplyRender
|
|
608
793
|
isInteractive
|
|
609
794
|
rest={rest}
|
|
610
|
-
{...metadata}
|
|
795
|
+
{...metadata.message}
|
|
611
796
|
type={type}
|
|
612
797
|
state={state}
|
|
798
|
+
connector={metadata.connector}
|
|
613
799
|
/>
|
|
614
|
-
) : metadata.type === 'list' ? (
|
|
800
|
+
) : metadata.message.type === 'list' ? (
|
|
615
801
|
<ListReplyRender
|
|
616
802
|
isInteractive
|
|
617
|
-
{...metadata}
|
|
803
|
+
{...metadata.message}
|
|
618
804
|
type={type}
|
|
619
805
|
state={state}
|
|
806
|
+
connector={metadata.connector}
|
|
620
807
|
/>
|
|
621
|
-
) : metadata.type === 'product_details' ? (
|
|
808
|
+
) : metadata.message.type === 'product_details' ? (
|
|
622
809
|
<ProductDetailRender
|
|
623
810
|
isInteractive
|
|
624
|
-
{...metadata}
|
|
811
|
+
{...metadata.message}
|
|
625
812
|
type={type}
|
|
626
813
|
state={state}
|
|
627
814
|
/>
|
|
628
|
-
) : metadata.type === 'order' ? (
|
|
629
|
-
<OrderRender
|
|
815
|
+
) : metadata.message.type === 'order' ? (
|
|
816
|
+
<OrderRender
|
|
817
|
+
isInteractive
|
|
818
|
+
{...metadata.message}
|
|
819
|
+
type={type}
|
|
820
|
+
state={state}
|
|
821
|
+
connector={metadata.connector}
|
|
822
|
+
/>
|
|
630
823
|
) : (
|
|
631
824
|
<Messages metadata={metadata} state={state}>
|
|
632
|
-
{metadata}
|
|
825
|
+
{metadata.message}
|
|
633
826
|
</Messages>
|
|
634
827
|
)}
|
|
635
828
|
|
|
@@ -639,30 +832,38 @@ BmChat.Details = ({
|
|
|
639
832
|
<>
|
|
640
833
|
{type && (type === 'interactive' || type === 'order') ? (
|
|
641
834
|
<>
|
|
642
|
-
{children
|
|
835
|
+
{(children?.message?.type === 'quick_reply' ||
|
|
836
|
+
children?.message?.type === 'button') && (
|
|
643
837
|
<QuickReplyRender
|
|
644
838
|
rest={rest}
|
|
645
|
-
{...children}
|
|
839
|
+
{...children.message}
|
|
646
840
|
type={type}
|
|
647
841
|
state={state}
|
|
842
|
+
connector={children?.connector}
|
|
648
843
|
/>
|
|
649
844
|
)}
|
|
650
|
-
{children.type === 'list' && (
|
|
845
|
+
{children.message.type === 'list' && (
|
|
651
846
|
<ListReplyRender
|
|
652
|
-
{...children}
|
|
847
|
+
{...children.message}
|
|
653
848
|
type={type}
|
|
654
849
|
state={state}
|
|
850
|
+
connector={children?.connector}
|
|
655
851
|
/>
|
|
656
852
|
)}
|
|
657
|
-
{children.type === 'product_details' && (
|
|
853
|
+
{children.message.type === 'product_details' && (
|
|
658
854
|
<ProductDetailRender
|
|
659
|
-
{...children}
|
|
855
|
+
{...children.message}
|
|
660
856
|
type={type}
|
|
661
857
|
state={state}
|
|
662
858
|
/>
|
|
663
859
|
)}
|
|
664
|
-
{children.type === 'order' && (
|
|
665
|
-
<OrderRender
|
|
860
|
+
{children.message.type === 'order' && (
|
|
861
|
+
<OrderRender
|
|
862
|
+
{...children.message}
|
|
863
|
+
type={type}
|
|
864
|
+
state={state}
|
|
865
|
+
connector={children?.connector}
|
|
866
|
+
/>
|
|
666
867
|
)}
|
|
667
868
|
</>
|
|
668
869
|
) : type === 'pdf' ? (
|
|
@@ -15,7 +15,7 @@ export const Overlay = styled.div`
|
|
|
15
15
|
position: fixed;
|
|
16
16
|
top: 0;
|
|
17
17
|
left: 0;
|
|
18
|
-
z-index: 20;
|
|
18
|
+
z-index: ${({ zIndex }) => zIndex || 20};
|
|
19
19
|
width: 100vw;
|
|
20
20
|
height: 100vh;
|
|
21
21
|
background-color: ${BmBgGrey45};
|
|
@@ -58,7 +58,15 @@ export const ModalWrapper = styled.div`
|
|
|
58
58
|
overflow-y: auto;
|
|
59
59
|
`;
|
|
60
60
|
|
|
61
|
-
const BmModal = ({
|
|
61
|
+
const BmModal = ({
|
|
62
|
+
children,
|
|
63
|
+
show,
|
|
64
|
+
size,
|
|
65
|
+
zIndex,
|
|
66
|
+
onHide,
|
|
67
|
+
centered,
|
|
68
|
+
...rest
|
|
69
|
+
}) => {
|
|
62
70
|
const [toggle, setToggle] = useState(show);
|
|
63
71
|
useEffect(() => {
|
|
64
72
|
setToggle(show);
|
|
@@ -82,7 +90,7 @@ const BmModal = ({ children, show, size, onHide, centered, ...rest }) => {
|
|
|
82
90
|
<>
|
|
83
91
|
{toggle && (
|
|
84
92
|
<>
|
|
85
|
-
<Overlay />
|
|
93
|
+
<Overlay zIndex={zIndex} />
|
|
86
94
|
<ModalWrapper showModal={show} centered={centered} onHide={onHide}>
|
|
87
95
|
<Provider value={{ toggle, setToggle, size, show, onHide }}>
|
|
88
96
|
<ModalContent size={size} {...rest}>
|
|
@@ -8,12 +8,11 @@ export default {
|
|
|
8
8
|
component: BmModal,
|
|
9
9
|
title: 'components/Modals',
|
|
10
10
|
argTypes: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// },
|
|
11
|
+
size: {
|
|
12
|
+
control: { type: 'text' },
|
|
13
|
+
description: 'Controls the width of the modal in Pixels',
|
|
14
|
+
defaultValue: '500px',
|
|
15
|
+
},
|
|
17
16
|
closeButton: {
|
|
18
17
|
description:
|
|
19
18
|
'Placed on BmModal.Header component. Displays the close button (X)',
|
|
@@ -28,6 +27,11 @@ export default {
|
|
|
28
27
|
onHide: {
|
|
29
28
|
description: 'Handling the closing of the modal',
|
|
30
29
|
},
|
|
30
|
+
zIndex: {
|
|
31
|
+
description:
|
|
32
|
+
'Controls the stacking order of the modal in an event you have multiple modals',
|
|
33
|
+
control: { type: 'number' },
|
|
34
|
+
},
|
|
31
35
|
},
|
|
32
36
|
};
|
|
33
37
|
|