Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
CorneliaKelinske committed Feb 1, 2025
1 parent 32308b8 commit 790791e
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 173 deletions.
1 change: 1 addition & 0 deletions DELETEME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETEME
11 changes: 9 additions & 2 deletions lib/women_in_tech_vic/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ defmodule WomenInTechVic.Accounts do
|> Actions.all()
end

@spec find_subscribers(Subscription.subscription_type()) :: [pos_integer()]
def find_subscribers(subscription_type) do
@spec find_subscriber_ids(Subscription.subscription_type()) :: [pos_integer()]
def find_subscriber_ids(subscription_type) do
Subscription
|> Subscription.by_subscription_type(subscription_type)
|> Subscription.return_user_ids()
Expand Down Expand Up @@ -646,4 +646,11 @@ defmodule WomenInTechVic.Accounts do
end
end)
end

@spec get_subscribers(Subscription.subscription_type()) :: [User.t()]
def get_subscribers(subscription_type) do
subscription_type
|> find_subscriber_ids()
|> then(&all_users(%{id: &1}))
end
end
8 changes: 1 addition & 7 deletions lib/women_in_tech_vic_web/live/event_live/edit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule WomenInTechVicWeb.EventLive.Edit do
case Content.update_event(socket.assigns.event, event_params) do
{:ok, %Event{} = event} ->
@subscription_type
|> get_subscribers()
|> Accounts.get_subscribers()
|> Enum.each(
&Accounts.deliver_event_update_notification(prep_event_for_display(event), &1, :update)
)
Expand All @@ -77,12 +77,6 @@ defmodule WomenInTechVicWeb.EventLive.Edit do
Map.put(event, :scheduled_at, Utils.utc_timestamp_to_pacific!(scheduled_at))
end

defp get_subscribers(subscription_type) do
subscription_type
|> Accounts.find_subscribers()
|> then(&Accounts.all_users(%{id: &1}))
end

defp prep_event_for_display(%Event{scheduled_at: scheduled_at} = event) do
Map.put(event, :scheduled_at, Utils.timestamp_to_formatted_pacific(scheduled_at))
end
Expand Down
20 changes: 7 additions & 13 deletions lib/women_in_tech_vic_web/live/event_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ defmodule WomenInTechVicWeb.EventLive.Index do

case Content.create_event(event_params) do
{:ok, %Event{} = event} ->
@subscription_type
|> get_subscribers()
|> Enum.each(
Enum.each(
socket.assigns.subscribers,
&Accounts.deliver_event_update_notification(prep_event_for_display(event), &1, :create)
)

Expand All @@ -64,9 +63,10 @@ defmodule WomenInTechVicWeb.EventLive.Index do

case Content.delete_event_by_admin(String.to_integer(event_id), socket.assigns.current_user) do
{:ok, %Event{}} ->
@subscription_type
|> get_subscribers()
|> Enum.each(&Accounts.deliver_event_update_notification(event, &1, :delete))
Enum.each(
socket.assigns.subscribers,
&Accounts.deliver_event_update_notification(event, &1, :delete)
)

{:noreply, assign_events(socket)}

Expand Down Expand Up @@ -115,12 +115,6 @@ defmodule WomenInTechVicWeb.EventLive.Index do
end

defp assign_subscribers(socket) do
assign(socket, :subscribers, get_subscribers(@subscription_type))
end

defp get_subscribers(subscription_type) do
subscription_type
|> Accounts.find_subscribers()
|> then(&Accounts.all_users(%{id: &1}))
assign(socket, :subscribers, Accounts.get_subscribers(@subscription_type))
end
end
8 changes: 1 addition & 7 deletions lib/women_in_tech_vic_web/live/event_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ defmodule WomenInTechVicWeb.EventLive.Show do
case Content.delete_event_by_admin(String.to_integer(event_id), socket.assigns.current_user) do
{:ok, %Event{}} ->
@subscription_type
|> get_subscribers()
|> Accounts.get_subscribers()
|> Enum.each(
&Accounts.deliver_event_update_notification(socket.assigns.event, &1, :delete)
)
Expand Down Expand Up @@ -103,10 +103,4 @@ defmodule WomenInTechVicWeb.EventLive.Show do
defp assign_google_calendar_url(socket, event) do
assign(socket, :google_calendar_url, CalendarHelper.google_calendar_url(event))
end

defp get_subscribers(subscription_type) do
subscription_type
|> Accounts.find_subscribers()
|> then(&Accounts.all_users(%{id: &1}))
end
end
139 changes: 0 additions & 139 deletions lib/women_in_tech_vic_web/live/user_settings_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,145 +6,6 @@ defmodule WomenInTechVicWeb.UserSettingsLive do
@delete_account_form_params %{"password" => nil}
@subscription_types Accounts.all_subscription_types()

def render(assigns) do
~H"""
<section class="relative text-gray-400 min-w-full">
<div
class="absolute inset-0 bg-cover bg-center"
style="background-image: url('/images/code.jpg'); opacity: 0.3;"
>
</div>
<div class="relative p-8 mx-auto max-w-3xl text-right md:text-center font-semibold font-sans text-2xl md:text-3xl md:tracking-widest z-10 text-gray-200">
Account Settings
</div>
</section>
<.link
navigate={~p"/home"}
class="text-gray-200 mb-0 m-8 hover:text-gray-400 font-semibold uppercase flex items-center space-x-1"
>
<.icon name="hero-chevron-double-left" class="h-5 w-5" />
<span>Home</span>
</.link>
<section class="w-full flex justify-center px-6 py-20 lg:px-8">
<div class="w-full max-w-2xl space-y-12 divide-y 6 px-6 pb-12 rounded-lg shadow-md mb-8 border border-gray-300 bg-gradient-to-r from-pink-200 via-gray-100 to-pink-300">
<div>
<.simple_form
for={@subscriptions_form}
id="subscriptions_form"
phx-submit="update_subscriptions"
>
<h3 class="block text font-semibold leading-6 text-zinc-800">
Update your subscriptions
</h3>
<%= for subscription <- @subscription_types do %>
<.input
field={@subscriptions_form[subscription]}
type="checkbox"
name={to_string(subscription)}
value={subscription in @user_subscription_types}
label={subscription |> to_string() |> String.capitalize()}
phx-hook="SubscriptionChangeHook"
/>
<% end %>
<:actions>
<.button
id="save-changes-button"
disabled="true"
class="disabled:pointer-events-none"
phx-disable-with="Changing..."
>
Save Changes
</.button>
</:actions>
</.simple_form>
</div>
<div>
<.simple_form
for={@email_form}
id="email_form"
phx-submit="update_email"
phx-change="validate_email"
>
<.input field={@email_form[:email]} type="email" label="New Email" required />
<.input
field={@email_form[:current_password]}
name="current_password"
id="current_password_for_email"
type="password"
label="Current password"
value={@email_form_current_password}
required
/>
<:actions>
<.button phx-disable-with="Changing...">Change Email</.button>
</:actions>
</.simple_form>
</div>
<div>
<.simple_form
for={@password_form}
id="password_form"
action={~p"/users/log_in?_action=password_updated"}
method="post"
phx-change="validate_password"
phx-submit="update_password"
phx-trigger-action={@trigger_submit}
>
<input
name={@password_form[:email].name}
type="hidden"
id="hidden_user_email"
value={@current_email}
/>
<.input
field={@password_form[:password]}
type="password"
label="New password"
required
phx-debounce
/>
<.input
field={@password_form[:password_confirmation]}
type="password"
label="Confirm new password"
phx-debounce
/>
<.input
field={@password_form[:current_password]}
name="current_password"
type="password"
label="Current password"
id="current_password_for_password"
value={@current_password}
required
/>
<:actions>
<.button phx-disable-with="Changing...">Change Password</.button>
</:actions>
</.simple_form>
</div>
<div>
<.simple_form
for={@delete_account_form}
id="delete_account_form"
phx-submit="delete_account"
>
<.input field={@delete_account_form[:password]} type="password" label="Password" required />
<:actions>
<.button data-confirm="Are you sure?" phx-disable-with="Changing...">
Delete Account
</.button>
</:actions>
</.simple_form>
</div>
</div>
</section>
"""
end

def mount(%{"token" => token}, _session, socket) do
socket =
case Accounts.update_user_email(socket.assigns.current_user, token) do
Expand Down
134 changes: 134 additions & 0 deletions lib/women_in_tech_vic_web/live/user_settings_live.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<section class="relative text-gray-400 min-w-full">
<div
class="absolute inset-0 bg-cover bg-center"
style="background-image: url('/images/code.jpg'); opacity: 0.3;"
>
</div>

<div class="relative p-8 mx-auto max-w-3xl text-right md:text-center font-semibold font-sans text-2xl md:text-3xl md:tracking-widest z-10 text-gray-200">
Account Settings
</div>
</section>
<.link
navigate={~p"/home"}
class="text-gray-200 mb-0 m-8 hover:text-gray-400 font-semibold uppercase flex items-center space-x-1"
>
<.icon name="hero-chevron-double-left" class="h-5 w-5" />
<span>Home</span>
</.link>

<section class="w-full flex justify-center px-6 py-20 lg:px-8">
<div class="w-full max-w-2xl space-y-12 divide-y 6 px-6 pb-12 rounded-lg shadow-md mb-8 border border-gray-300 bg-gradient-to-r from-pink-200 via-gray-100 to-pink-300">
<div>
<.simple_form
for={@subscriptions_form}
id="subscriptions_form"
phx-submit="update_subscriptions"
>
<h3 class="block text font-semibold leading-6 text-zinc-800">
Update your subscriptions
</h3>
<%= for subscription <- @subscription_types do %>
<.input
field={@subscriptions_form[subscription]}
type="checkbox"
name={to_string(subscription)}
value={subscription in @user_subscription_types}
label={subscription |> to_string() |> String.capitalize()}
phx-hook="SubscriptionChangeHook"
/>
<% end %>
<:actions>
<.button
id="save-changes-button"
disabled="true"
class="disabled:pointer-events-none"
phx-disable-with="Changing..."
>
Save Changes
</.button>
</:actions>
</.simple_form>
</div>

<div>
<.simple_form
for={@email_form}
id="email_form"
phx-submit="update_email"
phx-change="validate_email"
>
<.input field={@email_form[:email]} type="email" label="New Email" required />
<.input
field={@email_form[:current_password]}
name="current_password"
id="current_password_for_email"
type="password"
label="Current password"
value={@email_form_current_password}
required
/>
<:actions>
<.button phx-disable-with="Changing...">Change Email</.button>
</:actions>
</.simple_form>
</div>
<div>
<.simple_form
for={@password_form}
id="password_form"
action={~p"/users/log_in?_action=password_updated"}
method="post"
phx-change="validate_password"
phx-submit="update_password"
phx-trigger-action={@trigger_submit}
>
<input
name={@password_form[:email].name}
type="hidden"
id="hidden_user_email"
value={@current_email}
/>
<.input
field={@password_form[:password]}
type="password"
label="New password"
required
phx-debounce
/>
<.input
field={@password_form[:password_confirmation]}
type="password"
label="Confirm new password"
phx-debounce
/>
<.input
field={@password_form[:current_password]}
name="current_password"
type="password"
label="Current password"
id="current_password_for_password"
value={@current_password}
required
/>
<:actions>
<.button phx-disable-with="Changing...">Change Password</.button>
</:actions>
</.simple_form>
</div>
<div>
<.simple_form
for={@delete_account_form}
id="delete_account_form"
phx-submit="delete_account"
>
<.input field={@delete_account_form[:password]} type="password" label="Password" required />
<:actions>
<.button data-confirm="Are you sure?" phx-disable-with="Changing...">
Delete Account
</.button>
</:actions>
</.simple_form>
</div>
</div>
</section>
Loading

0 comments on commit 790791e

Please sign in to comment.