Skip to content

Commit b7c38b1

Browse files
authored
Merge pull request #89917 from callstack-internal/refactor/option-row-draft-indicator
[No QA] refactor: extract OptionRow.DraftIndicator leaf
2 parents 63196f1 + 2fc9b29 commit b7c38b1

2 files changed

Lines changed: 49 additions & 15 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react';
2+
import {View} from 'react-native';
3+
import Icon from '@components/Icon';
4+
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
5+
import useLocalize from '@hooks/useLocalize';
6+
import useTheme from '@hooks/useTheme';
7+
import useThemeStyles from '@hooks/useThemeStyles';
8+
import variables from '@styles/variables';
9+
10+
type DraftIndicatorProps = {
11+
hasDraftComment: boolean;
12+
isAllowedToComment: boolean | null | undefined;
13+
};
14+
15+
function DraftIndicator({hasDraftComment, isAllowedToComment}: DraftIndicatorProps) {
16+
const theme = useTheme();
17+
const styles = useThemeStyles();
18+
const {translate} = useLocalize();
19+
const {Pencil} = useMemoizedLazyExpensifyIcons(['Pencil']);
20+
21+
if (!hasDraftComment || !isAllowedToComment) {
22+
return null;
23+
}
24+
25+
return (
26+
<View
27+
style={styles.ml2}
28+
accessibilityLabel={translate('sidebarScreen.draftedMessage')}
29+
>
30+
<Icon
31+
testID="Pencil Icon"
32+
fill={theme.icon}
33+
src={Pencil}
34+
width={variables.iconSizeSmall}
35+
height={variables.iconSizeSmall}
36+
/>
37+
</View>
38+
);
39+
}
40+
41+
DraftIndicator.displayName = 'OptionRow.DraftIndicator';
42+
43+
export default DraftIndicator;

src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNCore.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import variables from '@styles/variables';
2626
import CONST from '@src/CONST';
2727
import ONYXKEYS from '@src/ONYXKEYS';
2828
import {isEmptyObject} from '@src/types/utils/EmptyObject';
29+
import DraftIndicator from './OptionRow/DraftIndicator';
2930
import OptionRowAlternateText from './OptionRowAlternateText';
3031
import OptionRowAvatar from './OptionRowAvatar';
3132
import OptionRowErrorBadge from './OptionRowErrorBadge';
@@ -50,7 +51,7 @@ function OptionRowLHN({
5051
const styles = useThemeStyles();
5152
const popoverAnchor = useRef<View>(null);
5253
const StyleUtils = useStyleUtils();
53-
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Pencil', 'Pin']);
54+
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Pin']);
5455

5556
const {onboardingPurpose, onboarding, isScreenFocused} = useLHNTooltipContext();
5657
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
@@ -204,20 +205,10 @@ function OptionRowLHN({
204205
brickRoadIndicator={brickRoadIndicator}
205206
actionBadgeText={actionBadgeText}
206207
/>
207-
{hasDraftComment && !!optionItem.isAllowedToComment && (
208-
<View
209-
style={styles.ml2}
210-
accessibilityLabel={translate('sidebarScreen.draftedMessage')}
211-
>
212-
<Icon
213-
testID="Pencil Icon"
214-
fill={theme.icon}
215-
src={expensifyIcons.Pencil}
216-
width={variables.iconSizeSmall}
217-
height={variables.iconSizeSmall}
218-
/>
219-
</View>
220-
)}
208+
<DraftIndicator
209+
hasDraftComment={hasDraftComment}
210+
isAllowedToComment={optionItem.isAllowedToComment}
211+
/>
221212
{!brickRoadIndicator && !!optionItem.isPinned && (
222213
<View
223214
style={styles.ml2}

0 commit comments

Comments
 (0)