Skip to content

The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.

1.2 KB
Raw Blame
import { Kbd } from '../ui/kit.tsx'
import type { ResultLine, ToastState } from './useToast.ts'
import { useT } from '@linedesk/i18n/react'

export function Toast({ toast, onUndo }: { toast: ToastState; onUndo: () => void }) {
  const t = useT()
  return (
    <div className={toast.undo ? 'toast has-undo' : 'toast'} role="status" aria-live="polite">
      <span>{toast.text}</span>
      {toast.undo && (
        <button type="button" className="toast-undo" onClick={onUndo}>
          <Kbd keys={['Z']} />
          {t('common.action.undo')}
        </button>
      )}
    </div>
  )
}

/**
 * The last results, newest first, kept in the page after their toasts are gone: a screen reader user or a browser
 * agent that looks a moment later still finds whether the action worked ("Marked done", "Couldn't mark done: …").
 * Not on screen and not a live region: the toast already announces each one.
 */
export function ResultLog({ log }: { log: ResultLine[] }) {
  const t = useT()
  return (
    <section className="sr-only" aria-label={t('shell.resultLog.label')} data-result-log>
      <ol>
        {log.map(line => (
          <li key={line.id} data-at={line.at}>
            {line.text}
          </li>
        ))}
      </ol>
    </section>
  )
}