module Web.View.ApiConsumers.Show where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
data ShowView = ShowView
{ consumer :: !ApiConsumer
, apiKeys :: ![ApiKey]
, webhooks :: ![WebhookSubscription]
, mManifest :: !(Maybe HubCapabilityManifest)
}
instance View ShowView where
html ShowView { .. } = [hsx|
{consumer.name}
{maybeDescription}
Status
{if consumer.isActive
then [hsx|
active|]
else [hsx|
inactive|]}
Rate Limit
{show consumer.rateLimitPerMinute} req/min
Quota
{show consumer.quotaPerDay} req/day
{manifestPanel}
{if null apiKeys
then [hsx|
No keys yet.
|]
else keysTable}
{if null webhooks
then [hsx|
No webhooks yet.
|]
else webhooksTable}
|]
where
maybeDescription = case consumer.description of
Just d -> [hsx|{d}
|]
Nothing -> mempty
manifestPanel = case mManifest of
Nothing -> mempty
Just m -> [hsx|
Hub Capability Manifest
{m.manifestVersion} — {m.status}
|]
keysTable = [hsx|
| Prefix |
Type |
Scopes |
Expires |
Status |
|
{forEach apiKeys renderKey}
|]
renderKey k = [hsx|
| {k.keyPrefix}... |
{k.tokenType} |
{if k.scopes == "" then "–" else k.scopes} |
{maybe "never" show k.expiresAt} |
{if isJust k.revokedAt
then [hsx|revoked|]
else [hsx|active|]}
|
{if isNothing k.revokedAt
then [hsx|Revoke|]
else mempty}
|
|]
webhooksTable = [hsx|
| Event Type |
Target URL |
Status |
|
{forEach webhooks renderWebhook}
|]
renderWebhook wh = [hsx|
| {wh.eventType} |
{wh.targetUrl} |
{if wh.isActive
then [hsx|active|]
else [hsx|paused|]}
|
Toggle
Delete
|
|]