Skip to content
Spools
Documentation
On this page

Alerts

Alerts are how the CRM tells whoever is using it what is happening: a save the server refused, an action that finished, work that is taking a while. They are drawn in one place, over the bottom of the page, by the CRM's shell. The CRM's own parts raise them, and so can your layouts, your components and your modules.

What the CRM raises on its own#

When What is said
A field changed in place is refused by the server "Value was not saved", and what the server said
A step of Stages is refused "Stage was not changed", and what the server said
A record action (actions in the config) runs for a while The action's label, with a spinner
A record action ends The action's message, or why it failed

A save that works says nothing: the new value on the page is the news.

From a layout#

@Alert(text, tone?) is an action, beside @Navigate and @Refresh:

text
win = Mutation("update", {object: "deals", id: $id, values: {stage: "won"}})done = Button("Mark won", Action([@Run(win), @Refresh(), @Alert("Marked won", "success")]))

The steps of an Action run in order and stop at a Mutation that fails, so an alert after @Run is raised only when the Mutation worked. tone is info (when left out), success, warning or danger.

From a component#

useAlerts() works in any component drawn inside the CRM: a layout component (defineLayoutComponent), a module's panel, a page of your own under src/routes/_crm.

tsx
import { useAlerts } from '@swirls/spools/ui/alerts'function SendToCrew({ jobId }: { jobId: string }) {  const alerts = useAlerts()  const send = () =>    alerts.during(sendToCrewFn({ data: { jobId } }), {      doing: 'Sending to the crew',      done: (sent) => `Sent to ${sent.count} people`,      failed: 'Not sent',    })  return <button onClick={() => void send()}>Send to the crew</button>}
Call What it does
alerts.show(alert) Raises an alert and gives its id.
alerts.change(id, alert) Replaces an alert that is up.
alerts.dismiss(id) Takes one down.
alerts.during(work, says) Says doing if the promise is still going after a moment, then done or failed. Gives the promise's own result, and fails when it does.

An alert is { text, tone?, detail?, link?, stays? }:

  • tone: info, success, warning, danger, or working (a spinner).
  • detail: a second line, such as why it failed.
  • link: { label, to }, somewhere in the CRM to go from here.
  • stays: keeps it up until it is dismissed. danger and working alerts always stay; the rest go after five seconds.

during leaves out done to say nothing when the work succeeds, and waits a moment before announcing work, so something quick never flashes a spinner. At most four alerts are up at once: the oldest that would have gone on its own makes room.

Outside the CRM's shell (a public page, a unit test) useAlerts() draws nothing and during still runs the work.

Hearing every alert#

onAlert in defineSpoolUi is called with every alert as it is raised or changed, the CRM's own included. Use it to log them or to send them somewhere of your own.

ts
// src/spool.ui.tsexport const ui = defineSpoolUi({  onAlert: (alert) => {    if (alert.tone === 'danger') {      reportProblem(alert.text, alert.detail)    }  },})

What alerts are not#

Alerts are for the person at the page, about what they just did. They are not kept, and nobody else sees them. To tell a teammate something later, make a task or use an automation (see configuration.md).