module Web.View.ApiConsumers.Show where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Web.Routes () data ShowView = ShowView { consumer :: !ApiConsumer , apiKeys :: ![ApiKey] , webhooks :: ![WebhookSubscription] , mManifest :: !(Maybe HubCapabilityManifest) } instance View ShowView where html ShowView { .. } = [hsx|

{consumer.name}

{maybeDescription}
Status
{renderConsumerStatusDetail consumer.isActive}
Rate Limit
{show consumer.rateLimitPerMinute} req/min
Quota
{show consumer.quotaPerDay} req/day
{manifestPanel}

API Keys

New Key
{if null apiKeys then noKeysMsg else keysTable}

Webhook Subscriptions

New Subscription
{if null webhooks then noWebhooksMsg 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} {renderKeyStatus (isJust k.revokedAt)} {renderRevokeLink k} |] webhooksTable = [hsx|
{forEach webhooks renderWebhook}
Event Type Target URL Status
|] renderWebhook wh = [hsx| {wh.eventType} {wh.targetUrl} {renderWebhookStatus wh.isActive} Toggle Delete |] noKeysMsg :: Html noKeysMsg = [hsx|

No keys yet.

|] noWebhooksMsg :: Html noWebhooksMsg = [hsx|

No webhooks yet.

|] renderWebhookStatus :: Bool -> Html renderWebhookStatus True = [hsx|active|] renderWebhookStatus False = [hsx|paused|] renderConsumerStatusDetail :: Bool -> Html renderConsumerStatusDetail True = [hsx|active|] renderConsumerStatusDetail False = [hsx|inactive|] renderKeyStatus :: Bool -> Html renderKeyStatus True = [hsx|revoked|] renderKeyStatus False = [hsx|active|] renderRevokeLink :: ApiKey -> Html renderRevokeLink k | isNothing k.revokedAt = [hsx|Revoke|] | otherwise = mempty