Skip to content

Commit 249173f

Browse files
committed
refactor: implement session warning in IterableEmbeddedView
1 parent 386d193 commit 249173f

6 files changed

Lines changed: 28 additions & 57 deletions

File tree

src/embedded/components/EmbeddedSessionDevWarning/EmbeddedSessionDevWarning.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const EmbeddedSessionDevWarning = ({
2020
return null;
2121
}
2222

23-
const message = `[Iterable] ${componentName}: wrap this view in <EmbeddedSessionManager> so embedded session tracking works correctly.`;
23+
const message = `[Iterable] ${componentName}: wrap this component in <EmbeddedSessionManager> so embedded session tracking works correctly.`;
2424

2525
return (
2626
<View
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './EmbeddedSessionDevWarning';
2+
export { EmbeddedSessionDevWarning as default } from './EmbeddedSessionDevWarning';

src/embedded/components/IterableEmbeddedBanner/IterableEmbeddedBanner.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
import {
22
Image,
3+
PixelRatio,
4+
Pressable,
35
Text,
46
TouchableOpacity,
57
View,
68
type TextStyle,
79
type ViewStyle,
8-
PixelRatio,
9-
Pressable,
1010
} from 'react-native';
1111

1212
import { IterableEmbeddedViewType } from '../../enums';
1313
import { useEmbeddedView } from '../../hooks/useEmbeddedView';
14-
import { useWarnIfOutsideEmbeddedSession } from '../../hooks/useWarnIfOutsideEmbeddedSession';
1514
import type { IterableEmbeddedComponentProps } from '../../types/IterableEmbeddedComponentProps';
16-
import { EmbeddedSessionDevWarning } from '../EmbeddedSessionDevWarning/EmbeddedSessionDevWarning';
1715
import {
18-
styles,
1916
IMAGE_HEIGHT,
2017
IMAGE_WIDTH,
18+
styles,
2119
} from './IterableEmbeddedBanner.styles';
2220

23-
const COMPONENT_NAME = 'IterableEmbeddedBanner';
24-
2521
/**
2622
* TODO: figure out how default action works.
2723
*/
@@ -32,9 +28,6 @@ export const IterableEmbeddedBanner = ({
3228
onButtonClick,
3329
onMessageClick,
3430
}: IterableEmbeddedComponentProps) => {
35-
const showEmbeddedSessionWarning =
36-
useWarnIfOutsideEmbeddedSession(COMPONENT_NAME);
37-
3831
const { parsedStyles, media, handleButtonClick, handleMessageClick } =
3932
useEmbeddedView(IterableEmbeddedViewType.Banner, {
4033
message,
@@ -45,12 +38,6 @@ export const IterableEmbeddedBanner = ({
4538

4639
const buttons = message.elements?.buttons ?? [];
4740

48-
if (showEmbeddedSessionWarning) {
49-
return (
50-
<EmbeddedSessionDevWarning visible componentName={COMPONENT_NAME} />
51-
);
52-
}
53-
5441
return (
5542
<Pressable onPress={handleMessageClick}>
5643
<View

src/embedded/components/IterableEmbeddedCard/IterableEmbeddedCard.tsx

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ import {
1212
import { IterableLogoGrey } from '../../../core/assets';
1313
import { IterableEmbeddedViewType } from '../../enums';
1414
import { useEmbeddedView } from '../../hooks/useEmbeddedView';
15-
import { useWarnIfOutsideEmbeddedSession } from '../../hooks/useWarnIfOutsideEmbeddedSession';
1615
import type { IterableEmbeddedComponentProps } from '../../types/IterableEmbeddedComponentProps';
17-
import { EmbeddedSessionDevWarning } from '../EmbeddedSessionDevWarning/EmbeddedSessionDevWarning';
1816
import { IMAGE_HEIGHT, styles } from './IterableEmbeddedCard.styles';
1917

20-
const COMPONENT_NAME = 'IterableEmbeddedCard';
21-
2218
/**
2319
* TODO: Add default action click handler. See IterableEmbeddedView for functionality.
2420
*/
@@ -29,28 +25,15 @@ export const IterableEmbeddedCard = ({
2925
onButtonClick = () => {},
3026
onMessageClick = () => {},
3127
}: IterableEmbeddedComponentProps) => {
32-
const showEmbeddedSessionWarning =
33-
useWarnIfOutsideEmbeddedSession(COMPONENT_NAME);
34-
35-
const {
36-
handleButtonClick,
37-
handleMessageClick,
38-
media,
39-
parsedStyles,
40-
} = useEmbeddedView(IterableEmbeddedViewType.Card, {
41-
message,
42-
config,
43-
onButtonClick,
44-
onMessageClick,
45-
});
28+
const { handleButtonClick, handleMessageClick, media, parsedStyles } =
29+
useEmbeddedView(IterableEmbeddedViewType.Card, {
30+
message,
31+
config,
32+
onButtonClick,
33+
onMessageClick,
34+
});
4635
const buttons = message?.elements?.buttons ?? [];
4736

48-
if (showEmbeddedSessionWarning) {
49-
return (
50-
<EmbeddedSessionDevWarning visible componentName={COMPONENT_NAME} />
51-
);
52-
}
53-
5437
return (
5538
<Pressable onPress={() => handleMessageClick()}>
5639
<View
@@ -77,8 +60,7 @@ export const IterableEmbeddedCard = ({
7760
uri: media.url as string,
7861
height: PixelRatio.getPixelSizeForLayoutSize(IMAGE_HEIGHT),
7962
}
80-
:
81-
IterableLogoGrey
63+
: IterableLogoGrey
8264
}
8365
style={
8466
media.shouldShow

src/embedded/components/IterableEmbeddedNotification/IterableEmbeddedNotification.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
import {
2+
Pressable,
23
Text,
34
TouchableOpacity,
45
View,
56
type TextStyle,
67
type ViewStyle,
7-
Pressable,
88
} from 'react-native';
99

1010
import { IterableEmbeddedViewType } from '../../enums/IterableEmbeddedViewType';
1111
import { useEmbeddedView } from '../../hooks/useEmbeddedView';
12-
import { useWarnIfOutsideEmbeddedSession } from '../../hooks/useWarnIfOutsideEmbeddedSession';
1312
import type { IterableEmbeddedComponentProps } from '../../types/IterableEmbeddedComponentProps';
14-
import { EmbeddedSessionDevWarning } from '../EmbeddedSessionDevWarning/EmbeddedSessionDevWarning';
1513
import { styles } from './IterableEmbeddedNotification.styles';
1614

17-
const COMPONENT_NAME = 'IterableEmbeddedNotification';
18-
1915
export const IterableEmbeddedNotification = ({
2016
config,
2117
message,
2218
onButtonClick,
2319
onMessageClick,
2420
}: IterableEmbeddedComponentProps) => {
25-
const showEmbeddedSessionWarning =
26-
useWarnIfOutsideEmbeddedSession(COMPONENT_NAME);
27-
2821
const { parsedStyles, handleButtonClick, handleMessageClick } =
2922
useEmbeddedView(IterableEmbeddedViewType.Notification, {
3023
message,
@@ -35,12 +28,6 @@ export const IterableEmbeddedNotification = ({
3528

3629
const buttons = message.elements?.buttons ?? [];
3730

38-
if (showEmbeddedSessionWarning) {
39-
return (
40-
<EmbeddedSessionDevWarning visible componentName={COMPONENT_NAME} />
41-
);
42-
}
43-
4431
return (
4532
<Pressable onPress={() => handleMessageClick()}>
4633
<View

src/embedded/components/IterableEmbeddedView.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { useMemo } from 'react';
22

33
import { IterableEmbeddedViewType } from '../enums/IterableEmbeddedViewType';
4+
import { useWarnIfOutsideEmbeddedSession } from '../hooks';
45
import type { IterableEmbeddedComponentProps } from '../types/IterableEmbeddedComponentProps';
6+
import { EmbeddedSessionDevWarning } from './EmbeddedSessionDevWarning';
57
import { IterableEmbeddedBanner } from './IterableEmbeddedBanner';
68
import { IterableEmbeddedCard } from './IterableEmbeddedCard';
79
import { IterableEmbeddedNotification } from './IterableEmbeddedNotification';
810

11+
const COMPONENT_NAME = 'IterableEmbeddedView';
12+
913
/**
1014
* The props for the IterableEmbeddedView component.
1115
*/
@@ -29,6 +33,9 @@ export const IterableEmbeddedView = ({
2933
viewType,
3034
...props
3135
}: IterableEmbeddedViewProps) => {
36+
const showEmbeddedSessionWarning =
37+
useWarnIfOutsideEmbeddedSession(COMPONENT_NAME);
38+
3239
const Cmp = useMemo(() => {
3340
switch (viewType) {
3441
case IterableEmbeddedViewType.Card:
@@ -42,5 +49,11 @@ export const IterableEmbeddedView = ({
4249
}
4350
}, [viewType]);
4451

52+
if (showEmbeddedSessionWarning) {
53+
return (
54+
<EmbeddedSessionDevWarning visible componentName={COMPONENT_NAME} />
55+
);
56+
}
57+
4558
return Cmp ? <Cmp {...props} /> : null;
4659
};

0 commit comments

Comments
 (0)