Tài liệu

Trang Admin

Admin page vẫn là primitive page, nhưng được đặt trong phần quản trị workspace. Dùng nó cho cấu hình và vận hành app, không phải workflow thường ngày của member.

YAML
contributes:
  ui:
    - id: reports-admin
      kind: nativeModule
      surface: page
      slot: admin.workspace.tab
      sectionId: reports
      label: Reports settings
      route: /admin/reports/*
      roles: [OWNER, ADMIN]
      module:
        entry: dist/ui/app.js
        export: ReportsAdmin
        styles: dist/ui/app.css

slot quyết định nơi Core mount page; Core vẫn truyền route/subroute như workspace page và phần nội dung do app sở hữu. Khai báo roles và vẫn kiểm tra authorization ở app backend vì việc ẩn UI không phải security boundary.

TSX
import { useAppFetch } from '@sota/platform';

export function ReportsAdmin() {
  const appFetch = useAppFetch();
  async function save() {
    const response = await appFetch('/settings', {
      method: 'PUT',
      headers: { 'content-type': 'application/json' },
      body: JSON.stringify({ enabled: true }),
    });
    if (!response.ok) throw new Error('Could not save settings');
  }
  return <button type="button" onClick={save}>Enable reports</button>;
}

Mục lục

Esc

Tìm theo tiêu đề và nội dung trong mọi chương.