-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3883 from parasharrajat/timezone
Feature: Show local time for User in 1:1 chat
- Loading branch information
Showing
8 changed files
with
158 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from 'react'; | ||
import { | ||
View, | ||
} from 'react-native'; | ||
import lodashGet from 'lodash/get'; | ||
import moment from 'moment'; | ||
import Str from 'expensify-common/lib/str'; | ||
import styles from '../../../styles/styles'; | ||
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; | ||
import {participantPropTypes} from '../sidebar/optionPropTypes'; | ||
import ExpensiText from '../../../components/Text'; | ||
import Timers from '../../../libs/Timers'; | ||
|
||
const propTypes = { | ||
/** Personal details of the participant */ | ||
participant: participantPropTypes.isRequired, | ||
|
||
...withLocalizePropTypes, | ||
}; | ||
|
||
class ParticipantLocalTime extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.getParticipantLocalTime = this.getParticipantLocalTime.bind(this); | ||
this.state = { | ||
localTime: this.getParticipantLocalTime(), | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
this.timer = Timers.register(setInterval(() => { | ||
this.setState({ | ||
localTime: this.getParticipantLocalTime(), | ||
}); | ||
}, 1000)); | ||
} | ||
|
||
componentWillUnmount() { | ||
clearInterval(this.timer); | ||
clearInterval(this.readyTimer); | ||
} | ||
|
||
getParticipantLocalTime() { | ||
const reportRecipientTimezone = lodashGet(this.props.participant, 'timezone', {}); | ||
return moment().tz(reportRecipientTimezone.selected).format('LT'); | ||
} | ||
|
||
|
||
render() { | ||
// Moment.format does not return AM or PM values immediately. | ||
// So we have to wait until we are ready before showing the time to the user | ||
const isReportRecipientLocalTimeReady = this.state.localTime.toString().match(/(A|P)M/ig); | ||
const reportRecipientDisplayName = this.props.participant.firstName | ||
|| (Str.isSMSLogin(this.props.participant.login) | ||
? this.props.toLocalPhone(this.props.participant.displayName) | ||
: this.props.participant.displayName); | ||
|
||
return ( | ||
isReportRecipientLocalTimeReady ? ( | ||
<View style={[styles.chatItemComposeSecondaryRow]}> | ||
<ExpensiText style={[ | ||
styles.chatItemComposeSecondaryRowSubText, | ||
styles.chatItemComposeSecondaryRowOffset, | ||
]} | ||
> | ||
{this.props.translate( | ||
'reportActionCompose.localTime', | ||
{ | ||
user: reportRecipientDisplayName, | ||
time: this.state.localTime, | ||
}, | ||
)} | ||
</ExpensiText> | ||
</View> | ||
) | ||
: <View style={[styles.chatItemComposeSecondaryRow]} /> | ||
); | ||
} | ||
} | ||
|
||
ParticipantLocalTime.propTypes = propTypes; | ||
|
||
export default withLocalize(ParticipantLocalTime); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/pages/settings/Profile/currentUserPersonalDetailsPropsTypes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
/** The personal details of the person who is logged in */ | ||
const currentUserPersonalDetailsPropsTypes = { | ||
/** Email/Phone login of the current user from their personal details */ | ||
login: PropTypes.string, | ||
|
||
/** Display first name of the current user from their personal details */ | ||
firstName: PropTypes.string, | ||
|
||
/** Display last name of the current user from their personal details */ | ||
lastName: PropTypes.string, | ||
|
||
/** Avatar URL of the current user from their personal details */ | ||
avatar: PropTypes.string, | ||
|
||
/** Pronouns of the current user from their personal details */ | ||
pronouns: PropTypes.string, | ||
|
||
/** Timezone of the current user from their personal details */ | ||
timezone: PropTypes.shape({ | ||
|
||
/** Value of selected timezone */ | ||
selected: PropTypes.string, | ||
|
||
/** Whether timezone is automatically set */ | ||
automatic: PropTypes.bool, | ||
}), | ||
}; | ||
|
||
export default currentUserPersonalDetailsPropsTypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters