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

[TS migration] Migrate 'ReportActionItemCreated.js' component to TypeScript #34463

Merged
merged 8 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
131 changes: 0 additions & 131 deletions src/pages/home/report/ReportActionItemCreated.js

This file was deleted.

120 changes: 120 additions & 0 deletions src/pages/home/report/ReportActionItemCreated.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React, {memo} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import MultipleAvatars from '@components/MultipleAvatars';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import ReportWelcomeText from '@components/ReportWelcomeText';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import reportWithoutHasDraftSelector from '@libs/OnyxSelectors/reportWithoutHasDraftSelector';
import * as ReportUtils from '@libs/ReportUtils';
import {navigateToConciergeChatAndDeleteReport} from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Policy, Report} from '@src/types/onyx';
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground';

type ReportActionItemCreatedOnyxProps = {
/** The report currently being looked at */
report: OnyxEntry<Report>;

/** The policy object for the current route */
policy: OnyxEntry<Policy>;

/** Personal details of all the users */
personalDetails: OnyxEntry<PersonalDetailsList>;
};

type ReportActionItemCreatedProps = ReportActionItemCreatedOnyxProps & {
/** The id of the report */
reportID: string;

/** The id of the policy */
// eslint-disable-next-line react/no-unused-prop-types
Tony-MK marked this conversation as resolved.
Show resolved Hide resolved
policyID: string;
};
function ReportActionItemCreated(props: ReportActionItemCreatedProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

const {translate} = useLocalize();
const {isSmallScreenWidth, isLargeScreenWidth} = useWindowDimensions();

if (!ReportUtils.isChatReport(props.report)) {
return null;
}

const icons = ReportUtils.getIcons(props.report, props.personalDetails);
const shouldDisableDetailPage = ReportUtils.shouldDisableDetailPage(props.report);

return (
<OfflineWithFeedback
pendingAction={props.report?.pendingFields?.addWorkspaceRoom ?? props.report?.pendingFields?.createChat}
errors={props.report?.errorFields?.addWorkspaceRoom ?? props.report?.errorFields?.createChat}
errorRowStyles={[styles.ml10, styles.mr2]}
onClose={() => navigateToConciergeChatAndDeleteReport(props.report?.reportID ?? props.reportID)}
needsOffscreenAlphaCompositing
>
<View style={StyleUtils.getReportWelcomeContainerStyle(isSmallScreenWidth)}>
<AnimatedEmptyStateBackground />
<View
accessibilityLabel={translate('accessibilityHints.chatWelcomeMessage')}
style={[styles.p5, StyleUtils.getReportWelcomeTopMarginStyle(isSmallScreenWidth)]}
>
<PressableWithoutFeedback
onPress={() => ReportUtils.navigateToDetailsPage(props.report)}
style={[styles.mh5, styles.mb3, styles.alignSelfStart]}
accessibilityLabel={translate('common.details')}
role={CONST.ROLE.BUTTON}
disabled={shouldDisableDetailPage}
>
<MultipleAvatars
icons={icons}
size={isLargeScreenWidth || (icons && icons.length < 3) ? CONST.AVATAR_SIZE.LARGE : CONST.AVATAR_SIZE.MEDIUM}
shouldStackHorizontally
shouldDisplayAvatarsInRows={isSmallScreenWidth}
maxAvatarsInRow={isSmallScreenWidth ? CONST.AVATAR_ROW_SIZE.DEFAULT : CONST.AVATAR_ROW_SIZE.LARGE_SCREEN}
/>
</PressableWithoutFeedback>
<View style={[styles.ph5]}>
<ReportWelcomeText
report={props.report}
policy={props.policy}
/>
</View>
</View>
</View>
</OfflineWithFeedback>
);
}

ReportActionItemCreated.displayName = 'ReportActionItemCreated';

export default withOnyx<ReportActionItemCreatedProps, ReportActionItemCreatedOnyxProps>({
report: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
selector: reportWithoutHasDraftSelector,
},

policy: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
},

personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
})(
memo(
ReportActionItemCreated,
(prevProps, nextProps) =>
prevProps.policy?.name === nextProps.policy?.name &&
prevProps.policy?.avatar === nextProps.policy?.avatar &&
prevProps.report?.stateNum === nextProps.report?.stateNum &&
prevProps.report?.statusNum === nextProps.report?.statusNum &&
prevProps.report?.lastReadTime === nextProps.report?.lastReadTime,
),
);
Loading