refactor: integrate approval ui review changes
This commit is contained in:
parent
28f97184b3
commit
f53a3ce3cc
13 changed files with 153 additions and 139 deletions
47
lib/mv_web/live/join_request_live/helpers.ex
Normal file
47
lib/mv_web/live/join_request_live/helpers.ex
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
defmodule MvWeb.JoinRequestLive.Helpers do
|
||||
@moduledoc """
|
||||
Shared helpers for JoinRequest LiveViews (Index, Show): status display,
|
||||
badge variants, and reviewer display.
|
||||
"""
|
||||
use Gettext, backend: MvWeb.Gettext
|
||||
|
||||
@doc "Human-readable label for a join request status atom."
|
||||
def format_status(:pending_confirmation), do: gettext("Pending confirmation")
|
||||
def format_status(:submitted), do: gettext("Submitted")
|
||||
def format_status(:approved), do: gettext("Approved")
|
||||
def format_status(:rejected), do: gettext("Rejected")
|
||||
def format_status(other), do: to_string(other)
|
||||
|
||||
@doc "Badge variant for the status (used with CoreComponents.badge)."
|
||||
def status_badge_variant(:submitted), do: :info
|
||||
def status_badge_variant(:approved), do: :success
|
||||
def status_badge_variant(:rejected), do: :error
|
||||
def status_badge_variant(_), do: :neutral
|
||||
|
||||
@doc """
|
||||
Returns the reviewer display string (e.g. email) for a join request, or nil if none.
|
||||
|
||||
Accepts a join request struct or map with optional :reviewed_by_user (loaded User struct).
|
||||
"""
|
||||
def reviewer_display(req) when is_map(req) do
|
||||
user = Map.get(req, :reviewed_by_user)
|
||||
|
||||
case user do
|
||||
nil ->
|
||||
nil
|
||||
|
||||
%{email: email} when is_binary(email) ->
|
||||
s = String.trim(email)
|
||||
if s == "", do: nil, else: s
|
||||
|
||||
%{"email" => email} when is_binary(email) ->
|
||||
s = String.trim(email)
|
||||
if s == "", do: nil, else: s
|
||||
|
||||
_ ->
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def reviewer_display(_), do: nil
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue