-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add PromotedActionsBar #41972
feat: add PromotedActionsBar #41972
Changes from 7 commits
8521e75
4b80097
2280259
abb830c
27bb412
9cf7497
08e44fc
7b3b2f9
b0c18e5
8ced990
902b774
3a4e6f4
5489810
bc6004e
dfdb1f5
738075d
324080b
8fe01f8
22ed96d
3fafaff
b8a6221
1e67021
5a86528
8771bd6
5971fb3
0f5aa5d
6d1e40e
f2d0e2f
cc302ff
0367b26
8431492
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import React, {useCallback, useMemo, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as HeaderUtils from '@libs/HeaderUtils'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as Report from '@userActions/Report'; | ||
import * as Session from '@userActions/Session'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type {Report as OnyxReportType} from '@src/types/onyx'; | ||
import Button from './Button'; | ||
import ConfirmModal from './ConfirmModal'; | ||
import type {ThreeDotsMenuItem} from './HeaderWithBackButton/types'; | ||
import * as Expensicons from './Icon/Expensicons'; | ||
|
||
type PromotedAction = { | ||
key: string; | ||
} & ThreeDotsMenuItem; | ||
|
||
type PromotedActionsParams = { | ||
report: OnyxReportType; | ||
}; | ||
|
||
function usePromotedActions({report}: PromotedActionsParams): Record<string, PromotedAction> { | ||
const {translate} = useLocalize(); | ||
const onShareButtonPress = useCallback(() => Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS_SHARE_CODE.getRoute(report?.reportID ?? '')), [report?.reportID]); | ||
const join = Session.checkIfActionIsAllowed(() => Report.joinRoom(report)); | ||
|
||
return useMemo( | ||
() => ({ | ||
pin: { | ||
key: 'pin', | ||
...HeaderUtils.getPinMenuItem(report), | ||
}, | ||
join: { | ||
key: 'join', | ||
icon: Expensicons.Pin, | ||
text: translate('common.join'), | ||
onSelected: join, | ||
}, | ||
share: { | ||
key: 'share', | ||
icon: Expensicons.QrCode, | ||
text: translate('common.share'), | ||
onSelected: onShareButtonPress, | ||
}, | ||
hold: { | ||
key: 'hold', | ||
icon: Expensicons.Stopwatch, | ||
text: translate('iou.hold'), | ||
onSelected: () => { | ||
// TODO: Implement this | ||
}, | ||
}, | ||
}), | ||
[report, translate, join, onShareButtonPress], | ||
); | ||
} | ||
|
||
type PromotedActionsBarProps = { | ||
report: OnyxReportType; | ||
|
||
promotedActions: PromotedAction[]; | ||
kosmydel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Whether to show the `Leave` button. | ||
* @deprecated Remove this prop when @src/pages/ReportDetailsPage.tsx is updated | ||
*/ | ||
shouldShowLeaveButton: boolean; | ||
kosmydel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
function PromotedActionsBar({report, promotedActions, shouldShowLeaveButton}: PromotedActionsBarProps) { | ||
const styles = useThemeStyles(); | ||
const [isLastMemberLeavingGroupModalVisible, setIsLastMemberLeavingGroupModalVisible] = useState(false); | ||
const {translate} = useLocalize(); | ||
|
||
return ( | ||
<View style={[styles.flexRow, styles.ph5, styles.mb5, styles.gap3]}> | ||
{promotedActions.map(({key, onSelected, ...props}) => ( | ||
<View style={[styles.flex1]}> | ||
<Button | ||
key={key} | ||
onPress={onSelected} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
/> | ||
</View> | ||
))} | ||
{/* TODO: Remove the `Leave` button when @src/pages/ReportDetailsPage.tsx is updated */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a WIP PR for this yet? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @cdOut There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m handling this one in my ReportDetailsPage PR, I’ll link it here after I put up a draft PR for it later in the evening. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check this PR we're already moving it there. |
||
{shouldShowLeaveButton && ( | ||
// The `Leave` button is left to make the component backward compatible with the existing code. | ||
// After the `Leave` button is moved to the `MenuItem` list, this block can be removed. | ||
<View style={[styles.flex1]}> | ||
<ConfirmModal | ||
danger | ||
title={translate('groupChat.lastMemberTitle')} | ||
isVisible={isLastMemberLeavingGroupModalVisible} | ||
onConfirm={() => { | ||
setIsLastMemberLeavingGroupModalVisible(false); | ||
Report.leaveGroupChat(report.reportID); | ||
}} | ||
onCancel={() => setIsLastMemberLeavingGroupModalVisible(false)} | ||
prompt={translate('groupChat.lastMemberWarning')} | ||
confirmText={translate('common.leave')} | ||
cancelText={translate('common.cancel')} | ||
/> | ||
<Button | ||
onPress={() => { | ||
if (Object.keys(report?.participants ?? {}).length === 1) { | ||
setIsLastMemberLeavingGroupModalVisible(true); | ||
return; | ||
} | ||
|
||
Report.leaveGroupChat(report.reportID); | ||
}} | ||
icon={Expensicons.Exit} | ||
style={styles.flex1} | ||
text={translate('common.leave')} | ||
/> | ||
</View> | ||
)} | ||
</View> | ||
); | ||
} | ||
|
||
PromotedActionsBar.displayName = 'PromotedActionsBar'; | ||
|
||
export default PromotedActionsBar; | ||
|
||
export {usePromotedActions}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to use
PromotedAction
typesjoin
,share
, andhold
in this PR? If not, let us keep this code commented and add relevant comments as to where this will be used. This can be uncommented later when this is used. This will also keep this PR neat.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've commented this out. However, adding all those actions here, in one place, might be a good idea, as later on, a few PRs might need in simultaneously, leading to conflicts and duplicated work.