A business resource can add its own pages to the tablet, such as a kitchen stock page or a mechanic's work orders. The page code lives in that resource, not in the tablet, so you can change and ship it with the business.
A custom page has three parts:
- The page list, given to
RegisterBusiness. - The page code, a built JavaScript file in your resource that draws the page.
- A server export,
BusinessTabletCall, that answers the page.
The page list#
extension = {
script = 'tablet/pages.js',
pages = {
{ id = 'stock', label = 'Stock', icon = 'box', group = 'Kitchen',
kind = 'pizza.stock', subtitle = 'Ingredients and boxes', home = true },
{ id = 'screens', label = 'Menu screens', icon = 'image', group = 'Kitchen',
kind = 'pizza.screens', permission = 'manage_menu' },
},
hide = { 'register' },
},
| Field | Description |
|---|---|
script |
Path of the built page code inside your resource. It is loaded from https://cfx-nui-<your resource>/<script>. |
pages[].id |
The page's name. Your server export receives it as page. |
pages[].kind |
Tells your page code which page to draw. |
pages[].label, subtitle |
What staff see. |
pages[].icon |
A tablet icon name, such as box, wrench, image, car, tag or users. |
pages[].group |
The sidebar section. Custom groups come right after Overview. |
pages[].home |
true also shows the page on the dashboard. |
pages[].permission |
A tablet permission. Ranks without it get no tab. Your server code must still check it on anything that changes data. |
hide |
Built-in pages this business does not use, such as 'register' or 'menu', and the dashboard's 'open_notice' card. |
A business can have up to 12 pages.
The page code#
Write the pages in tablet/src/pages.jsx in your resource. React and the tablet's UI parts come from the tablet, so the page looks like the rest of it:
import React, { useEffect, useState } from 'react';
import { Icon, Callout, Empty, Loading, registerPages } from 'glitch-businesstablet';
import css from './pages.css'; // optional
const Stock = ({ api, tick }) => {
const [data, setData] = useState(null);
useEffect(() => { api.ext('stock', 'list').then(setData); }, [tick]);
if (!data) return <Loading />;
if (!data.ok || data.items.length === 0) return <Empty icon="box" title="Nothing in stock" />;
return (
<div className="card">
{data.items.map(i => <div key={i.name}>{i.label}: {i.count}</div>)}
</div>
);
};
const KINDS = { 'pizza.stock': Stock };
const PizzaPage = (props) => {
const Page = KINDS[props.page.kind];
return Page ? <Page {...props} /> : null;
};
registerPages({ kinds: Object.keys(KINDS), component: PizzaPage, css });
The component gets these props:
| Prop | Description |
|---|---|
page |
The page from your list (id, page, kind, label and the rest). |
api.ext(page, action, data) |
Calls your BusinessTabletCall export and resolves with its answer. An answer with ok = false shows its error to the player. |
tick |
Goes up when your resource calls PushExtension, so the page can load its data again. |
navigate(pageId) |
Opens another tablet page. |
From glitch-businesstablet you can import Icon, Callout, ConfirmDialog, Empty, Field, ItemIcon, Loading, Modal, Person, SearchInput, Toggle, ToggleRow, Avatar, money and registerPages. CSS files are imported as text and added to the page when the script loads.
Build the file from the tablet's ui folder:
npm install
npm run pages -- my-pizzeria
This writes tablet/pages.js in your resource. npm run pages -- --all builds every resource that has a tablet/src/pages.jsx. Then list the built file in your resource's fxmanifest.lua:
files {
'tablet/pages.js',
}
FiveM only serves a new file after a server restart (or a refresh), so restart once after adding it.
Answering the page#
exports('BusinessTabletCall', function(source, businessId, page, action, data)
if page == 'stock' and action == 'list' then
return { ok = true, items = GetStock() }
end
return { ok = false, error = 'No such page.' }
end)
The tablet checks that the player holds the business's job before it calls your export. Check tablet permissions yourself with HasPermission before changing anything. If your export throws an error, the player sees "Something went wrong" and the error is printed in the server console.
When something changes outside the tablet, call exports['glitch-businesstablet']:PushExtension(businessId, 'stock') so open tablets reload the page.