diff --git a/lib/cannery_web/live/ammo_group_live/ammo_group_card.ex b/lib/cannery_web/live/ammo_group_live/ammo_group_card.ex new file mode 100644 index 00000000..6e1c4abe --- /dev/null +++ b/lib/cannery_web/live/ammo_group_live/ammo_group_card.ex @@ -0,0 +1,46 @@ +defmodule CanneryWeb.AmmoGroupLive.AmmoGroupCard do + @moduledoc """ + Display card for an ammo group + """ + + use CanneryWeb, :component + alias Cannery.Repo + alias CanneryWeb.Endpoint + + def ammo_group_card(assigns) do + assigns = assigns |> assign(:ammo_group, assigns.ammo_group |> Repo.preload(:ammo_type)) + + ~H""" +
+ <%= live_redirect to: Routes.ammo_group_show_path(Endpoint, :show, @ammo_group), + class: "mb-2 link" do %> +

+ <%= @ammo_group.ammo_type.name %> +

+ <% end %> + +
+ + Count: <%= @ammo_group.count %> + + + <%= if @ammo_group.notes do %> + + Notes: <%= @ammo_group.notes %> + + <% end %> + + <%= if @ammo_group.price_paid do %> + + Price paid: $ <%= @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %> + + <% end %> +
+
+ """ + end +end diff --git a/lib/cannery_web/live/ammo_group_live/form_component.ex b/lib/cannery_web/live/ammo_group_live/form_component.ex index a9b7018b..46e28b26 100644 --- a/lib/cannery_web/live/ammo_group_live/form_component.ex +++ b/lib/cannery_web/live/ammo_group_live/form_component.ex @@ -5,20 +5,25 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do use CanneryWeb, :live_component - alias Cannery.Ammo + alias Cannery.{Ammo, Containers} + alias Cannery.{Ammo.AmmoType, Containers.Container} + alias Ecto.Changeset @impl true def update(%{ammo_group: ammo_group} = assigns, socket) do - changeset = Ammo.change_ammo_group(ammo_group) + socket = socket |> assign(assigns) - {:ok, - socket - |> assign(assigns) - |> assign(:changeset, changeset)} + changeset = Ammo.change_ammo_group(ammo_group) + containers = Containers.list_containers(socket.assigns.current_user) + ammo_types = Ammo.list_ammo_types() + + {:ok, socket |> assign(changeset: changeset, containers: containers, ammo_types: ammo_types)} end @impl true def handle_event("validate", %{"ammo_group" => ammo_group_params}, socket) do + ammo_group_params = ammo_group_params |> Map.put("user_id", socket.assigns.current_user.id) + changeset = socket.assigns.ammo_group |> Ammo.change_ammo_group(ammo_group_params) @@ -28,6 +33,7 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do end def handle_event("save", %{"ammo_group" => ammo_group_params}, socket) do + ammo_group_params = ammo_group_params |> Map.put("user_id", socket.assigns.current_user.id) save_ammo_group(socket, socket.assigns.action, ammo_group_params) end @@ -35,7 +41,7 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do def render(assigns) do ~H"""
-

+

<%= @title %>

<.form @@ -45,31 +51,84 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do phx-target={@myself} phx-change="validate" phx-submit="save" + class="grid grid-cols-3 justify-center items-center space-y-4" > - <%= label(f, :count, class: "title text-lg text-primary-500") %> - <%= number_input(f, :count) %> - <%= error_tag(f, :count) %> - <%= label(f, :price_paid, class: "title text-lg text-primary-500") %> - <%= number_input(f, :price_paid, step: "any") %> - <%= error_tag(f, :price_paid) %> - <%= label(f, :notes, class: "title text-lg text-primary-500") %> - <%= textarea(f, :notes, class: "input") %> - <%= error_tag(f, :notes) %> - <%= submit("Save", phx_disable_with: "Saving...") %> + <%= label(f, :count, class: "mr-4 title text-lg text-primary-500") %> + <%= number_input(f, :count, + class: "text-center col-span-2 input input-primary", + min: 1 + ) %> +
+ <%= error_tag(f, :count) %> +
+ + <%= label(f, :price_paid, class: "mr-4 title text-lg text-primary-500") %> + <%= number_input(f, :price_paid, + step: "0.01", + class: "text-center col-span-2 input input-primary" + ) %> +
+ <%= error_tag(f, :price_paid) %> +
+ + <%= label(f, :notes, class: "mr-4 title text-lg text-primary-500") %> + <%= textarea(f, :notes, + class: "text-center col-span-2 input input-primary", + phx_hook: "MaintainAttrs" + ) %> +
+ <%= error_tag(f, :notes) %> +
+ + <%= label(f, :ammo_type_id, class: "mr-4 title text-lg text-primary-500") %> + <%= select(f, :ammo_type_id, ammo_type_options(@ammo_types), + class: "text-center col-span-2 input input-primary" + ) %> +
+ <%= error_tag(f, :ammo_type_id) %> +
+ + <%= label(f, :container, class: "mr-4 title text-lg text-primary-500") %> + <%= select(f, :container_id, container_options(@containers), + class: "text-center col-span-2 input input-primary" + ) %> +
+ <%= error_tag(f, :container_id) %> +
+ + <%= submit("Save", + phx_disable_with: "Saving...", + class: "mx-auto col-span-3 btn btn-primary" + ) %>
""" end + # HTML Helpers + @spec container_options([Container.t()]) :: [{String.t(), Container.id()}] + defp container_options(containers) do + containers |> Enum.map(fn container -> {container.name, container.id} end) + end + + @spec ammo_type_options([AmmoType.t()]) :: [{String.t(), AmmoType.id()}] + defp ammo_type_options(ammo_types) do + ammo_types |> Enum.map(fn ammo_type -> {ammo_type.name, ammo_type.id} end) + end + + # Save Helpers + defp save_ammo_group(socket, :edit, ammo_group_params) do - case Ammo.update_ammo_group(socket.assigns.ammo_group, ammo_group_params) do + socket.assigns.ammo_group + |> Ammo.update_ammo_group(ammo_group_params) + |> case do {:ok, _ammo_group} -> {:noreply, socket |> put_flash(:info, "Ammo group updated successfully") |> push_redirect(to: socket.assigns.return_to)} - {:error, %Ecto.Changeset{} = changeset} -> + {:error, %Changeset{} = changeset} -> {:noreply, socket |> assign(:changeset, changeset)} end end @@ -82,7 +141,7 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do |> put_flash(:info, "Ammo group created successfully") |> push_redirect(to: socket.assigns.return_to)} - {:error, %Ecto.Changeset{} = changeset} -> + {:error, %Changeset{} = changeset} -> {:noreply, socket |> assign(changeset: changeset)} end end diff --git a/lib/cannery_web/live/ammo_group_live/index.ex b/lib/cannery_web/live/ammo_group_live/index.ex index 5cc2fe1b..fed415d1 100644 --- a/lib/cannery_web/live/ammo_group_live/index.ex +++ b/lib/cannery_web/live/ammo_group_live/index.ex @@ -26,7 +26,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do defp apply_action(socket, :new, _params) do socket - |> assign(:page_title, "New Ammo group") + |> assign(:page_title, "Add Ammo") |> assign(:ammo_group, %AmmoGroup{}) end diff --git a/lib/cannery_web/live/ammo_group_live/index.html.heex b/lib/cannery_web/live/ammo_group_live/index.html.heex index 16c5e1b4..b32e68a4 100644 --- a/lib/cannery_web/live/ammo_group_live/index.html.heex +++ b/lib/cannery_web/live/ammo_group_live/index.html.heex @@ -37,32 +37,34 @@ <%= for ammo_group <- @ammo_groups do %> - + <%= ammo_group.count %> + - <%= ammo_group.price_paid %> + $ <%= ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %> + <%= ammo_group.notes %> - - - <%= live_redirect("Show", to: Routes.ammo_group_show_path(@socket, :show, ammo_group)) %> - - - <%= live_patch("Edit", to: Routes.ammo_group_index_path(@socket, :edit, ammo_group)) %> - - - <%= link("Delete", - to: "#", - phx_click: "delete", - phx_value_id: ammo_group.id, - data: [confirm: "Are you sure?"] - ) %> - + + <%= live_redirect("View", to: Routes.ammo_group_show_path(@socket, :show, ammo_group)) %> + + <%= live_patch to: Routes.ammo_group_index_path(@socket, :edit, ammo_group), + class: "text-primary-500 link" do %> + + <% end %> + + <%= link to: "#", + class: "text-primary-500 link", + phx_click: "delete", + phx_value_id: ammo_group.id, + data: [confirm: "Are you sure you want to delete this ammo?"] do %> + + <% end %> <% end %> @@ -78,6 +80,7 @@ title: @page_title, action: @live_action, ammo_group: @ammo_group, - return_to: Routes.ammo_group_index_path(@socket, :index) + return_to: Routes.ammo_group_index_path(@socket, :index), + current_user: @current_user ) %> <% end %> diff --git a/lib/cannery_web/live/ammo_group_live/show.ex b/lib/cannery_web/live/ammo_group_live/show.ex index 658377c8..49dbc2a3 100644 --- a/lib/cannery_web/live/ammo_group_live/show.ex +++ b/lib/cannery_web/live/ammo_group_live/show.ex @@ -4,20 +4,32 @@ defmodule CanneryWeb.AmmoGroupLive.Show do """ use CanneryWeb, :live_view - - alias Cannery.Ammo + import CanneryWeb.ContainerLive.ContainerCard + alias Cannery.{Ammo, Repo} @impl true def mount(_params, session, socket) do - {:ok, socket |> assign_defaults(session)} + socket = socket |> assign_defaults(session) + + {:ok, socket} end @impl true def handle_params(%{"id" => id}, _, socket) do - {:noreply, - socket - |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:ammo_group, Ammo.get_ammo_group!(id))} + socket = + socket + |> assign( + page_title: page_title(socket.assigns.live_action), + ammo_group: Ammo.get_ammo_group!(id) |> Repo.preload([:container, :ammo_type]) + ) + + {:noreply, socket} + end + + @impl true + def handle_event("delete", _, socket) do + socket.assigns.ammo_group |> Ammo.delete_ammo_group!() + {:noreply, socket |> push_redirect(to: Routes.ammo_group_index_path(socket, :index))} end defp page_title(:show), do: "Show Ammo group" diff --git a/lib/cannery_web/live/ammo_group_live/show.html.heex b/lib/cannery_web/live/ammo_group_live/show.html.heex new file mode 100644 index 00000000..ac94c563 --- /dev/null +++ b/lib/cannery_web/live/ammo_group_live/show.html.heex @@ -0,0 +1,62 @@ +
+

+ <%= @ammo_group.ammo_type.name %> +

+ +
+ + Count: <%= @ammo_group.count %> + + + <%= if @ammo_group.notes do %> + + Notes: <%= @ammo_group.notes %> + + <% end %> + + <%= if @ammo_group.price_paid do %> + + Price paid: $ <%= @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %> + + <% end %> +
+ +
+ <%= live_patch to: Routes.ammo_group_show_path(@socket, :edit, @ammo_group), + class: "text-primary-500 link" do %> + + <% end %> + + <%= link to: "#", + class: "text-primary-500 link", + phx_click: "delete", + data: [confirm: "Are you sure you want to delete this ammo?"] do %> + + <% end %> +
+ +
+ +
+ <%= if @ammo_group.container do %> +

+ Stored in +

+ + <.container_card container={@ammo_group.container} /> + <% else %> + This ammo group is not in a container + <% end %> +
+
+ +<%= if @live_action in [:edit] do %> + <%= live_modal(CanneryWeb.AmmoGroupLive.FormComponent, + id: @ammo_group.id, + title: @page_title, + action: @live_action, + ammo_group: @ammo_group, + return_to: Routes.ammo_group_show_path(@socket, :show, @ammo_group), + current_user: @current_user + ) %> +<% end %> diff --git a/lib/cannery_web/live/ammo_group_live/show.html.leex b/lib/cannery_web/live/ammo_group_live/show.html.leex deleted file mode 100644 index 67a00f80..00000000 --- a/lib/cannery_web/live/ammo_group_live/show.html.leex +++ /dev/null @@ -1,32 +0,0 @@ -

Show Ammo group

- -<%= if @live_action in [:edit] do %> - <%= live_modal CanneryWeb.AmmoGroupLive.FormComponent, - id: @ammo_group.id, - title: @page_title, - action: @live_action, - ammo_group: @ammo_group, - return_to: Routes.ammo_group_show_path(@socket, :show, @ammo_group) %> -<% end %> - - - -<%= live_patch "Edit", to: Routes.ammo_group_show_path(@socket, :edit, @ammo_group), class: "button" %> -<%= live_redirect "Back", to: Routes.ammo_group_index_path(@socket, :index) %> diff --git a/lib/cannery_web/live/ammo_type_live/ammo_type_card.ex b/lib/cannery_web/live/ammo_type_live/ammo_type_card.ex new file mode 100644 index 00000000..a985d1ad --- /dev/null +++ b/lib/cannery_web/live/ammo_type_live/ammo_type_card.ex @@ -0,0 +1,46 @@ +defmodule CanneryWeb.AmmoTypeLive.AmmoTypeCard do + @moduledoc """ + Display card for an ammo type + """ + + use CanneryWeb, :component + alias Cannery.Repo + alias CanneryWeb.Endpoint + + def ammo_group_card(assigns) do + assigns = assigns |> assign(:ammo_group, assigns.ammo_group |> Repo.preload(:ammo_type)) + + ~H""" +
+ <%= live_redirect to: Routes.ammo_group_show_path(Endpoint, :show, @ammo_group), + class: "mb-2 link" do %> +

+ <%= @ammo_group.ammo_type.name %> +

+ <% end %> + +
+ + Count: <%= @ammo_group.count %> + + + <%= if @ammo_group.notes do %> + + Notes: <%= @ammo_group.notes %> + + <% end %> + + <%= if @ammo_group.price_paid do %> + + Price paid: $ <%= @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %> + + <% end %> +
+
+ """ + end +end diff --git a/lib/cannery_web/live/ammo_type_live/index.html.heex b/lib/cannery_web/live/ammo_type_live/index.html.heex index ba5fd8a5..4b8ab08f 100644 --- a/lib/cannery_web/live/ammo_type_live/index.html.heex +++ b/lib/cannery_web/live/ammo_type_live/index.html.heex @@ -60,21 +60,21 @@ <%= ammo_type.manufacturer %> - - - <%= live_redirect("Show", to: Routes.ammo_type_show_path(@socket, :show, ammo_type)) %> - - - <%= live_patch("Edit", to: Routes.ammo_type_index_path(@socket, :edit, ammo_type)) %> - - - <%= link("Delete", - to: "#", - phx_click: "delete", - phx_value_id: ammo_type.id, - data: [confirm: "Are you sure?"] - ) %> - + + <%= live_redirect("View", to: Routes.ammo_type_show_path(@socket, :show, ammo_type)) %> + + <%= live_patch to: Routes.ammo_type_index_path(@socket, :edit, ammo_type), + class: "text-primary-500 link" do %> + + <% end %> + + <%= link to: "#", + class: "text-primary-500 link", + phx_click: "delete", + phx_value_id: ammo_type.id, + data: [confirm: "Are you sure you want to delete this ammo?"] do %> + + <% end %> <% end %> diff --git a/lib/cannery_web/live/ammo_type_live/show.ex b/lib/cannery_web/live/ammo_type_live/show.ex index f9e511c7..77e23125 100644 --- a/lib/cannery_web/live/ammo_type_live/show.ex +++ b/lib/cannery_web/live/ammo_type_live/show.ex @@ -4,8 +4,8 @@ defmodule CanneryWeb.AmmoTypeLive.Show do """ use CanneryWeb, :live_view - - alias Cannery.Ammo + import CanneryWeb.AmmoGroupLive.AmmoGroupCard + alias Cannery.{Ammo, Repo} @impl true def mount(_params, session, socket) do @@ -14,10 +14,14 @@ defmodule CanneryWeb.AmmoTypeLive.Show do @impl true def handle_params(%{"id" => id}, _, socket) do - {:noreply, - socket - |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:ammo_type, Ammo.get_ammo_type!(id))} + socket = + socket + |> assign( + page_title: page_title(socket.assigns.live_action), + ammo_type: Ammo.get_ammo_type!(id) |> Repo.preload(:ammo_groups) + ) + + {:noreply, socket} end @impl true diff --git a/lib/cannery_web/live/ammo_type_live/show.html.heex b/lib/cannery_web/live/ammo_type_live/show.html.heex index 5ff88763..cbed4587 100644 --- a/lib/cannery_web/live/ammo_type_live/show.html.heex +++ b/lib/cannery_web/live/ammo_type_live/show.html.heex @@ -3,45 +3,63 @@ <%= @ammo_type.name %> -
- <%= live_redirect("Back", to: Routes.ammo_type_index_path(@socket, :index), class: "link") %> - <%= live_patch("Edit", to: Routes.ammo_type_show_path(@socket, :edit, @ammo_type), class: "button") %> - <%= link("Delete", - to: "#", - class: "link", - phx_click: "delete", - data: [confirm: "Are you sure you want to delete #{@ammo_type.name}?"] - ) %> +
+ <%= if @ammo_type.desc do %> + + Desc: <%= @ammo_type.desc %> + + <% end %> + + <%= if @ammo_type.case_material do %> + + Case material: <%= @ammo_type.case_material %> + + <% end %> + + <%= if @ammo_type.bullet_type do %> + + Bullet type: <%= @ammo_type.bullet_type %> + + <% end %> + + <%= if @ammo_type.grain do %> + + Grain: <%= @ammo_type.grain %> + + <% end %> + + <%= if @ammo_type.manufacturer do %> + + Manufacturer: <%= @ammo_type.manufacturer %> + + <% end %>
-
+
+ <%= live_patch to: Routes.ammo_type_show_path(@socket, :edit, @ammo_type), + class: "text-primary-500 link" do %> + + <% end %> -
-
  • - Case material: - <%= @ammo_type.case_material %> -
  • +
    -
  • - Bullet type: - <%= @ammo_type.bullet_type %> -
  • - -
  • - Grain: - <%= @ammo_type.grain %> -
  • - -
  • - Manufacturer: - <%= @ammo_type.manufacturer %> -
  • - +
    + <%= if @ammo_type.ammo_groups |> Enum.empty?() do %> + No ammo for this type + <% else %> + <%= for ammo_group <- @ammo_type.ammo_groups do %> + <.ammo_group_card ammo_group={ammo_group} /> + <% end %> + <% end %> +
    <%= if @live_action in [:edit] do %> diff --git a/lib/cannery_web/live/container_live/container_card.ex b/lib/cannery_web/live/container_live/container_card.ex new file mode 100644 index 00000000..800b9062 --- /dev/null +++ b/lib/cannery_web/live/container_live/container_card.ex @@ -0,0 +1,49 @@ +defmodule CanneryWeb.ContainerLive.ContainerCard do + @moduledoc """ + Display card for a container + """ + + use CanneryWeb, :component + alias CanneryWeb.Endpoint + + def container_card(assigns) do + ~H""" +
    +
    + <%= live_redirect to: Routes.container_show_path(Endpoint, :show, @container), + class: "link" do %> +

    + <%= @container.name %> +

    + <% end %> + + <%= if @container.desc do %> + + Description: <%= @container.desc %> + + <% end %> + + + Type: <%= @container.type %> + + + <%= if @container.location do %> + + Location: <%= @container.location %> + + <% end %> +
    + + <%= if assigns |> Map.has_key?(:inner_block) do %> +
    + <%= render_slot(@inner_block) %> +
    + <% end %> +
    + """ + end +end diff --git a/lib/cannery_web/live/container_live/index.ex b/lib/cannery_web/live/container_live/index.ex index f269a152..87e9c987 100644 --- a/lib/cannery_web/live/container_live/index.ex +++ b/lib/cannery_web/live/container_live/index.ex @@ -4,7 +4,7 @@ defmodule CanneryWeb.ContainerLive.Index do """ use CanneryWeb, :live_view - + import CanneryWeb.ContainerLive.ContainerCard alias Cannery.Containers alias Cannery.Containers.Container diff --git a/lib/cannery_web/live/container_live/index.html.heex b/lib/cannery_web/live/container_live/index.html.heex index df63902d..8a531dc3 100644 --- a/lib/cannery_web/live/container_live/index.html.heex +++ b/lib/cannery_web/live/container_live/index.html.heex @@ -21,51 +21,20 @@
    <%= for container <- @containers do %> -
    -
    -

    - <%= container.name %> -

    + <.container_card container={container}> + <%= live_patch to: Routes.container_index_path(@socket, :edit, container), + class: "text-primary-500 link" do %> + + <% end %> - <%= if container.desc do %> - - Description: <%= container.desc %> - - <% end %> - - - Type: <%= container.type %> - - - <%= if container.location do %> - - Location: <%= container.location %> - - <% end %> -
    - -
    - <%= live_redirect("Show", - to: Routes.container_show_path(@socket, :show, container), - class: "text-primary-500 link" - ) %> - <%= live_patch("Edit", - to: Routes.container_index_path(@socket, :edit, container), - class: "text-primary-500 link" - ) %> - <%= link("Delete", - to: "#", - class: "text-primary-500 link", - phx_click: "delete", - phx_value_id: container.id, - data: [confirm: "Are you sure you want to delete #{container.name}?"] - ) %> -
    -
    + <%= link to: "#", + class: "text-primary-500 link", + phx_click: "delete", + phx_value_id: container.id, + data: [confirm: "Are you sure you want to delete #{container.name}?"] do %> + + <% end %> + <% end %>
    diff --git a/lib/cannery_web/live/container_live/show.ex b/lib/cannery_web/live/container_live/show.ex index a390d20f..bf1c4c46 100644 --- a/lib/cannery_web/live/container_live/show.ex +++ b/lib/cannery_web/live/container_live/show.ex @@ -4,8 +4,8 @@ defmodule CanneryWeb.ContainerLive.Show do """ use CanneryWeb, :live_view - - alias Cannery.Containers + import CanneryWeb.AmmoGroupLive.AmmoGroupCard + alias Cannery.{Containers, Repo} @impl true def mount(_params, session, socket) do @@ -18,7 +18,7 @@ defmodule CanneryWeb.ContainerLive.Show do socket |> assign( page_title: page_title(socket.assigns.live_action), - container: Containers.get_container!(id) + container: Containers.get_container!(id) |> Repo.preload(:ammo_groups) ) {:noreply, socket} diff --git a/lib/cannery_web/live/container_live/show.html.heex b/lib/cannery_web/live/container_live/show.html.heex index bf9f3a10..cf9ccc76 100644 --- a/lib/cannery_web/live/container_live/show.html.heex +++ b/lib/cannery_web/live/container_live/show.html.heex @@ -20,19 +20,30 @@ <% end %>
    - <%= live_redirect("Back", to: Routes.container_index_path(@socket, :index), class: "link") %> - <%= live_patch("Edit", to: Routes.container_show_path(@socket, :edit, @container), class: "link") %> - <%= link("Delete", - to: "#", - class: "link", - phx_click: "delete", - data: [confirm: "Are you sure you want to delete #{@container.name}?"] - ) %> + <%= live_patch to: Routes.container_show_path(@socket, :edit, @container), + class: "text-primary-500 link" do %> + + <% end %> + + <%= link to: "#", + class: "text-primary-500 link", + phx_click: "delete", + data: [confirm: "Are you sure you want to delete #{@container.name}?"] do %> + + <% end %>

    -

    No ammo groups in this container

    +

    + <%= if @container.ammo_groups |> Enum.empty?() do %> + No ammo groups in this container + <% else %> + <%= for ammo_group <- @container.ammo_groups do %> + <.ammo_group_card ammo_group={ammo_group} /> + <% end %> + <% end %> +

    <%= if @live_action in [:edit] do %> <%= live_modal(CanneryWeb.ContainerLive.FormComponent, diff --git a/lib/cannery_web/live/invite_live/index.html.leex b/lib/cannery_web/live/invite_live/index.html.leex index ea1f946c..e9830203 100644 --- a/lib/cannery_web/live/invite_live/index.html.leex +++ b/lib/cannery_web/live/invite_live/index.html.leex @@ -15,7 +15,7 @@ <% else %> <%= live_patch to: Routes.invite_index_path(@socket, :new), class: "btn btn-primary" do %> - Invite + Create Invite <% end %> <% end %> @@ -42,29 +42,33 @@
    - <%= live_patch "Edit", to: Routes.invite_index_path(@socket, :edit, invite), - class: "text-primary-500 link" %> + <%= live_patch to: Routes.invite_index_path(@socket, :edit, invite), + class: "text-primary-500 link" do %> + + <% end %> - <%= link "Delete", to: "#", - class: "text-primary-500 link", - phx_click: "delete", + <%= link to: "#", + class: "text-primary-500 link", + phx_click: "delete", phx_value_id: invite.id, - data: [confirm: "Are you sure?"] %> + data: [confirm: "Are you sure you want to delete the invite for #{invite.name}?"] do %> + + <% end %> <%= if invite.disabled_at |> is_nil() do %> - Disable <% else %> - Enable <% end %> <%= if invite.disabled_at |> is_nil() and not(invite.uses_left |> is_nil()) do %> - Set Unlimited diff --git a/lib/cannery_web/live/tag_live/index.ex b/lib/cannery_web/live/tag_live/index.ex index e5e5c050..04607e85 100644 --- a/lib/cannery_web/live/tag_live/index.ex +++ b/lib/cannery_web/live/tag_live/index.ex @@ -4,7 +4,7 @@ defmodule CanneryWeb.TagLive.Index do """ use CanneryWeb, :live_view - + import CanneryWeb.TagLive.TagCard alias Cannery.Tags alias Cannery.Tags.Tag diff --git a/lib/cannery_web/live/tag_live/index.html.heex b/lib/cannery_web/live/tag_live/index.html.heex index 05356a54..ee4d9e9e 100644 --- a/lib/cannery_web/live/tag_live/index.html.heex +++ b/lib/cannery_web/live/tag_live/index.html.heex @@ -22,32 +22,11 @@ <% end %>
    <%= for tag <- @tags do %> -
    -

    - <%= tag.name %> -

    - <%= live_patch to: Routes.tag_index_path(@socket, :edit, tag), - class: "text-primary-500 link" do %> - - <% end %> - <%= link to: "#", - class: "text-primary-500 link", - phx_click: "delete", - phx_value_id: tag.id, - data: [confirm: "Are you sure you want to delete #{tag.name}?"] do %> - - <% end %> -
    + <.tag_card tag={tag} /> <% end %>
    + <%= if @live_action in [:new, :edit] do %> <%= live_modal(CanneryWeb.TagLive.FormComponent, id: @tag.id || :new, diff --git a/lib/cannery_web/live/tag_live/tag_card.ex b/lib/cannery_web/live/tag_live/tag_card.ex new file mode 100644 index 00000000..4abceeb6 --- /dev/null +++ b/lib/cannery_web/live/tag_live/tag_card.ex @@ -0,0 +1,38 @@ +defmodule CanneryWeb.TagLive.TagCard do + @moduledoc """ + Display card for a tag + """ + + use CanneryWeb, :component + alias CanneryWeb.Endpoint + + def tag_card(assigns) do + ~H""" +
    +

    + <%= @tag.name %> +

    + + <%= live_patch to: Routes.tag_index_path(Endpoint, :edit, @tag), + class: "text-primary-500 link" do %> + + <% end %> + + <%= link to: "#", + class: "text-primary-500 link", + phx_click: "delete", + phx_value_id: @tag.id, + data: [confirm: "Are you sure you want to delete #{@tag.name}?"] do %> + + <% end %> +
    + """ + end +end