From ee60cc57569cdd3a905367a65e635ecccd2664f0 Mon Sep 17 00:00:00 2001 From: Santiago Botta Date: Sun, 22 Jan 2023 02:01:23 -0300 Subject: [PATCH 01/20] :arrow_up: Migrate to phoenix liveview 0.18.11 --- .credo.exs | 2 +- assets/css/base/base.css | 12 ++++ assets/package-lock.json | 8 +-- lib/ex_commerce_web.ex | 4 +- .../components/icon_component.ex | 19 ++++++ lib/ex_commerce_web/controllers/user_auth.ex | 19 +++--- lib/ex_commerce_web/live/admin_nav.ex | 2 +- lib/ex_commerce_web/live/brand_live/index.ex | 3 +- lib/ex_commerce_web/live/brand_live/show.ex | 2 +- .../live/catalogue_category_live/index.ex | 2 +- .../live/catalogue_category_live/show.ex | 2 +- .../live/catalogue_item_live/index.ex | 2 +- .../live/catalogue_item_live/show.ex | 2 +- .../catalogue_item_option_group_live/index.ex | 2 +- .../catalogue_item_option_group_live/show.ex | 2 +- .../live/catalogue_live/index.ex | 2 +- .../live/catalogue_live/show.ex | 2 +- .../live/checkout_live/catalogue.ex | 2 +- .../live/checkout_live/catalogue.html.heex | 4 +- .../live/checkout_live/catalogue_item.ex | 14 +++-- .../checkout_live/catalogue_item.html.heex | 4 +- .../components/cart_component.ex | 4 +- .../live/checkout_live/order.ex | 2 +- .../live/checkout_live/order_details.ex | 2 +- .../live/checkout_live/shop.ex | 2 +- .../live/checkout_live/shop.html.heex | 8 +-- lib/ex_commerce_web/live/checkout_nav.ex | 2 +- lib/ex_commerce_web/live/home_live/index.ex | 2 +- .../live/home_live/index.html.heex | 10 ++-- lib/ex_commerce_web/live/live_form_helpers.ex | 11 +++- lib/ex_commerce_web/live/live_helpers.ex | 45 +++++++++----- .../live/overview_live/index.ex | 3 +- lib/ex_commerce_web/live/places/show.ex | 2 +- .../live/places/show.html.heex | 14 ++--- lib/ex_commerce_web/live/places_nav.ex | 2 +- .../live/shop_live/form_component.ex | 3 +- lib/ex_commerce_web/live/shop_live/index.ex | 2 +- lib/ex_commerce_web/live/shop_live/show.ex | 2 +- lib/ex_commerce_web/mount_helpers.ex | 1 + .../templates/buttons/file_input.html.heex | 2 +- .../images/upload_image_preview.html.heex | 2 +- .../layout/live_brands_dashboard.html.heex | 15 ++--- .../templates/layout/live_checkout.html.heex | 8 +-- .../templates/layout/live_home.html.heex | 26 ++++---- .../layout/live_main_dashboard.html.heex | 11 ++-- .../templates/layout/live_places.html.heex | 4 +- lib/ex_commerce_web/views/layout_view.ex | 60 +++++++++---------- mix.exs | 10 ++-- mix.lock | 15 ++--- 49 files changed, 223 insertions(+), 158 deletions(-) create mode 100644 lib/ex_commerce_web/components/icon_component.ex diff --git a/.credo.exs b/.credo.exs index 36df55ee..92eab2c8 100644 --- a/.credo.exs +++ b/.credo.exs @@ -93,7 +93,7 @@ # set this value to 0 (zero). # {Credo.Check.Design.TagTODO, [exit_status: 0]}, - {Credo.Check.Design.TagFIXME, []}, + {Credo.Check.Design.TagFIXME, [exit_status: 0]}, # ## Readability Checks diff --git a/assets/css/base/base.css b/assets/css/base/base.css index 9c0614b7..396e7c2e 100644 --- a/assets/css/base/base.css +++ b/assets/css/base/base.css @@ -15,6 +15,18 @@ @apply focus:outline-gray-700 !important; } + .with-ring { + @apply focus:ring focus:ring-inset focus:ring-4 focus:ring-sky-500 !important; + } + + .with-ring-sm { + @apply focus:ring focus:ring-inset focus:ring-2 focus:ring-sky-500 !important; + } + + .with-ring.gray, .with-ring-sm.gray { + @apply focus:ring-gray-700 !important; + } + .icon { @apply h-6 w-6; } diff --git a/assets/package-lock.json b/assets/package-lock.json index 52a608f8..57202a8c 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -31,18 +31,18 @@ } }, "../deps/live_motion": { - "version": "0.1.1", + "version": "0.3.0", "license": "MIT" }, "../deps/phoenix": { - "version": "1.6.6", + "version": "1.6.15", "license": "MIT" }, "../deps/phoenix_html": { - "version": "3.1.0" + "version": "3.2.0" }, "../deps/phoenix_live_view": { - "version": "0.17.7", + "version": "0.18.11", "license": "MIT" }, "node_modules/@babel/code-frame": { diff --git a/lib/ex_commerce_web.ex b/lib/ex_commerce_web.ex index 58cdf5cf..f601ca2f 100644 --- a/lib/ex_commerce_web.ex +++ b/lib/ex_commerce_web.ex @@ -40,6 +40,8 @@ defmodule ExCommerceWeb do # Include shared imports and aliases for views import PhoenixInlineSvg.Helpers + import Phoenix.Component + unquote(view_helpers()) end end @@ -48,7 +50,7 @@ defmodule ExCommerceWeb do quote do @opts Keyword.merge( [ - layout: {ExCommerceWeb.LayoutView, "live.html"}, + layout: {ExCommerceWeb.LayoutView, :live}, container: {:div, class: "relative h-screen flex overflow-hidden bg-white"} diff --git a/lib/ex_commerce_web/components/icon_component.ex b/lib/ex_commerce_web/components/icon_component.ex new file mode 100644 index 00000000..db889654 --- /dev/null +++ b/lib/ex_commerce_web/components/icon_component.ex @@ -0,0 +1,19 @@ +defmodule ExCommerceWeb.Components.IconComponent do + @moduledoc """ + Wrapper for the Heroicons library + """ + use Phoenix.Component + + attr :rest, :global, + doc: "the arbitrary HTML attributes for the svg container", + include: ~w(fill stroke stroke-width) + + attr :name, :atom, required: true + attr :outline, :boolean, default: true + attr :solid, :boolean, default: false + attr :mini, :boolean, default: false + + def render_icon(assigns) do + apply(Heroicons, assigns.name, [assigns]) + end +end diff --git a/lib/ex_commerce_web/controllers/user_auth.ex b/lib/ex_commerce_web/controllers/user_auth.ex index 2877e8b9..f915a2ae 100644 --- a/lib/ex_commerce_web/controllers/user_auth.ex +++ b/lib/ex_commerce_web/controllers/user_auth.ex @@ -3,8 +3,9 @@ defmodule ExCommerceWeb.UserAuth do Controller for user authentication. """ import ExCommerceWeb.Gettext - import Plug.Conn + import Phoenix.Component, only: [assign: 3, assign_new: 3] import Phoenix.Controller + import Plug.Conn, except: [assign: 3] alias ExCommerce.Accounts alias ExCommerceWeb.Router.Helpers, as: Routes @@ -207,8 +208,8 @@ defmodule ExCommerceWeb.UserAuth do end conn - |> assign(:current_user, user) - |> assign(:visitor, visitor) + |> Plug.Conn.assign(:current_user, user) + |> Plug.Conn.assign(:visitor, visitor) end defp ensure_user_token(conn) do @@ -276,20 +277,20 @@ defmodule ExCommerceWeb.UserAuth do @spec get_recaptcha_response_field :: String.t() def get_recaptcha_response_field, do: @recaptcha_response_field - defp assign_current_user(socket, nil) do - LiveView.assign_new(socket, :current_user, fn -> nil end) - |> LiveView.assign(:visitor, true) + defp assign_current_user(%LiveView.Socket{} = socket, nil) do + assign_new(socket, :current_user, fn -> nil end) + |> assign(:visitor, true) end - defp assign_current_user(socket, user_token) do - LiveView.assign_new( + defp assign_current_user(%LiveView.Socket{} = socket, user_token) do + assign_new( socket, :current_user, fn -> Accounts.get_user_by_session_token!(user_token) end ) - |> LiveView.assign(:visitor, false) + |> assign(:visitor, false) end defp redirect_require_login(socket) do diff --git a/lib/ex_commerce_web/live/admin_nav.ex b/lib/ex_commerce_web/live/admin_nav.ex index 97b8ce77..38f7071f 100644 --- a/lib/ex_commerce_web/live/admin_nav.ex +++ b/lib/ex_commerce_web/live/admin_nav.ex @@ -1,7 +1,7 @@ defmodule ExCommerceWeb.AdminNav do @moduledoc false - import Phoenix.LiveView + use Phoenix.LiveView alias ExCommerceWeb.{ BrandLive, diff --git a/lib/ex_commerce_web/live/brand_live/index.ex b/lib/ex_commerce_web/live/brand_live/index.ex index e1f438cb..f214bc40 100644 --- a/lib/ex_commerce_web/live/brand_live/index.ex +++ b/lib/ex_commerce_web/live/brand_live/index.ex @@ -3,8 +3,7 @@ defmodule ExCommerceWeb.BrandLive.Index do Lists available brands """ use ExCommerceWeb, - {:live_view, - layout: {ExCommerceWeb.LayoutView, "live_brands_dashboard.html"}} + {:live_view, layout: {ExCommerceWeb.LayoutView, :live_brands_dashboard}} alias ExCommerce.Accounts.User alias ExCommerce.Marketplaces diff --git a/lib/ex_commerce_web/live/brand_live/show.ex b/lib/ex_commerce_web/live/brand_live/show.ex index ace973ff..da42cd20 100644 --- a/lib/ex_commerce_web/live/brand_live/show.ex +++ b/lib/ex_commerce_web/live/brand_live/show.ex @@ -4,7 +4,7 @@ defmodule ExCommerceWeb.BrandLive.Show do """ use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } @impl true diff --git a/lib/ex_commerce_web/live/catalogue_category_live/index.ex b/lib/ex_commerce_web/live/catalogue_category_live/index.ex index 7deed370..b23e5347 100644 --- a/lib/ex_commerce_web/live/catalogue_category_live/index.ex +++ b/lib/ex_commerce_web/live/catalogue_category_live/index.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CatalogueCategoryLive.Index do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } alias ExCommerce.Marketplaces.Brand diff --git a/lib/ex_commerce_web/live/catalogue_category_live/show.ex b/lib/ex_commerce_web/live/catalogue_category_live/show.ex index f3555a65..a00515a2 100644 --- a/lib/ex_commerce_web/live/catalogue_category_live/show.ex +++ b/lib/ex_commerce_web/live/catalogue_category_live/show.ex @@ -4,7 +4,7 @@ defmodule ExCommerceWeb.CatalogueCategoryLive.Show do """ use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } @impl true diff --git a/lib/ex_commerce_web/live/catalogue_item_live/index.ex b/lib/ex_commerce_web/live/catalogue_item_live/index.ex index 2ac0f750..bbb79ff7 100644 --- a/lib/ex_commerce_web/live/catalogue_item_live/index.ex +++ b/lib/ex_commerce_web/live/catalogue_item_live/index.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CatalogueItemLive.Index do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } use ExCommerceWeb.LiveFormHelpers, routes: Routes diff --git a/lib/ex_commerce_web/live/catalogue_item_live/show.ex b/lib/ex_commerce_web/live/catalogue_item_live/show.ex index d75e80a6..7dd7c93a 100644 --- a/lib/ex_commerce_web/live/catalogue_item_live/show.ex +++ b/lib/ex_commerce_web/live/catalogue_item_live/show.ex @@ -4,7 +4,7 @@ defmodule ExCommerceWeb.CatalogueItemLive.Show do """ use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } use ExCommerceWeb.LiveFormHelpers, routes: Routes diff --git a/lib/ex_commerce_web/live/catalogue_item_option_group_live/index.ex b/lib/ex_commerce_web/live/catalogue_item_option_group_live/index.ex index 0bfd845e..2b5083e7 100644 --- a/lib/ex_commerce_web/live/catalogue_item_option_group_live/index.ex +++ b/lib/ex_commerce_web/live/catalogue_item_option_group_live/index.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CatalogueItemOptionGroupLive.Index do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } alias ExCommerce.Marketplaces.Brand diff --git a/lib/ex_commerce_web/live/catalogue_item_option_group_live/show.ex b/lib/ex_commerce_web/live/catalogue_item_option_group_live/show.ex index e6c55a1c..97dcc84e 100644 --- a/lib/ex_commerce_web/live/catalogue_item_option_group_live/show.ex +++ b/lib/ex_commerce_web/live/catalogue_item_option_group_live/show.ex @@ -4,7 +4,7 @@ defmodule ExCommerceWeb.CatalogueItemOptionGroupLive.Show do """ use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } @impl true diff --git a/lib/ex_commerce_web/live/catalogue_live/index.ex b/lib/ex_commerce_web/live/catalogue_live/index.ex index 4da9cc7b..fd40a1ee 100644 --- a/lib/ex_commerce_web/live/catalogue_live/index.ex +++ b/lib/ex_commerce_web/live/catalogue_live/index.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CatalogueLive.Index do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } alias ExCommerce.Marketplaces.Brand diff --git a/lib/ex_commerce_web/live/catalogue_live/show.ex b/lib/ex_commerce_web/live/catalogue_live/show.ex index 3b44fde9..1dc5fc45 100644 --- a/lib/ex_commerce_web/live/catalogue_live/show.ex +++ b/lib/ex_commerce_web/live/catalogue_live/show.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CatalogueLive.Show do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } @impl true diff --git a/lib/ex_commerce_web/live/checkout_live/catalogue.ex b/lib/ex_commerce_web/live/checkout_live/catalogue.ex index 365cde8c..501007d6 100644 --- a/lib/ex_commerce_web/live/checkout_live/catalogue.ex +++ b/lib/ex_commerce_web/live/checkout_live/catalogue.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CheckoutLive.Catalogue do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_checkout.html"} + layout: {ExCommerceWeb.LayoutView, :live_checkout} } use ExCommerceWeb.LiveFormHelpers, routes: Routes diff --git a/lib/ex_commerce_web/live/checkout_live/catalogue.html.heex b/lib/ex_commerce_web/live/checkout_live/catalogue.html.heex index 2e6a8490..339e0ad2 100644 --- a/lib/ex_commerce_web/live/checkout_live/catalogue.html.heex +++ b/lib/ex_commerce_web/live/checkout_live/catalogue.html.heex @@ -108,7 +108,7 @@ col-span-6 lg:col-span-5 row-span-1 justify-self-end self-center "> - <.link + <.custom_link class="rounded-lg" patch={get_item_route(@socket, @brand_slug, @shop_slug, @catalogue, item_id)} tabindex="1" @@ -121,7 +121,7 @@ > <%= gettext("Add to order") %> - + diff --git a/lib/ex_commerce_web/live/checkout_live/catalogue_item.ex b/lib/ex_commerce_web/live/checkout_live/catalogue_item.ex index 93652da5..4138f7b8 100644 --- a/lib/ex_commerce_web/live/checkout_live/catalogue_item.ex +++ b/lib/ex_commerce_web/live/checkout_live/catalogue_item.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CheckoutLive.CatalogueItem do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_checkout.html"} + layout: {ExCommerceWeb.LayoutView, :live_checkout} } use ExCommerceWeb.LiveFormHelpers, routes: Routes @@ -216,21 +216,27 @@ defmodule ExCommerceWeb.CheckoutLive.CatalogueItem do # def render_option_price(price, price_modifier, assigns) do + assigns = assign(assigns, :price, get_price(price)) + case Decimal.eq?(price_modifier, Decimal.new(0)) do true -> ~H"""

- <%= get_price(price) %> + <%= @price %>

""" false -> + assigns = + assigns + |> assign(:discount_price, get_price(price, price_modifier)) + ~H"""

- <%= get_price(price) %> + <%= @price %>

- <%= get_price(price, price_modifier) %> + <%= @discount_price %>

""" end diff --git a/lib/ex_commerce_web/live/checkout_live/catalogue_item.html.heex b/lib/ex_commerce_web/live/checkout_live/catalogue_item.html.heex index 98ff6a80..53f05164 100644 --- a/lib/ex_commerce_web/live/checkout_live/catalogue_item.html.heex +++ b/lib/ex_commerce_web/live/checkout_live/catalogue_item.html.heex @@ -121,7 +121,7 @@ tabindex="-1" phx-click="remove_item" > - <.icon name={:minus_sm} class="text-white"/> + <.icon name={:minus_small} class="text-white"/> <% else %> <% end %> diff --git a/lib/ex_commerce_web/live/checkout_live/components/cart_component.ex b/lib/ex_commerce_web/live/checkout_live/components/cart_component.ex index 6e035ed3..7cf96e44 100644 --- a/lib/ex_commerce_web/live/checkout_live/components/cart_component.ex +++ b/lib/ex_commerce_web/live/checkout_live/components/cart_component.ex @@ -119,7 +119,7 @@ defmodule ExCommerceWeb.CheckoutLive.Components.CartComponent do justify-self-end self-center "> - <.link + <.custom_link to={"#"} class="rounded-xl" phx-click="remove_order_item" @@ -132,7 +132,7 @@ defmodule ExCommerceWeb.CheckoutLive.Components.CartComponent do > <%= gettext("Remove") %> - + diff --git a/lib/ex_commerce_web/live/checkout_live/order.ex b/lib/ex_commerce_web/live/checkout_live/order.ex index 6d09f407..978e8fbd 100644 --- a/lib/ex_commerce_web/live/checkout_live/order.ex +++ b/lib/ex_commerce_web/live/checkout_live/order.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CheckoutLive.Order do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_checkout.html"} + layout: {ExCommerceWeb.LayoutView, :live_checkout} } use ExCommerceWeb.LiveFormHelpers, routes: Routes diff --git a/lib/ex_commerce_web/live/checkout_live/order_details.ex b/lib/ex_commerce_web/live/checkout_live/order_details.ex index 2bdc5687..ec1b4029 100644 --- a/lib/ex_commerce_web/live/checkout_live/order_details.ex +++ b/lib/ex_commerce_web/live/checkout_live/order_details.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CheckoutLive.OrderDetails do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_checkout.html"} + layout: {ExCommerceWeb.LayoutView, :live_checkout} } use ExCommerceWeb.LiveFormHelpers, routes: Routes diff --git a/lib/ex_commerce_web/live/checkout_live/shop.ex b/lib/ex_commerce_web/live/checkout_live/shop.ex index 09011b92..f02f07fb 100644 --- a/lib/ex_commerce_web/live/checkout_live/shop.ex +++ b/lib/ex_commerce_web/live/checkout_live/shop.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.CheckoutLive.Shop do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_checkout.html"} + layout: {ExCommerceWeb.LayoutView, :live_checkout} } use ExCommerceWeb.LiveFormHelpers, routes: Routes diff --git a/lib/ex_commerce_web/live/checkout_live/shop.html.heex b/lib/ex_commerce_web/live/checkout_live/shop.html.heex index 88709392..61563261 100644 --- a/lib/ex_commerce_web/live/checkout_live/shop.html.heex +++ b/lib/ex_commerce_web/live/checkout_live/shop.html.heex @@ -70,7 +70,7 @@

- <.icon name={:location_marker} outlined class=" + <.icon name={:map_pin} outlined class=" text-sky-600 flex-shrink-0 h-4 w-4 "/> @@ -118,7 +118,7 @@ bg-gray-50 pressable "> - <.link + <.custom_link patch={Routes.checkout_catalogue_path( @socket, :index, @@ -128,7 +128,7 @@ )} >
- <.icon name={:clipboard_list} outlined class=" + <.icon name={:clipboard_document_list} outlined class=" text-sky-600 mr-2 flex-shrink-0 h-16 w-16 "/> @@ -138,7 +138,7 @@ <%= catalogue_name %>

- +
<% end %>
diff --git a/lib/ex_commerce_web/live/checkout_nav.ex b/lib/ex_commerce_web/live/checkout_nav.ex index 565dcb2d..832f23f2 100644 --- a/lib/ex_commerce_web/live/checkout_nav.ex +++ b/lib/ex_commerce_web/live/checkout_nav.ex @@ -1,7 +1,7 @@ defmodule ExCommerceWeb.CheckoutNav do @moduledoc false - import Phoenix.LiveView + use Phoenix.LiveView alias ExCommerce.Checkout.Cart diff --git a/lib/ex_commerce_web/live/home_live/index.ex b/lib/ex_commerce_web/live/home_live/index.ex index 361bf02f..3f07f069 100644 --- a/lib/ex_commerce_web/live/home_live/index.ex +++ b/lib/ex_commerce_web/live/home_live/index.ex @@ -2,7 +2,7 @@ defmodule ExCommerceWeb.HomeLive.Index do @moduledoc false use ExCommerceWeb, - {:live_view, layout: {ExCommerceWeb.LayoutView, "live_home.html"}} + {:live_view, layout: {ExCommerceWeb.LayoutView, :live_home}} @impl true def mount(_params, _session, socket) do diff --git a/lib/ex_commerce_web/live/home_live/index.html.heex b/lib/ex_commerce_web/live/home_live/index.html.heex index f220e9e1..1814905f 100644 --- a/lib/ex_commerce_web/live/home_live/index.html.heex +++ b/lib/ex_commerce_web/live/home_live/index.html.heex @@ -72,7 +72,7 @@
  • - <.icon outlined={true} name={:library} class="icon text-gray-500"/> + <.icon outlined={true} name={:building_library} class="icon text-gray-500"/>
    <%= gettext("Create brands that empower your business") %> @@ -82,7 +82,7 @@
  • - <.icon outlined={true} name={:office_building} class="icon text-gray-500"/> + <.icon outlined={true} name={:building_office} class="icon text-gray-500"/>
    <%= gettext("Setup shops within your brand to expand your reach") %> @@ -102,7 +102,7 @@
  • - <.icon outlined={true} name={:collection} class="icon text-gray-500"/> + <.icon outlined={true} name={:rectangle_stack} class="icon text-gray-500"/>
    <%= gettext("Create and manage additional product options with discounts") %> @@ -112,7 +112,7 @@
  • - <.icon outlined={true} name={:clipboard_list} class="icon text-gray-500"/> + <.icon outlined={true} name={:clipboard_document_list} class="icon text-gray-500"/>
    <%= gettext("Combine your products across catalogues to create custom menus") %> @@ -122,7 +122,7 @@
  • - <.icon outlined={true} name={:paper_airplane} class="rotate-90 icon text-gray-500"/> + <.icon outlined={true} name={:paper_airplane} class="icon text-gray-500"/>
    <%= gettext("Receive purchase requests in your phone directly from customers") %> diff --git a/lib/ex_commerce_web/live/live_form_helpers.ex b/lib/ex_commerce_web/live/live_form_helpers.ex index dfdf8c94..9bb523df 100644 --- a/lib/ex_commerce_web/live/live_form_helpers.ex +++ b/lib/ex_commerce_web/live/live_form_helpers.ex @@ -26,8 +26,9 @@ defmodule ExCommerceWeb.LiveFormHelpers do defp get_photos([], _opts), do: [] defp get_photos([photo | _photos] = photos, opts) do + # FIXME: we shouldn't equal to nil case Enum.find(photos, nil, fn %Photo{state: state} -> - state != :delete + state != :delete or state == nil end) do nil -> :ok = @@ -37,6 +38,14 @@ defmodule ExCommerceWeb.LiveFormHelpers do get_photos([], opts) + %Photo{state: nil} -> + :ok = + Logger.warn( + "#{__MODULE__} (get_photos/2) :: No non :delete photos found. Returning a placeholder. photos=#{inspect(photos)}" + ) + + get_photos([], opts) + %Photo{state: :local} = photo -> :ok = Logger.warn( diff --git a/lib/ex_commerce_web/live/live_helpers.ex b/lib/ex_commerce_web/live/live_helpers.ex index e1f6d69b..6471d659 100644 --- a/lib/ex_commerce_web/live/live_helpers.ex +++ b/lib/ex_commerce_web/live/live_helpers.ex @@ -2,9 +2,21 @@ defmodule ExCommerceWeb.LiveHelpers do @moduledoc """ Implements reusable helpers for live views """ + import ExCommerceWeb.Components.IconComponent + + import Phoenix.Component, + only: [ + assign: 3, + assign_new: 3, + assigns_to_attributes: 1, + live_component: 1, + live_flash: 2, + render_slot: 1, + sigil_H: 2 + ] + import Phoenix.HTML, only: [raw: 1] import Phoenix.LiveView.Helpers - import Phoenix.LiveView import Phoenix.View alias Phoenix.LiveView.JS @@ -434,7 +446,7 @@ defmodule ExCommerceWeb.LiveHelpers do >
    <%= for link <- @link do %> - <.link + <.custom_link tabindex="-1" role="menuitem" class=" @@ -447,7 +459,7 @@ defmodule ExCommerceWeb.LiveHelpers do focus:ring-offset-gray-100 focus:ring-blue-500 " {link} - ><%= render_slot(link) %> + ><%= render_slot(link) %> <% end %>
    @@ -532,7 +544,7 @@ defmodule ExCommerceWeb.LiveHelpers do |> JS.remove_attribute("aria-expanded", to: to) end - def link(%{navigate: _to} = assigns) do + def custom_link(%{navigate: _to} = assigns) do assigns = assign_new(assigns, :class, fn -> nil end) ~H""" @@ -547,7 +559,7 @@ defmodule ExCommerceWeb.LiveHelpers do """ end - def link(%{patch: to} = assigns) do + def custom_link(%{patch: to} = assigns) do opts = assigns |> assigns_to_attributes() |> Keyword.put(:to, to) assigns = assign(assigns, :opts, opts) @@ -556,7 +568,7 @@ defmodule ExCommerceWeb.LiveHelpers do """ end - def link(%{} = assigns) do + def custom_link(%{} = assigns) do opts = assigns |> assigns_to_attributes() @@ -572,18 +584,21 @@ defmodule ExCommerceWeb.LiveHelpers do def icon(assigns) do assigns = assigns - |> assign_new(:outlined, fn -> false end) - |> assign_new(:class, fn -> "w-4 h-4 inline-block" end) - |> assign_new(:"aria-hidden", fn -> + |> Map.put_new_lazy(:outlined, fn -> true end) + |> Map.put_new_lazy(:solid, fn -> false end) + |> Map.put_new_lazy(:class, fn -> "w-4 h-4 inline-block" end) + |> Map.put_new_lazy(:"aria-hidden", fn -> !Map.has_key?(assigns, :"aria-label") end) + # <%= if @outlined do %> + # <%= apply(Heroicons, :building_library, [assigns_to_attributes(assigns, [:outline, :name]) |> Enum.into(%{})]) %> + # <% else %> + # <%= apply(Heroicons, :building_library, [assigns_to_attributes(assigns, [:solid, :name]) |> Enum.into(%{})]) %> + # <% end %> + ~H""" - <%= if @outlined do %> - <%= apply(Heroicons.Outline, @name, [assigns_to_attributes(assigns, [:outlined, :name])]) %> - <% else %> - <%= apply(Heroicons.Solid, @name, [assigns_to_attributes(assigns, [:outlined, :name])]) %> - <% end %> + <.render_icon name={@name} outline={@outlined} class={@class} solid={@solid} /> """ end @@ -764,7 +779,7 @@ defmodule ExCommerceWeb.LiveHelpers do hover:bg-green-300 focus:ring-offset-green-50 focus:ring-green-600 " > - <.icon name={:x} class="base-alert-close-icon" /> + <.icon name={:x_mark} class="base-alert-close-icon" /> diff --git a/lib/ex_commerce_web/live/overview_live/index.ex b/lib/ex_commerce_web/live/overview_live/index.ex index 0e10a336..b2cfdee7 100644 --- a/lib/ex_commerce_web/live/overview_live/index.ex +++ b/lib/ex_commerce_web/live/overview_live/index.ex @@ -2,8 +2,7 @@ defmodule ExCommerceWeb.OverviewLive.Index do @moduledoc false use ExCommerceWeb, - {:live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"}} + {:live_view, layout: {ExCommerceWeb.LayoutView, :live_main_dashboard}} @impl true def mount(params, session, socket) do diff --git a/lib/ex_commerce_web/live/places/show.ex b/lib/ex_commerce_web/live/places/show.ex index 27db7c9c..3825954d 100644 --- a/lib/ex_commerce_web/live/places/show.ex +++ b/lib/ex_commerce_web/live/places/show.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.PlaceLive.Show do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_places.html"} + layout: {ExCommerceWeb.LayoutView, :live_places} } use ExCommerceWeb.LiveFormHelpers, routes: Routes diff --git a/lib/ex_commerce_web/live/places/show.html.heex b/lib/ex_commerce_web/live/places/show.html.heex index e43075d2..b2d3a0f0 100644 --- a/lib/ex_commerce_web/live/places/show.html.heex +++ b/lib/ex_commerce_web/live/places/show.html.heex @@ -12,7 +12,7 @@

    - <.icon name={:location_marker} outlined class=" + <.icon name={:map_pin} outlined class=" text-sky-600 flex-shrink-0 h-4 w-4 "/> @@ -62,7 +62,7 @@ transition-transform ease-in-out duration-100 active:scale-75 "> - <.link + <.custom_link patch={Routes.place_show_path( @socket, :show_catalogue, @@ -72,7 +72,7 @@ )} >
    - <.icon name={:clipboard_list} outlined class=" + <.icon name={:clipboard_document_list} outlined class=" text-sky-600 mr-2 flex-shrink-0 h-16 w-16 "/> @@ -82,7 +82,7 @@ <%= catalogue_name %>

    - +
    <% end %>
    @@ -163,7 +163,7 @@ col-span-6 lg:col-span-5 row-span-1 justify-self-end self-center "> - <.link + <.custom_link patch={Routes.place_show_path( @socket, :show_item, @@ -183,7 +183,7 @@ > <%= gettext("Add to order") %> - + @@ -241,7 +241,7 @@ "} phx-click="remove_item" > - <.icon name={:minus_sm} class="text-white"/> + <.icon name={:minus_small} class="text-white"/> diff --git a/lib/ex_commerce_web/live/places_nav.ex b/lib/ex_commerce_web/live/places_nav.ex index c1aaaa1b..4d4b6ae5 100644 --- a/lib/ex_commerce_web/live/places_nav.ex +++ b/lib/ex_commerce_web/live/places_nav.ex @@ -1,7 +1,7 @@ defmodule ExCommerceWeb.PlacesNav do @moduledoc false - import Phoenix.LiveView + use Phoenix.LiveView def on_mount(:check_action, _params, _session, socket) do {:cont, diff --git a/lib/ex_commerce_web/live/shop_live/form_component.ex b/lib/ex_commerce_web/live/shop_live/form_component.ex index afbb0bd4..66d52d18 100644 --- a/lib/ex_commerce_web/live/shop_live/form_component.ex +++ b/lib/ex_commerce_web/live/shop_live/form_component.ex @@ -219,9 +219,8 @@ defmodule ExCommerceWeb.ShopLive.FormComponent do defp consume_media_files( socket, - %Shop{avatars: avatars, banners: banners} = shop + %Shop{avatars: avatars, banners: banners, brand_id: brand_id} = shop ) do - %{brand: %Brand{id: brand_id}} = socket.assigns upload_opts = [folder: brand_id, tags: brand_id] :ok = diff --git a/lib/ex_commerce_web/live/shop_live/index.ex b/lib/ex_commerce_web/live/shop_live/index.ex index b08dcb45..e267f27b 100644 --- a/lib/ex_commerce_web/live/shop_live/index.ex +++ b/lib/ex_commerce_web/live/shop_live/index.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.ShopLive.Index do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } alias ExCommerce.Marketplaces diff --git a/lib/ex_commerce_web/live/shop_live/show.ex b/lib/ex_commerce_web/live/shop_live/show.ex index 4b97762e..569e872f 100644 --- a/lib/ex_commerce_web/live/shop_live/show.ex +++ b/lib/ex_commerce_web/live/shop_live/show.ex @@ -5,7 +5,7 @@ defmodule ExCommerceWeb.ShopLive.Show do use ExCommerceWeb, { :live_view, - layout: {ExCommerceWeb.LayoutView, "live_main_dashboard.html"} + layout: {ExCommerceWeb.LayoutView, :live_main_dashboard} } @impl true diff --git a/lib/ex_commerce_web/mount_helpers.ex b/lib/ex_commerce_web/mount_helpers.ex index 1efe0b99..0a16a274 100644 --- a/lib/ex_commerce_web/mount_helpers.ex +++ b/lib/ex_commerce_web/mount_helpers.ex @@ -2,6 +2,7 @@ defmodule ExCommerceWeb.MountHelpers do @moduledoc """ Responsible for implementing reusable mount helpers """ + import Phoenix.Component, only: [assign: 2, assign: 3, assign_new: 3] import Phoenix.LiveView import ExCommerceWeb.Gettext diff --git a/lib/ex_commerce_web/templates/buttons/file_input.html.heex b/lib/ex_commerce_web/templates/buttons/file_input.html.heex index b7e28442..ecb4d3a6 100644 --- a/lib/ex_commerce_web/templates/buttons/file_input.html.heex +++ b/lib/ex_commerce_web/templates/buttons/file_input.html.heex @@ -1,4 +1,4 @@ diff --git a/lib/ex_commerce_web/templates/images/upload_image_preview.html.heex b/lib/ex_commerce_web/templates/images/upload_image_preview.html.heex index 5a0230b6..15814835 100644 --- a/lib/ex_commerce_web/templates/images/upload_image_preview.html.heex +++ b/lib/ex_commerce_web/templates/images/upload_image_preview.html.heex @@ -4,7 +4,7 @@ sm:items-center ">
    - <%= live_img_preview @entry, class: "rounded-lg w-28 h-28" %> + <.live_img_preview entry={@entry} class="rounded-lg w-28 h-28" />
    - <.link navigate="#"}> + <.custom_link navigate="#"}> <.icon - name={:library} + name={:building_library} class="w-8 h-8 text-blue-600 -mt-2 inline-block" outlined /> <%= gettext("ExCommerce") %> - +