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

[No QA] Created IOU preview component within chat #2112

Merged
merged 35 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d581791
Created IOU preview component within chat
tugbadogan Mar 26, 2021
1e7a1c9
Added ReportActionItemIOUQuote component
tugbadogan Mar 28, 2021
095aad9
Added IOU Preview UI
tugbadogan Mar 30, 2021
8b2a0b4
Fixed live update issues and addressing comments
tugbadogan Mar 31, 2021
b04df47
Created IOU preview component within chat
tugbadogan Mar 26, 2021
6870e69
Added ReportActionItemIOUQuote component
tugbadogan Mar 28, 2021
8bc24d2
Added IOU Preview UI
tugbadogan Mar 30, 2021
5f68df7
Fixed live update issues and addressing comments
tugbadogan Mar 31, 2021
0c1e7f6
Update chat report real time on IOU report changes
tugbadogan Apr 5, 2021
eff5eb2
Merge branch 'tugbadogan-create-iou-preview-component' of https://git…
tugbadogan Apr 5, 2021
051fd09
Fix linter errors
tugbadogan Apr 5, 2021
3da3fb4
Addressing comments and styling changes
tugbadogan Apr 8, 2021
b66ab2e
Merge branch 'master' into tugbadogan-create-iou-preview-component
tugbadogan Apr 8, 2021
75d0302
Fixing merge issues
tugbadogan Apr 8, 2021
cdbaaff
Create a separate function for updateIOUAndChatReportData
tugbadogan Apr 8, 2021
d4be1b5
Addressing comments
tugbadogan Apr 9, 2021
893f34d
Merge branch 'master' into tugbadogan-create-iou-preview-component
tugbadogan Apr 9, 2021
61cb1e4
Updating Report.js to work with fixed push notifications
tugbadogan Apr 14, 2021
5976424
Merge pull request #14 from Expensify/master
tugbadogan Apr 14, 2021
cc83654
Merge branch 'master' into tugbadogan-create-iou-preview-component
tugbadogan Apr 14, 2021
d4455b8
Merge pull request #15 from Expensify/master
tugbadogan Apr 15, 2021
975c0fc
Addressing comments
tugbadogan Apr 18, 2021
195b424
Merge pull request #16 from Expensify/main
tugbadogan Apr 19, 2021
f64e2f3
Merge branch 'master' into tugbadogan-create-iou-preview-component
tugbadogan Apr 19, 2021
103e1d1
Simplify Report.js
tugbadogan Apr 20, 2021
70522c4
Another set of refactoring in Report.js
tugbadogan Apr 21, 2021
bada5ba
Merge pull request #17 from Expensify/main
tugbadogan Apr 21, 2021
ff0d54b
Merge branch 'master' into tugbadogan-create-iou-preview-component
tugbadogan Apr 21, 2021
f2fceb9
Fixed lint error
tugbadogan Apr 21, 2021
1ab7855
Updated comment and pod install
tugbadogan Apr 21, 2021
6d3bfa3
Revert changes from pod install
tugbadogan Apr 23, 2021
d16c1b2
Merge pull request #18 from Expensify/main
tugbadogan Apr 23, 2021
33ecad8
Merge branch 'master' into tugbadogan-create-iou-preview-component
tugbadogan Apr 23, 2021
a3a7063
Merge pull request #19 from Expensify/main
tugbadogan Apr 23, 2021
88989a6
Merge branch 'master' into tugbadogan-create-iou-preview-component
tugbadogan Apr 23, 2021
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
4 changes: 4 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const CONST = {
IOU: 'IOU',
},
},
TYPE: {
CHAT: 'chat',
IOU: 'iou',
},
},
MODAL: {
MODAL_TYPE: {
Expand Down
140 changes: 140 additions & 0 deletions src/components/ReportActionItemIOUPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import React from 'react';
import {View, TouchableOpacity} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import Str from 'expensify-common/lib/str';
import ONYXKEYS from '../ONYXKEYS';
import ReportActionItemIOUQuote from './ReportActionItemIOUQuote';
import ReportActionPropTypes from '../pages/home/report/ReportActionPropTypes';
import Text from './Text';
import MultipleAvatars from './MultipleAvatars';
import styles from '../styles/styles';

const propTypes = {
// All the data of the action
action: PropTypes.shape(ReportActionPropTypes).isRequired,

// Is this the most recent IOU Action?
isMostRecentIOUReportAction: PropTypes.bool.isRequired,

// Whether there is an outstanding amount in IOU
hasOutstandingIOU: PropTypes.bool.isRequired,

/* --- Onyx Props --- */
// Active IOU Report for current report
iou: PropTypes.shape({
// Email address of the manager in this iou report
managerEmail: PropTypes.string,

// Email address of the creator of this iou report
ownerEmail: PropTypes.string,

// Outstanding amount of this transaction
cachedTotal: PropTypes.string,
}),

// All of the personal details for everyone
personalDetails: PropTypes.objectOf(PropTypes.shape({

// This is either the user's full name, or their login if full name is an empty string
displayName: PropTypes.string.isRequired,
})).isRequired,

// Session info for the currently logged in user.
session: PropTypes.shape({
// Currently logged in user email
email: PropTypes.string,
}).isRequired,
};

const defaultProps = {
iou: {},
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
};

const ReportActionItemIOUPreview = ({
action,
isMostRecentIOUReportAction,
hasOutstandingIOU,
iou,
personalDetails,
session,
}) => {
const managerName = lodashGet(
personalDetails,
[iou.managerEmail, 'displayName'],
iou.managerEmail ? Str.removeSMSDomain(iou.managerEmail) : '',
);
const ownerName = lodashGet(
personalDetails,
[iou.ownerEmail, 'displayName'],
iou.ownerEmail ? Str.removeSMSDomain(iou.ownerEmail) : '',
);
const managerAvatar = lodashGet(personalDetails, [iou.managerEmail, 'avatar'], '');
const ownerAvatar = lodashGet(personalDetails, [iou.ownerEmail, 'avatar'], '');
const sessionEmail = lodashGet(session, 'email', null);
const cachedTotal = iou.cachedTotal ? iou.cachedTotal.replace(/[()]/g, '') : '';

// Pay button should be visible to manager person in the report
// Check if the currently logged in user is the manager.
const isCurrentUserManager = iou.managerEmail === sessionEmail;

return (
<View>
<ReportActionItemIOUQuote action={action} />
{isMostRecentIOUReportAction
&& hasOutstandingIOU
&& !_.isEmpty(iou) && (
<View style={styles.iouPreviewBox}>
<View style={styles.flexRow}>
<View style={styles.flex1}>
<Text style={styles.h1}>{cachedTotal}</Text>
<Text style={styles.mt2}>
{managerName}
{' owes '}
{ownerName}
</Text>
</View>
<View style={styles.iouPreviewBoxAvatar}>
<MultipleAvatars
avatarImageURLs={[managerAvatar, ownerAvatar]}
secondAvatarStyle={[styles.secondAvatarInline]}
/>
</View>
</View>
{isCurrentUserManager && (
<TouchableOpacity
style={[styles.buttonSmall, styles.buttonSuccess, styles.mt4]}
>
<Text
style={[
styles.buttonSmallText,
styles.buttonSuccessText,
]}
>
Pay
</Text>
</TouchableOpacity>
)}
</View>
)}
</View>
);
};

ReportActionItemIOUPreview.propTypes = propTypes;
ReportActionItemIOUPreview.defaultProps = defaultProps;
ReportActionItemIOUPreview.displayName = 'ReportActionItemIOUPreview';

export default withOnyx({
iou: {
key: ({iouReportID}) => `${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReportID}`,
},
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
session: {
key: ONYXKEYS.SESSION,
},
})(ReportActionItemIOUPreview);
29 changes: 29 additions & 0 deletions src/components/ReportActionItemIOUQuote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import styles from '../styles/styles';
import ReportActionPropTypes from '../pages/home/report/ReportActionPropTypes';
import RenderHTML from './RenderHTML';

const propTypes = {
// All the data of the action
action: PropTypes.shape(ReportActionPropTypes).isRequired,
};

const ReportActionItemIOUQuote = ({action}) => (
<View style={[styles.chatItemMessage]}>
{_.map(action.message, (fragment, index) => {
const viewDetails = '<br /><a href="#">View Details</a>';
const html = `<blockquote>${fragment.text}${viewDetails}</blockquote>`;
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
return (
<RenderHTML key={`iouQuote-${action.sequenceNumber}-${index}`} html={html} />
);
})}
</View>
);

ReportActionItemIOUQuote.propTypes = propTypes;
ReportActionItemIOUQuote.displayName = 'ReportActionItemIOUQuote';

export default ReportActionItemIOUQuote;
Loading