PtahUi.Components.CVUpload (PtahUI v0.1.0)

Copy Markdown View Source

LiveComponent for uploading a Curriculum Vitae (PDF/DOC/DOCX).

The on_save callback receives (path, entry) inside consume_uploaded_entries, so the temp file is guaranteed to exist while the callback runs. It must return {:ok, result} or {:error, message}.

After a successful save the component sends {__MODULE__, {:saved, result}} to the parent LiveView via send/2.

Example

# In the parent LiveView template:
<.live_component
  module={PtahUi.Components.CVUpload}
  id="cv-upload"
  current_file_name={@user.cv && @user.cv.file_name}
  on_save={fn path, entry ->
    MyApp.Accounts.update_user_cv(@user, %{
      "cv" => %Plug.Upload{
        content_type: entry.client_type,
        filename: entry.client_name,
        path: path
      }
    })
  end}
/>

# In the parent LiveView:
@impl true
def handle_info({PtahUi.Components.CVUpload, {:saved, result}}, socket) do
  {:noreply, assign(socket, :current_user, result)}
end

Summary

Functions

render(assigns)

Attributes

  • current_file_name (:string) - Filename of the currently stored CV. Defaults to nil.
  • button_label (:string) - Defaults to "Guardar CV".
  • in_app (:boolean) - Use action_button style instead of standard button. Defaults to false.
  • on_save (:any) (required) - fn(path, entry) :: {:ok, any} | {:error, String.t}.