I’m trying to render a live component with assigns but they’re not getting merged into the socket of the live component.
This is the liveview and template passing in profile. I have verified that profile is indeed an assign in the parent liveview.
defmodule HydroplaneWeb.OnboardLive do
use HydroplaneWeb, :live_view
alias Hydroplane.Users
alias Hydroplane.Users.Profile
alias HydroplaneWeb.Onboard.ProfileForm
alias HydroplaneWeb.Onboard.OrganizationForm
def mount(_params, _session, socket) do
{:ok,
socket
|> assign_profile()}
end
defp assign_profile(%{assigns: %{current_account: current_account}} = socket) do
profile =
case Users.get_profile_for_account(current_account) do
nil -> %Profile{}
profile -> profile
end
assign(socket, :profile, profile)
end
end
<div class="flex items-center justify-center h-screen">
<div class="bg-white w-full max-w-md flex flex-col shadow rounded-lg p-4 text-slate-900">
<h1 class="text-3xl text-slate-800 text-center font-bold">We're glad you can join us!</h1>
<p class="mt-3 mb-3 text-center">There are just a few things you need to take care of in order to make the best use of Hydroplane.</p>
<.live_component module={ProfileForm} id="profile-form" profile={@profile} />
</div>
</div>
And this is where I am trying to access profile but I’m getting an empty assigns with no profile key. Because of this, I’m getting a no function clause matching error.
defmodule HydroplaneWeb.Onboard.ProfileForm do
use HydroplaneWeb, :live_component
alias Hydroplane.Users
alias Hydroplane.Users.Profile
def mount(socket) do
{:ok, assign_changeset(socket)}
end
defp assign_changeset(%{assigns: %{profile: profile}} = socket) do
assign(socket, :changeset, Profile.changeset(profile))
end
end