module Web.View.StewardshipRoles.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Web.Routes ()
data IndexView = IndexView
{ roles :: ![StewardshipRole]
, hubs :: ![Hub]
}
instance View IndexView where
html IndexView { .. } = [hsx|
{renderRolesSection hubGroups}
|]
where
hubGroups = groupByHub hubs roles
groupByHub :: [Hub] -> [StewardshipRole] -> [(Hub, [StewardshipRole])]
groupByHub hs rs =
[ (h, filter (\r -> r.hubId == h.id) rs)
| h <- hs
, any (\r -> r.hubId == h.id) rs
]
renderHubGroup :: (Hub, [StewardshipRole]) -> Html
renderHubGroup (hub, hubRoles) = [hsx|
{hub.name}
| Role |
Assigned To |
Granted |
Status |
|
{forEach hubRoles renderRoleRow}
|]
renderRoleRow :: StewardshipRole -> Html
renderRoleRow r = [hsx|
| {r.roleName} |
{r.assignedTo} |
{show r.grantedAt} |
{renderRoleStatus (isNothing r.revokedAt)}
|
View
|
|]
renderRolesSection :: [(Hub, [StewardshipRole])] -> Html
renderRolesSection [] = [hsx|No stewardship roles assigned yet.
|]
renderRolesSection groups = [hsx|
{forEach groups renderHubGroup}
|]
renderRoleStatus :: Bool -> Html
renderRoleStatus True = [hsx|active|]
renderRoleStatus False = [hsx|revoked|]