From 8abdbdc201fe317c132fb5d0f0990998122b3fc2 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 9 Jun 2023 15:41:12 +0700 Subject: [PATCH 01/14] Auto assign when create a task in a DM --- src/libs/actions/Task.js | 18 ++++++++++++++++++ src/pages/tasks/NewTaskPage.js | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 59ea33e0d722..f2dbb3506380 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -424,6 +424,23 @@ function setShareDestinationValue(shareDestination) { Onyx.merge(ONYXKEYS.TASK, {shareDestination}); } +/** + * Auto-assign for participant when create a task in a DM + * @param {string} reportID + */ + +function setAssignValueWithParentReportID(reportID) { + const report = ReportUtils.getReport(reportID); + const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report)); + const participants = lodashGet(report, 'participants', []); + const isMultipleParticipant = lodashGet(report, 'participants', []).length > 1; + if (!isDefault || isMultipleParticipant) { + return; + } + + Onyx.merge(ONYXKEYS.TASK, {assignee: participants[0]}) +} + /** * Sets the assignee value for the task and checks for an existing chat with the assignee * If there is no existing chat, it creates an optimistic chat report @@ -591,6 +608,7 @@ export { setTaskReport, setDetailsValue, setAssigneeValue, + setAssignValueWithParentReportID, setShareDestinationValue, clearOutTaskInfo, reopenTask, diff --git a/src/pages/tasks/NewTaskPage.js b/src/pages/tasks/NewTaskPage.js index e9ba781f046f..e003af0f9ac7 100644 --- a/src/pages/tasks/NewTaskPage.js +++ b/src/pages/tasks/NewTaskPage.js @@ -85,10 +85,17 @@ const NewTaskPage = (props) => { setAssignee(displayDetails); } + // If we don't have an assignee and we are creating a task from a report + // this allows us to auto assign for a participant of the report + if (!props.task.assignee && props.task.parentReportID) { + TaskUtils.setAssignValueWithParentReportID(props.task.parentReportID); + } + // We only set the parentReportID if we are creating a task from a report // this allows us to go ahead and set that report as the share destination // and disable the share destination selector if (props.task.parentReportID) { + TaskUtils.setShareDestinationValue(props.task.parentReportID); } From 2c0343c00f00161d17bc0a5df9c4a11e9c92e896 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 9 Jun 2023 15:42:52 +0700 Subject: [PATCH 02/14] format code --- src/libs/actions/Task.js | 4 ++-- src/pages/tasks/NewTaskPage.js | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index f2dbb3506380..1a47b34d604b 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -432,13 +432,13 @@ function setShareDestinationValue(shareDestination) { function setAssignValueWithParentReportID(reportID) { const report = ReportUtils.getReport(reportID); const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report)); - const participants = lodashGet(report, 'participants', []); + const participants = lodashGet(report, 'participants', []); const isMultipleParticipant = lodashGet(report, 'participants', []).length > 1; if (!isDefault || isMultipleParticipant) { return; } - Onyx.merge(ONYXKEYS.TASK, {assignee: participants[0]}) + Onyx.merge(ONYXKEYS.TASK, {assignee: participants[0]}); } /** diff --git a/src/pages/tasks/NewTaskPage.js b/src/pages/tasks/NewTaskPage.js index e003af0f9ac7..95acc31ef9b0 100644 --- a/src/pages/tasks/NewTaskPage.js +++ b/src/pages/tasks/NewTaskPage.js @@ -95,7 +95,6 @@ const NewTaskPage = (props) => { // this allows us to go ahead and set that report as the share destination // and disable the share destination selector if (props.task.parentReportID) { - TaskUtils.setShareDestinationValue(props.task.parentReportID); } From 2d754a724465e8d8b46f5e39a935b52f75ce739a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 9 Jun 2023 16:12:08 +0700 Subject: [PATCH 03/14] disable auto assign for child report --- src/libs/Permissions.js | 1 + src/libs/actions/Task.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/Permissions.js b/src/libs/Permissions.js index d3e407260e20..d96d0584f903 100644 --- a/src/libs/Permissions.js +++ b/src/libs/Permissions.js @@ -99,6 +99,7 @@ function canUsePasswordlessLogins(betas) { * @returns {Boolean} */ function canUseTasks(betas) { + return true; return _.contains(betas, CONST.BETAS.TASKS) || _.contains(betas, CONST.BETAS.ALL); } diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 1a47b34d604b..5d7c8c6d536a 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -433,8 +433,9 @@ function setAssignValueWithParentReportID(reportID) { const report = ReportUtils.getReport(reportID); const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report)); const participants = lodashGet(report, 'participants', []); + console.log(report); const isMultipleParticipant = lodashGet(report, 'participants', []).length > 1; - if (!isDefault || isMultipleParticipant) { + if (!isDefault || isMultipleParticipant || report.parentReportID) { return; } From 944d8b561f6748f7fa0c45e17222569b79359e1a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 9 Jun 2023 16:17:53 +0700 Subject: [PATCH 04/14] fix lint --- src/libs/Permissions.js | 1 - src/libs/actions/Task.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/libs/Permissions.js b/src/libs/Permissions.js index d96d0584f903..d3e407260e20 100644 --- a/src/libs/Permissions.js +++ b/src/libs/Permissions.js @@ -99,7 +99,6 @@ function canUsePasswordlessLogins(betas) { * @returns {Boolean} */ function canUseTasks(betas) { - return true; return _.contains(betas, CONST.BETAS.TASKS) || _.contains(betas, CONST.BETAS.ALL); } diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 5d7c8c6d536a..5da6e37a2d54 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -433,7 +433,6 @@ function setAssignValueWithParentReportID(reportID) { const report = ReportUtils.getReport(reportID); const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report)); const participants = lodashGet(report, 'participants', []); - console.log(report); const isMultipleParticipant = lodashGet(report, 'participants', []).length > 1; if (!isDefault || isMultipleParticipant || report.parentReportID) { return; From 78d02b87c4d2885798b7f559d84dd26c375350c2 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 9 Jun 2023 16:34:16 +0700 Subject: [PATCH 05/14] refactor code --- src/libs/actions/Task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 5da6e37a2d54..88df35cb5b92 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -433,7 +433,7 @@ function setAssignValueWithParentReportID(reportID) { const report = ReportUtils.getReport(reportID); const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report)); const participants = lodashGet(report, 'participants', []); - const isMultipleParticipant = lodashGet(report, 'participants', []).length > 1; + const isMultipleParticipant = participants.length > 1; if (!isDefault || isMultipleParticipant || report.parentReportID) { return; } From ef9aeccbcc3b796e5fce6fe2255d2aeb1dce947b Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:18:45 +0700 Subject: [PATCH 06/14] Update src/pages/tasks/NewTaskPage.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/pages/tasks/NewTaskPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/tasks/NewTaskPage.js b/src/pages/tasks/NewTaskPage.js index 95acc31ef9b0..05ab1a18ef7c 100644 --- a/src/pages/tasks/NewTaskPage.js +++ b/src/pages/tasks/NewTaskPage.js @@ -86,7 +86,7 @@ const NewTaskPage = (props) => { } // If we don't have an assignee and we are creating a task from a report - // this allows us to auto assign for a participant of the report + // this allows us to auto assign for a participant of the report. if (!props.task.assignee && props.task.parentReportID) { TaskUtils.setAssignValueWithParentReportID(props.task.parentReportID); } From df9dea4292745dc7114443ba9d5053c5be669a8b Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:37:48 +0700 Subject: [PATCH 07/14] Update src/libs/actions/Task.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/libs/actions/Task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 88df35cb5b92..c4108c4810f3 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -426,7 +426,7 @@ function setShareDestinationValue(shareDestination) { /** * Auto-assign for participant when create a task in a DM - * @param {string} reportID + * @param {String} reportID */ function setAssignValueWithParentReportID(reportID) { From b204c86589e43055b98516fbc3dd03645f3de552 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:37:55 +0700 Subject: [PATCH 08/14] Update src/libs/actions/Task.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/libs/actions/Task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index c4108c4810f3..b8ae7d6deeb7 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -429,7 +429,7 @@ function setShareDestinationValue(shareDestination) { * @param {String} reportID */ -function setAssignValueWithParentReportID(reportID) { +function setAssigneeValueWithParentReportID(reportID) { const report = ReportUtils.getReport(reportID); const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report)); const participants = lodashGet(report, 'participants', []); From 57584773c24a524ffe6f05b6e7781e95bc93c930 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:38:04 +0700 Subject: [PATCH 09/14] Update src/pages/tasks/NewTaskPage.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/pages/tasks/NewTaskPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/tasks/NewTaskPage.js b/src/pages/tasks/NewTaskPage.js index 05ab1a18ef7c..21f18ec04b50 100644 --- a/src/pages/tasks/NewTaskPage.js +++ b/src/pages/tasks/NewTaskPage.js @@ -88,7 +88,7 @@ const NewTaskPage = (props) => { // If we don't have an assignee and we are creating a task from a report // this allows us to auto assign for a participant of the report. if (!props.task.assignee && props.task.parentReportID) { - TaskUtils.setAssignValueWithParentReportID(props.task.parentReportID); + TaskUtils.setAssigneeValueWithParentReportID(props.task.parentReportID); } // We only set the parentReportID if we are creating a task from a report From cfc2934740b095c1786755f1619a9c1814b53bf4 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:38:12 +0700 Subject: [PATCH 10/14] Update src/libs/actions/Task.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/libs/actions/Task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index b8ae7d6deeb7..26f21b28c0fe 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -608,7 +608,7 @@ export { setTaskReport, setDetailsValue, setAssigneeValue, - setAssignValueWithParentReportID, + setAssigneeValueWithParentReportID, setShareDestinationValue, clearOutTaskInfo, reopenTask, From 1894191f4fd494773345b2e33dd8a164224749d5 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Mon, 12 Jun 2023 22:40:40 +0700 Subject: [PATCH 11/14] Update src/libs/actions/Task.js Co-authored-by: Maria D'Costa --- src/libs/actions/Task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 26f21b28c0fe..024d88461ff4 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -425,7 +425,7 @@ function setShareDestinationValue(shareDestination) { } /** - * Auto-assign for participant when create a task in a DM + * Auto-assign participant when creating a task in a DM * @param {String} reportID */ From c4657f44bd2870be85f4201c2b593193f9a8165c Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Mon, 12 Jun 2023 22:40:48 +0700 Subject: [PATCH 12/14] Update src/pages/tasks/NewTaskPage.js Co-authored-by: Maria D'Costa --- src/pages/tasks/NewTaskPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/tasks/NewTaskPage.js b/src/pages/tasks/NewTaskPage.js index 21f18ec04b50..65c5b1e5959f 100644 --- a/src/pages/tasks/NewTaskPage.js +++ b/src/pages/tasks/NewTaskPage.js @@ -86,7 +86,7 @@ const NewTaskPage = (props) => { } // If we don't have an assignee and we are creating a task from a report - // this allows us to auto assign for a participant of the report. + // this allows us to auto assign a participant of the report. if (!props.task.assignee && props.task.parentReportID) { TaskUtils.setAssigneeValueWithParentReportID(props.task.parentReportID); } From b93f45f6509d8216e513dddd58e8823fbd3fced2 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Mon, 12 Jun 2023 22:40:56 +0700 Subject: [PATCH 13/14] Update src/libs/actions/Task.js Co-authored-by: Maria D'Costa --- src/libs/actions/Task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 024d88461ff4..0dee954ffd13 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -433,7 +433,7 @@ function setAssigneeValueWithParentReportID(reportID) { const report = ReportUtils.getReport(reportID); const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report)); const participants = lodashGet(report, 'participants', []); - const isMultipleParticipant = participants.length > 1; + const hasMultipleParticipants = participants.length > 1; if (!isDefault || isMultipleParticipant || report.parentReportID) { return; } From 6d4d4ef608b6542c864df0a6ff1f2933f788e771 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 12 Jun 2023 22:45:25 +0700 Subject: [PATCH 14/14] fix lint --- src/libs/actions/Task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 0dee954ffd13..4eb501b289e6 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -434,7 +434,7 @@ function setAssigneeValueWithParentReportID(reportID) { const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report)); const participants = lodashGet(report, 'participants', []); const hasMultipleParticipants = participants.length > 1; - if (!isDefault || isMultipleParticipant || report.parentReportID) { + if (!isDefault || hasMultipleParticipants || report.parentReportID) { return; }