Skip to content

Commit

Permalink
Revert mailer - keep the email option to send them the results
Browse files Browse the repository at this point in the history
  • Loading branch information
IciaCarroBarallobre committed Aug 22, 2024
1 parent 2e51c6a commit b06519a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
40 changes: 21 additions & 19 deletions lib/exploring_beam_community_web/controllers/home_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ defmodule ExploringBeamCommunityWeb.HomeController do

alias ExploringBeamCommunity.Subscriptions
alias ExploringBeamCommunity.Subscriptions.Subscription
alias ExploringBeamCommunity.Workers.BiWeeklyNewsletter
alias ExploringBeamCommunity.Mailer
alias ExploringBeamCommunity.PredefEmail
alias ExploringBeamCommunity.JobManager
# Mail (Deactived - TODO)
#alias ExploringBeamCommunity.Workers.BiWeeklyNewsletter
#alias ExploringBeamCommunity.Mailer
#alias ExploringBeamCommunity.PredefEmail
#alias ExploringBeamCommunity.JobManager

def index(conn, _params) do
changeset = Subscriptions.change_subscription(%Subscription{})
Expand All @@ -15,31 +16,31 @@ defmodule ExploringBeamCommunityWeb.HomeController do

def create(conn, %{"subscription" => subscription_params}) do
case Subscriptions.create_subscription(subscription_params) do
{:ok, subscription} ->
{:ok, _subscription} ->
# Send the welcome email
PredefEmail.welcome_email(
subscription.email,
subscription.activation_token,
subscription.unsubscribe_token
)
|> Mailer.deliver()
# Mail (Deactived - TODO)
# PredefEmail.welcome_email(
# subscription.email,
# subscription.activation_token,
# subscription.unsubscribe_token)
# |> Mailer.deliver()

conn
|> put_flash(:info, "Subscribed successfully! Check your email for validation.")
|> put_flash(:info, "Email saved successfully! ")
|> redirect(to: ~p"/")

{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :index, changeset: changeset, page_title: "Subscription fails")
render(conn, :index, changeset: changeset, page_title: "Failed to save email")
end
end

def validate_subs(conn, %{"token" => token}) do
case Subscriptions.activate_by_token(token) do
{:ok, subscription} ->
BiWeeklyNewsletter.schedule_biweekly_newsletter(
subscription.email,
subscription.unsubscribe_token
)
{:ok, _subscription} ->
# Mail (Deactived - TODO)
# BiWeeklyNewsletter.schedule_biweekly_newsletter(
# subscription.email,
# subscription.unsubscribe_token)

conn
|> put_flash(:info, "Confirmation of the subscription successfully! ")
Expand All @@ -55,7 +56,8 @@ defmodule ExploringBeamCommunityWeb.HomeController do
def unsubscribe(conn, %{"token" => token}) do
case Subscriptions.unsubscribe_by_token(token) do
{:ok, _subscription} ->
JobManager.cancel_jobs_by_token(token)
# Mail (Deactived - TODO)
# JobManager.cancel_jobs_by_token(token)

conn
|> put_flash(:info, "You have successfully unsubscribed.")
Expand Down
9 changes: 3 additions & 6 deletions lib/exploring_beam_community_web/controllers/home_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ defmodule ExploringBeamCommunityWeb.HomeHTML do
</div>
</section>
<section class="py-8 px-4 md:px-8 hidden">
<section class="py-8 px-4 md:px-8 ">
<div class="container mx-auto px-6">
<h1 class="text-3xl font-semibold mb-6 text-center">Subscribe to our newsletter!</h1>
<h1 class="text-3xl font-semibold mb-6 text-center">Would you like us to send you the results?</h1>
<p class="text-lg mb-4">
<b> Stay in the loop! </b> Subscribe to our newsletter for project updates
delivered on September 1st, September 20th, October 1st, and October 20th.
These newsletters will cover all key developments leading up to the
presentation of our results.
<b> Stay in the loop! </b> If you’d like us to notify you when it’s ready and send the study to your email, just leave us your email.
</p>
<div class="mx-auto w-4/5 md:w-2/3">
<.subscription_form changeset={@changeset} action={~p"/subscriptions"} />
Expand Down

0 comments on commit b06519a

Please sign in to comment.