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 'ReportActionItemChronosOOOListActions.js' component to TypeS… #32927

2 changes: 1 addition & 1 deletion src/components/OfflineWithFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import MessagesRow from './MessagesRow';

type OfflineWithFeedbackProps = ChildrenProps & {
/** The type of action that's pending */
pendingAction: OnyxCommon.PendingAction;
pendingAction?: OnyxCommon.PendingAction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test what will happen when pendingAction will be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing happened - all works good


/** Determine whether to hide the component's children if deletion is pending */
shouldHideOnDelete?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,68 @@
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import Button from '@components/Button';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import Text from '@components/Text';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import DateUtils from '@libs/DateUtils';
import reportActionPropTypes from '@pages/home/report/reportActionPropTypes';
import * as Chronos from '@userActions/Chronos';
import type {OriginalMessageChronosOOOList} from '@src/types/onyx/OriginalMessage';
import type {ReportActionBase} from '@src/types/onyx/ReportAction';

const propTypes = {
type ChronosOOOListActionsProps = {
/** The ID of the report */
reportID: PropTypes.string.isRequired,
reportID: string;

/** All the data of the action */
action: PropTypes.shape(reportActionPropTypes).isRequired,

...withLocalizePropTypes,
action: ReportActionBase & OriginalMessageChronosOOOList;
};

function ChronosOOOListActions(props) {
function ChronosOOOListActions({reportID, action}: ChronosOOOListActionsProps) {
const styles = useThemeStyles();
const events = lodashGet(props.action, 'originalMessage.events', []);

const {translate, preferredLocale} = useLocalize();

const events = action.originalMessage?.events ?? [];

if (!events.length) {
return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.pt, styles.ml18]}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.ml18]}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this style was removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this style .pt does not exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the .pt style has never existed

<Text>You haven&apos;t created any events</Text>
</View>
);
}

return (
<OfflineWithFeedback pendingAction={lodashGet(props.action, 'pendingAction', null)}>
<View style={[styles.chatItemMessage]}>
{_.map(events, (event) => {
const start = DateUtils.getLocalDateFromDatetime(props.preferredLocale, lodashGet(event, 'start.date', ''));
const end = DateUtils.getLocalDateFromDatetime(props.preferredLocale, lodashGet(event, 'end.date', ''));
<OfflineWithFeedback pendingAction={action.pendingAction}>
<View style={styles.chatItemMessage}>
{events.map((event) => {
const start = DateUtils.getLocalDateFromDatetime(preferredLocale, event?.end?.date ?? '');
const end = DateUtils.getLocalDateFromDatetime(preferredLocale, event?.end?.date ?? '');
pasyukevich marked this conversation as resolved.
Show resolved Hide resolved
return (
<View
key={event.id}
style={[styles.flexRow, styles.pt, styles.ml18, styles.pr4, styles.alignItemsCenter]}
style={[styles.flexRow, styles.ml18, styles.pr4, styles.alignItemsCenter]}
>
<Text style={[styles.flexShrink1]}>
<Text style={styles.flexShrink1}>
{event.lengthInDays > 0
? props.translate('chronos.oooEventSummaryFullDay', {
? translate('chronos.oooEventSummaryFullDay', {
summary: event.summary,
dayCount: event.lengthInDays,
date: DateUtils.formatToLongDateWithWeekday(end),
})
: props.translate('chronos.oooEventSummaryPartialDay', {
: translate('chronos.oooEventSummaryPartialDay', {
summary: event.summary,
timePeriod: `${DateUtils.formatToLocalTime(start)} - ${DateUtils.formatToLocalTime(end)}`,
date: DateUtils.formatToLongDateWithWeekday(end),
})}
</Text>
<Button
small
style={[styles.pl2]}
onPress={() => Chronos.removeEvent(props.reportID, props.action.reportActionID, event.id, events)}
style={styles.pl2}
onPress={() => Chronos.removeEvent(reportID, action.reportActionID, event.id, events)}
>
<Text style={styles.buttonSmallText}>{props.translate('common.remove')}</Text>
<Text style={styles.buttonSmallText}>{translate('common.remove')}</Text>
</Button>
</View>
);
Expand All @@ -73,7 +72,6 @@ function ChronosOOOListActions(props) {
);
}

ChronosOOOListActions.propTypes = propTypes;
ChronosOOOListActions.displayName = 'ChronosOOOListActions';

export default withLocalize(ChronosOOOListActions);
export default ChronosOOOListActions;
2 changes: 1 addition & 1 deletion src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function getZoneAbbreviation(datetime: string | Date, selectedTimezone: Selected
*
* @returns Sunday, July 9, 2023
*/
function formatToLongDateWithWeekday(datetime: string): string {
function formatToLongDateWithWeekday(datetime: string | Date): string {
return format(new Date(datetime), CONST.DATE.LONG_DATE_FORMAT_WITH_WEEKDAY);
}

Expand Down
1 change: 1 addition & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,5 @@ export type {
OriginalMessageIOU,
OriginalMessageCreated,
OriginalMessageAddComment,
OriginalMessageChronosOOOList,
};
Loading