-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9aea5da
commit d99a0ea
Showing
26 changed files
with
572 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/atomic/activities/location.ex → lib/atomic/location/location.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule Atomic.Socials do | ||
@moduledoc """ | ||
A socials embedded struct schema. | ||
""" | ||
use Atomic.Schema | ||
|
||
@optional_fields ~w(instagram facebook x youtube tiktok website)a | ||
|
||
@derive Jason.Encoder | ||
@primary_key false | ||
embedded_schema do | ||
field :instagram, :string | ||
field :facebook, :string | ||
field :x, :string | ||
field :youtube, :string | ||
field :tiktok, :string | ||
field :website, :string | ||
end | ||
|
||
def changeset(socials, attrs) do | ||
socials | ||
|> cast(attrs, @optional_fields) | ||
|> validate_format(:website, ~r{^https?://}, message: "must start with http:// or https://") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,127 @@ | ||
defmodule AtomicWeb.PartnerLive.Edit do | ||
use AtomicWeb, :live_view | ||
|
||
alias Atomic.Organizations.Partner | ||
alias Atomic.Partners | ||
alias Phoenix.LiveView.JS | ||
|
||
@impl true | ||
def mount(_params, _session, socket) do | ||
{:ok, socket} | ||
end | ||
|
||
@impl true | ||
def handle_params(%{"id" => partner_id} = _params, _, socket) do | ||
def handle_params( | ||
%{"id" => partner_id} = _params, | ||
_, | ||
%{:assigns => %{:live_action => :edit}} = socket | ||
) do | ||
partner = Partners.get_partner!(partner_id) | ||
|
||
{:noreply, | ||
socket | ||
|> assign(:page_title, partner.name) | ||
|> assign(:action, nil) | ||
|> assign(:partner, partner) | ||
|> assign(:current_page, :partner)} | ||
|> assign(:current_page, :partners)} | ||
end | ||
|
||
@impl true | ||
def handle_params(_params, _, %{:assigns => %{:live_action => :new}} = socket) do | ||
{:noreply, | ||
socket | ||
|> assign(:page_title, "New Partner") | ||
|> assign(:action, nil) | ||
|> assign(:partner, %Partner{organization_id: socket.assigns.current_organization.id}) | ||
|> assign(:current_page, :partners)} | ||
end | ||
|
||
@impl true | ||
def handle_event("set-action", %{"action" => action}, socket) do | ||
{:noreply, assign(socket, :action, action |> String.to_atom())} | ||
end | ||
|
||
@impl true | ||
def handle_event("clear-action", _params, socket) do | ||
{:noreply, assign(socket, :action, nil)} | ||
end | ||
|
||
@impl true | ||
def handle_event("confirm-action", _params, %{assigns: %{action: :delete}} = socket) do | ||
partner = socket.assigns.partner | ||
organization_id = partner.organization_id | ||
|
||
case Partners.delete_partner(partner) do | ||
{:ok, _partner} -> | ||
{:noreply, | ||
socket | ||
|> put_flash(:success, "Partner deleted successfully") | ||
|> push_redirect(to: Routes.partner_index_path(socket, :index, organization_id))} | ||
|
||
{:error, _reason} -> | ||
{:noreply, put_flash(socket, :error, "Failed to delete partner")} | ||
end | ||
end | ||
|
||
@impl true | ||
def handle_event("confirm-action", _params, %{assigns: %{action: :archive}} = socket) do | ||
partner = socket.assigns.partner | ||
organization_id = partner.organization_id | ||
|
||
case Partners.archive_partner(partner) do | ||
{:ok, _partner} -> | ||
{:noreply, | ||
socket | ||
|> put_flash(:success, "Partner archived successfully") | ||
|> push_redirect(to: Routes.partner_index_path(socket, :index, organization_id))} | ||
|
||
{:error, _reason} -> | ||
{:noreply, put_flash(socket, :error, "Failed to delete partner")} | ||
end | ||
end | ||
|
||
def handle_event("confirm-action", _params, %{assigns: %{action: :unarchive}} = socket) do | ||
partner = socket.assigns.partner | ||
organization_id = partner.organization_id | ||
|
||
case Partners.unarchive_partner(partner) do | ||
{:ok, _partner} -> | ||
{:noreply, | ||
socket | ||
|> put_flash(:success, "Partner archived successfully") | ||
|> push_redirect(to: Routes.partner_index_path(socket, :index, organization_id))} | ||
|
||
{:error, _reason} -> | ||
{:noreply, put_flash(socket, :error, "Failed to delete partner")} | ||
end | ||
end | ||
|
||
defp display_action_goal_confirm_title(action) do | ||
case action do | ||
:archive -> | ||
gettext("Are you sure you want to archive this partner?") | ||
|
||
:unarchive -> | ||
gettext("Are you sure you want to unarchive this partner?") | ||
|
||
:delete -> | ||
gettext("Are you sure you want do delete this partner?") | ||
end | ||
end | ||
|
||
defp display_action_goal_confirm_description(action, partner) do | ||
case action do | ||
:archive -> | ||
gettext("You can always change you mind later and make it public again.") | ||
|
||
:unarchive -> | ||
gettext("This will make it so that any person can view this partner.") | ||
|
||
:delete -> | ||
gettext( | ||
"This will permanently delete %{partner_name}, this action is not reversible.", | ||
partner_name: partner.name | ||
) | ||
end | ||
end | ||
end |
Oops, something went wrong.