Skip to content

Commit

Permalink
Merge pull request #33810 from Expensify/vit-updateStateStatus
Browse files Browse the repository at this point in the history
[NoQA] Clean up report state and status
  • Loading branch information
mountiny authored Jan 15, 2024
2 parents b976abf + 681967e commit 178a339
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 142 deletions.
11 changes: 3 additions & 8 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,18 +639,13 @@ const CONST = {
ANNOUNCE: '#announce',
ADMINS: '#admins',
},
STATE: {
OPEN: 'OPEN',
SUBMITTED: 'SUBMITTED',
PROCESSING: 'PROCESSING',
},
STATE_NUM: {
OPEN: 0,
PROCESSING: 1,
SUBMITTED: 2,
SUBMITTED: 1,
APPROVED: 2,
BILLING: 3,
},
STATUS: {
STATUS_NUM: {
OPEN: 0,
SUBMITTED: 1,
CLOSED: 2,
Expand Down
5 changes: 3 additions & 2 deletions src/components/ReportActionItem/TaskPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ function TaskPreview({
const StyleUtils = useStyleUtils();
const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT;
const {translate} = useLocalize();

// The reportAction might not contain details regarding the taskReport
// Only the direct parent reportAction will contain details about the taskReport
// Other linked reportActions will only contain the taskReportID and we will grab the details from there
const isTaskCompleted = !isEmptyObject(taskReport)
? taskReport?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && taskReport.statusNum === CONST.REPORT.STATUS.APPROVED
: action?.childStateNum === CONST.REPORT.STATE_NUM.SUBMITTED && action?.childStatusNum === CONST.REPORT.STATUS.APPROVED;
? taskReport?.stateNum === CONST.REPORT.STATE_NUM.APPROVED && taskReport.statusNum === CONST.REPORT.STATUS_NUM.APPROVED
: action?.childStateNum === CONST.REPORT.STATE_NUM.APPROVED && action?.childStatusNum === CONST.REPORT.STATUS_NUM.APPROVED;
const taskTitle = Str.htmlEncode(TaskUtils.getTaskTitle(taskReportID, action?.childReportName ?? ''));
const taskAssigneeAccountID = Task.getTaskAssigneeAccountID(taskReport ?? {}) ?? action?.childManagerAccountID ?? '';
const assigneeLogin = personalDetails[taskAssigneeAccountID]?.login ?? '';
Expand Down
4 changes: 2 additions & 2 deletions src/libs/E2E/apiMocks/openApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2043,21 +2043,21 @@ const openApp = (): Response => ({
managerID: 16,
currency: 'USD',
chatReportID: '98817646',
state: 'SUBMITTED',
cachedTotal: '($1,473.11)',
total: 147311,
stateNum: 1,
statusNum: 1,
},
report_4249286573496381: {
reportID: '4249286573496381',
ownerAccountID: 17,
managerID: 21,
currency: 'USD',
chatReportID: '4867098979334014',
state: 'SUBMITTED',
cachedTotal: '($212.78)',
total: 21278,
stateNum: 1,
statusNum: 1,
},
},
},
Expand Down
37 changes: 17 additions & 20 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ type OptimisticExpenseReport = Pick<
| 'ownerAccountID'
| 'currency'
| 'reportName'
| 'state'
| 'stateNum'
| 'statusNum'
| 'total'
Expand Down Expand Up @@ -311,13 +310,12 @@ type OptimisticIOUReport = Pick<
| 'participantAccountIDs'
| 'visibleChatMemberAccountIDs'
| 'reportID'
| 'state'
| 'stateNum'
| 'statusNum'
| 'total'
| 'reportName'
| 'notificationPreference'
| 'parentReportID'
| 'statusNum'
| 'lastVisibleActionCreated'
>;
type DisplayNameWithTooltips = Array<Pick<PersonalDetails, 'accountID' | 'pronouns' | 'displayName' | 'login' | 'avatar'>>;
Expand Down Expand Up @@ -588,14 +586,16 @@ function isCanceledTaskReport(report: OnyxEntry<Report> | EmptyObject = {}, pare
* @param parentReportAction - The parent report action of the report (Used to check if the task has been canceled)
*/
function isOpenTaskReport(report: OnyxEntry<Report>, parentReportAction: OnyxEntry<ReportAction> | EmptyObject = {}): boolean {
return isTaskReport(report) && !isCanceledTaskReport(report, parentReportAction) && report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS.OPEN;
return (
isTaskReport(report) && !isCanceledTaskReport(report, parentReportAction) && report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN
);
}

/**
* Checks if a report is a completed task report.
*/
function isCompletedTaskReport(report: OnyxEntry<Report>): boolean {
return isTaskReport(report) && report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS.APPROVED;
return isTaskReport(report) && report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED && report?.statusNum === CONST.REPORT.STATUS_NUM.APPROVED;
}

/**
Expand All @@ -610,14 +610,14 @@ function isReportManager(report: OnyxEntry<Report>): boolean {
*/
function isReportApproved(reportOrID: OnyxEntry<Report> | string | EmptyObject): boolean {
const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID;
return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS.APPROVED;
return report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED && report?.statusNum === CONST.REPORT.STATUS_NUM.APPROVED;
}

/**
* Checks if the supplied report is an expense report in Open state and status.
*/
function isDraftExpenseReport(report: OnyxEntry<Report> | EmptyObject): boolean {
return isExpenseReport(report) && report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS.OPEN;
return isExpenseReport(report) && report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN;
}

/**
Expand Down Expand Up @@ -648,11 +648,11 @@ function isSettled(reportID: string | undefined): boolean {

// In case the payment is scheduled and we are waiting for the payee to set up their wallet,
// consider the report as paid as well.
if (report.isWaitingOnBankAccount && report.statusNum === CONST.REPORT.STATUS.APPROVED) {
if (report.isWaitingOnBankAccount && report.statusNum === CONST.REPORT.STATUS_NUM.APPROVED) {
return true;
}

return report?.statusNum === CONST.REPORT.STATUS.REIMBURSED;
return report?.statusNum === CONST.REPORT.STATUS_NUM.REIMBURSED;
}

/**
Expand Down Expand Up @@ -835,7 +835,7 @@ function isConciergeChatReport(report: OnyxEntry<Report>): boolean {
* Returns true if report is still being processed
*/
function isProcessingReport(report: OnyxEntry<Report> | EmptyObject): boolean {
return report?.stateNum === CONST.REPORT.STATE_NUM.PROCESSING && report?.statusNum === CONST.REPORT.STATUS.SUBMITTED;
return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED;
}

/**
Expand Down Expand Up @@ -941,7 +941,7 @@ function findLastAccessedReport(
* Whether the provided report is an archived room
*/
function isArchivedRoom(report: OnyxEntry<Report> | EmptyObject): boolean {
return report?.statusNum === CONST.REPORT.STATUS.CLOSED && report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED;
return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED;
}

/**
Expand Down Expand Up @@ -2529,7 +2529,7 @@ function buildOptimisticTaskCommentReportAction(taskReportID: string, taskTitle:
reportAction.reportAction.childType = CONST.REPORT.TYPE.TASK;
reportAction.reportAction.childReportName = taskTitle;
reportAction.reportAction.childManagerAccountID = taskAssigneeAccountID;
reportAction.reportAction.childStatusNum = CONST.REPORT.STATUS.OPEN;
reportAction.reportAction.childStatusNum = CONST.REPORT.STATUS_NUM.OPEN;
reportAction.reportAction.childStateNum = CONST.REPORT.STATE_NUM.OPEN;

return reportAction;
Expand Down Expand Up @@ -2564,9 +2564,8 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number
participantAccountIDs: participantsAccountIDs,
visibleChatMemberAccountIDs: participantsAccountIDs,
reportID: generateReportID(),
state: CONST.REPORT.STATE.SUBMITTED,
stateNum: isSendingMoney ? CONST.REPORT.STATE_NUM.SUBMITTED : CONST.REPORT.STATE_NUM.PROCESSING,
statusNum: isSendingMoney ? CONST.REPORT.STATUS.REIMBURSED : CONST.REPORT.STATE_NUM.PROCESSING,
stateNum: isSendingMoney ? CONST.REPORT.STATE_NUM.APPROVED : CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: isSendingMoney ? CONST.REPORT.STATUS_NUM.REIMBURSED : CONST.REPORT.STATE_NUM.SUBMITTED,
total,

// We don't translate reportName because the server response is always in English
Expand Down Expand Up @@ -2597,9 +2596,8 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa
const isFree = policy?.type === CONST.POLICY.TYPE.FREE;

// Define the state and status of the report based on whether the policy is free or paid
const state = isFree ? CONST.REPORT.STATE.SUBMITTED : CONST.REPORT.STATE.OPEN;
const stateNum = isFree ? CONST.REPORT.STATE_NUM.PROCESSING : CONST.REPORT.STATE_NUM.OPEN;
const statusNum = isFree ? CONST.REPORT.STATUS.SUBMITTED : CONST.REPORT.STATUS.OPEN;
const stateNum = isFree ? CONST.REPORT.STATE_NUM.SUBMITTED : CONST.REPORT.STATE_NUM.OPEN;
const statusNum = isFree ? CONST.REPORT.STATUS_NUM.SUBMITTED : CONST.REPORT.STATUS_NUM.OPEN;

return {
reportID: generateReportID(),
Expand All @@ -2611,7 +2609,6 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa

// We don't translate reportName because the server response is always in English
reportName: `${policyName} owes ${formattedTotal}`,
state,
stateNum,
statusNum,
total: storedTotal,
Expand Down Expand Up @@ -3351,7 +3348,7 @@ function buildOptimisticTaskReport(
parentReportID,
policyID,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
lastVisibleActionCreated: DateUtils.getDBTime(),
};
Expand Down
20 changes: 9 additions & 11 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -3016,7 +3016,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
lastMessageText: optimisticIOUReportAction.message[0].text,
lastMessageHtml: optimisticIOUReportAction.message[0].html,
hasOutstandingChildRequest: false,
statusNum: CONST.REPORT.STATUS.REIMBURSED,
statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED,
},
},
{
Expand Down Expand Up @@ -3164,8 +3164,8 @@ function approveMoneyRequest(expenseReport) {
...expenseReport,
lastMessageText: optimisticApprovedReportAction.message[0].text,
lastMessageHtml: optimisticApprovedReportAction.message[0].html,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS.APPROVED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
},
};
const optimisticData = [optimisticIOUReportData, optimisticReportActionsData];
Expand Down Expand Up @@ -3238,9 +3238,8 @@ function submitReport(expenseReport) {
...expenseReport,
lastMessageText: lodashGet(optimisticSubmittedReportAction, 'message.0.text', ''),
lastMessageHtml: lodashGet(optimisticSubmittedReportAction, 'message.0.html', ''),
state: CONST.REPORT.STATE.SUBMITTED,
stateNum: CONST.REPORT.STATE_NUM.PROCESSING,
statusNum: CONST.REPORT.STATUS.SUBMITTED,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
},
},
...(parentReport.reportID
Expand Down Expand Up @@ -3286,7 +3285,7 @@ function submitReport(expenseReport) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`,
value: {
statusNum: CONST.REPORT.STATUS.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
},
},
Expand Down Expand Up @@ -3354,9 +3353,8 @@ function cancelPayment(expenseReport, chatReport) {
...expenseReport,
lastMessageText: lodashGet(optimisticReportAction, 'message.0.text', ''),
lastMessageHtml: lodashGet(optimisticReportAction, 'message.0.html', ''),
state: isFree ? CONST.REPORT.STATE.SUBMITTED : CONST.REPORT.STATE.OPEN,
stateNum: isFree ? CONST.REPORT.STATE_NUM.PROCESSING : CONST.REPORT.STATE.OPEN,
statusNum: isFree ? CONST.REPORT.STATUS.SUBMITTED : CONST.REPORT.STATE.OPEN,
stateNum: isFree ? CONST.REPORT.STATE_NUM.SUBMITTED : CONST.REPORT.STATE_NUM.OPEN,
statusNum: isFree ? CONST.REPORT.STATUS_NUM.SUBMITTED : CONST.REPORT.STATUS_NUM.OPEN,
},
},
...(chatReport.reportID
Expand Down Expand Up @@ -3401,7 +3399,7 @@ function cancelPayment(expenseReport, chatReport) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`,
value: {
statusNum: CONST.REPORT.STATUS.REIMBURSED,
statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED,
},
},
...(chatReport.reportID
Expand Down
10 changes: 5 additions & 5 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ function deleteWorkspace(policyID, reports, policyName) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS.CLOSED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
hasDraft: false,
oldPolicyName: allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`].name,
},
Expand Down Expand Up @@ -368,8 +368,8 @@ function removeMembers(accountIDs, policyID) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
value: {
statusNum: CONST.REPORT.STATUS.CLOSED,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
oldPolicyName: policy.name,
hasDraft: false,
},
Expand Down Expand Up @@ -475,7 +475,7 @@ function createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs, hasOutsta
key: `${ONYXKEYS.COLLECTION.REPORT}${oldChat.reportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
},
});
return;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2095,8 +2095,8 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal
}
: {
reportID: null,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS.CLOSED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
},
Expand Down
12 changes: 6 additions & 6 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ function completeTask(taskReport) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS.APPROVED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
},
},

Expand Down Expand Up @@ -275,7 +275,7 @@ function completeTask(taskReport) {
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
},
},
{
Expand Down Expand Up @@ -314,7 +314,7 @@ function reopenTask(taskReport) {
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
lastVisibleActionCreated: reopenedTaskReportAction.created,
lastMessageText: message,
lastActorAccountID: reopenedTaskReportAction.actorAccountID,
Expand Down Expand Up @@ -344,8 +344,8 @@ function reopenTask(taskReport) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS.APPROVED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false}

const workspaceChatReport = Object.values(allReports ?? {}).find((report) => {
if (report) {
return ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED;
return ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS_NUM.CLOSED;
}
return false;
});
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function HeaderView(props) {
}

// Task is not closed
if (props.report.stateNum !== CONST.REPORT.STATE_NUM.SUBMITTED && props.report.statusNum !== CONST.REPORT.STATUS.CLOSED && canModifyTask) {
if (props.report.stateNum !== CONST.REPORT.STATE_NUM.APPROVED && props.report.statusNum !== CONST.REPORT.STATUS_NUM.CLOSED && canModifyTask) {
threeDotMenuItems.push({
icon: Expensicons.Trashcan,
text: translate('common.delete'),
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function ReportScreen({

// There are no reportActions at all to display and we are still in the process of loading the next set of actions.
const isLoadingInitialReportActions = _.isEmpty(reportActions) && reportMetadata.isLoadingInitialReportActions;
const isOptimisticDelete = lodashGet(report, 'statusNum') === CONST.REPORT.STATUS.CLOSED;
const isOptimisticDelete = lodashGet(report, 'statusNum') === CONST.REPORT.STATUS_NUM.CLOSED;
const shouldHideReport = !ReportUtils.canAccessReport(report, policies, betas);
const isLoading = !reportID || !isSidebarLoaded || _.isEmpty(personalDetails);
const isSingleTransactionView = ReportUtils.isMoneyRequest(report);
Expand Down Expand Up @@ -383,8 +383,8 @@ function ReportScreen({
(prevOnyxReportID &&
prevOnyxReportID === routeReportID &&
!onyxReportID &&
prevReport.statusNum === CONST.REPORT.STATUS.OPEN &&
(report.statusNum === CONST.REPORT.STATUS.CLOSED || (!report.statusNum && !prevReport.parentReportID && prevReport.chatType === CONST.REPORT.CHAT_TYPE.POLICY_ROOM))) ||
prevReport.statusNum === CONST.REPORT.STATUS_NUM.OPEN &&
(report.statusNum === CONST.REPORT.STATUS_NUM.CLOSED || (!report.statusNum && !prevReport.parentReportID && prevReport.chatType === CONST.REPORT.CHAT_TYPE.POLICY_ROOM))) ||
((ReportUtils.isMoneyRequest(prevReport) || ReportUtils.isMoneyRequestReport(prevReport)) && _.isEmpty(report))
) {
Navigation.dismissModal();
Expand Down
Loading

0 comments on commit 178a339

Please sign in to comment.