From 61796def1452a9ac59b95a245d73d4fab5d431f1 Mon Sep 17 00:00:00 2001 From: IciaC Date: Mon, 14 Oct 2024 23:08:33 +0200 Subject: [PATCH] Delete the DB stuff and put results --- config/config.exs | 8 -- config/dev.exs | 15 --- config/prod.exs | 3 - config/runtime.exs | 29 ---- config/test.exs | 18 --- lib/exploring_beam_community/application.ex | 3 - lib/exploring_beam_community/emails.ex | 26 ---- lib/exploring_beam_community/emails/email.ex | 17 --- lib/exploring_beam_community/mailer.ex | 3 - lib/exploring_beam_community/predef_email.ex | 67 --------- lib/exploring_beam_community/release.ex | 28 ---- lib/exploring_beam_community/repo.ex | 5 - lib/exploring_beam_community/subscriptions.ex | 127 ------------------ .../subscriptions/subscription.ex | 39 ------ lib/exploring_beam_community/user.ex | 23 ---- .../workers/biweekly_newsletter.ex | 66 --------- .../workers/job_manager.ex | 23 ---- lib/exploring_beam_community_web.ex | 2 +- .../components/layouts/app.html.heex | 4 +- .../components/navbar.ex | 16 +-- .../controllers/home_controller.ex | 67 +-------- .../controllers/home_html.ex | 22 ++- .../subscription_form.html.heex | 11 -- .../live/results.ex | 31 +++++ lib/exploring_beam_community_web/router.ex | 7 +- mix.exs | 9 +- priv/repo/migrations/.formatter.exs | 4 - .../20240814004458_create_subscriptions.exs | 18 --- .../20240814015810_add_oban_jobs_table.exs | 6 - .../20240815232733_create_emails.exs | 14 -- priv/repo/seeds.exs | 11 -- priv/static/assets/app.css | 21 ++- rel/env.sh.eex | 1 - 33 files changed, 69 insertions(+), 675 deletions(-) delete mode 100644 lib/exploring_beam_community/emails.ex delete mode 100644 lib/exploring_beam_community/emails/email.ex delete mode 100644 lib/exploring_beam_community/mailer.ex delete mode 100644 lib/exploring_beam_community/predef_email.ex delete mode 100644 lib/exploring_beam_community/release.ex delete mode 100644 lib/exploring_beam_community/repo.ex delete mode 100644 lib/exploring_beam_community/subscriptions.ex delete mode 100644 lib/exploring_beam_community/subscriptions/subscription.ex delete mode 100644 lib/exploring_beam_community/user.ex delete mode 100644 lib/exploring_beam_community/workers/biweekly_newsletter.ex delete mode 100644 lib/exploring_beam_community/workers/job_manager.ex delete mode 100644 lib/exploring_beam_community_web/controllers/subscription_html/subscription_form.html.heex create mode 100644 lib/exploring_beam_community_web/live/results.ex delete mode 100644 priv/repo/migrations/.formatter.exs delete mode 100644 priv/repo/migrations/20240814004458_create_subscriptions.exs delete mode 100644 priv/repo/migrations/20240814015810_add_oban_jobs_table.exs delete mode 100644 priv/repo/migrations/20240815232733_create_emails.exs delete mode 100644 priv/repo/seeds.exs diff --git a/config/config.exs b/config/config.exs index 4521c17..370a66d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -7,9 +7,6 @@ # General application configuration import Config -config :exploring_beam_community, - ecto_repos: [ExploringBeamCommunity.Repo] - # Configures the endpoint config :exploring_beam_community, ExploringBeamCommunityWeb.Endpoint, url: [host: "localhost"], @@ -24,11 +21,6 @@ config :exploring_beam_community, ExploringBeamCommunityWeb.Endpoint, live_view: [signing_salt: "KEeqDH6/"] ############ CONFIG NEWSLETTER -# Oban -config :exploring_beam_community, Oban, - repo: ExploringBeamCommunity.Repo, - plugins: [Oban.Plugins.Pruner], - queues: [default: 10, scheduled: 5] # Configure esbuild (the version is required) config :esbuild, diff --git a/config/dev.exs b/config/dev.exs index ccd1eaf..7c365aa 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,15 +1,5 @@ import Config -# Configure your database -config :exploring_beam_community, ExploringBeamCommunity.Repo, - username: "postgres", - password: "postgres", - hostname: "localhost", - database: "exploring_beam_community_dev", - stacktrace: true, - show_sensitive_data_on_connection_error: true, - pool_size: 10 - # For development, we disable any cache and enable # debugging and code reloading. # @@ -70,8 +60,3 @@ config :phoenix, :stacktrace_depth, 20 # Initialize plugs at runtime for faster development compilation config :phoenix, :plug_init_mode, :runtime - -# Disable swoosh api client as it is only required for production adapters. -config :swoosh, :api_client, false - -config :exploring_beam_community, ExploringBeamCommunity.Mailer, adapter: Swoosh.Adapters.Local diff --git a/config/prod.exs b/config/prod.exs index e9d6f2b..9f0dac8 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -13,6 +13,3 @@ config :logger, level: :info # Runtime production configuration, including reading # of environment variables, is done on config/runtime.exs. - -# Mailer - Disable Swoosh Local Memory Storage -config :swoosh, local: false diff --git a/config/runtime.exs b/config/runtime.exs index ceeb8f5..c620b59 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -27,22 +27,7 @@ if System.get_env("PHX_SERVER") do config :exploring_beam_community, ExploringBeamCommunityWeb.Endpoint, server: true end -# DB PROD CONFIGURATION if config_env() == :prod do - database_url = - System.get_env("DATABASE_URL") || - raise """ - environment variable DATABASE_URL is missing. - For example: ecto://USER:PASS@HOST/DATABASE - """ - - maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: [] - - config :exploring_beam_community, ExploringBeamCommunity.Repo, - # ssl: true, - url: database_url, - pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), - socket_options: maybe_ipv6 # The secret key base is used to sign/encrypt cookies and other secrets. # A default value is used in config/dev.exs and config/test.exs but you @@ -103,17 +88,3 @@ if config_env() == :prod do # # Check `Plug.SSL` for all available options in `force_ssl`. end - -# Mail -config :swoosh, :api_client, Swoosh.ApiClient.Hackney - -config :exploring_beam_community, ExploringBeamCommunity.Mailer, - adapter: Swoosh.Adapters.SMTP, - relay: System.get_env("MAIL_HOST"), - username: System.get_env("MAIL_USERNAME"), - password: System.get_env("MAIL_PASSWORD"), - ssl: false, - tls: :always, - auth: :always, - port: String.to_integer(System.get_env("MAIL_PORT") || "587"), - from: {System.get_env("MAIL_FROM_NAME"), System.get_env("MAIL_FROM_ADDRESS")} diff --git a/config/test.exs b/config/test.exs index a2c4d38..33d4c3b 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,18 +1,5 @@ import Config -# Configure your database -# -# The MIX_TEST_PARTITION environment variable can be used -# to provide built-in test partitioning in CI environment. -# Run `mix help test` for more information. -config :exploring_beam_community, ExploringBeamCommunity.Repo, - username: "postgres", - password: "postgres", - hostname: "localhost", - database: "exploring_beam_community_test#{System.get_env("MIX_TEST_PARTITION")}", - pool: Ecto.Adapters.SQL.Sandbox, - pool_size: 10 - # We don't run a server during test. If one is required, # you can enable the server option below. config :exploring_beam_community, ExploringBeamCommunityWeb.Endpoint, @@ -20,13 +7,8 @@ config :exploring_beam_community, ExploringBeamCommunityWeb.Endpoint, secret_key_base: "TvG0FoiH9PYqICwdqc4TyJTeNmgKOWfCML3go99a1yxhJ04DDMT3LLkwOQuyO+0T", server: false -# Disable swoosh api client as it is only required for production adapters. -config :swoosh, :api_client, false - # Print only warnings and errors during test config :logger, level: :warning # Initialize plugs at runtime for faster test compilation config :phoenix, :plug_init_mode, :runtime - -config :my_app, MyApp.Mailer, adapter: Swoosh.Adapters.Test diff --git a/lib/exploring_beam_community/application.ex b/lib/exploring_beam_community/application.ex index 61b6365..19d20dd 100644 --- a/lib/exploring_beam_community/application.ex +++ b/lib/exploring_beam_community/application.ex @@ -8,9 +8,6 @@ defmodule ExploringBeamCommunity.Application do @impl true def start(_type, _args) do children = [ - # Start the Ecto repository - ExploringBeamCommunity.Repo, - {Oban, Application.fetch_env!(:exploring_beam_community, Oban)}, # Start the PubSub system {Phoenix.PubSub, name: ExploringBeamCommunity.PubSub}, # Start the Endpoint (http/https) diff --git a/lib/exploring_beam_community/emails.ex b/lib/exploring_beam_community/emails.ex deleted file mode 100644 index 35defbb..0000000 --- a/lib/exploring_beam_community/emails.ex +++ /dev/null @@ -1,26 +0,0 @@ -defmodule ExploringBeamCommunity.Emails do - @moduledoc """ - The Catalog context. - """ - alias ExploringBeamCommunity.Repo - alias ExploringBeamCommunity.Emails.Email - - def get_current_email do - Repo.get_by(Email, activated: true) - end - - @doc """ - Inserts a new email, activating it and deactivating any other emails. - """ - def insert_email(attrs) do - Repo.transaction(fn -> - # Deactivate any currently activated email - Repo.update_all(Email, set: [activated: false]) - - # Insert the new email with activated: true - %Email{} - |> Email.changeset(Map.put(attrs, :activated, true)) - |> Repo.insert() - end) - end -end diff --git a/lib/exploring_beam_community/emails/email.ex b/lib/exploring_beam_community/emails/email.ex deleted file mode 100644 index f9f7e85..0000000 --- a/lib/exploring_beam_community/emails/email.ex +++ /dev/null @@ -1,17 +0,0 @@ -defmodule ExploringBeamCommunity.Emails.Email do - use Ecto.Schema - import Ecto.Changeset - - schema "emails" do - field(:content, :string) - field(:activated, :boolean, default: false) - timestamps() - end - - @doc false - def changeset(email, attrs) do - email - |> cast(attrs, [:content]) - |> validate_required([:content]) - end -end diff --git a/lib/exploring_beam_community/mailer.ex b/lib/exploring_beam_community/mailer.ex deleted file mode 100644 index 7ae4a60..0000000 --- a/lib/exploring_beam_community/mailer.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule ExploringBeamCommunity.Mailer do - use Swoosh.Mailer, otp_app: :exploring_beam_community -end diff --git a/lib/exploring_beam_community/predef_email.ex b/lib/exploring_beam_community/predef_email.ex deleted file mode 100644 index 0eb7562..0000000 --- a/lib/exploring_beam_community/predef_email.ex +++ /dev/null @@ -1,67 +0,0 @@ -defmodule ExploringBeamCommunity.PredefEmail do - import Swoosh.Email - - @from_name "Icia & Mariajo" - @from_email "iciacarrobarallobre@gmail.com" - @cc "mariajose.gavilan@gmail.com" - - # Import the necessary helpers for path and URL generation - alias ExploringBeamCommunityWeb.Endpoint - - def welcome_email(to_email, activation_token, unsubscribe_token) do - base_url = Endpoint.url() - unsubscribe_url = "#{base_url}/unsubscribe/#{unsubscribe_token}" - activate_url = "#{base_url}/subscriptions/#{activation_token}" - - new() - |> to(to_email) - |> cc(@cc) - |> from({@from_name, @from_email}) - |> subject("Welcome to our 2024 research on the European BEAM Community!") - |> text_body(""" - Hi beamer, - - Welcome to our 2024 research on the European BEAM Community! - - Next step - Confirm your subscription: #{activate_url} - - If you confirmed it, every fifteen days, you will receive updates on our - progress as long as the project continues. - - We invite you to explore and participate in our surveys (and share them) - to help us understand the adoption, diversity, and challenges of BEAM - languages across Europe. - - If you no longer wish to receive these emails, you can unsubscribe at any - time by clicking the link below: - #{unsubscribe_url} - - Best regards, - #{@from_name} - """) - end - - def newsletter(to_email, unsubscribe_token, text) do - base_url = Endpoint.url() - unsubscribe_url = "#{base_url}/unsubscribe/#{unsubscribe_token}" - - new() - |> to(to_email) - |> cc(@cc) - |> from({@from_name, @from_email}) - |> subject("2024 research on the European BEAM Community Status!") - |> text_body(""" - Hi beamer, - - #{text} - - - If you no longer wish to receive these emails, you can unsubscribe at any - time by clicking the link below: - #{unsubscribe_url} - - Best regards, - #{@from_name} - """) - end -end diff --git a/lib/exploring_beam_community/release.ex b/lib/exploring_beam_community/release.ex deleted file mode 100644 index ea41ce6..0000000 --- a/lib/exploring_beam_community/release.ex +++ /dev/null @@ -1,28 +0,0 @@ -defmodule ExploringBeamCommunity.Release do - @moduledoc """ - Used for executing DB release tasks when run in production without Mix - installed. - """ - @app :exploring_beam_community - - def migrate do - load_app() - - for repo <- repos() do - {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) - end - end - - def rollback(repo, version) do - load_app() - {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version)) - end - - defp repos do - Application.fetch_env!(@app, :ecto_repos) - end - - defp load_app do - Application.load(@app) - end -end diff --git a/lib/exploring_beam_community/repo.ex b/lib/exploring_beam_community/repo.ex deleted file mode 100644 index 8246b16..0000000 --- a/lib/exploring_beam_community/repo.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule ExploringBeamCommunity.Repo do - use Ecto.Repo, - otp_app: :exploring_beam_community, - adapter: Ecto.Adapters.Postgres -end diff --git a/lib/exploring_beam_community/subscriptions.ex b/lib/exploring_beam_community/subscriptions.ex deleted file mode 100644 index 6cfd92b..0000000 --- a/lib/exploring_beam_community/subscriptions.ex +++ /dev/null @@ -1,127 +0,0 @@ -defmodule ExploringBeamCommunity.Subscriptions do - @moduledoc """ - The Catalog context. - """ - - import Ecto.Query, warn: false - alias ExploringBeamCommunity.Repo - - alias ExploringBeamCommunity.Subscriptions.Subscription - - @doc """ - Returns the list of subscriptions. - - ## Examples - - iex> list_subscriptions() - [%Subscription{}, ...] - - """ - def list_subscriptions do - Repo.all(Subscription) - end - - @doc """ - Gets a single subscription. - - Raises `Ecto.NoResultsError` if the Subscription does not exist. - - ## Examples - - iex> get_subscription!(123) - %Subscription{} - - iex> get_subscription!(456) - ** (Ecto.NoResultsError) - - """ - def get_subscription!(id), do: Repo.get!(Subscription, id) - - @doc """ - Creates a subscription. - - ## Examples - - iex> create_subscription(%{field: value}) - {:ok, %Subscription{}} - - iex> create_subscription(%{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def create_subscription(attrs \\ %{}) do - %Subscription{} - |> Subscription.changeset(attrs) - |> Repo.insert() - end - - @doc """ - Updates a subscription. - - ## Examples - - iex> update_subscription(subscription, %{field: new_value}) - {:ok, %Subscription{}} - - iex> update_subscription(subscription, %{field: bad_value}) - {:error, %Ecto.Changeset{}} - - """ - def update_subscription(%Subscription{} = subscription, attrs) do - subscription - |> Subscription.changeset(attrs) - |> Repo.update() - end - - @doc """ - Deletes a subscription. - - ## Examples - - iex> delete_subscription(subscription) - {:ok, %Subscription{}} - - iex> delete_subscription(subscription) - {:error, %Ecto.Changeset{}} - - """ - def delete_subscription(%Subscription{} = subscription) do - Repo.delete(subscription) - end - - @doc """ - Returns an `%Ecto.Changeset{}` for tracking subscription changes. - - ## Examples - - iex> change_subscription(subscription) - %Ecto.Changeset{data: %Subscription{}} - - """ - def change_subscription(%Subscription{} = subscription, attrs \\ %{}) do - Subscription.changeset(subscription, attrs) - end - - def unsubscribe_by_token(token) do - subscription = Repo.get_by(Subscription, unsubscribe_token: token) - - if subscription do - Repo.delete(subscription) - {:ok, subscription} - else - {:error, :not_found} - end - end - - def activate_by_token(token) do - case Repo.get_by(Subscription, activation_token: token) do - nil -> - {:error, "Invalid token"} - - subscription -> - subscription - |> Subscription.changeset(%{activated: true}) - |> Repo.update() - end - end -end diff --git a/lib/exploring_beam_community/subscriptions/subscription.ex b/lib/exploring_beam_community/subscriptions/subscription.ex deleted file mode 100644 index 0762fc6..0000000 --- a/lib/exploring_beam_community/subscriptions/subscription.ex +++ /dev/null @@ -1,39 +0,0 @@ -defmodule ExploringBeamCommunity.Subscriptions.Subscription do - use Ecto.Schema - import Ecto.Changeset - - schema "subscriptions" do - field(:email, :string) - field(:activated, :boolean, default: false) - field(:activation_token, :string) - field(:unsubscribe_token, :string) - - timestamps() - end - - def changeset(subscription, attrs) do - subscription - |> cast(attrs, [:email]) - |> validate_required([:email]) - |> validate_format(:email, email_regex()) - |> unique_constraint(:email) - |> put_tokens_on_create(subscription) - end - - defp email_regex do - ~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/ - end - - defp put_tokens_on_create(changeset, %__MODULE__{id: nil}), - do: - changeset - |> put_change(:unsubscribe_token, generate_token()) - |> put_change(:activation_token, generate_token()) - - defp put_tokens_on_create(changeset, %__MODULE__{id: _id}), - do: changeset - - defp generate_token do - :crypto.strong_rand_bytes(16) |> Base.url_encode64() |> binary_part(0, 16) - end -end diff --git a/lib/exploring_beam_community/user.ex b/lib/exploring_beam_community/user.ex deleted file mode 100644 index 8384d96..0000000 --- a/lib/exploring_beam_community/user.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule ExploringBeamCommunity.User do - use Ecto.Schema - import Ecto.Changeset - - schema "users" do - field(:bio, :string) - field(:email, :string) - field(:name, :string) - field(:number_of_pets, :integer) - - timestamps() - end - - @doc false - def changeset(user, attrs) do - user - |> cast(attrs, [:name, :email, :bio, :number_of_pets]) - |> validate_required([:name, :email, :bio, :number_of_pets]) - |> validate_length(:bio, min: 2) - |> validate_length(:bio, max: 140) - |> validate_format(:email, ~r/@/) - end -end diff --git a/lib/exploring_beam_community/workers/biweekly_newsletter.ex b/lib/exploring_beam_community/workers/biweekly_newsletter.ex deleted file mode 100644 index f1366f1..0000000 --- a/lib/exploring_beam_community/workers/biweekly_newsletter.ex +++ /dev/null @@ -1,66 +0,0 @@ -defmodule ExploringBeamCommunity.Workers.BiWeeklyNewsletter do - use Oban.Worker, queue: :scheduled, max_attempts: 2 - - alias ExploringBeamCommunity.Mailer - alias ExploringBeamCommunity.Emails - alias ExploringBeamCommunity.PredefEmail - - def schedule_biweekly_newsletter(email, unsubscribe_token) do - job_changeset = - Oban.Job.new( - %{"email" => email, "unsubscribe_token" => unsubscribe_token}, - worker: __MODULE__, - scheduled_at: calculate_next_date(), - unique: [period: :infinity, states: [:available, :scheduled]] - ) - - Oban.insert(job_changeset) - end - - @impl true - def perform(%Oban.Job{ - args: %{"email" => email, "unsubscribe_token" => unsubscribe_token} = _args, - attempt: 1 - }) do - schedule_biweekly_newsletter(email, unsubscribe_token) - deliver_mail(email, unsubscribe_token) - end - - def perform(%Oban.Job{args: %{"email" => email, "unsubscribe_token" => unsubscribe_token}}), - do: deliver_mail(email, unsubscribe_token) - - def perform(%Oban.Job{args: %{}} = job), - do: {:error, "Job has empty args: #{inspect(job)}"} - - defp deliver_mail(email, unsubscribe_token) do - newsletter_content = - case Emails.get_current_email() do - nil -> - "Here are the latest updates on the European BEAM Community project..." - - email_record -> - email_record.content - end - - PredefEmail.newsletter(email, unsubscribe_token, newsletter_content) - |> Mailer.deliver() - end - - defp calculate_next_date() do - now = DateTime.utc_now() - day = now.day - - cond do - day < 20 -> - NaiveDateTime.new!(now.year, now.month, 20, 9, 0, 0, 0) - |> DateTime.from_naive!("Etc/UTC") - - day >= 20 -> - next_month = if now.month == 12, do: 1, else: now.month + 1 - next_year = if next_month == 1, do: now.year + 1, else: now.year - - NaiveDateTime.new!(next_year, next_month, 1, 9, 0, 0, 0) - |> DateTime.from_naive!("Etc/UTC") - end - end -end diff --git a/lib/exploring_beam_community/workers/job_manager.ex b/lib/exploring_beam_community/workers/job_manager.ex deleted file mode 100644 index 4839c4b..0000000 --- a/lib/exploring_beam_community/workers/job_manager.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule ExploringBeamCommunity.JobManager do - import Ecto.Query, only: [from: 2] - alias ExploringBeamCommunity.Repo - alias Oban.Job - - def cancel_jobs_by_token(unsubscribe_token) do - from(j in Job, - where: - fragment("?->>? = ?", j.args, "unsubscribe_token", ^unsubscribe_token) and - j.state in ["scheduled", "available"] - ) - |> Repo.update_all(set: [state: "cancelled"]) - end - - def get_scheduled_jobs do - Repo.all( - from(j in Job, - where: j.state == "scheduled", - order_by: [asc: j.scheduled_at] - ) - ) - end -end diff --git a/lib/exploring_beam_community_web.ex b/lib/exploring_beam_community_web.ex index 1ec1624..4604ff5 100644 --- a/lib/exploring_beam_community_web.ex +++ b/lib/exploring_beam_community_web.ex @@ -17,7 +17,7 @@ defmodule ExploringBeamCommunityWeb do those modules here. """ - def static_paths, do: ~w(assets fonts images favicon.ico robots.txt) + def static_paths, do: ~w(assets fonts images favicon.ico robots.txt pdf) def router do quote do diff --git a/lib/exploring_beam_community_web/components/layouts/app.html.heex b/lib/exploring_beam_community_web/components/layouts/app.html.heex index df545ab..ae1facf 100644 --- a/lib/exploring_beam_community_web/components/layouts/app.html.heex +++ b/lib/exploring_beam_community_web/components/layouts/app.html.heex @@ -1,7 +1,7 @@ <.navbar navigation_pages={[ %{route: ~p"/", name: "Home"}, - %{route: ~p"/survey", name: "Survey"}, + %{route: ~p"/results", name: "Results"}, %{route: ~p"/about-us", name: "About Us"} ]} logo={~p"/images/logo_simple.svg"} @@ -31,7 +31,7 @@ text="© 2024 BEAM Developer Community. All rights reserved." navigation_pages={[ %{route: ~p"/", name: "Home"}, - %{route: ~p"/survey", name: "Survey"}, + %{route: ~p"/results", name: "Results"}, %{route: ~p"/about-us", name: "About Us"}, %{route: "https://github.com/IciaCarroBarallobre/exploring_beam_community/issues", name: "Github Issues"} ]} diff --git a/lib/exploring_beam_community_web/components/navbar.ex b/lib/exploring_beam_community_web/components/navbar.ex index 5e4eb8a..172bdca 100644 --- a/lib/exploring_beam_community_web/components/navbar.ex +++ b/lib/exploring_beam_community_web/components/navbar.ex @@ -16,9 +16,8 @@ defmodule ExploringBeamCommunityWeb.Navbar do def navbar(assigns) do ~H""" -
-
+
+
    - <%= for %{route: route, name: name} <- @navigation_pages do %> + <%= for %{route: route, name: name} <- @navigation_pages do %> <.hamburger_nav_link href={route} label={name} /> <% end %>
diff --git a/lib/exploring_beam_community_web/controllers/home_controller.ex b/lib/exploring_beam_community_web/controllers/home_controller.ex index e6aa0ae..06ed888 100644 --- a/lib/exploring_beam_community_web/controllers/home_controller.ex +++ b/lib/exploring_beam_community_web/controllers/home_controller.ex @@ -1,72 +1,7 @@ defmodule ExploringBeamCommunityWeb.HomeController do use ExploringBeamCommunityWeb, :controller - alias ExploringBeamCommunity.Subscriptions - alias ExploringBeamCommunity.Subscriptions.Subscription - # 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{}) - render(conn, :index, page_title: "Home", changeset: changeset) - end - - def create(conn, %{"subscription" => subscription_params}) do - case Subscriptions.create_subscription(subscription_params) do - {:ok, _subscription} -> - # Send the welcome email - # Mail (Deactived - TODO) - # PredefEmail.welcome_email( - # subscription.email, - # subscription.activation_token, - # subscription.unsubscribe_token) - # |> Mailer.deliver() - - conn - |> put_flash(:info, "Email saved successfully! ") - |> redirect(to: ~p"/") - - {:error, %Ecto.Changeset{} = changeset} -> - 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} -> - # Mail (Deactived - TODO) - # BiWeeklyNewsletter.schedule_biweekly_newsletter( - # subscription.email, - # subscription.unsubscribe_token) - - conn - |> put_flash(:info, "Confirmation of the subscription successfully! ") - |> redirect(to: ~p"/") - - {:error, info} -> - conn - |> put_flash(:error, info) - |> redirect(to: ~p"/") - end - end - - def unsubscribe(conn, %{"token" => token}) do - case Subscriptions.unsubscribe_by_token(token) do - {:ok, _subscription} -> - # Mail (Deactived - TODO) - # JobManager.cancel_jobs_by_token(token) - - conn - |> put_flash(:info, "You have successfully unsubscribed.") - |> redirect(to: ~p"/") - - {:error, :not_found} -> - conn - |> put_flash(:error, "Invalid or expired unsubscribe link.") - |> redirect(to: ~p"/") - end + render(conn, :index, page_title: "Home") end end diff --git a/lib/exploring_beam_community_web/controllers/home_html.ex b/lib/exploring_beam_community_web/controllers/home_html.ex index 6ed7089..c5d8d56 100644 --- a/lib/exploring_beam_community_web/controllers/home_html.ex +++ b/lib/exploring_beam_community_web/controllers/home_html.ex @@ -3,15 +3,9 @@ defmodule ExploringBeamCommunityWeb.HomeHTML do import ExploringBeamCommunityWeb.ComplexLogo, only: [complex_logo: 1] - embed_templates("subscription_html/*") - @doc """ Renders a subscription form. """ - attr(:changeset, Ecto.Changeset, required: true) - attr(:action, :string, required: true) - - def subscription_form(assigns) def index(assigns) do ~H""" @@ -30,20 +24,20 @@ defmodule ExploringBeamCommunityWeb.HomeHTML do
-
- <.button type="submit">Complete the surveys + + <.button type="submit">Take a look to the results!
-

Would you like us to send you the results?

-

- Stay in the loop! If you’d like us to notify you when it’s ready and send the study to your email, just leave us your email. -

-
- <.subscription_form changeset={@changeset} action={~p"/subscriptions"} /> +
+
diff --git a/lib/exploring_beam_community_web/controllers/subscription_html/subscription_form.html.heex b/lib/exploring_beam_community_web/controllers/subscription_html/subscription_form.html.heex deleted file mode 100644 index 323d748..0000000 --- a/lib/exploring_beam_community_web/controllers/subscription_html/subscription_form.html.heex +++ /dev/null @@ -1,11 +0,0 @@ -<.simple_form :let={f} for={@changeset} action={@action}> - <.error :if={@changeset.action}> - Oops, something went wrong! Please check the errors below. - - <.input field={f[:email]} type="text" label="Email*" /> - <:actions> -
- <.button>Subscribe -
- - diff --git a/lib/exploring_beam_community_web/live/results.ex b/lib/exploring_beam_community_web/live/results.ex new file mode 100644 index 0000000..fa8f692 --- /dev/null +++ b/lib/exploring_beam_community_web/live/results.ex @@ -0,0 +1,31 @@ +defmodule ExploringBeamCommunityWeb.ResultsView do + use ExploringBeamCommunityWeb, :live_view + + def mount(_params, _session, socket) do + slides = + %{ + id: "form1", + path: "/pdf/slides.pdf" + } + + {:ok, assign(socket, slides: slides, page_title: "Results")} + end + + def render(assigns) do + ~H""" +
+
+ <.button phx-click={JS.navigate("/pdf/slides.pdf")}> + Download PDF <.icon name="hero-arrow-down-on-square" class="h-6 w-6" /> + +
+
+ +
+ +
+ """ + end +end diff --git a/lib/exploring_beam_community_web/router.ex b/lib/exploring_beam_community_web/router.ex index a45a1b9..e1bf6ae 100644 --- a/lib/exploring_beam_community_web/router.ex +++ b/lib/exploring_beam_community_web/router.ex @@ -15,18 +15,13 @@ defmodule ExploringBeamCommunityWeb.Router do pipe_through(:browser) get("/", HomeController, :index) - post("/subscriptions", HomeController, :create) - get("/subscriptions/:token", HomeController, :validate_subs) - get("/unsubscribe/:token", HomeController, :unsubscribe) - live("/survey", SurveyView) + live("/results", ResultsView) get("/about-us", AboutUsController, :index) end if Mix.env() == :dev do scope "/dev" do pipe_through([:browser]) - - forward("/mailbox", Plug.Swoosh.MailboxPreview) end end end diff --git a/mix.exs b/mix.exs index 7c92a97..5c88faf 100644 --- a/mix.exs +++ b/mix.exs @@ -34,7 +34,6 @@ defmodule ExploringBeamCommunity.MixProject do [ {:phoenix, "~> 1.7.7"}, {:phoenix_ecto, "~> 4.4"}, - {:ecto_sql, "~> 3.10"}, {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 3.3"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, @@ -46,10 +45,7 @@ defmodule ExploringBeamCommunity.MixProject do {:gettext, "~> 0.20"}, {:jason, "~> 1.2"}, {:plug_cowboy, "~> 2.5"}, - {:oban, "~> 2.14"}, - {:swoosh, "~> 1.16"}, {:hackney, "~> 1.20"}, - {:gen_smtp, "~> 1.1"}, {:timex, "~> 3.7"}, {:dotenvy, "~> 0.8.0"} ] @@ -63,10 +59,7 @@ defmodule ExploringBeamCommunity.MixProject do # See the documentation for `Mix` for more info on aliases. defp aliases do [ - setup: ["deps.get", "ecto.setup", "assets.setup", "assets.build"], - "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], - "ecto.reset": ["ecto.drop", "ecto.setup"], - test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"], + setup: ["deps.get", "assets.setup", "assets.build"], "assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"], "assets.build": ["tailwind default", "esbuild default"], "assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"] diff --git a/priv/repo/migrations/.formatter.exs b/priv/repo/migrations/.formatter.exs deleted file mode 100644 index 49f9151..0000000 --- a/priv/repo/migrations/.formatter.exs +++ /dev/null @@ -1,4 +0,0 @@ -[ - import_deps: [:ecto_sql], - inputs: ["*.exs"] -] diff --git a/priv/repo/migrations/20240814004458_create_subscriptions.exs b/priv/repo/migrations/20240814004458_create_subscriptions.exs deleted file mode 100644 index 2ca36e9..0000000 --- a/priv/repo/migrations/20240814004458_create_subscriptions.exs +++ /dev/null @@ -1,18 +0,0 @@ -defmodule ExploringBeamCommunity.Repo.Migrations.CreateSubscriptions do - use Ecto.Migration - - def change do - create table(:subscriptions) do - add :email, :string - add :activated, :boolean, default: false, null: false - add :activation_token, :string - add :unsubscribe_token, :string - - timestamps() - end - - create unique_index(:subscriptions, [:email]) - create unique_index(:subscriptions, [:unsubscribe_token]) - create unique_index(:subscriptions, [:activation_token]) - end -end diff --git a/priv/repo/migrations/20240814015810_add_oban_jobs_table.exs b/priv/repo/migrations/20240814015810_add_oban_jobs_table.exs deleted file mode 100644 index 4ce4a98..0000000 --- a/priv/repo/migrations/20240814015810_add_oban_jobs_table.exs +++ /dev/null @@ -1,6 +0,0 @@ -defmodule ExploringBeamCommunity.Repo.Migrations.AddObanJobsTable do - use Ecto.Migration - - defdelegate up, to: Oban.Migrations - defdelegate down, to: Oban.Migrations -end diff --git a/priv/repo/migrations/20240815232733_create_emails.exs b/priv/repo/migrations/20240815232733_create_emails.exs deleted file mode 100644 index 46dd7b6..0000000 --- a/priv/repo/migrations/20240815232733_create_emails.exs +++ /dev/null @@ -1,14 +0,0 @@ -defmodule ExploringBeamCommunity.Repo.Migrations.CreateEmails do - use Ecto.Migration - - def change do - create table(:emails) do - add :content, :text, null: false - add :activated, :boolean, default: false, null: false - - timestamps() - end - - create unique_index(:emails, [:activated], where: "activated = true") - end -end diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs deleted file mode 100644 index 03cb3e9..0000000 --- a/priv/repo/seeds.exs +++ /dev/null @@ -1,11 +0,0 @@ -# Script for populating the database. You can run it as: -# -# mix run priv/repo/seeds.exs -# -# Inside the script, you can read and write to any of your -# repositories directly: -# -# ExploringBeamCommunity.Repo.insert!(%ExploringBeamCommunity.SomeSchema{}) -# -# We recommend using the bang functions (`insert!`, `update!` -# and so on) as they will fail if something goes wrong. diff --git a/priv/static/assets/app.css b/priv/static/assets/app.css index 7786403..14b63c9 100644 --- a/priv/static/assets/app.css +++ b/priv/static/assets/app.css @@ -722,6 +722,19 @@ select { } } +.hero-arrow-down-on-square { + --hero-arrow-down-on-square: url('data:image/svg+xml;utf8,'); + -webkit-mask: var(--hero-arrow-down-on-square); + mask: var(--hero-arrow-down-on-square); + -webkit-mask-repeat: no-repeat; + mask-repeat: no-repeat; + background-color: currentColor; + vertical-align: middle; + display: inline-block; + width: 1.25rem; + height: 1.25rem; +} + .hero-arrow-left-solid { --hero-arrow-left-solid: url('data:image/svg+xml;utf8,'); -webkit-mask: var(--hero-arrow-left-solid); @@ -947,6 +960,10 @@ select { margin: 5rem; } +.m-6 { + margin: 1.5rem; +} + .-my-4 { margin-top: -1rem; margin-bottom: -1rem; @@ -2244,10 +2261,6 @@ select { width: 33.333333%; } - .md\:w-2\/3 { - width: 66.666667%; - } - .md\:w-full { width: 100%; } diff --git a/rel/env.sh.eex b/rel/env.sh.eex index efeb7ff..f7a9788 100755 --- a/rel/env.sh.eex +++ b/rel/env.sh.eex @@ -2,7 +2,6 @@ # configure node for distributed erlang with IPV6 support export ERL_AFLAGS="-proto_dist inet6_tcp" -export ECTO_IPV6="true" export DNS_CLUSTER_QUERY="${FLY_APP_NAME}.internal" export RELEASE_DISTRIBUTION="name" export RELEASE_NODE="${FLY_APP_NAME}-${FLY_IMAGE_REF##*-}@${FLY_PRIVATE_IP}"