From f774eaae7f31ce88b81db1d6c61788bef7d29acf Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Fri, 20 Oct 2023 13:52:58 -0400 Subject: [PATCH] Display flash message (feedback) on actions (#82) * Display flash message (feedback) on actions Close #56 * pipe --- .../live_admin/components/admin_components.ex | 24 +++++++++++++++++++ .../component_editor_live/form_component.ex | 2 ++ .../live/layout_editor_live/form_component.ex | 2 +- .../live/layout_editor_live/meta_tags.ex | 5 ++-- .../live/layout_editor_live/resource_links.ex | 4 +++- .../live/layout_editor_live/revisions.ex | 2 +- .../live/page_editor_live/event_handlers.ex | 3 ++- .../live/page_editor_live/form_component.ex | 2 +- .../live/page_editor_live/meta_tags.ex | 5 ++-- .../live/page_editor_live/revisions.ex | 3 ++- .../live/page_editor_live/schema.ex | 8 +++++-- .../live/page_editor_live/variants.ex | 3 ++- 12 files changed, 50 insertions(+), 13 deletions(-) diff --git a/lib/beacon/live_admin/components/admin_components.ex b/lib/beacon/live_admin/components/admin_components.ex index d46dff62..4271b750 100644 --- a/lib/beacon/live_admin/components/admin_components.ex +++ b/lib/beacon/live_admin/components/admin_components.ex @@ -26,6 +26,18 @@ defmodule Beacon.LiveAdmin.AdminComponents do @menu_link_active_class "inline-block p-4 text-blue-600 border-b-2 border-blue-600 rounded-t-lg active" @menu_link_regular_class "inline-block p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-300" + attr :socket, :map + attr :flash, :map + attr :beacon_layout, :map + attr :live_action, :atom + + def layout_header(assigns) do + ~H""" + <.flash_group flash={@flash} /> + + """ + end + attr :socket, :map attr :site, :atom attr :current_action, :atom @@ -72,6 +84,18 @@ defmodule Beacon.LiveAdmin.AdminComponents do """ end + attr :socket, :map + attr :flash, :map + attr :page, :any + attr :live_action, :atom + + def page_header(assigns) do + ~H""" + <.flash_group flash={@flash} /> + + """ + end + attr :socket, :map attr :site, :atom attr :current_action, :atom diff --git a/lib/beacon/live_admin/live/component_editor_live/form_component.ex b/lib/beacon/live_admin/live/component_editor_live/form_component.ex index 8ccb48ab..a181fd39 100644 --- a/lib/beacon/live_admin/live/component_editor_live/form_component.ex +++ b/lib/beacon/live_admin/live/component_editor_live/form_component.ex @@ -65,6 +65,8 @@ defmodule Beacon.LiveAdmin.ComponentEditorLive.FormComponent do def render(assigns) do ~H"""
+ <.flash_group flash={@flash} /> + <.header> <%= @page_title %> <:actions> diff --git a/lib/beacon/live_admin/live/layout_editor_live/form_component.ex b/lib/beacon/live_admin/live/layout_editor_live/form_component.ex index c75916c4..04c7427f 100644 --- a/lib/beacon/live_admin/live/layout_editor_live/form_component.ex +++ b/lib/beacon/live_admin/live/layout_editor_live/form_component.ex @@ -97,7 +97,7 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.FormComponent do def render(assigns) do ~H"""
- + <.header> <%= layout_name(@form.source) %> diff --git a/lib/beacon/live_admin/live/layout_editor_live/meta_tags.ex b/lib/beacon/live_admin/live/layout_editor_live/meta_tags.ex index b96ca237..acc118cf 100644 --- a/lib/beacon/live_admin/live/layout_editor_live/meta_tags.ex +++ b/lib/beacon/live_admin/live/layout_editor_live/meta_tags.ex @@ -40,7 +40,8 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.MetaTags do {:noreply, socket |> assign(:beacon_layout, layout) - |> assign_field(changeset)} + |> assign_field(changeset) + |> put_flash(:info, "Layout updated successfully")} {:error, changeset} -> {:noreply, assign_field(socket, changeset)} @@ -56,7 +57,7 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.MetaTags do def render(assigns) do ~H"""
- + <.live_component module={MetaTagsComponent} id="layout-meta-tags" site={@beacon_layout.site} page_title={@page_title} live_action={@live_action} field={@field} meta_tags={@beacon_layout.meta_tags} />
""" diff --git a/lib/beacon/live_admin/live/layout_editor_live/resource_links.ex b/lib/beacon/live_admin/live/layout_editor_live/resource_links.ex index 5b58f178..9facecc1 100644 --- a/lib/beacon/live_admin/live/layout_editor_live/resource_links.ex +++ b/lib/beacon/live_admin/live/layout_editor_live/resource_links.ex @@ -86,6 +86,7 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.ResourceLinks do |> assign(:beacon_layout, layout) |> assign_field(changeset) |> assign_attributes() + |> put_flash(:info, "Layout updated successfully") {:error, changeset} -> assign_field(socket, changeset) @@ -102,7 +103,7 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.ResourceLinks do def render(assigns) do ~H"""
- + <.header> <%= @page_title %> @@ -110,6 +111,7 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.ResourceLinks do <.button phx-disable-with="Saving..." form="resource-links-form" class="uppercase">Save Changes + <.main_content class="h-[calc(100vh_-_223px)]">
<.button type="button" phx-click="add">New Resource Link diff --git a/lib/beacon/live_admin/live/layout_editor_live/revisions.ex b/lib/beacon/live_admin/live/layout_editor_live/revisions.ex index f85cf9b8..cb964a1b 100644 --- a/lib/beacon/live_admin/live/layout_editor_live/revisions.ex +++ b/lib/beacon/live_admin/live/layout_editor_live/revisions.ex @@ -28,7 +28,7 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.Revisions do def render(assigns) do ~H"""
- + <.header> <%= @page_title %> diff --git a/lib/beacon/live_admin/live/page_editor_live/event_handlers.ex b/lib/beacon/live_admin/live/page_editor_live/event_handlers.ex index ee4ffa63..0ca482e6 100644 --- a/lib/beacon/live_admin/live/page_editor_live/event_handlers.ex +++ b/lib/beacon/live_admin/live/page_editor_live/event_handlers.ex @@ -94,6 +94,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.EventHandlers do |> assign_selected(selected.id) |> assign_form() |> assign(unsaved_changes: false) + |> put_flash(:info, "Page updated successfully") {:error, changeset} -> changeset = Map.put(changeset, :action, :update) @@ -146,7 +147,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.EventHandlers do def render(assigns) do ~H"""
- + <.header> <%= @page_title %> diff --git a/lib/beacon/live_admin/live/page_editor_live/form_component.ex b/lib/beacon/live_admin/live/page_editor_live/form_component.ex index 030af3c3..059fb33a 100644 --- a/lib/beacon/live_admin/live/page_editor_live/form_component.ex +++ b/lib/beacon/live_admin/live/page_editor_live/form_component.ex @@ -130,7 +130,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.FormComponent do def render(assigns) do ~H"""
- + <.header> <%= @page_title %> diff --git a/lib/beacon/live_admin/live/page_editor_live/meta_tags.ex b/lib/beacon/live_admin/live/page_editor_live/meta_tags.ex index e7ccb252..2bfcc392 100644 --- a/lib/beacon/live_admin/live/page_editor_live/meta_tags.ex +++ b/lib/beacon/live_admin/live/page_editor_live/meta_tags.ex @@ -40,7 +40,8 @@ defmodule Beacon.LiveAdmin.PageEditorLive.MetaTags do {:noreply, socket |> assign(:page, page) - |> assign_field(changeset)} + |> assign_field(changeset) + |> put_flash(:info, "Page updated successfully")} {:error, changeset} -> {:noreply, assign_field(socket, changeset)} @@ -56,7 +57,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.MetaTags do def render(assigns) do ~H"""
- + <.live_component module={MetaTagsComponent} id="page-meta-tags" page_title={@page_title} site={@page.site} live_action={@live_action} field={@field} meta_tags={@page.meta_tags} />
""" diff --git a/lib/beacon/live_admin/live/page_editor_live/revisions.ex b/lib/beacon/live_admin/live/page_editor_live/revisions.ex index 5aa7fd45..6226f230 100644 --- a/lib/beacon/live_admin/live/page_editor_live/revisions.ex +++ b/lib/beacon/live_admin/live/page_editor_live/revisions.ex @@ -53,7 +53,8 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Revisions do def render(assigns) do ~H"""
- + + <.header> <%= @page_title %> diff --git a/lib/beacon/live_admin/live/page_editor_live/schema.ex b/lib/beacon/live_admin/live/page_editor_live/schema.ex index 940013d5..3e23d175 100644 --- a/lib/beacon/live_admin/live/page_editor_live/schema.ex +++ b/lib/beacon/live_admin/live/page_editor_live/schema.ex @@ -35,7 +35,11 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Schema do case Content.update_page(page.site, page, attrs) do {:ok, page} -> changeset = Content.change_page(page.site, page) - {:noreply, assign_form(socket, changeset)} + + {:noreply, + socket + |> assign_form(changeset) + |> put_flash(:info, "Page updated successfully")} {:error, changeset} -> {:noreply, assign_form(socket, changeset)} @@ -50,7 +54,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Schema do def render(assigns) do ~H"""
- + <.header> <%= @page_title %> diff --git a/lib/beacon/live_admin/live/page_editor_live/variants.ex b/lib/beacon/live_admin/live/page_editor_live/variants.ex index d833aff7..579683fe 100644 --- a/lib/beacon/live_admin/live/page_editor_live/variants.ex +++ b/lib/beacon/live_admin/live/page_editor_live/variants.ex @@ -59,6 +59,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Variants do |> assign(form: to_form(changeset)) |> assign(changed_template: template) |> assign(unsaved_changes: !(changeset.changes == %{})) + |> put_flash(:info, "Page updated successfully") {:noreply, socket} end @@ -144,7 +145,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Variants do def render(assigns) do ~H"""
- + <.header> <%= @page_title %>