Skip to content

Commit c102cdd

Browse files
authored
fix: set fallback values \w global configs in App comp (#640)
Fixes https://sendbird.atlassian.net/browse/UIKIT-4140 Put fallback value for replyType, isReactionEnabled, showSearchIcon \w global configs in `AppLayout` to reduce a chance to get these value get undefined
1 parent 8ba5e06 commit c102cdd

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/modules/App/AppLayout.tsx

+19-7
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,50 @@ import { useMediaQueryContext } from '../../lib/MediaQueryContext';
77
import { DesktopLayout } from './DesktopLayout';
88
import { MobileLayout } from './MobileLayout';
99

10+
import useSendbirdStateContext from '../../hooks/useSendbirdStateContext';
11+
1012
export const AppLayout: React.FC<AppLayoutProps> = (
1113
props: AppLayoutProps,
1214
) => {
1315
const {
14-
isReactionEnabled,
15-
replyType,
1616
isMessageGroupingEnabled,
1717
allowProfileEdit,
18-
showSearchIcon,
1918
onProfileEditSuccess,
2019
disableAutoSelect,
2120
currentChannel,
2221
setCurrentChannel,
2322
} = props;
23+
24+
const globalStore = useSendbirdStateContext();
25+
const globalConfigs = globalStore?.config;
26+
2427
const [showThread, setShowThread] = useState(false);
2528
const [threadTargetMessage, setThreadTargetMessage] = useState<UserMessage | FileMessage | null>(null);
2629
const [showSettings, setShowSettings] = useState(false);
2730
const [showSearch, setShowSearch] = useState(false);
2831
const [highlightedMessage, setHighlightedMessage] = useState<number | null>(null);
2932
const [startingPoint, setStartingPoint] = useState<number | null>(null);
3033
const { isMobile } = useMediaQueryContext();
34+
35+
/**
36+
* Below configs can be set via Dashboard UIKit config setting but as a lower priority than App props.
37+
* So need to be have fallback value \w global configs even though each prop values are undefined
38+
*/
39+
const replyType = props.replyType ?? globalConfigs?.replyType;
40+
const isReactionEnabled = props.isReactionEnabled ?? globalConfigs?.isReactionEnabled;
41+
const showSearchIcon = props.showSearchIcon ?? globalConfigs?.showSearchIcon;
42+
3143
return (
3244
<>
3345
{
3446
isMobile
3547
? (
3648
<MobileLayout
3749
replyType={replyType}
50+
showSearchIcon={showSearchIcon}
51+
isReactionEnabled={isReactionEnabled}
3852
isMessageGroupingEnabled={isMessageGroupingEnabled}
3953
allowProfileEdit={allowProfileEdit}
40-
isReactionEnabled={isReactionEnabled}
41-
showSearchIcon={showSearchIcon}
4254
onProfileEditSuccess={onProfileEditSuccess}
4355
currentChannel={currentChannel}
4456
setCurrentChannel={setCurrentChannel}
@@ -52,11 +64,11 @@ export const AppLayout: React.FC<AppLayoutProps> = (
5264
)
5365
: (
5466
<DesktopLayout
55-
isReactionEnabled={isReactionEnabled}
5667
replyType={replyType}
68+
isReactionEnabled={isReactionEnabled}
69+
showSearchIcon={showSearchIcon}
5770
isMessageGroupingEnabled={isMessageGroupingEnabled}
5871
allowProfileEdit={allowProfileEdit}
59-
showSearchIcon={showSearchIcon}
6072
onProfileEditSuccess={onProfileEditSuccess}
6173
disableAutoSelect={disableAutoSelect}
6274
currentChannel={currentChannel}

0 commit comments

Comments
 (0)