Update AuthorRole and SelectedAuthor component to require Author.
This commit is contained in:
@@ -27,7 +27,7 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
|
|||||||
create :create do
|
create :create do
|
||||||
primary? true
|
primary? true
|
||||||
accept [:id, :order, :role]
|
accept [:id, :order, :role]
|
||||||
argument :author_id, :uuid
|
argument :author_id, :uuid, allow_nil?: false
|
||||||
|
|
||||||
change fn changeset, _ ->
|
change fn changeset, _ ->
|
||||||
author_id =
|
author_id =
|
||||||
@@ -57,7 +57,7 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
|
|||||||
update :update do
|
update :update do
|
||||||
primary? true
|
primary? true
|
||||||
accept [:order, :role]
|
accept [:order, :role]
|
||||||
argument :author_id, :uuid, allow_nil?: true
|
argument :author_id, :uuid, allow_nil?: false
|
||||||
require_atomic? false
|
require_atomic? false
|
||||||
|
|
||||||
change fn changeset, _ ->
|
change fn changeset, _ ->
|
||||||
@@ -121,7 +121,7 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
|
|||||||
end
|
end
|
||||||
|
|
||||||
belongs_to :author, Metadata.Author do
|
belongs_to :author, Metadata.Author do
|
||||||
allow_nil? true
|
allow_nil? false
|
||||||
public? true
|
public? true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.SelectedAuthor do
|
|||||||
use Phoenix.Component
|
use Phoenix.Component
|
||||||
use DecentralisedBookIndexWeb, :verified_routes
|
use DecentralisedBookIndexWeb, :verified_routes
|
||||||
|
|
||||||
|
alias DecentralisedBookIndexWeb.CoreComponents
|
||||||
|
|
||||||
attr :author_form, :map, default: nil
|
attr :author_form, :map, default: nil
|
||||||
attr :form_path, :string, default: ""
|
attr :form_path, :string, default: ""
|
||||||
attr :class, :string, default: ""
|
attr :class, :string, default: ""
|
||||||
@@ -16,16 +18,32 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.SelectedAuthor do
|
|||||||
DecentralisedBookIndex.Metadata.get_author_by_id!(author_id)
|
DecentralisedBookIndex.Metadata.get_author_by_id!(author_id)
|
||||||
end
|
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"""
|
~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 %>
|
<%= if @author != nil do %>
|
||||||
{@author.name}
|
{@author.name}
|
||||||
<% else %>
|
<% else %>
|
||||||
Select an author
|
Select an author
|
||||||
<% end %>
|
<% end %>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<CoreComponents.error :for={msg <- @errors}>{msg}</CoreComponents.error>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
</td>
|
</td>
|
||||||
<td class="px-3 w-48">
|
<td class="px-3 w-48">
|
||||||
<label for={author_roles_form[:author_id].id} class="hidden">Type</label>
|
<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
|
<.selected_author
|
||||||
author_form={author_roles_form[:author_id]}
|
author_form={author_roles_form[:author_id]}
|
||||||
notify_component={@notify_component}
|
notify_component={@notify_component}
|
||||||
|
|||||||
Reference in New Issue
Block a user