Update AuthorRole and SelectedAuthor component to require Author.
This commit is contained in:
@@ -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"""
|
||||
<button type="button" phx-click="open-select-author" phx-target={@notify_component} phx-value-path={@form_path} class={"text-white bg-blue-700 hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 font-medium rounded-full text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 #{@class}"}>
|
||||
<button
|
||||
type="button"
|
||||
phx-click="open-select-author"
|
||||
phx-target={@notify_component}
|
||||
phx-value-path={@form_path}
|
||||
class={"text-white bg-blue-700 hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 font-medium rounded-full text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 #{@class}"}
|
||||
>
|
||||
<%= if @author != nil do %>
|
||||
{@author.name}
|
||||
<% else %>
|
||||
Select an author
|
||||
<% end %>
|
||||
</button>
|
||||
|
||||
<CoreComponents.error :for={msg <- @errors}>{msg}</CoreComponents.error>
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
||||
@@ -236,7 +236,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
||||
</td>
|
||||
<td class="px-3 w-48">
|
||||
<label for={author_roles_form[:author_id].id} class="hidden">Type</label>
|
||||
<.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}
|
||||
|
||||
Reference in New Issue
Block a user