From 01999534f6b29e48709e14ef1dae4616f6b15105 Mon Sep 17 00:00:00 2001 From: Samuel Montambault Date: Thu, 29 Feb 2024 16:01:48 -0500 Subject: [PATCH] Add layout and render body component (#12) * Add layout and render body component * Fix button UI --- core/Controllers/MailTestController.cs | 14 +- core/Data/Responses/EventResponseDTO.cs | 1 + emails/EmailsUtils.cs | 3 +- emails/Models/HelloWorldModel.cs | 6 - ...ilBaseModel.cs => LayoutEmailBaseModel.cs} | 2 +- emails/Models/StatusChangeModel.cs | 38 ++ emails/Views/ComplexHelloWorld.cshtml | 40 -- emails/Views/HelloWorld.cshtml | 1 - emails/Views/Shared/_Layout.cshtml | 453 ++++++++++-------- emails/Views/StatusChange.cshtml | 136 ++++++ emails/api.emails.csproj | 11 +- 11 files changed, 455 insertions(+), 250 deletions(-) delete mode 100644 emails/Models/HelloWorldModel.cs rename emails/Models/{EmailBaseModel.cs => LayoutEmailBaseModel.cs} (69%) create mode 100644 emails/Models/StatusChangeModel.cs delete mode 100644 emails/Views/ComplexHelloWorld.cshtml delete mode 100644 emails/Views/HelloWorld.cshtml create mode 100644 emails/Views/StatusChange.cshtml diff --git a/core/Controllers/MailTestController.cs b/core/Controllers/MailTestController.cs index a1555e1..f23a73d 100644 --- a/core/Controllers/MailTestController.cs +++ b/core/Controllers/MailTestController.cs @@ -17,12 +17,18 @@ public async Task Create() var result = await service.SendEmailAsync( "test recipient", "test subject", - new HelloWorldModel + new StatusChangeModel { - Title = "Hello World", - Name = "Test name" + Title = "Changement de status", + Salutation = "Bonjour ApplETS,", + StatusHeaderText = "La publication « Compétition de développement mobile » a été", + StatusNameText = "refusée", + StatusRefusalHeader = "Raison du refus :", + StatusRefusalReason = "La publication ne respecte pas les règles de publication", + ButtonSeePublicationText = "Voir la publication", + ButtonLink = new Uri("https://github.com/ApplETS/Backend-Hello/compare/ftr/first-email-and-layout?expand=1"), }, - emails.EmailsUtils.ComplexHelloWorldTemplate); + emails.EmailsUtils.StatusChangeTemplate); return Ok(); } diff --git a/core/Data/Responses/EventResponseDTO.cs b/core/Data/Responses/EventResponseDTO.cs index 9d91901..8a076ad 100644 --- a/core/Data/Responses/EventResponseDTO.cs +++ b/core/Data/Responses/EventResponseDTO.cs @@ -18,6 +18,7 @@ public class EventResponseDTO public DateTime PublicationDate { get; set; } public DateTime EventStartDate { get; set; } + public DateTime EventEndDate { get; set; } public DateTime CreatedAt { get; set; } diff --git a/emails/EmailsUtils.cs b/emails/EmailsUtils.cs index f9d1c08..b044402 100644 --- a/emails/EmailsUtils.cs +++ b/emails/EmailsUtils.cs @@ -1,8 +1,7 @@ namespace api.emails; public static class EmailsUtils { - public const string HelloWorldTemplate = "HelloWorld.cshtml"; - public const string ComplexHelloWorldTemplate = "ComplexHelloWorld.cshtml"; + public const string StatusChangeTemplate = "StatusChange.cshtml"; internal static readonly string TemplateEmbeddedResourceNamespace = "api.emails.Views."; } diff --git a/emails/Models/HelloWorldModel.cs b/emails/Models/HelloWorldModel.cs deleted file mode 100644 index 5db5de1..0000000 --- a/emails/Models/HelloWorldModel.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace api.emails.Models; - -public class HelloWorldModel : EmailBaseModel -{ - public string Name { get; set; } -} diff --git a/emails/Models/EmailBaseModel.cs b/emails/Models/LayoutEmailBaseModel.cs similarity index 69% rename from emails/Models/EmailBaseModel.cs rename to emails/Models/LayoutEmailBaseModel.cs index 5b28888..1b58813 100644 --- a/emails/Models/EmailBaseModel.cs +++ b/emails/Models/LayoutEmailBaseModel.cs @@ -1,7 +1,7 @@  namespace api.emails.Models; -public class EmailBaseModel +public class LayoutEmailBaseModel { public string Title { get; set; } } diff --git a/emails/Models/StatusChangeModel.cs b/emails/Models/StatusChangeModel.cs new file mode 100644 index 0000000..ce11582 --- /dev/null +++ b/emails/Models/StatusChangeModel.cs @@ -0,0 +1,38 @@ + +namespace api.emails.Models; + +public class StatusChangeModel : LayoutEmailBaseModel +{ + /// + /// Example: "Dear ACCOUNT_NAME," + /// + public string Salutation { get; set; } + + /// + /// Example "The post « POST_NAME » was placed in the status of " + /// + public string StatusHeaderText { get; set; } + + /// + /// Example: "refused" + /// + public string StatusNameText { get; set; } + + /// + /// if null should not render the refusal reason + /// + public string? StatusRefusalReason { get; set; } + + /// + /// Example "Reason for refusal :" + /// + public string StatusRefusalHeader { get; set; } + + + /// + /// Example "See publication" + /// + public string ButtonSeePublicationText { get; set; } + + public Uri ButtonLink { get; set; } +} diff --git a/emails/Views/ComplexHelloWorld.cshtml b/emails/Views/ComplexHelloWorld.cshtml deleted file mode 100644 index 08f0d89..0000000 --- a/emails/Views/ComplexHelloWorld.cshtml +++ /dev/null @@ -1,40 +0,0 @@ -@using api.emails.Models -@model HelloWorldModel - -@{ - Layout = "Shared._Layout.cshtml"; -} - -

- We're excited to have you get started. First, you need to confirm your account. Just press the button below. -

- -
- - - - - -
- - - - -
- - @Model.Name - -
-
- -
- -

- If you have any questions, just reply to this email—we're always happy to help out. -

- -
- -

- The Contoso Team -

\ No newline at end of file diff --git a/emails/Views/HelloWorld.cshtml b/emails/Views/HelloWorld.cshtml deleted file mode 100644 index aad1b7c..0000000 --- a/emails/Views/HelloWorld.cshtml +++ /dev/null @@ -1 +0,0 @@ -Hello @Model.Name, World! diff --git a/emails/Views/Shared/_Layout.cshtml b/emails/Views/Shared/_Layout.cshtml index 30ee9ed..7836ebe 100644 --- a/emails/Views/Shared/_Layout.cshtml +++ b/emails/Views/Shared/_Layout.cshtml @@ -1,219 +1,296 @@ @using RazorLight; - - + + - - - - - - - - -
- We're thrilled to have you here! Get ready to dive into your new account. -
- - - - - - - - - - - + + + +
- - - - - -
- - Logo - -
- -
- - - - - -
-

@Model.Title

-
- -
+ - - - - - + + + + - - - \ No newline at end of file + + + diff --git a/emails/Views/StatusChange.cshtml b/emails/Views/StatusChange.cshtml new file mode 100644 index 0000000..abf8848 --- /dev/null +++ b/emails/Views/StatusChange.cshtml @@ -0,0 +1,136 @@ +@using api.emails.Models +@model StatusChangeModel + +@{ + Layout = "Shared._Layout.cshtml"; +} + + + + + + + + \ No newline at end of file diff --git a/emails/api.emails.csproj b/emails/api.emails.csproj index 50a1d98..fca9d8b 100644 --- a/emails/api.emails.csproj +++ b/emails/api.emails.csproj @@ -10,19 +10,14 @@ - - - + - - Always - - + Always - + Always