Skip to content

Commit

Permalink
fix: boost forms
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm committed Sep 3, 2023
1 parent 60da5e9 commit e9f4046
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 88 deletions.
10 changes: 5 additions & 5 deletions lib/parzival_web/live/app/store/boost_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ defmodule ParzivalWeb.App.BoostLive.Show do

@impl true
def handle_event("delete", _payload, socket) do
case Store.delete_product(socket.assigns.product) do
{:ok, _product} ->
case Store.delete_boost(socket.assigns.boost) do
{:ok, _boost} ->
{:noreply,
socket
|> put_flash(:success, "Product deleted successfully!")
|> push_redirect(to: Routes.product_index_path(socket, :index))}
|> put_flash(:success, "Boost deleted successfully!")
|> push_redirect(to: Routes.boost_index_path(socket, :index))}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply,
socket
|> put_flash(:error, elem(changeset.errors[:orders], 0))
|> put_flash(:error, elem(changeset.errors[:error], 0))
|> assign(:changeset, changeset)}
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/parzival_web/live/app/store/boost_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
<!-- Action buttons -->
<%= if @current_user.role in [:admin] do %>
<div class="flex flex-row gap-x-4">
<div type="button" class="inline-flex justify-center py-4 px-8 w-full text-sm font-medium text-gray-700 bg-white rounded-md border border-gray-300 shadow-sm hover:bg-gray-50" id="sort-menu-button" aria-expanded="false" aria-haspopup="true">
<%= link("Edit", to: Routes.admin_boost_edit_path(@socket, :edit, @boost), class: "") %>
</div>
<%= live_patch to: Routes.admin_boost_edit_path(@socket, :edit, @boost), class: "button" do %>
<div type="button" class="inline-flex justify-center py-2 px-4 w-full text-sm font-medium text-gray-700 bg-white rounded-md border border-gray-300 shadow-sm hover:bg-gray-50" id="sort-menu-button" aria-expanded="false" aria-haspopup="true">
<Heroicons.Solid.pencil class="mr-3 w-5 h-5 text-gray-400" /> Edit
</div>
<% end %>
<%= link("Delete", to: "#", phx_click: "delete", data: [confirm: "Are you sure?"], class: "inline-flex items-center justify-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-secondary hover:bg-primary xl:w-full") %>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion lib/parzival_web/live/app/store/product_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule ParzivalWeb.App.ProductLive.Show do
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply,
socket
|> put_flash(:error, elem(changeset.errors[:orders], 0))
|> put_flash(:error, elem(changeset.errors[:error], 0))
|> assign(:changeset, changeset)}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule ParzivalWeb.Backoffice.BoostLive.FormComponent do
use ParzivalWeb, :live_component

alias Parzival.Store

@extensions_whitelist ~w(.jpg .jpeg .gif .png)

@impl true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,34 @@
<!-- Boost details -->
<div class="lg:self-end lg:max-w-lg">
<div class="">
<label for="street-address" class="block text-sm font-medium text-gray-700">Name</label>
<label class="block text-sm font-medium text-gray-700">Name</label>
<%= text_input(f, :name, phx_debounce: "blur", class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :name) %></p>

<div class="mt-4">
<label for="street-address" class="block text-sm font-medium text-gray-700">Price</label>
<label class="block text-sm font-medium text-gray-700">Price</label>
<%= number_input(f, :price, phx_debounce: "blur", class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :price) %></p>

<div class="mt-4">
<label for="street-address" class="block text-sm font-medium text-gray-700">Multiplier</label>
<label class="block text-sm font-medium text-gray-700">Multiplier</label>
<%= number_input(f, :multiplier, phx_debounce: "blur", class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :price) %></p>
<p class="text-xs text-red-500"><%= error_tag(f, :multiplier) %></p>

<div class="mt-4">
<label class="block text-sm font-medium text-gray-700">Type</label>
<%= select(f, :type, [[key: "EXP", value: :exp], [key: "Tokens", value: :tokens], [key: "Skip task", value: :skip_task]], prompt: "Choose a type", selected: f.data.type, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :type) %></p>

<div class="mt-4">
<label for="street-address" class="block text-sm font-medium text-gray-700">Description</label>
<label class="block text-sm font-medium text-gray-700">Description</label>
<%= textarea(f, :description, rows: 3, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :description) %></p>
</div>
<!-- Boost image -->
<div class="mt-10 lg:col-start-2 lg:row-span-2 lg:self-center lg:mt-0">
Expand Down
56 changes: 0 additions & 56 deletions lib/parzival_web/live/backoffice/store/item_live/form_component.ex

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
<!-- Product details -->
<div class="lg:self-end lg:max-w-lg">
<div class="">
<label for="street-address" class="block text-sm font-medium text-gray-700">Name</label>
<label class="block text-sm font-medium text-gray-700">Name</label>
<%= text_input(f, :name, phx_debounce: "blur", class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :name) %></p>

<div class="mt-4">
<label for="street-address" class="block text-sm font-medium text-gray-700">Price</label>
<label class="block text-sm font-medium text-gray-700">Price</label>
<%= number_input(f, :price, phx_debounce: "blur", class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :price) %></p>
<div class="mt-4">
<label for="street-address" class="block text-sm font-medium text-gray-700">Description</label>
<label class="block text-sm font-medium text-gray-700">Description</label>
<%= textarea(f, :description, rows: 3, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :description) %></p>
<div class="mt-4">
<label for="street-address" class="block text-sm font-medium text-gray-700">Stock</label>
<label class="block text-sm font-medium text-gray-700">Stock</label>
<%= number_input(f, :stock, rows: 3, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :stock) %></p>
<div class="mt-4">
<label for="street-address" class="block text-sm font-medium text-gray-700">Maximum purchases per user</label>
<label class="block text-sm font-medium text-gray-700">Maximum purchases per user</label>
<%= number_input(f, :max_per_user, rows: 3, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :max_per_user) %></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
<%= live_redirect("< Back", to: @return_to, class: "hover:underline inline-flex items-center justify-center whitespace-nowrap") %>
</div>
<div>
<label for="street-address" class="block text-sm font-medium text-gray-700">Title</label>
<label class="block text-sm font-medium text-gray-700">Title</label>
<%= text_input(f, :title, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :title) %></p>

<div>
<label for="street-address" class="block text-sm font-medium text-gray-700">Description</label>
<label class="block text-sm font-medium text-gray-700">Description</label>
<%= textarea(f, :text, rows: 12, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :text) %></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<%= live_redirect("< Back", to: @return_to, class: "hover:underline inline-flex items-center justify-center whitespace-nowrap") %>
</div>
<div>
<label for="street-address" class="block text-sm font-medium text-gray-700">Question</label>
<label class="block text-sm font-medium text-gray-700">Question</label>
<%= text_input(f, :question, rows: 3, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :question) %></p>
<div>
<label for="street-address" class="block text-sm font-medium text-gray-700">Answer</label>
<label class="block text-sm font-medium text-gray-700">Answer</label>
<%= textarea(f, :answer, rows: 3, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md") %>
</div>
<p class="text-xs text-red-500"><%= error_tag(f, :answer) %></p>
Expand Down

0 comments on commit e9f4046

Please sign in to comment.