saleor-apps-redis_apl/packages/shared/src/use-dashboard-notification.ts
Lukasz Ostrowski 2e518906d1
Extract useDashboardNotification (#362)
* Extract useDashboardNotification

Play with config to make app-sdk working in monorepo

bump pnpm

remove local locks

unify deps

Changesets

Replace appBridge.dispatch(Notification()) with shared useDashboardNotification package

Fix build

Update klaviyo packages

update deps

update deps - root next version

* update and ix

* Restore logic in cms
2023-04-14 17:40:49 +02:00

58 lines
1.3 KiB
TypeScript

import { useCallback } from "react";
import { actions, useAppBridge } from "@saleor/app-sdk/app-bridge";
export const useDashboardNotification = () => {
const { appBridge } = useAppBridge();
return {
notifySuccess: useCallback(
(title: string, text?: string) => {
appBridge?.dispatch(
actions.Notification({
status: "success",
title,
text,
})
);
},
[appBridge]
),
notifyError: useCallback(
(title: string, text?: string, apiMessage?: string) => {
appBridge?.dispatch(
actions.Notification({
status: "error",
title,
text,
apiMessage: apiMessage,
})
);
},
[appBridge]
),
notifyWarning: useCallback(
(title: string, text?: string) => {
appBridge?.dispatch(
actions.Notification({
status: "warning",
title,
text,
})
);
},
[appBridge]
),
notifyInfo: useCallback(
(title: string, text?: string) => {
appBridge?.dispatch(
actions.Notification({
status: "info",
title,
text,
})
);
},
[appBridge]
),
};
};