From 118dd2d6c7b2663d4a1ba7fb24447fd58cccb1b3 Mon Sep 17 00:00:00 2001 From: Cong Pham Date: Wed, 13 Dec 2023 01:16:49 +0700 Subject: [PATCH 1/9] #32864 md syntax create task --- src/pages/home/ReportScreen.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 6afe7f92075b..7896b835b064 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -10,6 +10,7 @@ import DragAndDropProvider from '@components/DragAndDrop/Provider'; import MoneyReportHeader from '@components/MoneyReportHeader'; import MoneyRequestHeader from '@components/MoneyRequestHeader'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; +import {usePersonalDetails} from '@components/OnyxProvider'; import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView'; import ScreenWrapper from '@components/ScreenWrapper'; import TaskHeaderActionButton from '@components/TaskHeaderActionButton'; @@ -34,6 +35,7 @@ import reportMetadataPropTypes from '@pages/reportMetadataPropTypes'; import reportPropTypes from '@pages/reportPropTypes'; import * as ComposerActions from '@userActions/Composer'; import * as Report from '@userActions/Report'; +import * as Task from '@userActions/Task'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -282,12 +284,26 @@ function ReportScreen({ Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(accountManagerReportID)); }, [accountManagerReportID]); + const allPersonalDetails = usePersonalDetails(); + /** * @param {String} text */ const onSubmitComment = useCallback( (text) => { - Report.addComment(getReportID(route), text); + const taskRegex = /^\[\](?:\s+@([^\s@]+@[\w.-]+))?\s+(.+)/; + const match = text.match(taskRegex); + if (match) { + const email = match[1] ? match[1].trim() : undefined; // Email might be undefined if not captured + const title = match[2]; + let assignee = {}; + if (email) { + assignee = _.find(_.values(allPersonalDetails), (p) => p.login === email) || {}; + } + Task.createTaskAndNavigate(getReportID(route), title, '', assignee.login, assignee.accountID, assignee.assigneeChatReport, report.policyID); + } else { + Report.addComment(getReportID(route), text); + } // We need to scroll to the bottom of the list after the comment is added const refID = setTimeout(() => { From 82b6560151e03abf3a12c5f2049b79570ea51886 Mon Sep 17 00:00:00 2001 From: Cong Pham Date: Thu, 21 Dec 2023 18:07:42 +0700 Subject: [PATCH 2/9] #32864 validate email is valid --- src/pages/home/ReportScreen.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 7896b835b064..0adf246bf7e3 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -291,16 +291,27 @@ function ReportScreen({ */ const onSubmitComment = useCallback( (text) => { - const taskRegex = /^\[\](?:\s+@([^\s@]+@[\w.-]+))?\s+(.+)/; + /** + * Matching task rule by group + * Group 1: Start task rule with [] + * Group 2: Optional email group between \s+....\s* start rule with @+valid email + * Group 3: Title is remaining characters + */ + const taskRegex = /^\[\]\s+(?:@([^\s@]+@[\w.-]+\.[a-zA-Z]{2,}))?\s*(.*)/; + const match = text.match(taskRegex); if (match) { - const email = match[1] ? match[1].trim() : undefined; // Email might be undefined if not captured - const title = match[2]; - let assignee = {}; - if (email) { - assignee = _.find(_.values(allPersonalDetails), (p) => p.login === email) || {}; + const email = match[1] ? match[1].trim() : undefined; + const title = match[2] ? match[2].trim() : undefined; + if (title) { + let assignee = {}; + if (email) { + assignee = _.find(_.values(allPersonalDetails), (p) => p.login === email) || {}; + } + Task.createTaskAndNavigate(getReportID(route), title, '', assignee.login, assignee.accountID, assignee.assigneeChatReport, report.policyID); + } else { + Report.addComment(getReportID(route), text); } - Task.createTaskAndNavigate(getReportID(route), title, '', assignee.login, assignee.accountID, assignee.assigneeChatReport, report.policyID); } else { Report.addComment(getReportID(route), text); } From a4b21b690f2afe9bdaa76faf749b8228e5935b68 Mon Sep 17 00:00:00 2001 From: Cong Pham Date: Thu, 21 Dec 2023 23:23:15 +0700 Subject: [PATCH 3/9] markdown task replace multiple line --- src/pages/home/ReportScreen.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 0adf246bf7e3..e740b2244674 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -297,12 +297,12 @@ function ReportScreen({ * Group 2: Optional email group between \s+....\s* start rule with @+valid email * Group 3: Title is remaining characters */ - const taskRegex = /^\[\]\s+(?:@([^\s@]+@[\w.-]+\.[a-zA-Z]{2,}))?\s*(.*)/; + const taskRegex = /^\[\]\s+(?:@([^\s@]+@[\w.-]+\.[a-zA-Z]{2,}))?\s*([\s\S]*)/; const match = text.match(taskRegex); if (match) { const email = match[1] ? match[1].trim() : undefined; - const title = match[2] ? match[2].trim() : undefined; + const title = match[2] ? match[2].trim().replace(/\n/g, ' ') : undefined; if (title) { let assignee = {}; if (email) { From a47ba92753bb3b24c9c7de11d3f18d2315cbfb4d Mon Sep 17 00:00:00 2001 From: Cong Pham Date: Thu, 21 Dec 2023 23:50:26 +0700 Subject: [PATCH 4/9] update lint code, prettier --- src/pages/home/ReportScreen.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index e740b2244674..47b75eba9bda 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -323,7 +323,7 @@ function ReportScreen({ return () => clearTimeout(refID); }, - [route], + [route, allPersonalDetails], ); // Clear notifications for the current report when it's opened and re-focused From 06829c82852ac46c86a621e0fa19ae31f5b5e4fb Mon Sep 17 00:00:00 2001 From: Cong Pham Date: Fri, 22 Dec 2023 00:49:05 +0700 Subject: [PATCH 5/9] update code lint --- src/pages/home/ReportScreen.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 47b75eba9bda..e681aa1f1023 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -323,7 +323,7 @@ function ReportScreen({ return () => clearTimeout(refID); }, - [route, allPersonalDetails], + [route, allPersonalDetails, report.policyID], ); // Clear notifications for the current report when it's opened and re-focused From 5d5fe536bdc3adcad74b2e783f2dd6976c3de1d1 Mon Sep 17 00:00:00 2001 From: Cong Pham Date: Mon, 8 Jan 2024 23:18:16 +0700 Subject: [PATCH 6/9] 32864 cleanup elsewhere condition --- src/pages/home/ReportScreen.js | 40 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index e681aa1f1023..0e9c2eb95c93 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -289,7 +289,7 @@ function ReportScreen({ /** * @param {String} text */ - const onSubmitComment = useCallback( + const handleCreateTask = useCallback( (text) => { /** * Matching task rule by group @@ -300,19 +300,31 @@ function ReportScreen({ const taskRegex = /^\[\]\s+(?:@([^\s@]+@[\w.-]+\.[a-zA-Z]{2,}))?\s*([\s\S]*)/; const match = text.match(taskRegex); - if (match) { - const email = match[1] ? match[1].trim() : undefined; - const title = match[2] ? match[2].trim().replace(/\n/g, ' ') : undefined; - if (title) { - let assignee = {}; - if (email) { - assignee = _.find(_.values(allPersonalDetails), (p) => p.login === email) || {}; - } - Task.createTaskAndNavigate(getReportID(route), title, '', assignee.login, assignee.accountID, assignee.assigneeChatReport, report.policyID); - } else { - Report.addComment(getReportID(route), text); + if (!match) { + return false; + } + const email = match[1] ? match[1].trim() : undefined; + const title = match[2] ? match[2].trim().replace(/\n/g, ' ') : undefined; + if (title) { + let assignee = {}; + if (email) { + assignee = _.find(_.values(allPersonalDetails), (p) => p.login === email) || {}; } - } else { + Task.createTaskAndNavigate(getReportID(route), title, '', assignee.login, assignee.accountID, assignee.assigneeChatReport, report.policyID); + return true; + } + return false; + }, + [allPersonalDetails, report.policyID, route], + ); + + /** + * @param {String} text + */ + const onSubmitComment = useCallback( + (text) => { + const isHandled = handleCreateTask(text); + if (!isHandled) { Report.addComment(getReportID(route), text); } @@ -323,7 +335,7 @@ function ReportScreen({ return () => clearTimeout(refID); }, - [route, allPersonalDetails, report.policyID], + [route, handleCreateTask], ); // Clear notifications for the current report when it's opened and re-focused From 6c788e94994df88f29078279a589a7add3762b0c Mon Sep 17 00:00:00 2001 From: Cong Pham Date: Mon, 8 Jan 2024 23:24:31 +0700 Subject: [PATCH 7/9] 32864 cleanup elsewhere condition --- src/pages/home/ReportScreen.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 0e9c2eb95c93..c972618ff1e8 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -303,17 +303,17 @@ function ReportScreen({ if (!match) { return false; } - const email = match[1] ? match[1].trim() : undefined; const title = match[2] ? match[2].trim().replace(/\n/g, ' ') : undefined; - if (title) { - let assignee = {}; - if (email) { - assignee = _.find(_.values(allPersonalDetails), (p) => p.login === email) || {}; - } - Task.createTaskAndNavigate(getReportID(route), title, '', assignee.login, assignee.accountID, assignee.assigneeChatReport, report.policyID); - return true; + if (!title) { + return false; + } + const email = match[1] ? match[1].trim() : undefined; + let assignee = {}; + if (email) { + assignee = _.find(_.values(allPersonalDetails), (p) => p.login === email) || {}; } - return false; + Task.createTaskAndNavigate(getReportID(route), title, '', assignee.login, assignee.accountID, assignee.assigneeChatReport, report.policyID); + return true; }, [allPersonalDetails, report.policyID, route], ); From b5f09b6614cac97bab159dc0bc0aaa22fe908fde Mon Sep 17 00:00:00 2001 From: Cong Pham Date: Tue, 9 Jan 2024 01:24:19 +0700 Subject: [PATCH 8/9] update code review --- src/pages/home/ReportScreen.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index c972618ff1e8..67bd95ab5ce0 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -323,8 +323,8 @@ function ReportScreen({ */ const onSubmitComment = useCallback( (text) => { - const isHandled = handleCreateTask(text); - if (!isHandled) { + const isTaskCreated = handleCreateTask(text); + if (!isTaskCreated) { Report.addComment(getReportID(route), text); } From d8dc8d4249f254ba9d4c607e77bb7890d6d147b1 Mon Sep 17 00:00:00 2001 From: Cong Pham Date: Tue, 9 Jan 2024 22:05:46 +0700 Subject: [PATCH 9/9] update early condition --- src/pages/home/ReportScreen.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index ead72d760c1d..9d8564a835a0 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -329,9 +329,10 @@ function ReportScreen({ const onSubmitComment = useCallback( (text) => { const isTaskCreated = handleCreateTask(text); - if (!isTaskCreated) { - Report.addComment(getReportID(route), text); + if (isTaskCreated) { + return; } + Report.addComment(getReportID(route), text); }, [route, handleCreateTask], );