Fix
This commit is contained in:
parent
fef1f17938
commit
51092490b8
2 changed files with 11 additions and 5 deletions
|
@ -61,11 +61,15 @@ defmodule ChoreTracker.Chores do
|
|||
end
|
||||
|
||||
def change_chore(%Chore{} = chore, attrs \\ %{}) do
|
||||
assignees = Accounts.list_users_by_id(attrs["assignee_ids"])
|
||||
|
||||
chore
|
||||
|> Chore.changeset(attrs)
|
||||
|> Changeset.put_assoc(:assignees, assignees)
|
||||
|> then(fn changeset ->
|
||||
if ids = attrs["assignee_ids"] do
|
||||
Changeset.put_assoc(changeset, :assignees, Accounts.list_users_by_id(ids))
|
||||
else
|
||||
changeset
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
def change_chore_assignee(%Chore{} = chore, user) do
|
||||
|
|
|
@ -75,6 +75,8 @@ defmodule ChoreTrackerWeb.ChoreLive.FormComponent do
|
|||
end
|
||||
|
||||
defp save_chore(socket, :edit, chore_params) do
|
||||
chore_params = Map.merge(%{"assignee_ids" => []}, chore_params)
|
||||
|
||||
case Chores.update_chore(socket.assigns.chore, chore_params) do
|
||||
{:ok, chore} ->
|
||||
notify_parent({:saved, chore})
|
||||
|
@ -109,8 +111,8 @@ defmodule ChoreTrackerWeb.ChoreLive.FormComponent do
|
|||
defp user_options(form) do
|
||||
existing_ids =
|
||||
form.source
|
||||
|> Ecto.Changeset.get_change(:assignees, [])
|
||||
|> Enum.map(& &1.data.id)
|
||||
|> Ecto.Changeset.get_field(:assignees)
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
Accounts.list_users()
|
||||
|> Enum.map(&[key: Accounts.display_user(&1), value: &1.id, selected: &1.id in existing_ids])
|
||||
|
|
Loading…
Reference in a new issue