From 1d7e88f6526dbdaedb1aa338949577f19edd2f85 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luis=20Ara=C3=BAjo?= <l.araujoo.1996@gmail.com>
Date: Tue, 28 Jun 2022 16:57:24 +0100
Subject: [PATCH] Connect recruiter to companies

---
 .../live/app/profile_live/form_component.ex        | 14 +++++++++++++-
 .../live/app/profile_live/form_component.html.heex |  8 ++++++++
 .../live/backoffice/accounts/user_live/new.ex      |  2 +-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/lib/parzival_web/live/app/profile_live/form_component.ex b/lib/parzival_web/live/app/profile_live/form_component.ex
index 1bc8d756..22ea193f 100644
--- a/lib/parzival_web/live/app/profile_live/form_component.ex
+++ b/lib/parzival_web/live/app/profile_live/form_component.ex
@@ -4,6 +4,7 @@ defmodule ParzivalWeb.App.ProfileLive.FormComponent do
 
   alias Parzival.Accounts
   alias Parzival.Accounts.User
+  alias Parzival.Companies
 
   @extensions_whitelist ~w(.jpg .jpeg .gif .png)
   @cycles [:Bachelors, :Masters, :Phd]
@@ -27,7 +28,8 @@ defmodule ParzivalWeb.App.ProfileLive.FormComponent do
      |> assign(assigns)
      |> assign(:user, user)
      |> assign(:cycles, @cycles)
-     |> assign(:changeset, changeset)}
+     |> assign(:changeset, changeset)
+     |> assign(list_companies(assigns))}
   end
 
   @impl true
@@ -98,4 +100,14 @@ defmodule ParzivalWeb.App.ProfileLive.FormComponent do
         {:ok, user}
     end
   end
+
+  defp list_companies(params) do
+    case Companies.list_companies(params) do
+      {:ok, {companies, _meta}} ->
+        %{companies: companies}
+
+      {:error, _flop} ->
+        %{companies: []}
+    end
+  end
 end
diff --git a/lib/parzival_web/live/app/profile_live/form_component.html.heex b/lib/parzival_web/live/app/profile_live/form_component.html.heex
index c50b54f3..6816b822 100644
--- a/lib/parzival_web/live/app/profile_live/form_component.html.heex
+++ b/lib/parzival_web/live/app/profile_live/form_component.html.heex
@@ -118,6 +118,14 @@
               <%= text_input(f, :website, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm text-sm border-gray-300 rounded-md") %>
             </dd>
           </div>
+          <%= if @role in [:recruiter] && @current_user.role in [:admin] do %>
+            <div class="sm:col-span-1">
+              <dt class="text-sm font-medium text-gray-500">Company</dt>
+              <dd class="flex flex-row gap-x-4 mt-1 text-sm text-gray-900">
+                <%= select(f, :company_id, Enum.map(@companies, &{&1.name, &1.id}), prompt: "Choose a Sponsorship Level", selected: f.data.company_id, class: "mt-1 focus:ring-red-500 focus:border-red-500 block w-full shadow-sm text-sm border-gray-300 rounded-md") %>
+              </dd>
+            </div>
+          <% end %>
         </dl>
         <dl class="grid grid-cols-1 gap-4 py-6 px-4 border-b border-gray-200 sm:grid-cols-2 sm:px-6 lg:px-8">
           <div class="sm:col-span-1">
diff --git a/lib/parzival_web/live/backoffice/accounts/user_live/new.ex b/lib/parzival_web/live/backoffice/accounts/user_live/new.ex
index 7f70f0f2..f1d7bf63 100644
--- a/lib/parzival_web/live/backoffice/accounts/user_live/new.ex
+++ b/lib/parzival_web/live/backoffice/accounts/user_live/new.ex
@@ -16,7 +16,7 @@ defmodule ParzivalWeb.Backoffice.UserLive.New do
         "admin" -> :admin
         "staff" -> :staff
         "attendee" -> :attendee
-        "company" -> :company
+        "recruiter" -> :recruiter
       end
 
     {:noreply,