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}

API Keys

New Key
{if null apiKeys then [hsx|

No keys yet.

|] else keysTable}

Webhook Subscriptions

New Subscription
{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|
{forEach apiKeys renderKey}
Prefix Type Scopes Expires Status
|] 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|
{forEach webhooks renderWebhook}
Event Type Target URL Status
|] renderWebhook wh = [hsx| {wh.eventType} {wh.targetUrl} {if wh.isActive then [hsx|active|] else [hsx|paused|]} Toggle Delete |]