Skip to content

Commit

Permalink
Display flash message (feedback) on actions (#82)
Browse files Browse the repository at this point in the history
* Display flash message (feedback) on actions

Close #56

* pipe
  • Loading branch information
leandrocp authored Oct 20, 2023
1 parent e14c146 commit f774eaa
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 13 deletions.
24 changes: 24 additions & 0 deletions lib/beacon/live_admin/components/admin_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
<Beacon.LiveAdmin.AdminComponents.layout_menu socket={@socket} site={@beacon_layout.site} current_action={@live_action} layout_id={@beacon_layout.id} />
"""
end

attr :socket, :map
attr :site, :atom
attr :current_action, :atom
Expand Down Expand Up @@ -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} />
<Beacon.LiveAdmin.AdminComponents.page_menu socket={@socket} site={@page.site} current_action={@live_action} page_id={@page.id} />
"""
end

attr :socket, :map
attr :site, :atom
attr :current_action, :atom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ defmodule Beacon.LiveAdmin.ComponentEditorLive.FormComponent do
def render(assigns) do
~H"""
<div>
<.flash_group flash={@flash} />
<.header>
<%= @page_title %>
<:actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.FormComponent do
def render(assigns) do
~H"""
<div>
<Beacon.LiveAdmin.AdminComponents.layout_menu socket={@socket} site={@site} current_action={@live_action} layout_id={@beacon_layout.id} />
<Beacon.LiveAdmin.AdminComponents.layout_header socket={@socket} flash={@flash} beacon_layout={@beacon_layout} live_action={@live_action} />
<.header>
<%= layout_name(@form.source) %>
Expand Down
5 changes: 3 additions & 2 deletions lib/beacon/live_admin/live/layout_editor_live/meta_tags.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -56,7 +57,7 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.MetaTags do
def render(assigns) do
~H"""
<div>
<Beacon.LiveAdmin.AdminComponents.layout_menu socket={@socket} site={@beacon_layout.site} current_action={@live_action} layout_id={@beacon_layout.id} />
<Beacon.LiveAdmin.AdminComponents.layout_header socket={@socket} flash={@flash} beacon_layout={@beacon_layout} live_action={@live_action} />
<.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} />
</div>
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -102,14 +103,15 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.ResourceLinks do
def render(assigns) do
~H"""
<div>
<Beacon.LiveAdmin.AdminComponents.layout_menu socket={@socket} site={@beacon_layout.site} current_action={@live_action} layout_id={@beacon_layout.id} />
<Beacon.LiveAdmin.AdminComponents.layout_header socket={@socket} flash={@flash} beacon_layout={@beacon_layout} live_action={@live_action} />
<.header>
<%= @page_title %>
<:actions>
<.button phx-disable-with="Saving..." form="resource-links-form" class="uppercase">Save Changes</.button>
</:actions>
</.header>
<.main_content class="h-[calc(100vh_-_223px)]">
<div class="flex gap-4">
<.button type="button" phx-click="add">New Resource Link</.button>
Expand Down
2 changes: 1 addition & 1 deletion lib/beacon/live_admin/live/layout_editor_live/revisions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Beacon.LiveAdmin.LayoutEditorLive.Revisions do
def render(assigns) do
~H"""
<div>
<Beacon.LiveAdmin.AdminComponents.layout_menu socket={@socket} site={@beacon_page.site} current_action={@live_action} layout_id={@layout_id} />
<Beacon.LiveAdmin.AdminComponents.layout_header socket={@socket} flash={@flash} beacon_layout={@beacon_layout} live_action={@live_action} />
<.header>
<%= @page_title %>
</.header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -146,7 +147,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.EventHandlers do
def render(assigns) do
~H"""
<div>
<Beacon.LiveAdmin.AdminComponents.page_menu socket={@socket} site={@beacon_page.site} current_action={@live_action} page_id={@page.id} />
<Beacon.LiveAdmin.AdminComponents.page_header socket={@socket} flash={@flash} page={@page} live_action={@live_action} />
<.header>
<%= @page_title %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.FormComponent do
def render(assigns) do
~H"""
<div>
<Beacon.LiveAdmin.AdminComponents.page_menu socket={@socket} site={@site} current_action={@live_action} page_id={@page.id} />
<Beacon.LiveAdmin.AdminComponents.page_header socket={@socket} flash={@flash} page={@page} live_action={@live_action} />
<.header>
<%= @page_title %>
Expand Down
5 changes: 3 additions & 2 deletions lib/beacon/live_admin/live/page_editor_live/meta_tags.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -56,7 +57,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.MetaTags do
def render(assigns) do
~H"""
<div>
<Beacon.LiveAdmin.AdminComponents.page_menu socket={@socket} site={@page.site} current_action={@live_action} page_id={@page.id} />
<Beacon.LiveAdmin.AdminComponents.page_header socket={@socket} flash={@flash} page={@page} live_action={@live_action} />
<.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} />
</div>
"""
Expand Down
3 changes: 2 additions & 1 deletion lib/beacon/live_admin/live/page_editor_live/revisions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Revisions do
def render(assigns) do
~H"""
<div class="content">
<Beacon.LiveAdmin.AdminComponents.page_menu socket={@socket} site={@beacon_page.site} current_action={@live_action} page_id={@page_id} />
<Beacon.LiveAdmin.AdminComponents.page_header socket={@socket} flash={@flash} page={@page} live_action={@live_action} />
<.header>
<%= @page_title %>
</.header>
Expand Down
8 changes: 6 additions & 2 deletions lib/beacon/live_admin/live/page_editor_live/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -50,7 +54,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Schema do
def render(assigns) do
~H"""
<div>
<Beacon.LiveAdmin.AdminComponents.page_menu socket={@socket} site={@page.site} current_action={@live_action} page_id={@page.id} />
<Beacon.LiveAdmin.AdminComponents.page_header socket={@socket} flash={@flash} page={@page} live_action={@live_action} />
<.header>
<%= @page_title %>
Expand Down
3 changes: 2 additions & 1 deletion lib/beacon/live_admin/live/page_editor_live/variants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -144,7 +145,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Variants do
def render(assigns) do
~H"""
<div>
<Beacon.LiveAdmin.AdminComponents.page_menu socket={@socket} site={@beacon_page.site} current_action={@live_action} page_id={@page.id} />
<Beacon.LiveAdmin.AdminComponents.page_header socket={@socket} flash={@flash} page={@page} live_action={@live_action} />
<.header>
<%= @page_title %>
Expand Down

0 comments on commit f774eaa

Please sign in to comment.