# Upgrade Prompt

> Explains a plan limit and offers what to do next.

Page: https://uicontext.com/docs/components/upgrade-prompt

Group: Settings.

## When to use

Explains a plan limit and offers what to do next. Use [Usage](https://uicontext.com/docs/components/usage.md) instead when you show how much has been used.

## Usage

```ts
import { Gate } from "./ui/uicontext/components/Gate.ts"

const Message = UiSchema.TaggedEnum({ ClickedUpgrade: {} })

export const SeatLimit = (h: Html.H<typeof Message.Type>, used: number, limit: number) =>
	Gate(h, {
		props: {
			feature: "Inviting members",
			kind: "limit",
			limit: { used, limit, unit: "seats" },
			needs: "more seats",
			action: { label: "Add seats" },
		},
		onEmit: { RequestedAction: () => Message.ClickedUpgrade(), RequestedSecondary: () => undefined },
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A limit reached

Says what's used of what, what lifts it, and the next step; once asked, it says the request is waiting.

```ts title="src/demo.ts" source="www/src/examples/upgrade-prompt/demo.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { Gate } from "./ui/uicontext/components/Gate.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ frame: { inlineSize: "min(100%, 32rem)" } })

const Message = UiSchema.TaggedEnum({ Asked: {} })

export const WorkflowLimit = Html.component({
	name: "WorkflowLimit",
	model: Schema.Boolean,
	message: Message,
}).make({
	init: () => false,
	update: { Asked: () => true },
	view: (h, asked) =>
		h.div.attrs(sx(styles.frame)).children(
			Gate(h, {
				props: {
					agentId: "gate-workflows",
					feature: "New workflows",
					kind: "limit",
					limit: { used: 5, limit: 5, unit: "workflows" },
					needs: "the Team plan",
					detail: "Free includes 5 workflows. Team has no limit, and adds paths and version history.",
					status: asked ? "requested" : "locked",
					action: { label: "Ask an admin to upgrade" },
					secondary: { label: "Compare plans", href: "#plans" },
				},
				onEmit: { RequestedAction: () => Message.Asked(), RequestedSecondary: () => undefined },
			}),
		),
})
```

### Banner and inline

A banner over a screen when a limit stops work; one line beside a control a role keeps from this person.

```ts title="src/inline.ts" source="www/src/examples/upgrade-prompt/inline.ts"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { Gate } from "./ui/uicontext/components/Gate.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { space } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({ frame: { inlineSize: "min(100%, 40rem)", display: "flex", flexDirection: "column", gap: space.lg } })

export const GateLayouts = Html.component({
	name: "GateLayouts",
	model: Schema.Struct({}),
	message: Schema.Never,
}).make({
	init: () => ({}),
	update: ($) => $.model,
	view: (h) =>
		h.div.attrs(sx(styles.frame)).children(
			Gate(h, {
				key: "banner",
				props: {
					agentId: "gate-banner",
					feature: "Runs",
					kind: "limit",
					limit: { used: 20_000, limit: 20_000, unit: "tasks" },
					detail: "New runs are paused until Dec 1. Running work finishes.",
					action: { label: "Upgrade" },
					layout: "banner",
				},
				onEmit: { RequestedAction: () => undefined, RequestedSecondary: () => undefined },
			}),
			Gate(h, {
				key: "role",
				props: {
					agentId: "gate-inline",
					feature: "Publishing",
					kind: "role",
					needs: "an admin",
					layout: "inline",
				},
				onEmit: { RequestedAction: () => undefined, RequestedSecondary: () => undefined },
			}),
		),
})
```

## API reference

**Props**

| Name | Type | Description |
| --- | --- | --- |
| `agentId` | `string` | This gate's id for agents, unique on the page: "gate-private-teams" |
| `feature` (required) | `string` | What is gated, as a noun phrase: "Private teams" |
| `kind` (required) | `"plan" \| "addon" \| "role" \| "region" \| "limit" \| "waitlist"` | What kind of gate, for the default sentence |
| `needs` | `string` | What lifts it, as the sentence's object: "the Business plan", "an admin", "the AI add-on" |
| `limit` | `{ used, limit, unit }` | For a limit: the count against it |
| `status` | `"locked" \| "requested" \| "waitlisted" \| "invited"` | Where the person stands: locked, asked an admin already, on the waitlist, or invited |
| `sentence` | `string` | Replaces the default sentence |
| `detail` | `string` | A second line: what the plan adds, or when the limit resets |
| `action` | `GateAction` | The next step: "Upgrade", "Ask an admin", "Join the waitlist" |
| `secondary` | `GateAction` | A second, quieter step: "Compare plans" |
| `layout` | `"card" \| "banner" \| "inline"` | A card in place of the feature, a banner over a screen, or one line beside a control |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedAction` | `{}` | The next step was pressed: upgrade, ask an admin, join the waitlist |
| `RequestedSecondary` | `{}` | The second step was pressed |

**Agent actions**

| Action | Description |
| --- | --- |
| `ClickedAction` | Take the gate's next step (its `action`: upgrade, ask an admin, join a waitlist) |
| `ClickedSecondary` | Take the gate's second step (its `secondary`) |

## Keyboard and accessibility

- The prompt is a note beside the feature, or a named region over a screen, with its next step as a real button or link.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/upgrade-prompt
```

With npm: `npx shadcn@latest add checkfu/uicontext/upgrade-prompt`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/upgrade-prompt`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/upgrade-prompt`.

It writes these files:

- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Gate.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/Gate.ts](https://github.com/checkfu/uicontext/blob/main/src/Gate.ts)

## Related

- [Sign-in Form](https://uicontext.com/docs/components/sign-in-form.md) (`sign-in-form`): Sign in, accept an invitation and manage sessions.
- [Settings](https://uicontext.com/docs/components/settings.md) (`settings`): A settings page with sections, fields and a save bar.
- [Env Editor](https://uicontext.com/docs/components/env-editor.md) (`env-editor`): Names and values such as API keys and URLs, one row each: secrets hidden, a pasted .env file split into rows, mistakes marked.
- [Setting List](https://uicontext.com/docs/components/setting-list.md) (`setting-list`): Settings as rows, each with its control.
- [Inherited Settings](https://uicontext.com/docs/components/inherited-settings.md) (`inherited-settings`): Settings that a workspace sets and a team or project can override.
- [Members](https://uicontext.com/docs/components/members.md) (`members`): Workspace members, their roles and pending invitations.
