diff --git a/applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Domain/NotificationsDataSeedContributor.cs b/applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Domain/NotificationsDataSeedContributor.cs index c47d8a0b0..caa34d854 100644 --- a/applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Domain/NotificationsDataSeedContributor.cs +++ b/applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Domain/NotificationsDataSeedContributor.cs @@ -44,7 +44,8 @@ public async Task SeedAsync(DataSeedContext context) new() { Name = "Applicant ID", Token = "applicant_id", MapTo = "applicant.unityApplicantId" }, new() { Name = "Requested Amount", Token = "requested_amount", MapTo = "requestedAmount" }, new() { Name = "Recommended Amount", Token = "recommended_amount", MapTo = "recommendedAmount" }, - new() { Name = "Unity Application ID", Token = "unity_application_id", MapTo = "unityApplicationId" } + new() { Name = "Unity Application ID", Token = "unity_application_id", MapTo = "unityApplicationId" }, + new() { Name = "Today's Date", Token = "today_date", MapTo = "" } }; try @@ -74,9 +75,9 @@ await templateVariablesRepository.InsertAsync( var emailGroups = new List { - new() {Name = "FSB-AP", Description = "This group manages the recipients for PO-related payments, which will be sent to FSB-AP to update contracts and initiate payment creation.",Type = "static"}, - new() {Name = "Payments", Description = "This group manages the recipients for payment notifications, such as failures or errors",Type = "static"} - }; + new() {Name = "FSB-AP", Description = "This group manages the recipients for PO-related payments, which will be sent to FSB-AP to update contracts and initiate payment creation.",Type = "static"}, + new() {Name = "Payments", Description = "This group manages the recipients for payment notifications, such as failures or errors",Type = "static"} + }; try { var allGroups = await emailGroupsRepository.GetListAsync(); @@ -111,4 +112,4 @@ internal class EmailTempateVariableDto public string Token { get; set; } = string.Empty; public string MapTo { get; set; } = string.Empty; } -} +} diff --git a/applications/Unity.GrantManager/src/Unity.GrantManager.Web/Views/Shared/Components/EmailsWidget/Default.js b/applications/Unity.GrantManager/src/Unity.GrantManager.Web/Views/Shared/Components/EmailsWidget/Default.js index 7a5188757..ba75a8b60 100644 --- a/applications/Unity.GrantManager/src/Unity.GrantManager.Web/Views/Shared/Components/EmailsWidget/Default.js +++ b/applications/Unity.GrantManager/src/Unity.GrantManager.Web/Views/Shared/Components/EmailsWidget/Default.js @@ -613,6 +613,26 @@ return inputString; } + const buildTodayDateSpan = () => new Handlebars.SafeString(buildTodayDateHtml()); + + const buildTodayDateHtml = () => { + const formatted = new Intl.DateTimeFormat('en-CA', { + timeZone: 'America/Vancouver', + year: 'numeric', + month: 'long', + day: 'numeric' + }).format(new Date()); + return `${formatted}`; + }; + + const refreshTodayDateSpans = (html) => { + if (!html) return html; + return html.replaceAll( + /]*data-token="today_date"[^>]*>[\s\S]*?<\/span>/gi, + buildTodayDateHtml() + ); + }; + function extractTemplateData(apiResponse, mappingConfig) { const templateData = {}; @@ -620,7 +640,7 @@ const { token, mapTo } = mapping; if (!mapTo) { - templateData[token] = ""; // handle empty MapTo + templateData[token] = token === 'today_date' ? buildTodayDateSpan() : ""; return; } @@ -690,7 +710,7 @@ handleDraftChange(); }); editorInstance = editor; - editorInstance.setContent(data.body); + editorInstance.setContent(refreshTodayDateSpans(data.body)); } }); UIElements.inputEmailTo.val(data.toAddress); @@ -698,7 +718,7 @@ UIElements.inputEmailBCC.val(data.bcc ? data.bcc.replace(/,/g, '; ') : ''); UIElements.inputEmailFrom.val(data.fromAddress); UIElements.inputEmailSubject.val(data.subject); - UIElements.inputEmailBody.val(data.body); + UIElements.inputEmailBody.val(refreshTodayDateSpans(data.body)); const isDraft = data?.status === 'Draft'; if (isDraft) {