From 59cc87cd97ccf494db8eabbdf13e04a64c0c7095 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 7 May 2025 19:05:22 +0300 Subject: [PATCH] Update AuthorRole and SelectedAuthor component to require Author. --- .../metadata/author_role.ex | 6 ++--- .../my_components/selected_author.ex | 22 +++++++++++++++++-- .../live/book_live/form_component.ex | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/decentralised_book_index/metadata/author_role.ex b/lib/decentralised_book_index/metadata/author_role.ex index 45eb4b1..80bb2c8 100644 --- a/lib/decentralised_book_index/metadata/author_role.ex +++ b/lib/decentralised_book_index/metadata/author_role.ex @@ -27,7 +27,7 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do create :create do primary? true accept [:id, :order, :role] - argument :author_id, :uuid + argument :author_id, :uuid, allow_nil?: false change fn changeset, _ -> author_id = @@ -57,7 +57,7 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do update :update do primary? true accept [:order, :role] - argument :author_id, :uuid, allow_nil?: true + argument :author_id, :uuid, allow_nil?: false require_atomic? false change fn changeset, _ -> @@ -121,7 +121,7 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do end belongs_to :author, Metadata.Author do - allow_nil? true + allow_nil? false public? true end end diff --git a/lib/decentralised_book_index_web/components/my_components/selected_author.ex b/lib/decentralised_book_index_web/components/my_components/selected_author.ex index 2d3eb47..6f3dfc0 100644 --- a/lib/decentralised_book_index_web/components/my_components/selected_author.ex +++ b/lib/decentralised_book_index_web/components/my_components/selected_author.ex @@ -2,6 +2,8 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.SelectedAuthor do use Phoenix.Component use DecentralisedBookIndexWeb, :verified_routes + alias DecentralisedBookIndexWeb.CoreComponents + attr :author_form, :map, default: nil attr :form_path, :string, default: "" attr :class, :string, default: "" @@ -16,16 +18,32 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.SelectedAuthor do DecentralisedBookIndex.Metadata.get_author_by_id!(author_id) end - assigns = assign(assigns, :author, author) + errors = + if Phoenix.Component.used_input?(assigns.author_form), do: assigns.author_form.errors, else: [] + IO.inspect("errors") + IO.inspect(errors) + + assigns = + assigns + |> assign(:author, author) + |> assign(:errors, Enum.map(errors, &CoreComponents.translate_error(&1))) ~H""" - + + {msg} """ end end diff --git a/lib/decentralised_book_index_web/live/book_live/form_component.ex b/lib/decentralised_book_index_web/live/book_live/form_component.ex index 3d2c87c..ea2e53b 100644 --- a/lib/decentralised_book_index_web/live/book_live/form_component.ex +++ b/lib/decentralised_book_index_web/live/book_live/form_component.ex @@ -236,7 +236,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do - <.input field={author_roles_form[:author_id]} type="hidden" /> + <.input field={author_roles_form[:author_id]} type="hidden" show_errors?={false} /> <.selected_author author_form={author_roles_form[:author_id]} notify_component={@notify_component}