Skip to content
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

Add new GBRs to task message #49389

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 33 additions & 36 deletions src/components/ReportActionItem/TaskPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Str} from 'expensify-common';
import React from 'react';
import {View} from 'react-native';
import {useOnyx, withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Avatar from '@components/Avatar';
import Checkbox from '@components/Checkbox';
Expand All @@ -14,6 +14,7 @@ import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalD
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import ControlSelection from '@libs/ControlSelection';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
Expand All @@ -27,44 +28,38 @@ import * as Task from '@userActions/Task';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Report, ReportAction} from '@src/types/onyx';
import type {ReportAction} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type TaskPreviewOnyxProps = {
/* Onyx Props */
type TaskPreviewProps = WithCurrentUserPersonalDetailsProps & {
/** The ID of the associated policy */
// eslint-disable-next-line react/no-unused-prop-types
policyID: string;
/** The ID of the associated taskReport */
taskReportID: string;

/* current report of TaskPreview */
taskReport: OnyxEntry<Report>;
};

type TaskPreviewProps = WithCurrentUserPersonalDetailsProps &
TaskPreviewOnyxProps & {
/** The ID of the associated policy */
// eslint-disable-next-line react/no-unused-prop-types
policyID: string;
/** The ID of the associated taskReport */
taskReportID: string;
/** Whether the task preview is hovered so we can modify its style */
isHovered: boolean;

/** Whether the task preview is hovered so we can modify its style */
isHovered: boolean;
/** The linked reportAction */
action: OnyxEntry<ReportAction>;

/** The linked reportAction */
action: OnyxEntry<ReportAction>;
/** The chat report associated with taskReport */
chatReportID: string;

/** The chat report associated with taskReport */
chatReportID: string;
/** Popover context menu anchor, used for showing context menu */
contextMenuAnchor: ContextMenuAnchor;

/** Popover context menu anchor, used for showing context menu */
contextMenuAnchor: ContextMenuAnchor;

/** Callback for updating context menu active state, used for showing context menu */
checkIfContextMenuActive: () => void;
};
/** Callback for updating context menu active state, used for showing context menu */
checkIfContextMenuActive: () => void;
};

function TaskPreview({taskReport, taskReportID, action, contextMenuAnchor, chatReportID, checkIfContextMenuActive, currentUserPersonalDetails, isHovered = false}: TaskPreviewProps) {
function TaskPreview({taskReportID, action, contextMenuAnchor, chatReportID, checkIfContextMenuActive, currentUserPersonalDetails, isHovered = false}: TaskPreviewProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const theme = useTheme();
const [taskReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`);

// The reportAction might not contain details regarding the taskReport
// Only the direct parent reportAction will contain details about the taskReport
Expand All @@ -77,7 +72,7 @@ function TaskPreview({taskReport, taskReportID, action, contextMenuAnchor, chatR
const [avatar] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: (personalDetails) => personalDetails?.[taskAssigneeAccountID]?.avatar});
const htmlForTaskPreview = `<comment>${taskTitle}</comment>`;
const isDeletedParentAction = ReportUtils.isCanceledTaskReport(taskReport, action);

const shouldShowGreenDotIndicator = ReportUtils.isOpenTaskReport(taskReport, action) && ReportUtils.isReportManager(taskReport);
if (isDeletedParentAction) {
return <RenderHTML html={`<comment>${translate('parentReportAction.deletedTask')}</comment>`} />;
}
Expand Down Expand Up @@ -123,6 +118,14 @@ function TaskPreview({taskReport, taskReportID, action, contextMenuAnchor, chatR
<RenderHTML html={isTaskCompleted ? `<completed-task>${htmlForTaskPreview}</completed-task>` : htmlForTaskPreview} />
</View>
</View>
{shouldShowGreenDotIndicator && (
<View style={styles.ml2}>
<Icon
src={Expensicons.DotIndicator}
fill={theme.success}
/>
</View>
)}
<Icon
src={Expensicons.ArrowRight}
fill={StyleUtils.getIconFillColor(getButtonState(isHovered))}
Expand All @@ -134,10 +137,4 @@ function TaskPreview({taskReport, taskReportID, action, contextMenuAnchor, chatR

TaskPreview.displayName = 'TaskPreview';

export default withCurrentUserPersonalDetails(
withOnyx<TaskPreviewProps, TaskPreviewOnyxProps>({
taskReport: {
key: ({taskReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
},
})(TaskPreview),
);
export default withCurrentUserPersonalDetails(TaskPreview);
Loading