What you will build
A public roadmap inside your React app: four columns showing what is being considered, planned, in progress and shipped; a vote button on each item; and a form for suggesting a feature. Visitors need no account. They verify their email with a code the first time they vote. Your team curates the roadmap in Decuga, and the suggestions come back to the roadmap inbox there for review before anything appears. You will start with the ready-made widget, which takes a few lines, then see how to restyle it, listen to votes and, if you want a design of your own, build the cards yourself on a hook.
Before you start
You need three things, and none of them is in your code. First, a Decuga project whose roadmap has some public items, since the widget shows what the public roadmap shows. Second, the Pro plan or higher, which the public roadmap requires. Third, your project id: it is the long id in the address of your public roadmap page. If any of these is missing the widget says the page is not available, rather than showing something half-loaded.
No API key
The SDK reads the same public roadmap your customers can already open, so there is nothing secret to keep out of your code. Your project id is not a secret either.
Four steps from nothing to a working roadmap
Follow these in order. Each step works on its own, so you can stop after the one that is enough for you.
Install the package
Run npm install @decuga/react @decuga/elements. The second package holds the widget's web components, which load in the browser after the first render.
Wrap your app in the provider
Give DecugaProvider your project id once, so every component below it knows the project.
Drop in the widget
Render DecugaRoadmap where you want the roadmap. Add showHeader to show the roadmap's title and description from Decuga.
Match your brand
Set a few CSS custom properties for colour, font and corner radius, or add theme="auto" for dark mode.
import { DecugaProvider, DecugaRoadmap } from '@decuga/react'
export default function RoadmapPage() {
return (
<DecugaProvider projectId="YOUR_PROJECT_ID">
<DecugaRoadmap
showHeader
theme="auto"
style={{
'--decuga-color-primary': '#0f766e',
'--decuga-radius': '6px',
} as React.CSSProperties}
/>
</DecugaProvider>
)
}How a vote works for the visitor
When someone presses the vote button for the first time, the widget asks for their email and sends a code. They type the code, and the vote they started is counted straight away, with no second click. From then on they are signed in for the session, so voting and removing a vote are one click each. They are signed in for the length of the browser session by default, which means closing the tab ends it; set the storage option to local to keep them signed in between visits. We use an emailed code rather than an account so that the person who votes is a real address, without asking anyone to create a password.
The first vote
After the first vote the visitor is signed in, so later votes are one click.
- 1Press vote
The visitor is not signed in yet.
- 2Enter email
A code is sent to that address.
- 3Enter the code
The address is verified.
- 4Vote counted
The count goes up, and the button shows it is theirs.
Listen to what visitors do
The widget reports what happens as events, which you can pass to your analytics. onVote runs after a vote is added or removed, with the item. onSignIn runs when a visitor verifies their email. onSuggest runs when a suggestion is sent. onError gives you a message when something could not be loaded or sent. This is how you learn which features your customers want most, without leaving your own analytics.
- ✓onVote(item): the item, after a vote or a removed vote
- ✓onSignIn(voter): the voter who verified their email
- ✓onSuggest(): a feature suggestion was sent to your team
- ✓onError(message): something could not be loaded or sent
Draw it yourself with useRoadmap
If the widget is not the look you want, build the cards on the hook and keep all the behaviour. useRoadmap returns the items grouped by status and sorted by votes, the signed-in visitor, and functions to request a code, verify it, vote and suggest. Voting before sign-in rejects with a session-expired error, which is your cue to show your own sign-in. The hook handles the rest: it remembers which items the visitor voted for, and it takes the visitor back to signed out when the server says their sign-in has ended.
'use client'
import { useRoadmap, isDecugaError } from '@decuga/react'
export function Planned() {
const { grouped, toggleVote } = useRoadmap({ projectId: 'YOUR_PROJECT_ID' })
async function vote(item) {
try {
await toggleVote(item)
} catch (e) {
// Not signed in yet: show your sign-in (requestCode, then verifyCode)
if (isDecugaError(e) && e.code === 'session-expired') openSignIn()
}
}
return grouped.PLANNED.map(item => (
<button key={item.id} aria-pressed={item.hasVoted} onClick={() => vote(item)}>
{item.title} ({item.voteCount})
</button>
))
}Test it without the network
Pass a client built with your own fetch, and your tests never call Decuga. The client takes a fetch option for exactly this, and a memory storage so a test starts signed out. That also lets you test what your page does when the server is slow or answers with an error, which is the case that is hardest to see by hand.