forked from shibao/cannery
prompt to create first ammo type before trying to create first ammo
This commit is contained in:
@ -22,7 +22,8 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
|
||||
|
||||
@spec update(Socket.t()) :: {:ok, Socket.t()}
|
||||
def update(%{assigns: %{current_user: current_user}} = socket) do
|
||||
%{assigns: %{ammo_types: ammo_types, containers: containers}} = socket =
|
||||
%{assigns: %{ammo_types: ammo_types, containers: containers}} =
|
||||
socket =
|
||||
socket
|
||||
|> assign(:ammo_group_create_limit, @ammo_group_create_limit)
|
||||
|> assign(:ammo_types, Ammo.list_ammo_types(current_user))
|
||||
|
@ -74,7 +74,8 @@ 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])
|
||||
containers = Containers.list_containers(current_user)
|
||||
ammo_types_count = Ammo.get_ammo_types_count!(current_user)
|
||||
containers_count = Containers.get_containers_count!(current_user)
|
||||
|
||||
columns = [
|
||||
%{label: gettext("Ammo type"), key: "ammo_type"},
|
||||
@ -92,7 +93,13 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
||||
|> Enum.map(fn ammo_group -> ammo_group |> get_row_data_for_ammo_group(columns) end)
|
||||
|
||||
socket
|
||||
|> assign(ammo_groups: ammo_groups, containers: containers, columns: columns, rows: rows)
|
||||
|> assign(
|
||||
ammo_groups: ammo_groups,
|
||||
ammo_types_count: ammo_types_count,
|
||||
containers_count: containers_count,
|
||||
columns: columns,
|
||||
rows: rows
|
||||
)
|
||||
end
|
||||
|
||||
@spec get_row_data_for_ammo_group(AmmoGroup.t(), [map()]) :: [map()]
|
||||
|
@ -8,8 +8,10 @@
|
||||
<%= gettext("No Ammo") %>
|
||||
<%= display_emoji("😔") %>
|
||||
</h2>
|
||||
<% end %>
|
||||
|
||||
<%= if @containers |> Enum.empty?() do %>
|
||||
<%= cond do %>
|
||||
<% @containers_count == 0 -> %>
|
||||
<div class="flex justify-center items-center">
|
||||
<h2 class="m-2 title text-md text-primary-600">
|
||||
<%= dgettext("prompts", "You'll need to") %>
|
||||
@ -20,31 +22,30 @@
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
</div>
|
||||
<% else %>
|
||||
<% @ammo_types_count == 0 -> %>
|
||||
<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 an ammo type first"),
|
||||
to: Routes.ammo_type_index_path(Endpoint, :new),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
</div>
|
||||
<% @ammo_groups |> Enum.empty?() -> %>
|
||||
<%= live_patch(dgettext("actions", "Add your first box!"),
|
||||
to: Routes.ammo_group_index_path(Endpoint, :new),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= 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 %>
|
||||
<% true -> %>
|
||||
<%= live_patch(dgettext("actions", "Add Ammo"),
|
||||
to: Routes.ammo_group_index_path(Endpoint, :new),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= unless @ammo_groups |> Enum.empty?() do %>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.TableComponent}
|
||||
id="ammo_groups_index_table"
|
||||
@ -66,7 +67,6 @@
|
||||
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 -> %>
|
||||
|
Reference in New Issue
Block a user