Update app actions for new action type (#2200)

This commit is contained in:
Wojciech Mista 2022-08-10 15:26:09 +02:00 committed by GitHub
parent eea1ba235f
commit c6e8537174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 12 deletions

16
package-lock.json generated
View file

@ -5293,9 +5293,9 @@
}
},
"@saleor/app-bridge": {
"version": "0.1.9",
"resolved": "https://registry.npmjs.org/@saleor/app-bridge/-/app-bridge-0.1.9.tgz",
"integrity": "sha512-p0+rXVAyOMrW6IfSrQg91UA330yO8xcCdSI73VcPpwFQb7es9i4Iqr/eFC4UsHTsQn/qZYp8Mnw+6TMnh4YjTQ==",
"version": "0.1.10",
"resolved": "https://registry.npmjs.org/@saleor/app-bridge/-/app-bridge-0.1.10.tgz",
"integrity": "sha512-ULQohMC/uZQWc4JeKzNOB8T9SkM5NwnvRw3YSAWj+WEeD+vil9hfGqml+2E8jjT5RsVCl3Dx9frgvvWPqnnrUw==",
"dev": true,
"requires": {
"uuid": "^8.3.2"
@ -10091,7 +10091,7 @@
"buffer-crc32": {
"version": "0.2.13",
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
"integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=",
"integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==",
"dev": true
},
"buffer-equal-constant-time": {
@ -14970,7 +14970,7 @@
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==",
"dev": true
}
}
@ -15453,7 +15453,7 @@
"fd-slicer": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
"integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=",
"integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==",
"dev": true,
"requires": {
"pend": "~1.2.0"
@ -23602,7 +23602,7 @@
"ospath": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/ospath/-/ospath-1.2.2.tgz",
"integrity": "sha1-EnZjl3Sj+O8lcvf+QoDg6kVQwHs=",
"integrity": "sha512-o6E5qJV5zkAbIDNhGSIlyOhScKXgQrSRMilfph0clDfM0nEnBOlKlH4sWDmG95BW/CvwNz0vmm7dJVtU2KlMiA==",
"dev": true
},
"p-cancelable": {
@ -24155,7 +24155,7 @@
"pend": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
"integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=",
"integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==",
"dev": true
},
"performance-now": {

View file

@ -110,7 +110,7 @@
"@pollyjs/core": "^5.0.0",
"@pollyjs/persister-fs": "^5.0.0",
"@release-it/bumper": "^2.0.0",
"@saleor/app-bridge": "^0.1.9",
"@saleor/app-bridge": "^0.1.10",
"@sentry/webpack-plugin": "^1.14.0",
"@storybook/addon-storyshots": "^5.2.8",
"@storybook/react": "^5.1.9",

View file

@ -1,7 +1,14 @@
import { Actions, DispatchResponseEvent, Events } from "@saleor/app-bridge";
import {
Actions,
DispatchResponseEvent,
Events,
NotificationAction,
RedirectAction,
} from "@saleor/app-bridge";
import { appPath } from "@saleor/apps/urls";
import { APP_MOUNT_URI } from "@saleor/config";
import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
import React from "react";
import { useIntl } from "react-intl";
import { useLocation } from "react-router";
@ -32,6 +39,7 @@ export const useAppActions = (
appId: string,
) => {
const navigate = useNavigator();
const notify = useNotifier();
const location = useLocation();
const { closeApp } = useExternalApp();
const intl = useIntl();
@ -40,8 +48,24 @@ export const useAppActions = (
action: Actions | undefined,
): DispatchResponseEvent => {
switch (action?.type) {
case "notification": {
const {
actionId,
...notification
} = action.payload as NotificationAction["payload"];
notify({
...notification,
});
return sendResponseStatus(actionId, true);
}
case "redirect": {
const { to, newContext, actionId } = action.payload;
const {
to,
newContext,
actionId,
} = action.payload as RedirectAction["payload"];
let success = true;
const appDeepUrlChange = isAppDeepUrlChange(
@ -86,7 +110,7 @@ export const useAppActions = (
return sendResponseStatus(actionId, success);
}
default: {
return sendResponseStatus(action?.payload?.actionId, false);
throw new Error("Unknown action type");
}
}
};