gettext invites and tags
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
shibao 2022-02-09 00:58:53 -05:00
parent 91b9e8a730
commit 5451728541
10 changed files with 192 additions and 47 deletions

View File

@ -50,17 +50,17 @@ defmodule CanneryWeb.InviteLive.FormComponent do
</div> </div>
<% end %> <% end %>
<%= label(f, :name, class: "title text-lg text-primary-500") %> <%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-500") %>
<%= text_input(f, :name, class: "input input-primary col-span-2") %> <%= text_input(f, :name, class: "input input-primary col-span-2") %>
<%= error_tag(f, :name, "col-span-3") %> <%= error_tag(f, :name, "col-span-3") %>
<%= label(f, :uses_left, class: "title text-lg text-primary-500") %> <%= label(f, :uses_left, gettext("Uses left"), class: "title text-lg text-primary-500") %>
<%= number_input(f, :uses_left, min: 0, class: "input input-primary col-span-2") %> <%= number_input(f, :uses_left, min: 0, class: "input input-primary col-span-2") %>
<%= error_tag(f, :uses_left, "col-span-3") %> <%= error_tag(f, :uses_left, "col-span-3") %>
<%= submit("Save", <%= submit(dgettext("actions", "Save"),
class: "mx-auto btn btn-primary col-span-3", class: "mx-auto btn btn-primary col-span-3",
phx_disable_with: "Saving..." phx_disable_with: dgettext("prompts", "Saving...")
) %> ) %>
</.form> </.form>
</div> </div>
@ -72,7 +72,7 @@ defmodule CanneryWeb.InviteLive.FormComponent do
{:ok, _invite} -> {:ok, _invite} ->
{:noreply, {:noreply,
socket socket
|> put_flash(:info, "Invite updated successfully") |> put_flash(:info, dgettext("prompts", "Invite updated successfully"))
|> push_redirect(to: socket.assigns.return_to)} |> push_redirect(to: socket.assigns.return_to)}
{:error, %Changeset{} = changeset} -> {:error, %Changeset{} = changeset} ->
@ -85,7 +85,7 @@ defmodule CanneryWeb.InviteLive.FormComponent do
{:ok, _invite} -> {:ok, _invite} ->
{:noreply, {:noreply,
socket socket
|> put_flash(:info, "Invite created successfully") |> put_flash(:info, dgettext("prompts", "Invite created successfully"))
|> push_redirect(to: socket.assigns.return_to)} |> push_redirect(to: socket.assigns.return_to)}
{:error, %Changeset{} = changeset} -> {:error, %Changeset{} = changeset} ->

View File

@ -20,17 +20,17 @@ defmodule CanneryWeb.InviteLive.Index do
defp apply_action(socket, :edit, %{"id" => id}) do defp apply_action(socket, :edit, %{"id" => id}) do
socket socket
|> assign(page_title: "Edit Invite", invite: Invites.get_invite!(id)) |> assign(page_title: gettext("Edit Invite"), invite: Invites.get_invite!(id))
end end
defp apply_action(socket, :new, _params) do defp apply_action(socket, :new, _params) do
socket socket
|> assign(page_title: "New Invite", invite: %Invite{}) |> assign(page_title: gettext("New Invite"), invite: %Invite{})
end end
defp apply_action(socket, :index, _params) do defp apply_action(socket, :index, _params) do
socket socket
|> assign(page_title: "Listing Invites", invite: nil) |> assign(page_title: gettext("Listing Invites"), invite: nil)
end end
@impl true @impl true

View File

@ -1,22 +1,20 @@
<div class="flex flex-col space-y-8 justify-center items-center"> <div class="flex flex-col space-y-8 justify-center items-center">
<h1 class="title text-2xl title-primary-500"> <h1 class="title text-2xl title-primary-500">
Listing Invites <%= gettext("Listing Invites") %>
</h1> </h1>
<%= if @invites |> Enum.empty?() do %> <%= if @invites |> Enum.empty?() do %>
<h1 class="title text-xl text-primary-500"> <h1 class="title text-xl text-primary-500">
No invites 😔 <%= gettext("No invites") %> 😔
</h1> </h1>
<%= live_patch to: Routes.invite_index_path(@socket, :new), <%= live_patch dgettext("actions", "Invite someone new!"),
class: "btn btn-primary" do %> to: Routes.invite_index_path(@socket, :new),
Invite someone new! class: "btn btn-primary" %>
<% end %>
<% else %> <% else %>
<%= live_patch to: Routes.invite_index_path(@socket, :new), <%= live_patch dgettext("actions", "Create Invite"),
class: "btn btn-primary" do %> to: Routes.invite_index_path(@socket, :new),
Create Invite class: "btn btn-primary" %>
<% end %>
<% end %> <% end %>
<div class="flex flex-row flex-wrap space-x-4 space-y-4"> <div class="flex flex-row flex-wrap space-x-4 space-y-4">
@ -29,11 +27,12 @@
<%= if invite.disabled_at |> is_nil() do %> <%= if invite.disabled_at |> is_nil() do %>
<h2 class="title text-md"> <h2 class="title text-md">
Uses Left: <%= invite.uses_left || "Unlimited" %> <%= gettext("Uses Left:") %>
<%= invite.uses_left || "Unlimited" %>
</h2> </h2>
<% else %> <% else %>
<h2 class="title text-md"> <h2 class="title text-md">
Invite Disabled <%= gettext("Invite Disabled") %>
</h2> </h2>
<% end %> <% end %>
@ -51,27 +50,27 @@
class: "text-primary-500 link", class: "text-primary-500 link",
phx_click: "delete", phx_click: "delete",
phx_value_id: invite.id, phx_value_id: invite.id,
data: [confirm: "Are you sure you want to delete the invite for #{invite.name}?"] do %> data: [confirm: dgettext("prompts", "Are you sure you want to delete the invite for %{name}?", name: invite.name)] do %>
<i class="fa-fw fa-lg fas fa-trash"></i> <i class="fa-fw fa-lg fas fa-trash"></i>
<% end %> <% end %>
<%= if invite.disabled_at |> is_nil() do %> <%= if invite.disabled_at |> is_nil() do %>
<a href="#" class="btn btn-primary" <a href="#" class="btn btn-primary"
phx-click="disable" phx-value-id="<%= invite.id %>"> phx-click="disable" phx-value-id="<%= invite.id %>">
Disable <%= gettext("Disable") %>
</a> </a>
<% else %> <% else %>
<a href="#" class="btn btn-primary" <a href="#" class="btn btn-primary"
phx-click="enable" phx-value-id="<%= invite.id %>"> phx-click="enable" phx-value-id="<%= invite.id %>">
Enable <%= gettext("Enable") %>
</a> </a>
<% end %> <% end %>
<%= if invite.disabled_at |> is_nil() and not(invite.uses_left |> is_nil()) do %> <%= if invite.disabled_at |> is_nil() and not(invite.uses_left |> is_nil()) do %>
<a href="#" class="btn btn-primary" <a href="#" class="btn btn-primary"
phx-click="set_unlimited" phx-value-id="<%= invite.id %>" phx-click="set_unlimited" phx-value-id="<%= invite.id %>"
data-confirm="Are you sure you want to make this invite unlimited?"> data-confirm={dgettext("prompts", "Are you sure you want to make this invite unlimited?")}>
Set Unlimited <%= gettext("Set Unlimited") %>
</a> </a>
<% end %> <% end %>
</div> </div>

View File

@ -21,14 +21,11 @@ defmodule CanneryWeb.TagLive.FormComponent do
@impl true @impl true
def handle_event("validate", %{"tag" => tag_params}, socket) do def handle_event("validate", %{"tag" => tag_params}, socket) do
tag_params = tag_params |> Map.put("user_id", socket.assigns.current_user.id) tag_params = tag_params |> Map.put("user_id", socket.assigns.current_user.id)
changeset = socket.assigns.tag |> Tags.change_tag(tag_params) changeset = socket.assigns.tag |> Tags.change_tag(tag_params)
{:noreply, socket |> assign(:changeset, changeset)} {:noreply, socket |> assign(:changeset, changeset)}
end end
def handle_event("save", %{"tag" => tag_params}, socket) do def handle_event("save", %{"tag" => tag_params}, socket) do
tag_params = tag_params |> Map.put("user_id", socket.assigns.current_user.id)
save_tag(socket, socket.assigns.action, tag_params) save_tag(socket, socket.assigns.action, tag_params)
end end
@ -54,25 +51,25 @@ defmodule CanneryWeb.TagLive.FormComponent do
</div> </div>
<% end %> <% end %>
<%= label(f, :name, class: "title text-lg text-primary-500") %> <%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-500") %>
<%= text_input(f, :name, class: "input input-primary col-span-2") %> <%= text_input(f, :name, class: "input input-primary col-span-2") %>
<%= error_tag(f, :name, "col-span-3") %> <%= error_tag(f, :name, "col-span-3") %>
<%= label(f, :bg_color, class: "title text-lg text-primary-500") %> <%= label(f, :bg_color, gettext("Background color"), class: "title text-lg text-primary-500") %>
<span class="mx-auto col-span-2" phx-update="ignore"> <span class="mx-auto col-span-2" phx-update="ignore">
<%= color_input(f, :bg_color) %> <%= color_input(f, :bg_color) %>
</span> </span>
<%= error_tag(f, :bg_color, "col-span-3") %> <%= error_tag(f, :bg_color, "col-span-3") %>
<%= label(f, :text_color, class: "title text-lg text-primary-500") %> <%= label(f, :text_color, gettext("Text color"), class: "title text-lg text-primary-500") %>
<span class="mx-auto col-span-2" phx-update="ignore"> <span class="mx-auto col-span-2" phx-update="ignore">
<%= color_input(f, :text_color) %> <%= color_input(f, :text_color) %>
</span> </span>
<%= error_tag(f, :text_color, "col-span-3") %> <%= error_tag(f, :text_color, "col-span-3") %>
<%= submit("Save", <%= submit(dgettext("actions", "Save"),
class: "mx-auto btn btn-primary col-span-3", class: "mx-auto btn btn-primary col-span-3",
phx_disable_with: "Saving..." phx_disable_with: dgettext("prompts", "Saving...")
) %> ) %>
</.form> </.form>
</div> </div>
@ -84,7 +81,7 @@ defmodule CanneryWeb.TagLive.FormComponent do
{:ok, _tag} -> {:ok, _tag} ->
{:noreply, {:noreply,
socket socket
|> put_flash(:info, "Tag updated successfully") |> put_flash(:info, dgettext("prompts", "Tag updated successfully"))
|> push_redirect(to: socket.assigns.return_to)} |> push_redirect(to: socket.assigns.return_to)}
{:error, %Changeset{} = changeset} -> {:error, %Changeset{} = changeset} ->
@ -93,11 +90,14 @@ defmodule CanneryWeb.TagLive.FormComponent do
end end
defp save_tag(socket, :new, tag_params) do defp save_tag(socket, :new, tag_params) do
case Tags.create_tag(tag_params) do tag_params
|> Map.put("user_id", socket.assigns.current_user.id)
|> Tags.create_tag()
|> case do
{:ok, _tag} -> {:ok, _tag} ->
{:noreply, {:noreply,
socket socket
|> put_flash(:info, "Tag created successfully") |> put_flash(:info, dgettext("prompts", "Tag created successfully"))
|> push_redirect(to: socket.assigns.return_to)} |> push_redirect(to: socket.assigns.return_to)}
{:error, %Changeset{} = changeset} -> {:error, %Changeset{} = changeset} ->

View File

@ -20,19 +20,19 @@ defmodule CanneryWeb.TagLive.Index do
defp apply_action(socket, :edit, %{"id" => id}) do defp apply_action(socket, :edit, %{"id" => id}) do
socket socket
|> assign(:page_title, "Edit Tag") |> assign(:page_title, gettext("Edit Tag"))
|> assign(:tag, Tags.get_tag!(id)) |> assign(:tag, Tags.get_tag!(id))
end end
defp apply_action(socket, :new, _params) do defp apply_action(socket, :new, _params) do
socket socket
|> assign(:page_title, "New Tag") |> assign(:page_title, gettext("New Tag"))
|> assign(:tag, %Tag{bg_color: Tags.random_bg_color(), text_color: "#ffffff"}) |> assign(:tag, %Tag{bg_color: Tags.random_bg_color(), text_color: "#ffffff"})
end end
defp apply_action(socket, :index, _params) do defp apply_action(socket, :index, _params) do
socket socket
|> assign(:page_title, "Listing Tags") |> assign(:page_title, gettext("Listing Tags"))
|> assign(:tag, nil) |> assign(:tag, nil)
end end
@ -40,7 +40,7 @@ defmodule CanneryWeb.TagLive.Index do
def handle_event("delete", %{"id" => id}, socket) do def handle_event("delete", %{"id" => id}, socket) do
tag = Tags.get_tag!(id) tag = Tags.get_tag!(id)
{:ok, _} = Tags.delete_tag(tag) {:ok, _} = Tags.delete_tag(tag)
socket = socket |> put_flash(:info, "Tag deleted succesfully") socket = socket |> put_flash(:info, dgettext("prompts", "Tag deleted succesfully"))
{:noreply, socket |> display_tags()} {:noreply, socket |> display_tags()}
end end

View File

@ -1,21 +1,21 @@
<div class="flex flex-col space-y-8 justify-center items-center"> <div class="flex flex-col space-y-8 justify-center items-center">
<h1 class="title text-2xl title-primary-500"> <h1 class="title text-2xl title-primary-500">
Listing Tags <%= gettext("Listing Tags") %>
</h1> </h1>
<p class="title text-md text-primary-500"> <p class="title text-md text-primary-500">
Tags can be added to your containers to help you organize <%= gettext("Tags can be added to your containers to help you organize") %>
</p> </p>
<%= if @tags |> Enum.empty?() do %> <%= if @tags |> Enum.empty?() do %>
<h2 class="title text-xl text-primary-500"> <h2 class="title text-xl text-primary-500">
No tags 😔 <%= gettext("No tags") %> 😔
</h2> </h2>
<%= live_patch("Make your first tag!", <%= live_patch(dgettext("actions", "Make your first tag!"),
to: Routes.tag_index_path(@socket, :new), to: Routes.tag_index_path(@socket, :new),
class: "btn btn-primary" class: "btn btn-primary"
) %> ) %>
<% else %> <% else %>
<%= live_patch("New Tag", <%= live_patch(dgettext("actions", "New Tag"),
to: Routes.tag_index_path(@socket, :new), to: Routes.tag_index_path(@socket, :new),
class: "btn btn-primary" class: "btn btn-primary"
) %> ) %>

View File

@ -29,7 +29,9 @@ defmodule CanneryWeb.TagLive.TagCard do
class: "text-primary-500 link", class: "text-primary-500 link",
phx_click: "delete", phx_click: "delete",
phx_value_id: @tag.id, phx_value_id: @tag.id,
data: [confirm: "Are you sure you want to delete #{@tag.name}?"] do %> data: [
confirm: dgettext("prompts", "Are you sure you want to delete %{name}?", name: @tag.name)
] do %>
<i class="fa-fw fa-lg fas fa-trash"></i> <i class="fa-fw fa-lg fas fa-trash"></i>
<% end %> <% end %>
</div> </div>

View File

@ -94,6 +94,8 @@ msgstr ""
#: lib/cannery_web/live/ammo_group_live/form_component.ex:90 #: lib/cannery_web/live/ammo_group_live/form_component.ex:90
#: lib/cannery_web/live/ammo_type_live/form_component.ex:155 #: lib/cannery_web/live/ammo_type_live/form_component.ex:155
#: lib/cannery_web/live/container_live/form_component.ex:79 #: lib/cannery_web/live/container_live/form_component.ex:79
#: lib/cannery_web/live/invite_live/form_component.ex:61
#: lib/cannery_web/live/tag_live/form_component.ex:70
msgid "Save" msgid "Save"
msgstr "" msgstr ""
@ -121,3 +123,23 @@ msgstr ""
#: lib/cannery_web/live/container_live/index.html.heex:16 #: lib/cannery_web/live/container_live/index.html.heex:16
msgid "New Container" msgid "New Container"
msgstr "" msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.html.leex:15
msgid "Create Invite"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.html.leex:11
msgid "Invite someone new!"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.html.heex:18
msgid "New Tag"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.html.heex:13
msgid "Make your first tag!"
msgstr ""

View File

@ -304,6 +304,8 @@ msgstr ""
#: lib/cannery_web/live/ammo_type_live/form_component.ex:53 #: lib/cannery_web/live/ammo_type_live/form_component.ex:53
#: lib/cannery_web/live/ammo_type_live/index.html.heex:26 #: lib/cannery_web/live/ammo_type_live/index.html.heex:26
#: lib/cannery_web/live/container_live/form_component.ex:49 #: lib/cannery_web/live/container_live/form_component.ex:49
#: lib/cannery_web/live/invite_live/form_component.ex:53
#: lib/cannery_web/live/tag_live/form_component.ex:54
msgid "Name" msgid "Name"
msgstr "" msgstr ""
@ -447,3 +449,90 @@ msgstr ""
#: lib/cannery_web/live/container_live/show.html.heex:14 #: lib/cannery_web/live/container_live/show.html.heex:14
msgid "Type:" msgid "Type:"
msgstr "" msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/form_component.ex:58
msgid "Background color"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.html.leex:60
msgid "Disable"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.ex:23
msgid "Edit Invite"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.ex:23
msgid "Edit Tag"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.html.leex:65
msgid "Enable"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.html.leex:35
msgid "Invite Disabled"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.ex:33
#: lib/cannery_web/live/invite_live/index.html.leex:3
msgid "Listing Invites"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.ex:35
#: lib/cannery_web/live/tag_live/index.html.heex:3
msgid "Listing Tags"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.ex:28
msgid "New Invite"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.ex:29
msgid "New Tag"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.html.leex:8
msgid "No invites"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.html.heex:10
msgid "No tags"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.html.leex:73
msgid "Set Unlimited"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.html.heex:6
msgid "Tags can be added to your containers to help you organize"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/form_component.ex:64
msgid "Text color"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.html.leex:30
msgid "Uses Left:"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/form_component.ex:57
msgid "Uses left"
msgstr ""

View File

@ -97,6 +97,8 @@ msgstr ""
#: lib/cannery_web/live/ammo_group_live/form_component.ex:91 #: lib/cannery_web/live/ammo_group_live/form_component.ex:91
#: lib/cannery_web/live/ammo_type_live/form_component.ex:156 #: lib/cannery_web/live/ammo_type_live/form_component.ex:156
#: lib/cannery_web/live/container_live/form_component.ex:81 #: lib/cannery_web/live/container_live/form_component.ex:81
#: lib/cannery_web/live/invite_live/form_component.ex:63
#: lib/cannery_web/live/tag_live/form_component.ex:72
msgid "Saving..." msgid "Saving..."
msgstr "" msgstr ""
@ -114,6 +116,7 @@ msgstr ""
#: lib/cannery_web/live/ammo_type_live/show.html.heex:26 #: lib/cannery_web/live/ammo_type_live/show.html.heex:26
#: lib/cannery_web/live/container_live/index.html.heex:36 #: lib/cannery_web/live/container_live/index.html.heex:36
#: lib/cannery_web/live/container_live/show.html.heex:36 #: lib/cannery_web/live/container_live/show.html.heex:36
#: lib/cannery_web/live/tag_live/tag_card.ex:33
msgid "Are you sure you want to delete %{name}?" msgid "Are you sure you want to delete %{name}?"
msgstr "" msgstr ""
@ -132,3 +135,33 @@ msgstr ""
#: lib/cannery_web/live/container_live/form_component.ex:98 #: lib/cannery_web/live/container_live/form_component.ex:98
msgid "Container updated successfully" msgid "Container updated successfully"
msgstr "" msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/index.html.leex:53
msgid "Are you sure you want to delete the invite for %{name}?"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/form_component.ex:88
msgid "Invite created successfully"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/invite_live/form_component.ex:75
msgid "Invite updated successfully"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/form_component.ex:100
msgid "Tag created successfully"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.ex:43
msgid "Tag deleted succesfully"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/form_component.ex:84
msgid "Tag updated successfully"
msgstr ""