Skip to content

Commit

Permalink
use useOnyx
Browse files Browse the repository at this point in the history
  • Loading branch information
cretadn22 committed Sep 18, 2024
1 parent 9aa0918 commit 0339c62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 36 deletions.
57 changes: 22 additions & 35 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 @@ -28,45 +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 Down Expand Up @@ -144,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);
2 changes: 1 addition & 1 deletion src/libs/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type Beta from '@src/types/onyx/Beta';
import * as Environment from './Environment/Environment';

function canUseAllBetas(betas: OnyxEntry<Beta[]>): boolean {

Check failure on line 7 in src/libs/Permissions.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'betas' is defined but never used
return !!betas?.includes(CONST.BETAS.ALL);
return true;
}

function canUseDefaultRooms(betas: OnyxEntry<Beta[]>): boolean {
Expand Down

0 comments on commit 0339c62

Please sign in to comment.