diff --git a/lib/algora_web/live/onboarding/dev.ex b/lib/algora_web/live/onboarding/dev.ex index f345be9af..0ea9b1055 100644 --- a/lib/algora_web/live/onboarding/dev.ex +++ b/lib/algora_web/live/onboarding/dev.ex @@ -1,14 +1,62 @@ defmodule AlgoraWeb.Onboarding.DevLive do @moduledoc false use AlgoraWeb, :live_view + use LiveSvelte.Components + import Ecto.Changeset import Ecto.Query + alias Algora.Accounts.User + alias Algora.Github alias Algora.Payments.Transaction alias Algora.Repo alias AlgoraWeb.Components.Logos + require Logger + + @steps [:info, :oauth] + + defmodule InfoForm do + @moduledoc false + use Ecto.Schema + + import Ecto.Changeset + + @primary_key false + embedded_schema do + field :tech_stack, {:array, :string} + field :intentions, {:array, :string} + end + + def init do + to_form(InfoForm.changeset(%InfoForm{}, %{tech_stack: [], intentions: []})) + end + + def changeset(form, attrs) do + form + |> cast(attrs, [:tech_stack, :intentions]) + |> validate_required(:tech_stack, message: "Please select at least one technology") + |> validate_required(:intentions, message: "Please select at least one intention") + |> validate_length(:tech_stack, min: 1, message: "Please enter at least one technology") + |> validate_length(:intentions, min: 1, message: "Please select at least one intention") + |> validate_subset(:intentions, Enum.map(intentions_options(), &elem(&1, 0))) + end + + def intentions_options do + [ + {"bounties", "Solve Bounties", "Work on open source issues and earn rewards", "tabler-diamond"}, + {"jobs", "Find Full-time Work", "Get matched with companies hiring developers", "tabler-briefcase"}, + {"contracts", "Freelance Work", "Take on flexible contract-based projects", "tabler-clock"} + ] + end + end + + @impl true def mount(_params, _session, socket) do + if connected?(socket) do + Phoenix.PubSub.subscribe(Algora.PubSub, "auth:#{socket.id}") + end + context = %{ country: socket.assigns.current_country, tech_stack: [], @@ -37,179 +85,185 @@ defmodule AlgoraWeb.Onboarding.DevLive do {:ok, socket - |> assign(:step, 1) - |> assign(:total_steps, 2) + |> assign(:step, Enum.at(@steps, 0)) + |> assign(:steps, @steps) + |> assign(:total_steps, length(@steps)) |> assign(:context, context) - |> assign(:transactions, transactions)} + |> assign(:transactions, transactions) + |> assign(:info_form, InfoForm.init())} end + @impl true def render(assigns) do ~H"""
No completed bounties available
- <% else %> - <%= for transaction <- @transactions do %> -Select the technologies you work with
- -Select the technologies you work with
+ + <.TechStack + class="mt-4" + tech={get_field(@info_form.source, :tech_stack) || []} + socket={@socket} + form="info_form" /> -Select all that apply
- -No completed bounties available
+ <% else %> + <%= for transaction <- @transactions do %> +