Skip to content

Commit bfa0e07

Browse files
committed
feat: enhance ListItem and ActionsSection with disabled state handling
- Added `disabledReason` prop to IListItemButton and IListItemContent interfaces. - Implemented event emission for disabled buttons in ListItem. - Updated ActionsSection to conditionally disable the invite user action based on ABAC attributes.
1 parent d7073d3 commit bfa0e07

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

app/containers/List/ListItem.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { Icon } from '.';
1818
import { BASE_HEIGHT, ICON_SIZE, PADDING_HORIZONTAL } from './constants';
1919
import { CustomIcon } from '../CustomIcon';
2020
import { useResponsiveLayout } from '../../lib/hooks/useResponsiveLayout/useResponsiveLayout';
21+
import EventEmitter from '../../lib/methods/helpers/events';
22+
import { LISTENER } from '../Toast';
2123

2224
const styles = StyleSheet.create({
2325
container: {
@@ -90,6 +92,7 @@ interface IListItemContent {
9092
left?: () => JSX.Element | null;
9193
right?: () => JSX.Element | null;
9294
disabled?: boolean;
95+
disabledReason?: string;
9396
testID?: string;
9497
color?: string;
9598
translateTitle?: boolean;
@@ -154,7 +157,15 @@ const Content = React.memo(
154157
}
155158
}
156159
return label;
157-
}, [title, subtitle, translateTitle, translateSubtitle, additionalAcessibilityLabel, additionalAcessibilityLabelCheck]);
160+
}, [
161+
accessibilityLabel,
162+
title,
163+
subtitle,
164+
translateTitle,
165+
translateSubtitle,
166+
additionalAcessibilityLabel,
167+
additionalAcessibilityLabelCheck
168+
]);
158169

159170
return (
160171
<View
@@ -205,6 +216,7 @@ interface IListButtonPress extends IListItemButton {
205216
interface IListItemButton {
206217
title: string | (() => JSX.Element | null);
207218
disabled?: boolean;
219+
disabledReason?: string;
208220
backgroundColor?: string;
209221
underlayColor?: string;
210222
}
@@ -214,12 +226,20 @@ const Button = React.memo(({ onPress, backgroundColor, underlayColor, ...props }
214226

215227
const { colors } = useTheme();
216228

229+
const handlePress = () => {
230+
if (props.disabled && props.disabledReason) {
231+
EventEmitter.emit(LISTENER, { message: props.disabledReason });
232+
} else if (!props.disabled) {
233+
onPress(props.title);
234+
}
235+
};
236+
217237
return (
218238
<Touch
219-
onPress={() => onPress(props.title)}
239+
onPress={handlePress}
220240
style={{ backgroundColor: backgroundColor || colors.surfaceRoom }}
221241
underlayColor={underlayColor}
222-
enabled={!props.disabled}>
242+
enabled={!props.disabled || !!props.disabledReason}>
223243
<Content {...props} />
224244
</Touch>
225245
);

app/views/RoomMembersView/components/ActionsSection.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default function ActionsSection({ rid, t, joined, abacAttributes }: IActi
9090
</>
9191
) : null}
9292

93-
{['c', 'p'].includes(t) && canInviteUser && !abacAttributes ? (
93+
{['c', 'p'].includes(t) && canInviteUser ? (
9494
<>
9595
<List.Item
9696
title='Invite_users'
@@ -103,6 +103,8 @@ export default function ActionsSection({ rid, t, joined, abacAttributes }: IActi
103103
testID='room-actions-invite-user'
104104
left={() => <List.Icon name='user-add' />}
105105
showActionIndicator
106+
disabled={!!abacAttributes}
107+
disabledReason={abacAttributes ? i18n.t('ABAC_disabled_action_reason') : undefined}
106108
/>
107109
<List.Separator />
108110
</>

0 commit comments

Comments
 (0)