-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from 3 commits
2e192b3
59b6952
6dbcba9
2f3c8e8
991f77e
e0a0f61
f14a7ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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]}> | ||
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. Why this style was removed? 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. Looks like this style 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. Yes, the |
||
<Text>You haven'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> | ||
); | ||
|
@@ -73,7 +72,6 @@ function ChronosOOOListActions(props) { | |
); | ||
} | ||
|
||
ChronosOOOListActions.propTypes = propTypes; | ||
ChronosOOOListActions.displayName = 'ChronosOOOListActions'; | ||
|
||
export default withLocalize(ChronosOOOListActions); | ||
export default ChronosOOOListActions; |
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.
Can you test what will happen when
pendingAction
will be undefined?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.
Nothing happened - all works good