Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: integrate toast notifications for API error handling
  • Loading branch information
gciotola committed Apr 27, 2026
commit e9c6400ba58dc7113e167e2d6162691a9dd6e4c7
2 changes: 1 addition & 1 deletion packages/app-elements/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export {
type TimelineEvent,
type TimelineProps,
} from "#ui/composite/Timeline"
export { ToastContainer, toast } from "#ui/composite/Toast"
export { isToastInitialized, ToastContainer, toast } from "#ui/composite/Toast"
export {
Toolbar,
type ToolbarItem,
Expand Down
14 changes: 14 additions & 0 deletions packages/app-elements/src/ui/composite/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from "classnames"
import type React from "react"
import { useEffect } from "react"
import {
type Id,
ToastContainer as OriginalToastContainer,
Expand All @@ -9,7 +10,20 @@ import {
} from "react-toastify"
import { Icon } from "#ui/atoms/Icon"

// Function to check if toast is initialized
export const isToastInitialized = (): boolean => {
return document.body.hasAttribute("data-toast-initialized")
}

export const ToastContainer = (): React.JSX.Element => {
// Add data attribute when component mounts
useEffect(() => {
document.body.setAttribute("data-toast-initialized", "true")
return () => {
document.body.removeAttribute("data-toast-initialized")
}
}, [])

return (
<OriginalToastContainer
newestOnTop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { UseFormSetError } from "react-hook-form"
import { isToastInitialized, toast } from "#ui/composite/Toast"

interface ApiError {
/**
Expand Down Expand Up @@ -172,9 +173,17 @@ export function setApiFormErrors({
})

if (errorByTypes.others.length > 0) {
setError(API_ERROR_FIELD_NAME, {
type: "server",
message: errorByTypes.others.join(". "),
})
if (isToastInitialized()) {
errorByTypes.others.forEach((message) => {
toast(message, {
type: "error",
})
})
} else {
setError(API_ERROR_FIELD_NAME, {
type: "server",
message: errorByTypes.others.join(". "),
})
}
}
}
Loading