diff --git a/lib/safira/activities.ex b/lib/safira/activities.ex index e4fb374ad..0c7f8da2d 100644 --- a/lib/safira/activities.ex +++ b/lib/safira/activities.ex @@ -450,13 +450,7 @@ defmodule Safira.Activities do |> Repo.transaction() end - def create_enrolment(attrs) do - %Enrolment{} - |> Enrolment.changeset(attrs) - |> Repo.insert() - end - - def delete_enrolment(%Enrolment{} = enrolment, attrs \\ %{}) do + def delete_enrolment(%Enrolment{} = enrolment) do Repo.delete(enrolment) end diff --git a/lib/safira_web/live/backoffice/schedule_live/enrolment_live/form_component.ex b/lib/safira_web/live/backoffice/schedule_live/enrolment_live/form_component.ex index 1b0fb0159..d140162a2 100644 --- a/lib/safira_web/live/backoffice/schedule_live/enrolment_live/form_component.ex +++ b/lib/safira_web/live/backoffice/schedule_live/enrolment_live/form_component.ex @@ -182,7 +182,7 @@ defmodule SafiraWeb.Backoffice.ScheduleLive.EnrolmentLive.FormComponent do if valid_enrolments do # For each enrolment, update or create it Enum.each(enrolments, fn {_, _, _enrolment, form} -> - Activities.create_enrolment(form.params) + Activities.enrol(form.params.attendee_id, form.params.activity_id) end) {:noreply, diff --git a/lib/safira_web/live/landing/components/schedule.ex b/lib/safira_web/live/landing/components/schedule.ex index e92774c6e..2b7db583b 100644 --- a/lib/safira_web/live/landing/components/schedule.ex +++ b/lib/safira_web/live/landing/components/schedule.ex @@ -161,6 +161,7 @@ defmodule SafiraWeb.Landing.Components.Schedule do :if={enrolments_enabled(@activity, @user_role, @enrolments)} class="relative hover:underline cursor-pointer -mr-3 font-iregular text-lg text-accent sm:mr-1" phx-click="enrol" + data-confirm={"#{gettext("You are enrolling for")} #{@activity.title}. #{gettext("This action cannot be undone. Are you sure?")}"} phx-value-activity_id={@activity.id} > <%= gettext("Enrol") %> diff --git a/lib/safira_web/live/landing/home_live/index.ex b/lib/safira_web/live/landing/home_live/index.ex index 7d607c523..1a17a3798 100644 --- a/lib/safira_web/live/landing/home_live/index.ex +++ b/lib/safira_web/live/landing/home_live/index.ex @@ -21,6 +21,7 @@ defmodule SafiraWeb.Landing.HomeLive.Index do |> assign(:has_sponsors?, Companies.get_companies_count() > 0) |> assign(:has_schedule?, Activities.get_activities_count() > 0) |> assign(:enrolments, get_enrolments(socket.assigns.current_user)) + |> assign(:user_role, get_user_role(socket.assigns.current_user)) |> stream(:speakers, speakers |> Enum.shuffle())} end @@ -35,7 +36,7 @@ defmodule SafiraWeb.Landing.HomeLive.Index do {:noreply, socket |> put_flash(:error, gettext("You must be logged in to enrol in activities")) - |> push_navigate(to: ~p"/users/log_in")} + |> redirect(to: ~p"/users/log_in?redirect=/")} else if socket.assigns.current_user.type == :attendee do actual_enrol(activity_id, socket) @@ -68,4 +69,12 @@ defmodule SafiraWeb.Landing.HomeLive.Index do |> put_flash(:error, gettext("Something happened"))} end end + + defp get_user_role(user) do + if is_nil(user) do + :attendee + else + user.type + end + end end diff --git a/lib/safira_web/live/landing/home_live/index.html.heex b/lib/safira_web/live/landing/home_live/index.html.heex index ac7593f6a..7547d6542 100644 --- a/lib/safira_web/live/landing/home_live/index.html.heex +++ b/lib/safira_web/live/landing/home_live/index.html.heex @@ -14,7 +14,7 @@ url={~p"/"} params={@params} enrolments={@enrolments} - user_role={Map.get(@current_user, :type, :attendee)} + user_role={@user_role} />