Events
<friendly-payroll> dispatches DOM CustomEvents. In React, use the matching props.
| Event | React prop | detail |
|---|---|---|
statuschange |
onStatusChange |
The new status. |
screenevent |
onScreenEvent |
{ name, data }. See Screen events. |
modalchange |
onModalChange |
{ open }. In React: open. |
const payroll = document.querySelector('friendly-payroll');payroll.addEventListener('statuschange', e => console.log(e.detail.status));payroll.addEventListener('screenevent', e => { if (e.detail.name === 'complete') window.location.assign('/payroll');});Status
Section titled “Status”The element’s status property and the statuschange event share this shape. The element also mirrors the current value in data-status, which is handy for CSS such as friendly-payroll[data-status='loading'].
status |
Meaning |
|---|---|
loading |
The Screen is loading. |
provisioning |
A new Employer or Worker is being set up. This usually takes a few seconds. |
ready |
The Screen is showing. |
expired |
The Session has ended. Create a new one and set the new client-secret. |
error |
Something went wrong. See code and message below. |
Error code |
Meaning |
|---|---|
invalid_session |
The client secret isn’t valid, or it belongs to a different mode. |
screen_not_allowed |
The Session wasn’t created with this Screen. |
unknown_screen |
No Screen has this name. |
provisioning_failed |
The Employer or Worker couldn’t be set up. Contact support with the Session id. |
load_error |
The Screen failed to load. |
network_error |
Friendly Payroll couldn’t be reached. |
A common pattern is to create a new Session when the status becomes expired:
payroll.addEventListener('statuschange', async e => { if (e.detail.status !== 'expired') return; const { clientSecret } = await (await fetch('/payroll-session')).json(); payroll.clientSecret = clientSecret;});Screen events
Section titled “Screen events”Every Screen can emit:
name |
When |
|---|---|
complete |
The person finished the Screen’s flow, such as completing onboarding. |
error |
The Screen hit an error it couldn’t recover from. |
request-privileged-access |
The person tried something the Session’s access doesn’t allow. |
Some Screens emit more:
| Screen | Events |
|---|---|
employer-bank-accounts |
bankaccountcreated, bankaccountverified, bankaccountauthorized |
run-payroll |
runpayrollview, runpayrollclick, runpayrollcompleted |
modalchange
Section titled “modalchange”Fires when the Screen opens or closes a dialog. While open is true, the element covers the whole viewport.
Plain iframes
Section titled “Plain iframes”If you embed with a plain iframe and set parentOrigin, the same information arrives as postMessage messages with source: "friendlypayroll". Check event.origin === "https://embed.friendlypayroll.com" before trusting a message.