Skip to content

Commit 2855a50

Browse files
committed
add checks for active hiring sub before processing job-related events
1 parent d6b6c91 commit 2855a50

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

lib/algora_web/live/org/job_live.ex

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ defmodule AlgoraWeb.Org.JobLive do
452452
:critical
453453
)
454454

455-
{:noreply, put_flash(socket, :info, "#{dev.provider_login} is invited to an interview")}
455+
{:noreply, put_flash(socket, :info, "Invitation sent!")}
456456
end
457457

458458
@impl true
@@ -461,42 +461,50 @@ defmodule AlgoraWeb.Org.JobLive do
461461
%{"user_id" => user_id, "type" => "contract", "contract_type" => contract_type},
462462
socket
463463
) do
464-
developer = Enum.find(socket.assigns.developers, &(&1.id == user_id))
465-
match = Enum.find(socket.assigns.matches, &(&1.user.id == user_id))
466-
hourly_rate = match[:hourly_rate]
464+
if socket.assigns.current_org.hiring_subscription == :active do
465+
developer = Enum.find(socket.assigns.developers, &(&1.id == user_id))
466+
match = Enum.find(socket.assigns.matches, &(&1.user.id == user_id))
467+
hourly_rate = match[:hourly_rate]
467468

468-
hours_per_week = developer.hours_per_week || 30
469+
hours_per_week = developer.hours_per_week || 30
469470

470-
{:noreply,
471-
socket
472-
|> assign(:main_contract_form_open?, true)
473-
|> assign(
474-
:main_contract_form,
475-
%ContractForm{
476-
contract_type: String.to_existing_atom(contract_type),
477-
contractor: match[:user] || developer
478-
}
479-
|> ContractForm.changeset(%{
480-
amount: if(hourly_rate, do: Money.mult!(hourly_rate, hours_per_week)),
481-
hourly_rate: hourly_rate,
482-
contractor_handle: developer.provider_login,
483-
hours_per_week: hours_per_week,
484-
title: "#{socket.assigns.current_org.name} OSS Development",
485-
description: "Open source contribution to #{socket.assigns.current_org.name} for a week"
486-
})
487-
|> to_form()
488-
)}
471+
{:noreply,
472+
socket
473+
|> assign(:main_contract_form_open?, true)
474+
|> assign(
475+
:main_contract_form,
476+
%ContractForm{
477+
contract_type: String.to_existing_atom(contract_type),
478+
contractor: match[:user] || developer
479+
}
480+
|> ContractForm.changeset(%{
481+
amount: if(hourly_rate, do: Money.mult!(hourly_rate, hours_per_week)),
482+
hourly_rate: hourly_rate,
483+
contractor_handle: developer.provider_login,
484+
hours_per_week: hours_per_week,
485+
title: "#{socket.assigns.current_org.name} OSS Development",
486+
description: "Open source contribution to #{socket.assigns.current_org.name} for a week"
487+
})
488+
|> to_form()
489+
)}
490+
else
491+
{:noreply, push_patch(socket, to: ~p"/#{socket.assigns.job.user.handle}/jobs/#{socket.assigns.job.id}/activate")}
492+
end
489493
end
490494

491495
@impl true
492496
def handle_event("share_opportunity", %{"user_id" => user_id, "type" => type}, socket) do
493-
developer = Enum.find(socket.assigns.developers, &(&1.id == user_id))
497+
if socket.assigns.current_org.hiring_subscription == :active do
498+
developer = Enum.find(socket.assigns.developers, &(&1.id == user_id))
494499

495-
{:noreply,
496-
socket
497-
|> assign(:selected_developer, developer)
498-
|> assign(:share_drawer_type, type)
499-
|> assign(:show_share_drawer, true)}
500+
{:noreply,
501+
socket
502+
|> assign(:selected_developer, developer)
503+
|> assign(:share_drawer_type, type)
504+
|> assign(:show_share_drawer, true)}
505+
else
506+
{:noreply, push_patch(socket, to: ~p"/#{socket.assigns.job.user.handle}/jobs/#{socket.assigns.job.id}/activate")}
507+
end
500508
end
501509

502510
@impl true
@@ -630,12 +638,13 @@ defmodule AlgoraWeb.Org.JobLive do
630638
end
631639

632640
# Sort matches by total contributions (0 if no heatmap) and take top 6
633-
sorted_matches =
641+
sorted_matches =
634642
all_matches
635643
|> Enum.sort_by(fn match ->
636644
heatmap_data = Map.get(heatmaps_map, match.user.id)
637645
total_contributions = if heatmap_data, do: get_in(heatmap_data, ["totalContributions"]) || 0, else: 0
638-
-total_contributions # negative for descending sort
646+
# negative for descending sort
647+
-total_contributions
639648
end)
640649
|> Enum.take(6)
641650

0 commit comments

Comments
 (0)