انتقل إلى المحتوى الرئيسي

Toast & Modal

Display notifications and dialog windows from your embedded app.

Toast

Show brief notification messages at the bottom of the admin panel.

useToast()

import { useToast } from "@qumra/jisr";

function MyComponent() {
const toast = useToast();

function handleSave() {
// Save logic...
toast.show({ message: "Changes saved successfully" });
}

function handleError() {
toast.show({
message: "Failed to save changes",
isError: true,
});
}

return (
<div>
<button onClick={handleSave}>Save</button>
<button onClick={handleError}>Simulate Error</button>
</div>
);
}

Methods

MethodDescription
toast.show(options)Display a toast notification.
toast.hide()Dismiss the current toast.

ToastOptions

PropertyTypeDefaultDescription
messagestring--The message to display.
durationnumber3000Duration in milliseconds before auto-dismiss.
isErrorbooleanfalseShow as an error toast (red styling).
actionobject--Optional action button { label, onAction }.

Toast with Action

toast.show({
message: "Product deleted",
action: {
label: "Undo",
onAction: () => {
// Restore the product
},
},
});

Open dialog windows for confirmations, forms, or detailed content.

useModal()

import { useModal } from "@qumra/jisr";

function MyComponent() {
const modal = useModal();

function handleDelete() {
modal.show({
title: "Delete Product",
message: "Are you sure you want to delete this product? This action cannot be undone.",
primaryAction: {
label: "Delete",
destructive: true,
onAction: async () => {
await deleteProduct();
modal.close();
},
},
secondaryAction: {
label: "Cancel",
onAction: () => modal.close(),
},
});
}

return <button onClick={handleDelete}>Delete Product</button>;
}

Methods

MethodDescription
modal.show(options)Open a modal dialog.
modal.close()Close the current modal.

ModalOptions

PropertyTypeDescription
titlestringThe modal title.
messagestringThe modal body text.
primaryActionActionOptionPrimary action button (e.g. "Confirm").
secondaryActionActionOptionSecondary action button (e.g. "Cancel").
size"small" | "medium" | "large"Modal size. Default "medium".

ActionOption

PropertyTypeDescription
labelstringButton label text.
onAction() => voidCallback when clicked.
destructivebooleanShow as a destructive/red button.
loadingbooleanShow a loading spinner on the button.