Skip to content

Commit f1415f4

Browse files
committed
tab state in url
1 parent e813a35 commit f1415f4

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

lib/algora_web/live/org/job_live.ex

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule AlgoraWeb.Org.JobLive do
4444
end
4545

4646
@impl true
47-
def mount(%{"org_handle" => handle, "id" => id, "tab" => tab}, _session, socket) do
47+
def mount(%{"org_handle" => handle, "id" => id}, _session, socket) do
4848
case Jobs.get_job_posting(id) do
4949
{:ok, job} ->
5050
if job.user_id == socket.assigns.current_org.id do
@@ -60,7 +60,6 @@ defmodule AlgoraWeb.Org.JobLive do
6060
|> assign(:show_share_drawer, false)
6161
|> assign(:show_payment_drawer, false)
6262
|> assign(:payment_form, to_form(%{"payment_type" => "stripe"}, as: :payment))
63-
|> assign(:current_tab, tab)
6463
|> assign(:bounty_form, to_form(BountyForm.changeset(%BountyForm{}, %{})))
6564
|> assign(:tip_form, to_form(TipForm.changeset(%TipForm{}, %{})))
6665
|> assign(:contract_form, to_form(ContractForm.changeset(%ContractForm{}, %{})))
@@ -96,17 +95,14 @@ defmodule AlgoraWeb.Org.JobLive do
9695
end
9796
end
9897

99-
@impl true
100-
def mount(%{"org_handle" => handle, "id" => id}, _session, socket) do
101-
{:ok, push_navigate(socket, to: ~p"/#{handle}/jobs/#{id}/#{default_tab()}")}
102-
end
103-
10498
@impl true
10599
def handle_params(%{"tab" => "activate"}, _uri, socket) do
106-
{:noreply,
107-
socket
108-
|> assign(:current_tab, default_tab())
109-
|> assign(:show_payment_drawer, true)}
100+
socket =
101+
if socket.assigns.current_org.subscription_price,
102+
do: assign(socket, :show_payment_drawer, true),
103+
else: redirect(socket, external: AlgoraWeb.Constants.get(:calendar_url))
104+
105+
{:noreply, assign_new(socket, :current_tab, fn -> default_tab() end)}
110106
end
111107

112108
@impl true
@@ -121,6 +117,11 @@ defmodule AlgoraWeb.Org.JobLive do
121117
{:noreply, assign(socket, :current_tab, tab)}
122118
end
123119

120+
@impl true
121+
def handle_params(%{"org_handle" => handle, "id" => id}, _uri, socket) do
122+
{:noreply, push_navigate(socket, to: ~p"/#{handle}/jobs/#{id}/#{default_tab()}")}
123+
end
124+
124125
@impl true
125126
def render(assigns) do
126127
~H"""
@@ -241,12 +242,9 @@ defmodule AlgoraWeb.Org.JobLive do
241242
<% "applicants" -> %>
242243
<.section title="Applicants" subtitle="Developers who applied for this position">
243244
<:actions>
244-
<.button variant="secondary" phx-click="toggle_import_drawer">
245+
<.button variant="default" phx-click="toggle_import_drawer">
245246
Import
246247
</.button>
247-
<.button variant="default" phx-click="screen_applicants">
248-
Screen
249-
</.button>
250248
</:actions>
251249
<%= if Enum.empty?(@applicants) do %>
252250
<.card class="rounded-lg bg-card py-12 text-center lg:rounded-[2rem]">
@@ -314,8 +312,8 @@ defmodule AlgoraWeb.Org.JobLive do
314312
<% "matches" -> %>
315313
<.section title="Matches" subtitle="Top developers matching your requirements">
316314
<:actions>
317-
<.button variant="default" phx-click="screen_applicants">
318-
Screen
315+
<.button variant="default" phx-click="toggle_import_drawer">
316+
Import
319317
</.button>
320318
</:actions>
321319
<%= if Enum.empty?(@matches) do %>
@@ -409,7 +407,7 @@ defmodule AlgoraWeb.Org.JobLive do
409407
</div>
410408
<div class="flex flex-col justify-center items-center text-center">
411409
<.button
412-
phx-click="toggle_payment_drawer"
410+
phx-click="show_payment_drawer"
413411
variant="none"
414412
class="group bg-emerald-900/10 text-emerald-300 transition-colors duration-75 hover:bg-emerald-800/10 hover:text-emerald-300 hover:drop-shadow-[0_1px_5px_#34d39980] focus:bg-emerald-800/10 focus:text-emerald-300 focus:outline-none focus:drop-shadow-[0_1px_5px_#34d39980] border border-emerald-400/40 hover:border-emerald-400/50 focus:border-emerald-400/50 h-[8rem]"
415413
size="xl"
@@ -536,13 +534,8 @@ defmodule AlgoraWeb.Org.JobLive do
536534
end
537535

538536
@impl true
539-
def handle_event("toggle_payment_drawer", _, socket) do
540-
socket =
541-
if socket.assigns.current_org.subscription_price,
542-
do: assign(socket, :show_payment_drawer, !socket.assigns.show_payment_drawer),
543-
else: redirect(socket, external: AlgoraWeb.Constants.get(:calendar_url))
544-
545-
{:noreply, socket}
537+
def handle_event("show_payment_drawer", _, socket) do
538+
{:noreply, push_patch(socket, to: ~p"/#{socket.assigns.job.user.handle}/jobs/#{socket.assigns.job.id}/activate")}
546539
end
547540

548541
@impl true
@@ -673,7 +666,10 @@ defmodule AlgoraWeb.Org.JobLive do
673666

674667
@impl true
675668
def handle_event("close_payment_drawer", _, socket) do
676-
{:noreply, assign(socket, :show_payment_drawer, false)}
669+
{:noreply,
670+
socket
671+
|> assign(:show_payment_drawer, false)
672+
|> push_patch(to: ~p"/#{socket.assigns.job.user.handle}/jobs/#{socket.assigns.job.id}/#{socket.assigns.current_tab}")}
677673
end
678674

679675
@impl true

0 commit comments

Comments
 (0)