@molecule/app-settings-panel-solid

Feature · settings-panel · App (browser) · v2.0.5 · Apache-2.0

Composable settings panel — a SettingsContainer + family of section sub-components (Account, Auth, Notifications, Billing, Devices, ThisDevice, LogOutDelete). Apps compose via JSX children, picking which sections to include and what order.

npm install @molecule/app-settings-panel-solid

npm · Source on GitHub

How it works

@molecule/app-settings-panel-solid is a ready-made settings-panel feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import {
  AccountSection,
  AppearanceSection,
  AuthSection,
  BillingSection,
  DevicesSection,
  LogOutDeleteSection,
  NotificationsSection,
  SettingsContainer,
  ThisDeviceSection,
} from '@molecule/app-settings-panel-solid'

function SettingsPanel(props: { onClose: () => void }) {
  return (
    <SettingsContainer onClose={props.onClose}>
      <AccountSection />
      <AppearanceSection />
      <AuthSection />
      <NotificationsSection />
      <BillingSection />
      <DevicesSection />
      <ThisDeviceSection />
      <LogOutDeleteSection />
    </SettingsContainer>
  )
}

Works with: @molecule/app-auth, @molecule/app-http, @molecule/app-push, @molecule/app-solid, @molecule/app-ui, @molecule/app-ui-solid, @molecule/app-utilities

Reference

@molecule/app-settings-panel-solid — the Solid counterpart of @molecule/app-settings-panel-react: the same composable, batteries-included settings panel, with the same props, DOM, callbacks, service calls and i18n keys, rendered with Solid.

<SettingsContainer onClose={…}> owns the layout and publishes onClose via context; each section component is independent and loads its own data through hooks:

  • <AccountSection> — name/email edit (PATCH /api/users/:id).
  • <AppearanceSection> — dark-mode toggle (useTheme()).
  • <AuthSection> — password change + TOTP two-factor (POST /api/users/:id/verify-two-factor).
  • <NotificationsSection> — web-push toggle (see the exported enablePushOnCurrentDevice / disablePushOnCurrentDevice helpers and their documented device-row contract).
  • <BillingSection> — read-only plan display (GET /api/billing/status), or <TiersUpgradeSection> — full Stripe upgrade/cancel flow (/api/billing/tiers|checkout|cancel). Use one or the other, not both.
  • <DevicesSection> / <ThisDeviceSection> — device list + current device (GET/DELETE /api/devices).
  • <LogOutDeleteSection> — sign out + delete account (DELETE /api/users/:id). Apps compose via JSX children — pick sections, order them, and interleave custom sections.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import {
  AccountSection,
  AppearanceSection,
  AuthSection,
  BillingSection,
  DevicesSection,
  LogOutDeleteSection,
  NotificationsSection,
  SettingsContainer,
  ThisDeviceSection,
} from '@molecule/app-settings-panel-solid'

function SettingsPanel(props: { onClose: () => void }) {
  return (
    <SettingsContainer onClose={props.onClose}>
      <AccountSection />
      <AppearanceSection />
      <AuthSection />
      <NotificationsSection />
      <BillingSection />
      <DevicesSection />
      <ThisDeviceSection />
      <LogOutDeleteSection />
    </SettingsContainer>
  )
}

Type

feature

Installation

npm install @molecule/app-settings-panel-solid @molecule/app-auth @molecule/app-http @molecule/app-push @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid @molecule/app-utilities solid-js

API

Interfaces

AccountValues

The profile values AccountSection edits (its controlled form fields).

interface AccountValues {
  name: string
  email: string
}

TwoFactorSetup

The two-factor enrollment payload POST /users/:id/verify-two-factor answers with.

interface TwoFactorSetup {
  QRImageUrl?: string
  keyUrl?: string
  secret?: string
}

AuthSectionProps

Options for AuthSection.

interface AuthSectionProps {
  /**
   * Show the two-factor row. Set false when the API has no two-factor provider
   * (no `POST /users/:id/verify-two-factor` route). Default true.
   */
  twoFactor?: boolean
}

DevicesSectionProps

Props for DevicesSection.

interface DevicesSectionProps {
  /**
   * Custom trailing element per device row, replacing the built-in revoke
   * control. Render nothing to suppress the control entirely.
   */
  renderRowIcon?: (device: Device) => JSX.Element
}

SettingsContainerProps

Props for SettingsContainer.

interface SettingsContainerProps {
  /** Dismiss-the-panel handler, published to every section through context. */
  onClose: () => void
  /** The section sub-components to host. */
  children?: JSX.Element
}

TierPrice

One price of a billing tier, mapped from /api/billing/tiers.

interface TierPrice {
  stripePriceId?: string
  interval: string
  priceLabel: string
}

Tier

One paid tier, mapped from /api/billing/tiers.

interface Tier {
  planKey: string
  name: string
  prices: TierPrice[]
}

SettingsPanelContextValue

Context published by <SettingsContainer> to its children.

The container owns the dismiss-the-panel handler; sub-components that need to close after an action (logout, delete account, email error) read it from context rather than threading the prop down.

interface SettingsPanelContextValue {
  /** Dismisses the settings panel (the container's `onClose` prop). */
  onClose: () => void
}

Device

A user's registered device (subset rendered in the settings list).

interface Device {
  /** The device's id on the wire (`DELETE /api/devices/:id`). */
  id: string
  /** The device's display name; may be empty (the platform is shown then). */
  name: string
  /** The device's platform (`ios`, `linux`, …). */
  platform: string
  /** When the device was last seen, as the API renders it. */
  lastSeen?: string
  /** `true` for the device making the current request (the API marks it). */
  isCurrent?: boolean
}

TiersUpgradeSectionProps

Props for TiersUpgradeSection.

interface TiersUpgradeSectionProps {
  /**
   * How the page leaves for the checkout URL the server returns. Defaults to a
   * full-page navigation (`openUrl` from `@molecule/app-utilities`).
   */
  redirectToCheckout?: (checkoutUrl: string) => void
}

PushToggleHttp

Minimal structural slice of @molecule/app-http's HttpClient used here.

interface PushToggleHttp {
  get<T = unknown>(url: string): Promise<{ data: T }>
  patch<T = unknown>(url: string, data?: unknown): Promise<{ data: T }>
}

PushToggleDevice

Device row slice returned by GET /api/devices.

interface PushToggleDevice {
  id: string
  isCurrent?: boolean
  hasPushSubscription?: boolean
}

PushToggleToken

Push token slice returned by @molecule/app-push register().

interface PushToggleToken {
  value: string
  platform: 'web' | 'ios' | 'android'
}

Types

PushToggleFailureReason

Why an enable/disable attempt failed (mapped to i18n by the component).

type PushToggleFailureReason =
  'permission-denied' | 'server-unconfigured' | 'register-failed' | 'persist-failed'

PushToggleResult

Result of an enable/disable attempt.

type PushToggleResult =
  { ok: true } | { ok: false; reason: PushToggleFailureReason; message?: string }

Functions

AccountSection()

Account fields over the shared profile lifecycle. Background validation uses the auth client's configured route, mapping and session ownership guards.

UserProfile.email is optional (phone/handle accounts have none), so email is validated only when non-empty and a blank email is never sent: clearing the field leaves the stored address untouched, and a name-only account can still save its name.

function AccountSection(): JSX.Element

Returns: The account settings section.

AppearanceSection()

Appearance section — dark-mode toggle wired to the theme bond.

Apps that expose other appearance knobs (font size, density, etc.) can either add more sub-components to this package or render their own section in line with <AppearanceSection> via children.

function AppearanceSection(): JSX.Element

Returns: The appearance settings section.

AuthSection(props)

Authentication section — change password (modal) + two-factor (TOTP) setup.

Two-factor uses the real enrollment flow against the user resource's POST /users/:id/verify-two-factor endpoint (@molecule/api-two-factor):

  • Enable → {action:'setup'} returns a QR code + secret to scan into an authenticator app → user enters the 6-digit code → {action:'enable', token}.
  • Disable → user enters a current code → {action:'disable', token}. The current status is read from /users/me. (This replaces the previous boolean toggle, which PATCHed twoFactorEnabled — a field the update handler deliberately ignores — so it never actually enrolled 2FA.)

Auto-hides for OAuth-only users (user.oauthServer truthy) since password / 2FA wouldn't apply. Pass twoFactor={false} when the app's API has no two-factor provider: it then serves no verify-two-factor route, so the section shows only the password change and reads no 2FA status.

function AuthSection(props?: AuthSectionProps): JSX.Element
  • props — The section's options.
  • props.twoFactor — Show the two-factor row (default true).

Returns: The authentication settings section.

BillingSection(props)

Billing section — current plan + Upgrade button.

Fetches /api/billing/status on mount and uses the returned plan name as a more accurate label than the parent-supplied default. The plan prop remains a fallback (e.g. for offline rendering or apps that don't expose /billing/status).

The Upgrade button opens upgradeTo, the app's page for choosing a plan (/pricing, /billing). It has no default: no one route is right for every app, and the settings page this section sits in has no plans to choose. An app with no such page renders <TiersUpgradeSection>, which lists the tiers and starts the checkout itself. A section given no upgradeTo anyway (from JavaScript, or a template the compiler does not check) shows the plan without the button.

function BillingSection(props: {
  /** Fallback plan label until (or unless) `/api/billing/status` answers. */
  plan?: string
  /** The app's page for choosing a plan, which the Upgrade button opens. */
  upgradeTo: string
}): JSX.Element
  • props — Component props.

Returns: The billing section.

DevicesSection(props)

Devices section — lists the user's registered devices and lets them revoke (sign out) any device other than the one they're currently using.

Revoking deletes the device row (DELETE /api/devices/:id). The API's authorization layer enforces server-side revocation: it rejects that device's session the next time it makes a request (within the device-exists cache TTL), so the removed device is actually signed out — not just hidden from the list. The current device is labelled "This device" and is not revocable here (use Sign out for the current session). Recreates molecule v1's device-revocation behaviour.

Apps that want a different trailing element per row can pass a renderRowIcon callback (which then replaces the built-in revoke control); pass () => null to suppress it entirely.

function DevicesSection(props: DevicesSectionProps): JSX.Element
  • props — Component props.

Returns: The devices settings section.

LogOutDeleteSection()

Bottom actions section — Log out + Delete account.

Owns the delete-account modal internally (the trigger lives in the same section so the modal lives here too). Reads onClose from the <SettingsContainer> context to dismiss the panel after either action and navigates to /login.

function LogOutDeleteSection(): JSX.Element

Returns: The bottom actions section.

NotificationsSection()

Push-notification toggle section — the full receive-side enable chain: browser permission → runtime VAPID public key (GET /api/devices/push/public-key) → pushManager.subscribe with applicationServerKey → PATCH the subscription onto the current device row (/api/devices/:id { pushSubscription, hasPushSubscription }), which is where the api-side push fan-outs look for it.

Initial state reflects SERVER truth (the current device row's hasPushSubscription), and every failure surfaces as an honest inline message — a dev build without a service worker fails fast instead of hanging the switch.

function NotificationsSection(): JSX.Element

Returns: The notifications settings section.

SettingsContainer(props)

Outer settings-panel layout: padded vertical stack that hosts the section sub-components. Publishes onClose to descendants via context so <LogOutDeleteSection> etc. can dismiss the panel after an action without explicit prop threading.

function SettingsContainer(props: SettingsContainerProps): JSX.Element
  • props — The component props.

Returns: The settings panel container.

ThisDeviceSection()

"This device" detail strip — OS, browser, online/offline.

Reads everything from @molecule/app-device through the useDevice hook (deviceInfo and isOnline()), so the bonded device provider decides what it shows. No side effects, no app-specific state.

function ThisDeviceSection(): JSX.Element

Returns: The this-device settings section.

TiersUpgradeSection(props)

Billing section with full multi-tier upgrade flow.

Replaces the simpler <BillingSection> for apps backed by @molecule/api-payments-stripe + @molecule/api-resource-payment — loads the user's current plan from /api/billing/status, loads available tiers from /api/billing/tiers, and renders an Upgrade modal with a Subscribe button per price that is for sale (one the server lists with a price id). Upgrade appears only for a free user and only when something is for sale. Subscribe POSTs to /api/billing/checkout and redirects to the checkout URL; a paid user (isFree: false in the status) sees a Cancel button that POSTs to /api/billing/cancel. A refused request shows the server's message.

function TiersUpgradeSection(props: TiersUpgradeSectionProps): JSX.Element
  • props — Component props.

Returns: The billing section.

useSettingsPanelContext()

Reads the onClose handler exposed by the parent <SettingsContainer>. Throws if used outside the container so component misuse is loud.

function useSettingsPanelContext(): SettingsPanelContextValue

Returns: The container's context value.

findCurrentDevice(devices)

Picks the caller's own device row: the api flags the session device isCurrent; fall back to the first row for sessions predating the flag.

function findCurrentDevice(devices: PushToggleDevice[] | undefined): PushToggleDevice | undefined
  • devices — Rows from GET /api/devices.

Returns: The current device row, or undefined when the user has none.

subscriptionFromToken(token)

Converts an @molecule/app-push token into the device resource's pushSubscription shape (web PushSubscription JSON, FCM registration for Android, APNs registration for iOS).

function subscriptionFromToken(token: PushToggleToken): unknown
  • token — The push token returned by register().

Returns: The pushSubscription value to PATCH onto the device row.

enablePushOnCurrentDevice(deps)

Runs the full enable chain: browser permission → runtime VAPID public key (GET /api/devices/push/public-key) → register({ vapidPublicKey }) → persist the subscription on the current device row.

Every failure is returned as a typed reason (never thrown) so the UI can show an honest, specific message instead of hanging or silently reverting.

function enablePushOnCurrentDevice(deps: {
  http: PushToggleHttp
  requestPermission: () => Promise<string>
  register: (options?: { vapidPublicKey?: string }) => Promise<PushToggleToken>
}): Promise<PushToggleResult>
  • deps — The http client + push actions from usePush().
  • deps.http — Authenticated http client (useHttpClient()).
  • deps.requestPermission — usePush().requestPermission.
  • deps.register — usePush().register.

Returns: { ok: true } or a typed failure.

disablePushOnCurrentDevice(deps)

Disables push: unsubscribes the browser (best-effort — a dev build without a service worker has nothing to unsubscribe) and ALWAYS clears the server state so no further pushes target this device.

function disablePushOnCurrentDevice(deps: {
  http: PushToggleHttp
  unregister: () => Promise<void>
}): Promise<PushToggleResult>
  • deps — The http client + push action from usePush().
  • deps.http — Authenticated http client (useHttpClient()).
  • deps.unregister — usePush().unregister.

Returns: { ok: true } or a typed failure (server state not cleared).

readCurrentDevicePushEnabled(http)

Reads whether push is currently enabled for THIS device (server truth: the current device row's hasPushSubscription).

function readCurrentDevicePushEnabled(http: PushToggleHttp): Promise<boolean>
  • http — Authenticated http client (useHttpClient()).

Returns: true when the current device has a stored subscription.

Constants

SettingsPanelContext

Solid context object for the settings panel; consume via useSettingsPanelContext.

const SettingsPanelContext: Context<SettingsPanelContextValue | null>

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-auth ^3.4.0
  • @molecule/app-http ^1.8.0
  • @molecule/app-push ^1.1.0
  • @molecule/app-solid ^3.18.0 || ^4.0.0
  • @molecule/app-ui ^1.3.11
  • @molecule/app-ui-solid ^1.1.0
  • @molecule/app-utilities ^1.0.6
  • solid-js ^1.8.0

Runtime Dependencies

  • @molecule/app-auth

  • @molecule/app-http

  • @molecule/app-push

  • @molecule/app-solid

  • @molecule/app-ui

  • @molecule/app-ui-solid

  • @molecule/app-utilities

  • solid-js

  • Wiring prereqs: sections need the standard @molecule/app-solid provider stack — MoleculeProvider with i18n, http (authenticated client), auth, theme (AppearanceSection), and the bonded device + push providers (NotificationsSection/ThisDeviceSection) — plus a bonded ClassMap. <BillingSection> and <LogOutDeleteSection> also navigate through the binding's router (useRouter()).

  • Section components throw if rendered outside <SettingsContainer> (they read its context for onClose).

  • Server contract: the molecule API surface from @molecule/api-resource-user, @molecule/api-resource-device, @molecule/api-two-factor, and the billing endpoints (/api/billing/*) wired by the payments stack. Missing read endpoints degrade gracefully (sections render empty); the mutating actions do not.

  • Translations: @molecule/app-locales-settings-panel companion bond.

Translations

Translation strings are provided by @molecule/app-locales-settings-panel.