From 3a98b23d3a6d1fb9f6de2069f0fc338df7b3ffb7 Mon Sep 17 00:00:00 2001 From: bryans-go Date: Sat, 28 Sep 2024 17:38:11 +0530 Subject: [PATCH] fix Signed-off-by: bryans-go --- lib/algora_web/live/show_live/show.ex | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/algora_web/live/show_live/show.ex b/lib/algora_web/live/show_live/show.ex index acd58796..5c423364 100644 --- a/lib/algora_web/live/show_live/show.ex +++ b/lib/algora_web/live/show_live/show.ex @@ -341,30 +341,33 @@ defmodule AlgoraWeb.ShowLive.Show do end defp apply_action(socket, :edit, %{"slug" => slug}) do - %{current_user: current_user} = socket.assigns + %{current_user: current_user} = socket.assigns - show = Shows.get_show_by_fields!(slug: slug) + show = Shows.get_show_by_fields!(slug: slug) - conn = Phoenix.LiveView.get_connect_info(socket).conn + conn_info = Phoenix.LiveView.get_connect_info(socket) + request_path = socket.assigns[:request_path] || "" + query_string = conn_info[:query_string] || "" + return_to = if query_string == "", do: request_path, else: request_path <> "?" <> query_string - cond do - current_user == nil -> - conn - |> maybe_store_return_to() - |> redirect(to: ~p"/auth/login") + cond do + current_user == nil -> + socket + |> Phoenix.LiveView.put_session(:user_return_to, return_to) + |> redirect(to: ~p"/auth/login") - current_user.id != show.user_id && !Accounts.admin?(current_user) -> - socket - |> put_flash(:error, "You don't have permission to edit this show") - |> redirect(to: ~p"/shows/#{show.slug}") + current_user.id != show.user_id && !Accounts.admin?(current_user) -> + socket + |> put_flash(:error, "You don't have permission to edit this show") + |> redirect(to: ~p"/shows/#{show.slug}") - true -> - socket - |> assign(:page_title, show.title) - |> assign(:page_description, show.description) - |> assign(:page_image, show.og_image_url) - end + true -> + socket + |> assign(:page_title, show.title) + |> assign(:page_description, show.description) + |> assign(:page_image, show.og_image_url) end +end defp assign_attendees(socket, show) do attendees = Events.fetch_attendees(show)