add prompt to create container before creating ammo group
This commit is contained in:
parent
9cd2bc574b
commit
9773ccc6ff
@ -4,7 +4,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_view
|
||||
alias Cannery.{Ammo, Ammo.AmmoGroup, Repo}
|
||||
alias Cannery.{Ammo, Ammo.AmmoGroup, Containers, Repo}
|
||||
alias CanneryWeb.Endpoint
|
||||
|
||||
@impl true
|
||||
@ -17,9 +17,11 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
||||
{:noreply, apply_action(socket, live_action, params)}
|
||||
end
|
||||
|
||||
defp apply_action(%{assigns: %{current_user: current_user}} = socket, :add_shot_group, %{
|
||||
"id" => id
|
||||
}) do
|
||||
defp apply_action(
|
||||
%{assigns: %{current_user: current_user}} = socket,
|
||||
:add_shot_group,
|
||||
%{"id" => id}
|
||||
) do
|
||||
socket
|
||||
|> assign(:page_title, gettext("Record shots"))
|
||||
|> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user))
|
||||
@ -72,6 +74,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
||||
|
||||
defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do
|
||||
ammo_groups = Ammo.list_ammo_groups(current_user) |> Repo.preload([:ammo_type, :container])
|
||||
socket |> assign(:ammo_groups, ammo_groups)
|
||||
containers = Containers.list_containers(current_user)
|
||||
socket |> assign(ammo_groups: ammo_groups, containers: containers)
|
||||
end
|
||||
end
|
||||
|
@ -9,15 +9,41 @@
|
||||
<%= display_emoji("😔") %>
|
||||
</h2>
|
||||
|
||||
<%= live_patch(dgettext("actions", "Add your first box!"),
|
||||
to: Routes.ammo_group_index_path(Endpoint, :new),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
<%= if @containers |> Enum.empty?() do %>
|
||||
<div class="flex justify-center items-center">
|
||||
<h2 class="m-2 title text-md text-primary-600">
|
||||
<%= dgettext("prompts", "You'll need to") %>
|
||||
</h2>
|
||||
|
||||
<%= live_patch(dgettext("actions", "add a container first"),
|
||||
to: Routes.container_index_path(Endpoint, :new),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= live_patch(dgettext("actions", "Add your first box!"),
|
||||
to: Routes.ammo_group_index_path(Endpoint, :new),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= live_patch(dgettext("actions", "New Ammo group"),
|
||||
to: Routes.ammo_group_index_path(Endpoint, :new),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
<%= if @containers |> Enum.empty?() do %>
|
||||
<div class="flex justify-center items-center">
|
||||
<h2 class="m-2 title text-md text-primary-600">
|
||||
<%= dgettext("prompts", "You'll need to") %>
|
||||
</h2>
|
||||
|
||||
<%= live_patch(dgettext("actions", "add a container first"),
|
||||
to: Routes.container_index_path(Endpoint, :new),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= live_patch(dgettext("actions", "New Ammo group"),
|
||||
to: Routes.ammo_group_index_path(Endpoint, :new),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
<% end %>
|
||||
|
||||
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
|
||||
<table class="min-w-full table-auto text-center bg-white">
|
||||
@ -143,6 +169,7 @@
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
containers={@containers}
|
||||
/>
|
||||
</.modal>
|
||||
<% @live_action == :add_shot_group -> %>
|
||||
|
Loading…
Reference in New Issue
Block a user