diff --git a/lib/ares_web/components/core_components.ex b/lib/ares_web/components/core_components.ex index 9c758239..2741e720 100644 --- a/lib/ares_web/components/core_components.ex +++ b/lib/ares_web/components/core_components.ex @@ -32,6 +32,77 @@ defmodule AresWeb.CoreComponents do alias Phoenix.HTML.Form alias Phoenix.LiveView.JS + @doc """ + Renders a modal. + + ## Examples + + <.modal id="confirm-modal"> + This is a modal. + + + JS commands may be passed to the `:on_cancel` to configure + the closing/cancel event, for example: + + <.modal id="confirm" on_cancel={JS.navigate(~p"/posts")}> + This is another modal. + + + """ + attr :id, :string, required: true + attr :show, :boolean, default: false + attr :wrapper_class, :string, default: "" + attr :on_cancel, JS, default: %JS{} + slot :inner_block, required: true + + def modal(assigns) do + ~H""" + <% else %> - <.link + <%!-- <.link navigate="/register" class="rounded-full px-3 py-2 text-sm font-semibold text-white shadow-sm ring-1 ring-inset ring-white hover:ring-primary hover:text-primary transition-all" > Register - + --%> <% end %> @@ -177,12 +183,12 @@ defmodule AresWeb.Components.Navbar do Profile <% else %> - Register - + --%> <% end %> <%= if @user do %> @@ -196,6 +202,14 @@ defmodule AresWeb.Components.Navbar do <% end %> +
  • + <.link + navigate="/users/settings" + class="block w-full py-3 sm:py-4 text-center text-lg sm:text-xl hover:text-primary transition-colors" + > + Settings + +
  • <.link href="/users/log-out" @@ -238,14 +252,14 @@ defmodule AresWeb.Components.Navbar do Previous edition
  • -
  • + <%!--
  • <.link class="block py-3 sm:py-4 text-center text-lg sm:text-xl hover:text-primary transition-colors" navigate="/app/team-formation" > Team formation -
  • + --%> diff --git a/lib/ares_web/live/app/team-formation.ex b/lib/ares_web/live/app/team-formation.ex index 68b1d92e..6a22bcfa 100644 --- a/lib/ares_web/live/app/team-formation.ex +++ b/lib/ares_web/live/app/team-formation.ex @@ -186,10 +186,9 @@ defmodule AresWeb.AppLive.TeamFormation do
    <.button - phx-click="join-team" + phx-click="open-join-modal" class="btn btn-primary flex items-center" phx-value-team_code={team.code} - data-confirm={"Are you sure you want to join #{team.name}?"} > <.icon name="hero-user-plus" class="w-5 h-5 mr-2" /> Join @@ -276,6 +275,42 @@ defmodule AresWeb.AppLive.TeamFormation do
    + + <.modal + :if={@live_action == :join} + id="join-team-modal" + show + on_cancel={JS.patch(~p"/app/team-formation?#{[tab: @tab]}")} + > +
    +
    + +
    +
    +

    Join Team?

    +

    + You are about to join {@selected_team.name}. Confirm that this is the team you want to participate with. +

    +
    +
    + + +
    +
    + """ end @@ -314,6 +349,25 @@ defmodule AresWeb.AppLive.TeamFormation do |> assign_form(Teams.change_team(%Teams.Team{}, %{}))} end + @impl true + def handle_params(params, _url, socket) do + {:noreply, apply_action(socket, socket.assigns.live_action, params)} + end + + defp apply_action(socket, :index, params) do + tab = Map.get(params, "tab", "create") + + socket + |> assign(:tab, tab) + end + + defp apply_action(socket, :join, params) do + tab = Map.get(params, "tab", "join") + + socket + |> assign(:tab, tab) + end + @impl true def handle_event("save", %{"team" => team_params}, socket) do case Teams.create_and_join_team(socket.assigns.user, team_params) do @@ -353,6 +407,16 @@ defmodule AresWeb.AppLive.TeamFormation do end end + @impl true + def handle_event("open-join-modal", %{"team_code" => team_code}, socket) do + selected_team = Enum.find(socket.assigns.available_teams, &(&1.code == team_code)) + + {:noreply, + socket + |> assign(:selected_team, selected_team) + |> push_patch(to: ~p"/app/team-formation/join?#{[tab: socket.assigns.tab]}")} + end + @impl true def handle_event("join-team", %{"team_code" => team_code}, socket) do case Teams.add_user_to_team_by_code(socket.assigns.user, team_code) do diff --git a/lib/ares_web/live/auth/login.ex b/lib/ares_web/live/auth/login.ex index fec756e4..506090ed 100644 --- a/lib/ares_web/live/auth/login.ex +++ b/lib/ares_web/live/auth/login.ex @@ -17,7 +17,7 @@ defmodule AresWeb.UserLive.Login do <% else %>

    Don't have an account? <.link - navigate={~p"/register"} + navigate="/register" class="font-semibold text-primary hover:underline" phx-no-format >Register to participate now. diff --git a/lib/ares_web/live/auth/settings.ex b/lib/ares_web/live/auth/settings.ex index bf98f600..4ff216c4 100644 --- a/lib/ares_web/live/auth/settings.ex +++ b/lib/ares_web/live/auth/settings.ex @@ -9,59 +9,68 @@ defmodule AresWeb.UserLive.Settings do def render(assigns) do ~H""" -

    - <.header> - Account Settings - <:subtitle>Manage your account email address and password settings - +
    +
    + <.header> +

    Account Settings

    +

    Manage your account email address and password settings

    + +
    + + <.form + for={@email_form} + id="email_form" + phx-submit="update_email" + phx-change="validate_email" + class="font-inter" + > + <.input + field={@email_form[:email]} + type="email" + label="Email" + autocomplete="username" + required + /> + <.button variant="primary" phx-disable-with="Changing...">Change Email + + +
    + + <.form + for={@password_form} + id="password_form" + action={~p"/users/update-password"} + method="post" + phx-change="validate_password" + phx-submit="update_password" + phx-trigger-action={@trigger_submit} + class="font-inter" + > + + <.input + field={@password_form[:password]} + type="password" + label="New password" + autocomplete="new-password" + required + /> + <.input + field={@password_form[:password_confirmation]} + type="password" + label="Confirm new password" + autocomplete="new-password" + /> + <.button variant="primary" phx-disable-with="Saving..."> + Save Password + +
    - - <.form for={@email_form} id="email_form" phx-submit="update_email" phx-change="validate_email"> - <.input - field={@email_form[:email]} - type="email" - label="Email" - autocomplete="username" - required - /> - <.button variant="primary" phx-disable-with="Changing...">Change Email - - -
    - - <.form - for={@password_form} - id="password_form" - action={~p"/users/update-password"} - method="post" - phx-change="validate_password" - phx-submit="update_password" - phx-trigger-action={@trigger_submit} - > - - <.input - field={@password_form[:password]} - type="password" - label="New password" - autocomplete="new-password" - required - /> - <.input - field={@password_form[:password_confirmation]} - type="password" - label="Confirm new password" - autocomplete="new-password" - /> - <.button variant="primary" phx-disable-with="Saving..."> - Save Password - - """ end diff --git a/lib/ares_web/live/landing/faqs.html.heex b/lib/ares_web/live/landing/faqs.html.heex index 8780b929..e1ab8758 100644 --- a/lib/ares_web/live/landing/faqs.html.heex +++ b/lib/ares_web/live/landing/faqs.html.heex @@ -1,11 +1,11 @@ --%> -
    +<%!--

    Sponsors @@ -206,9 +206,9 @@

    -
    +
    --%> -
    +<%!--

    Gallery @@ -232,4 +232,4 @@ <% end %>

    -
    +
    --%> diff --git a/lib/ares_web/router.ex b/lib/ares_web/router.ex index 14ba747b..93e63886 100644 --- a/lib/ares_web/router.ex +++ b/lib/ares_web/router.ex @@ -60,6 +60,7 @@ defmodule AresWeb.Router do live "/app/dashboard", AppLive.Dashboard, :index live "/app/profile", AppLive.Profile, :index live "/app/team-formation", AppLive.TeamFormation, :index + live "/app/team-formation/join", AppLive.TeamFormation, :join live "/app/payment", AppLive.Payment, :index live "/app/payment/:id", AppLive.PaymentStatus, :index live "/users/settings", UserLive.Settings, :edit @@ -74,7 +75,7 @@ defmodule AresWeb.Router do live_session :current_user, on_mount: [{AresWeb.UserAuth, :mount_current_scope}] do - live "/register", UserLive.Registration, :new + # live "/register", UserLive.Registration, :new live "/log-in", UserLive.Login, :new live "/log-in/:token", UserLive.Confirmation, :new end diff --git a/test/ares_web/live/user_live/login_test.exs b/test/ares_web/live/user_live/login_test.exs index 2054181b..dde52e97 100644 --- a/test/ares_web/live/user_live/login_test.exs +++ b/test/ares_web/live/user_live/login_test.exs @@ -75,19 +75,19 @@ defmodule AresWeb.UserLive.LoginTest do end end - describe "login navigation" do - test "redirects to registration page when the Register button is clicked", %{conn: conn} do - {:ok, lv, _html} = live(conn, ~p"/log-in") - - {:ok, _login_live, login_html} = - lv - |> element("main a", "Register") - |> render_click() - |> follow_redirect(conn, ~p"/register") - - assert login_html =~ "Register" - end - end + # describe "login navigation" do + # test "redirects to registration page when the Register button is clicked", %{conn: conn} do + # {:ok, lv, _html} = live(conn, ~p"/log-in") + + # {:ok, _login_live, login_html} = + # lv + # |> element("main a", "Register") + # |> render_click() + # |> follow_redirect(conn, ~p"/register") + + # assert login_html =~ "Register" + # end + # end describe "re-authentication (sudo mode)" do setup %{conn: conn} do diff --git a/test/ares_web/live/user_live/registration_test.exs b/test/ares_web/live/user_live/registration_test.exs index fd0295ab..fcecadf1 100644 --- a/test/ares_web/live/user_live/registration_test.exs +++ b/test/ares_web/live/user_live/registration_test.exs @@ -1,98 +1,98 @@ defmodule AresWeb.UserLive.RegistrationTest do use AresWeb.ConnCase, async: true - import Phoenix.LiveViewTest - import Ares.AccountsFixtures - - describe "Registration page" do - test "renders registration page", %{conn: conn} do - {:ok, _lv, html} = live(conn, ~p"/register") - - assert html =~ "Registration" - assert html =~ "Log in" - end - - test "redirects if already logged in", %{conn: conn} do - result = - conn - |> log_in_user(user_fixture()) - |> live(~p"/register") - |> follow_redirect(conn, ~p"/") - - assert {:ok, _conn} = result - end - - test "renders errors for invalid data", %{conn: conn} do - {:ok, lv, _html} = live(conn, ~p"/register") - - result = - lv - |> element("#registration_form") - |> render_change(user: %{"email" => "with spaces"}) - - assert result =~ "Registration" - assert result =~ "must have the @ sign and no spaces" - end - end - - describe "register user" do - test "creates account but does not log in", %{conn: conn} do - {:ok, lv, _html} = live(conn, ~p"/register") - - email = unique_user_email() - form = form(lv, "#registration_form", user: valid_user_attributes(email: email)) - - fi = - file_input(lv, "#registration_form", :cv, [ - %{name: "cv.pdf", content: "dummy", type: "application/pdf"} - ]) - - render_upload(fi, "cv.pdf") - - {:ok, _lv, html} = - render_submit(form) - |> follow_redirect(conn, ~p"/log-in") - - assert html =~ - ~r/An email was sent to .*, please access it to confirm your account/ - end - - test "renders errors for duplicated email", %{conn: conn} do - {:ok, lv, _html} = live(conn, ~p"/register") - - user = user_fixture(%{email: "test@email.com"}) - - result = - lv - |> form("#registration_form", - user: %{"email" => user.email} - ) - |> then(fn form -> - fi = - file_input(lv, "#registration_form", :cv, [ - %{name: "cv.pdf", content: "dummy", type: "application/pdf"} - ]) - - render_upload(fi, "cv.pdf") - form - end) - |> render_submit() - - assert result =~ "has already been taken" - end - end - - describe "registration navigation" do - test "redirects to login page when the Log in button is clicked", %{conn: conn} do - {:ok, lv, _html} = live(conn, ~p"/register") - - {:ok, _login_live, login_html} = - lv - |> element("main a", "Log in") - |> render_click() - |> follow_redirect(conn, ~p"/log-in") - - assert login_html =~ "Log in" - end - end + # import Phoenix.LiveViewTest + # import Ares.AccountsFixtures + + # describe "Registration page" do + # test "renders registration page", %{conn: conn} do + # {:ok, _lv, html} = live(conn, ~p"/register") + + # assert html =~ "Registration" + # assert html =~ "Log in" + # end + + # test "redirects if already logged in", %{conn: conn} do + # result = + # conn + # |> log_in_user(user_fixture()) + # |> live(~p"/register") + # |> follow_redirect(conn, ~p"/") + + # assert {:ok, _conn} = result + # end + + # test "renders errors for invalid data", %{conn: conn} do + # {:ok, lv, _html} = live(conn, ~p"/register") + + # result = + # lv + # |> element("#registration_form") + # |> render_change(user: %{"email" => "with spaces"}) + + # assert result =~ "Registration" + # assert result =~ "must have the @ sign and no spaces" + # end + # end + + # describe "register user" do + # test "creates account but does not log in", %{conn: conn} do + # {:ok, lv, _html} = live(conn, ~p"/register") + + # email = unique_user_email() + # form = form(lv, "#registration_form", user: valid_user_attributes(email: email)) + + # fi = + # file_input(lv, "#registration_form", :cv, [ + # %{name: "cv.pdf", content: "dummy", type: "application/pdf"} + # ]) + + # render_upload(fi, "cv.pdf") + + # {:ok, _lv, html} = + # render_submit(form) + # |> follow_redirect(conn, ~p"/log-in") + + # assert html =~ + # ~r/An email was sent to .*, please access it to confirm your account/ + # end + + # test "renders errors for duplicated email", %{conn: conn} do + # {:ok, lv, _html} = live(conn, ~p"/register") + + # user = user_fixture(%{email: "test@email.com"}) + + # result = + # lv + # |> form("#registration_form", + # user: %{"email" => user.email} + # ) + # |> then(fn form -> + # fi = + # file_input(lv, "#registration_form", :cv, [ + # %{name: "cv.pdf", content: "dummy", type: "application/pdf"} + # ]) + + # render_upload(fi, "cv.pdf") + # form + # end) + # |> render_submit() + + # assert result =~ "has already been taken" + # end + # end + + # describe "registration navigation" do + # test "redirects to login page when the Log in button is clicked", %{conn: conn} do + # {:ok, lv, _html} = live(conn, ~p"/register") + + # {:ok, _login_live, login_html} = + # lv + # |> element("main a", "Log in") + # |> render_click() + # |> follow_redirect(conn, ~p"/log-in") + + # assert login_html =~ "Log in" + # end + # end end