Update app actions for new action type (#2200)
This commit is contained in:
parent
eea1ba235f
commit
c6e8537174
3 changed files with 36 additions and 12 deletions
16
package-lock.json
generated
16
package-lock.json
generated
|
@ -5293,9 +5293,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@saleor/app-bridge": {
|
"@saleor/app-bridge": {
|
||||||
"version": "0.1.9",
|
"version": "0.1.10",
|
||||||
"resolved": "https://registry.npmjs.org/@saleor/app-bridge/-/app-bridge-0.1.9.tgz",
|
"resolved": "https://registry.npmjs.org/@saleor/app-bridge/-/app-bridge-0.1.10.tgz",
|
||||||
"integrity": "sha512-p0+rXVAyOMrW6IfSrQg91UA330yO8xcCdSI73VcPpwFQb7es9i4Iqr/eFC4UsHTsQn/qZYp8Mnw+6TMnh4YjTQ==",
|
"integrity": "sha512-ULQohMC/uZQWc4JeKzNOB8T9SkM5NwnvRw3YSAWj+WEeD+vil9hfGqml+2E8jjT5RsVCl3Dx9frgvvWPqnnrUw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
|
@ -10091,7 +10091,7 @@
|
||||||
"buffer-crc32": {
|
"buffer-crc32": {
|
||||||
"version": "0.2.13",
|
"version": "0.2.13",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
|
"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
|
"dev": true
|
||||||
},
|
},
|
||||||
"buffer-equal-constant-time": {
|
"buffer-equal-constant-time": {
|
||||||
|
@ -14970,7 +14970,7 @@
|
||||||
"pify": {
|
"pify": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
||||||
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
|
"integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==",
|
||||||
"dev": true
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15453,7 +15453,7 @@
|
||||||
"fd-slicer": {
|
"fd-slicer": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
|
"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,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"pend": "~1.2.0"
|
"pend": "~1.2.0"
|
||||||
|
@ -23602,7 +23602,7 @@
|
||||||
"ospath": {
|
"ospath": {
|
||||||
"version": "1.2.2",
|
"version": "1.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/ospath/-/ospath-1.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/ospath/-/ospath-1.2.2.tgz",
|
||||||
"integrity": "sha1-EnZjl3Sj+O8lcvf+QoDg6kVQwHs=",
|
"integrity": "sha512-o6E5qJV5zkAbIDNhGSIlyOhScKXgQrSRMilfph0clDfM0nEnBOlKlH4sWDmG95BW/CvwNz0vmm7dJVtU2KlMiA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"p-cancelable": {
|
"p-cancelable": {
|
||||||
|
@ -24155,7 +24155,7 @@
|
||||||
"pend": {
|
"pend": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
|
||||||
"integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=",
|
"integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"performance-now": {
|
"performance-now": {
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
"@pollyjs/core": "^5.0.0",
|
"@pollyjs/core": "^5.0.0",
|
||||||
"@pollyjs/persister-fs": "^5.0.0",
|
"@pollyjs/persister-fs": "^5.0.0",
|
||||||
"@release-it/bumper": "^2.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",
|
"@sentry/webpack-plugin": "^1.14.0",
|
||||||
"@storybook/addon-storyshots": "^5.2.8",
|
"@storybook/addon-storyshots": "^5.2.8",
|
||||||
"@storybook/react": "^5.1.9",
|
"@storybook/react": "^5.1.9",
|
||||||
|
|
|
@ -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 { appPath } from "@saleor/apps/urls";
|
||||||
import { APP_MOUNT_URI } from "@saleor/config";
|
import { APP_MOUNT_URI } from "@saleor/config";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
import { useLocation } from "react-router";
|
import { useLocation } from "react-router";
|
||||||
|
@ -32,6 +39,7 @@ export const useAppActions = (
|
||||||
appId: string,
|
appId: string,
|
||||||
) => {
|
) => {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
|
const notify = useNotifier();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { closeApp } = useExternalApp();
|
const { closeApp } = useExternalApp();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
@ -40,8 +48,24 @@ export const useAppActions = (
|
||||||
action: Actions | undefined,
|
action: Actions | undefined,
|
||||||
): DispatchResponseEvent => {
|
): DispatchResponseEvent => {
|
||||||
switch (action?.type) {
|
switch (action?.type) {
|
||||||
|
case "notification": {
|
||||||
|
const {
|
||||||
|
actionId,
|
||||||
|
...notification
|
||||||
|
} = action.payload as NotificationAction["payload"];
|
||||||
|
|
||||||
|
notify({
|
||||||
|
...notification,
|
||||||
|
});
|
||||||
|
|
||||||
|
return sendResponseStatus(actionId, true);
|
||||||
|
}
|
||||||
case "redirect": {
|
case "redirect": {
|
||||||
const { to, newContext, actionId } = action.payload;
|
const {
|
||||||
|
to,
|
||||||
|
newContext,
|
||||||
|
actionId,
|
||||||
|
} = action.payload as RedirectAction["payload"];
|
||||||
|
|
||||||
let success = true;
|
let success = true;
|
||||||
const appDeepUrlChange = isAppDeepUrlChange(
|
const appDeepUrlChange = isAppDeepUrlChange(
|
||||||
|
@ -86,7 +110,7 @@ export const useAppActions = (
|
||||||
return sendResponseStatus(actionId, success);
|
return sendResponseStatus(actionId, success);
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return sendResponseStatus(action?.payload?.actionId, false);
|
throw new Error("Unknown action type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue