forked from shibao/cannery
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
|
use CanneryWeb, :live_view
|
||||||
alias Cannery.{Ammo, Ammo.AmmoGroup, Repo}
|
alias Cannery.{Ammo, Ammo.AmmoGroup, Containers, Repo}
|
||||||
alias CanneryWeb.Endpoint
|
alias CanneryWeb.Endpoint
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@ -17,9 +17,11 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
|||||||
{:noreply, apply_action(socket, live_action, params)}
|
{:noreply, apply_action(socket, live_action, params)}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp apply_action(%{assigns: %{current_user: current_user}} = socket, :add_shot_group, %{
|
defp apply_action(
|
||||||
"id" => id
|
%{assigns: %{current_user: current_user}} = socket,
|
||||||
}) do
|
:add_shot_group,
|
||||||
|
%{"id" => id}
|
||||||
|
) do
|
||||||
socket
|
socket
|
||||||
|> assign(:page_title, gettext("Record shots"))
|
|> assign(:page_title, gettext("Record shots"))
|
||||||
|> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user))
|
|> 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
|
defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do
|
||||||
ammo_groups = Ammo.list_ammo_groups(current_user) |> Repo.preload([:ammo_type, :container])
|
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
|
||||||
end
|
end
|
||||||
|
@ -9,15 +9,41 @@
|
|||||||
<%= display_emoji("😔") %>
|
<%= display_emoji("😔") %>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<%= live_patch(dgettext("actions", "Add your first box!"),
|
<%= if @containers |> Enum.empty?() do %>
|
||||||
to: Routes.ammo_group_index_path(Endpoint, :new),
|
<div class="flex justify-center items-center">
|
||||||
class: "btn btn-primary"
|
<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 %>
|
<% else %>
|
||||||
<%= live_patch(dgettext("actions", "New Ammo group"),
|
<%= if @containers |> Enum.empty?() do %>
|
||||||
to: Routes.ammo_group_index_path(Endpoint, :new),
|
<div class="flex justify-center items-center">
|
||||||
class: "btn btn-primary"
|
<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">
|
<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">
|
<table class="min-w-full table-auto text-center bg-white">
|
||||||
@ -143,6 +169,7 @@
|
|||||||
ammo_group={@ammo_group}
|
ammo_group={@ammo_group}
|
||||||
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
|
containers={@containers}
|
||||||
/>
|
/>
|
||||||
</.modal>
|
</.modal>
|
||||||
<% @live_action == :add_shot_group -> %>
|
<% @live_action == :add_shot_group -> %>
|
||||||
|
Loading…
Reference in New Issue
Block a user