Skip to content

Commit

Permalink
refactor: announcements is not part of the admin pages
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoCoelho2003 committed Nov 7, 2024
1 parent 4a36fa3 commit a80c0fa
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
14 changes: 7 additions & 7 deletions lib/atomic_web/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ defmodule AtomicWeb.Config do
url: ~p"/organizations/#{current_organization}/departments",
tabs: []
},
%{
key: :announcements,
title: "Announcements",
icon: "hero-newspaper",
url: ~p"/organizations/#{current_organization}/announcements",
tabs: []
},
%{
key: :partners,
title: "Partners",
Expand Down Expand Up @@ -83,13 +90,6 @@ defmodule AtomicWeb.Config do
url: ~p"/activities",
tabs: []
},
%{
key: :announcements,
title: "Announcements",
icon: "hero-newspaper",
url: ~p"/announcements",
tabs: []
},
%{
key: :organizations,
title: "Organizations",
Expand Down
2 changes: 1 addition & 1 deletion lib/atomic_web/live/announcement_live/edit.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</.button>
</:actions>
<div class="pt-4 px-4">
<.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={@announcement.id} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/announcements/#{@announcement}"} />
<.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={@announcement.id} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/organizations/#{@current_organization}/announcements"} />
</div>
</.page>
5 changes: 4 additions & 1 deletion lib/atomic_web/live/announcement_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ defmodule AtomicWeb.AnnouncementLive.Index do
end

@impl true
def handle_params(params, _, socket) do
def handle_params(%{"organization_id" => organization_id} = params, _, socket) do
organization = Organizations.get_organization!(organization_id)

{:noreply,
socket
|> assign(:page_title, gettext("Announcements"))
|> assign(:current_page, :announcements)
|> assign(:current_tab, current_tab(socket, params))
|> assign(:organization, organization)
|> assign(:params, params)
|> assign(:has_permissions?, has_permissions?(socket))
|> assign(list_announcements(socket, params))
Expand Down
6 changes: 3 additions & 3 deletions lib/atomic_web/live/announcement_live/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<.page title="Announcements">
<:actions>
<%= if not @empty? and @has_permissions? do %>
<.button navigate={~p"/announcements/new"}>
<.button navigate={~p"/organizations/#{@current_organization}/announcements/new"} icon="hero-plus">
<%= gettext("New") %>
</.button>
<% end %>
Expand All @@ -23,14 +23,14 @@
<!-- Announcements index -->
<%= if @empty? and @has_permissions? do %>
<div class="mt-32">
<.empty_state url={~p"/announcements/new"} placeholder="announcement" />
<.empty_state url={~p"/organizations/#{@organization}/announcements/new"} placeholder="announcement" />
</div>
<% else %>
<div class="overflow-hidden bg-white">
<ul role="list" class="divide-y divide-zinc-200 overflow-auto">
<%= for announcement <- @announcements do %>
<li id={announcement.id}>
<.link navigate={~p"/announcements/#{announcement}"} class="block hover:bg-zinc-50">
<.link navigate={~p"/organizations/#{@organization}/announcements/#{announcement}"} class="block hover:bg-zinc-50">
<div class="px-4 py-4 lg:px-6">
<div class="flex items-center justify-between">
<p class="truncate text-sm font-medium text-zinc-900">
Expand Down
2 changes: 1 addition & 1 deletion lib/atomic_web/live/announcement_live/new.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<.page title={gettext("New Announcement")}>
<div class="pt-4 px-4">
<.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={:new} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/announcements"} />
<.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={:new} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/organizations/#{@current_organization}/announcements"} />
</div>
</.page>
6 changes: 6 additions & 0 deletions lib/atomic_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ defmodule AtomicWeb.Router do
live "/", PartnerLive.Index, :index
live "/:id", PartnerLive.Show, :show
end

scope "/announcements" do
pipe_through :confirm_announcement_association
live "/", AnnouncementLive.Index, :index
live "/:id", AnnouncementLive.Show, :show
end
end

# Only masters can create organizations
Expand Down

0 comments on commit a80c0fa

Please sign in to comment.