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

[CP Staging] fixes optimistc case and delay submission current user bad grammar #49482

Merged
merged 9 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
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
20 changes: 11 additions & 9 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ Onyx.connect({
function parseMessage(messages: Message[] | undefined) {
let nextStepHTML = '';

messages?.forEach((part) => {
messages?.forEach((part, index) => {
const isEmail = Str.isValidEmail(part.text);
let tagType = part.type ?? 'span';
let content = Str.safeEscape(part.text);

if (currentUserEmail === part.text || part.clickToCopyText === currentUserEmail) {
tagType = 'strong';
content = 'You';
content = messages[index + 1].text === `'s` ? 'Your' : 'You';
} else if (part.text === `'s` && (messages[index - 1].text === currentUserEmail || messages[index - 1].clickToCopyText === currentUserEmail)) {
content = '';
} else if (isEmail) {
tagType = 'next-step-email';
content = EmailUtils.prefixMailSeparatorsWithBreakOpportunities(content);
Expand All @@ -65,15 +67,15 @@ function parseMessage(messages: Message[] | undefined) {
function getNextApproverDisplayName(policy: Policy, ownerAccountID: number, submitToAccountID: number, report: OnyxEntry<Report>) {
const approvalChain = ReportUtils.getApprovalChain(policy, ownerAccountID, report?.total ?? 0);
if (approvalChain.length === 0) {
return ReportUtils.getDisplayNameForParticipant(submitToAccountID);
return submitToAccountID === currentUserAccountID ? 'You' : ReportUtils.getDisplayNameForParticipant(submitToAccountID);
}

const nextApproverEmail = approvalChain.length === 1 ? approvalChain[0] : approvalChain[approvalChain.indexOf(currentUserEmail) + 1];
if (!nextApproverEmail) {
return ReportUtils.getDisplayNameForParticipant(submitToAccountID);
return submitToAccountID === currentUserAccountID ? 'You' : ReportUtils.getDisplayNameForParticipant(submitToAccountID);
}

return PersonalDetailsUtils.getPersonalDetailByEmail(nextApproverEmail)?.displayName ?? nextApproverEmail;
return nextApproverEmail === currentUserEmail ? 'You' : PersonalDetailsUtils.getPersonalDetailByEmail(nextApproverEmail)?.displayName ?? nextApproverEmail;
}

/**
Expand All @@ -98,9 +100,10 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
const nextApproverDisplayName = getNextApproverDisplayName(policy, ownerAccountID, submitToAccountID, report);

const reimburserAccountID = PolicyUtils.getReimburserAccountID(policy);
const reimburserDisplayName = ReportUtils.getDisplayNameForParticipant(reimburserAccountID);
const reimburserDisplayName = reimburserAccountID === currentUserAccountID ? 'You' : ReportUtils.getDisplayNameForParticipant(reimburserAccountID);
const type: ReportNextStep['type'] = 'neutral';
let optimisticNextStep: ReportNextStep | null;
const isOwnerCurrentUser = ownerAccountID === currentUserAccountID;

switch (predictedNextStatus) {
// Generates an optimistic nextStep once a report has been opened
Expand All @@ -114,7 +117,7 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
text: 'Waiting for ',
},
{
text: `${ownerDisplayName}`,
text: isOwnerCurrentUser ? 'You' : `${ownerDisplayName}`,
type: 'strong',
},
{
Expand All @@ -128,15 +131,14 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
},
],
};

// Scheduled submit enabled
if (harvesting?.enabled && autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL) {
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: `${ownerDisplayName}'s`,
text: isOwnerCurrentUser ? 'Your' : `${ownerDisplayName}'s`,
type: 'strong',
},
{
Expand Down
Loading