Add purchase function
This commit is contained in:
@@ -118,6 +118,22 @@ defmodule MusicLibraryWeb.WishlistLive.Index do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("purchase", %{"id" => id}, socket) do
|
||||||
|
record = Records.get_record!(id)
|
||||||
|
current_time = DateTime.utc_now()
|
||||||
|
|
||||||
|
case Records.update_record(record, %{"purchased_at" => current_time}) do
|
||||||
|
{:ok, _} ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> put_flash(:info, gettext("Record updated successfully"))
|
||||||
|
|> push_patch(to: ~p"/wishlist")}
|
||||||
|
|
||||||
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
{:noreply, assign(socket, form: to_form(changeset))}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp merge_query(record_list_params, query) do
|
defp merge_query(record_list_params, query) do
|
||||||
Map.put(record_list_params, :query, query)
|
Map.put(record_list_params, :query, query)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -145,6 +145,16 @@
|
|||||||
<%= gettext("Edit") %>
|
<%= gettext("Edit") %>
|
||||||
</.link>
|
</.link>
|
||||||
|
|
||||||
|
<.link
|
||||||
|
class="block px-3 py-1 text-sm leading-6 text-gray-900 hover:bg-gray-50"
|
||||||
|
role="menuitem"
|
||||||
|
tabindex="-1"
|
||||||
|
id={"actions-#{record.id}-purchase"}
|
||||||
|
phx-click={JS.push("purchase", value: %{id: record.id})}
|
||||||
|
>
|
||||||
|
<%= gettext("Purchase") %>
|
||||||
|
</.link>
|
||||||
|
|
||||||
<.link
|
<.link
|
||||||
class="block px-3 py-1 text-sm leading-6 text-red-900 hover:bg-red-50"
|
class="block px-3 py-1 text-sm leading-6 text-red-900 hover:bg-red-50"
|
||||||
role="menuitem"
|
role="menuitem"
|
||||||
|
|||||||
Reference in New Issue
Block a user