Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix cancel button

dominik-zeglen2cdb79e8466b
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
index 57b75d998d..381d617681 100644
--- a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
@@ -24,8 +24,9 @@ export interface SiteSettingsPageProps {
errors: Array<{
field: string;
message: string;
- }>
+ }>;
shop: SiteSettings_shop;
+ onBack: () => void;
onKeyAdd: () => void;
onKeyRemove: (keyType: AuthorizationKeyType) => void;
onSubmit: (data: SiteSettingsPageFormData) => void;
@@ -45,6 +46,7 @@ const SiteSettingsPage = decorate<SiteSettingsPageProps>(
disabled,
errors,
shop,
+ onBack,
onKeyAdd,
onKeyRemove,
onSubmit
@@ -94,7 +96,7 @@ const SiteSettingsPage = decorate<SiteSettingsPageProps>(
</div>
<SaveButtonBar
disabled={disabled || !hasChanged}
- onCancel={() => undefined}
+ onCancel={onBack}
onSave={submit}
/>
</Container>
diff --git a/saleor/static/dashboard-next/siteSettings/views/index.tsx b/saleor/static/dashboard-next/siteSettings/views/index.tsx
index b6a3dfbd1f..fab4991579 100644
--- a/saleor/static/dashboard-next/siteSettings/views/index.tsx
+++ b/saleor/static/dashboard-next/siteSettings/views/index.tsx
@@ -1,7 +1,9 @@
import * as React from "react";
import Messages from "../../components/messages";
+import Navigator from "../../components/Navigator";
import Toggle from "../../components/Toggle";
+import { configurationMenuUrl } from "../../configuration";
import i18n from "../../i18n";
import { maybe } from "../../misc";
import { AuthorizationKeyType } from "../../types/globalTypes";
@@ -22,153 +24,160 @@ import { AuthorizationKeyDelete } from "../types/AuthorizationKeyDelete";
import { ShopSettingsUpdate } from "../types/ShopSettingsUpdate";
export const SiteSettings: React.StatelessComponent<{}> = () => (
- <Messages>
- {pushMessage => (
- <Toggle>
- {(openedAddKeyDialog, { toggle: toggleAddKeyDialog }) => {
- const handleAddKeySuccess = (data: AuthorizationKeyAdd) => {
- if (!maybe(() => data.authorizationKeyAdd.errors.length)) {
- pushMessage({
- text: i18n.t("Authorization key added", {
- context: "notification"
- })
- });
- toggleAddKeyDialog();
- }
- };
- const handleDeleteKeySuccess = (data: AuthorizationKeyDelete) => {
- if (!maybe(() => data.authorizationKeyDelete.errors.length)) {
- pushMessage({
- text: i18n.t("Authorization key deleted", {
- context: "notification"
- })
- });
- } else {
- pushMessage({
- text: i18n.t(
- "Could not delete authorization key: {{ message }}",
- {
- context: "notification",
- message: data.authorizationKeyDelete.errors[0].message
- }
- )
- });
- }
- };
- const handleSiteSettingsSuccess = (data: ShopSettingsUpdate) => {
- if (
- !maybe(() => data.shopDomainUpdate.errors.length) &&
- !maybe(() => data.shopSettingsUpdate.errors.length)
- ) {
- pushMessage({
- text: i18n.t("Site settings updated", {
- context: "notification"
- })
- });
- }
- };
- return (
- <TypedSiteSettingsQuery>
- {siteSettings => (
- <TypedAuthorizationKeyAdd onCompleted={handleAddKeySuccess}>
- {(addAuthorizationKey, addAuthorizationKeyOpts) => (
- <TypedAuthorizationKeyDelete
- onCompleted={handleDeleteKeySuccess}
- >
- {(deleteAuthorizationKey, _) => (
- <TypedShopSettingsUpdate
- onCompleted={handleSiteSettingsSuccess}
+ <Navigator>
+ {navigate => (
+ <Messages>
+ {pushMessage => (
+ <Toggle>
+ {(openedAddKeyDialog, { toggle: toggleAddKeyDialog }) => {
+ const handleAddKeySuccess = (data: AuthorizationKeyAdd) => {
+ if (!maybe(() => data.authorizationKeyAdd.errors.length)) {
+ pushMessage({
+ text: i18n.t("Authorization key added", {
+ context: "notification"
+ })
+ });
+ toggleAddKeyDialog();
+ }
+ };
+ const handleDeleteKeySuccess = (data: AuthorizationKeyDelete) => {
+ if (!maybe(() => data.authorizationKeyDelete.errors.length)) {
+ pushMessage({
+ text: i18n.t("Authorization key deleted", {
+ context: "notification"
+ })
+ });
+ } else {
+ pushMessage({
+ text: i18n.t(
+ "Could not delete authorization key: {{ message }}",
+ {
+ context: "notification",
+ message: data.authorizationKeyDelete.errors[0].message
+ }
+ )
+ });
+ }
+ };
+ const handleSiteSettingsSuccess = (data: ShopSettingsUpdate) => {
+ if (
+ !maybe(() => data.shopDomainUpdate.errors.length) &&
+ !maybe(() => data.shopSettingsUpdate.errors.length)
+ ) {
+ pushMessage({
+ text: i18n.t("Site settings updated", {
+ context: "notification"
+ })
+ });
+ }
+ };
+ return (
+ <TypedSiteSettingsQuery>
+ {siteSettings => (
+ <TypedAuthorizationKeyAdd onCompleted={handleAddKeySuccess}>
+ {(addAuthorizationKey, addAuthorizationKeyOpts) => (
+ <TypedAuthorizationKeyDelete
+ onCompleted={handleDeleteKeySuccess}
>
- {(updateShopSettings, updateShopSettingsOpts) => {
- const errors = [
- ...maybe(
- () =>
- updateShopSettingsOpts.data.shopDomainUpdate
- .errors,
- []
- ),
- ...maybe(
- () =>
- updateShopSettingsOpts.data.shopSettingsUpdate
- .errors,
- []
- )
- ];
- const loading =
- siteSettings.loading ||
- addAuthorizationKeyOpts.loading ||
- updateShopSettingsOpts.loading;
-
- const handleAuthenticationKeyAdd = (
- data: SiteSettingsKeyDialogForm
- ) =>
- addAuthorizationKey({
- variables: {
- input: {
- key: data.key,
- password: data.password
- },
- keyType: data.type
- }
- });
- const handleUpdateShopSettings = (
- data: SiteSettingsPageFormData
- ) =>
- updateShopSettings({
- variables: {
- shopDomainInput: {
- domain: data.domain,
- name: data.name,
- },
- shopSettingsInput: {
- description: data.description,
- }
- }
- });
- return (
- <>
- <SiteSettingsPage
- disabled={loading}
- errors={errors}
- shop={maybe(() => siteSettings.data.shop)}
- onKeyAdd={toggleAddKeyDialog}
- onKeyRemove={keyType =>
- deleteAuthorizationKey({
- variables: { keyType }
- })
- }
- onSubmit={handleUpdateShopSettings}
- />
- <SiteSettingsKeyDialog
- errors={maybe(
+ {(deleteAuthorizationKey, _) => (
+ <TypedShopSettingsUpdate
+ onCompleted={handleSiteSettingsSuccess}
+ >
+ {(updateShopSettings, updateShopSettingsOpts) => {
+ const errors = [
+ ...maybe(
+ () =>
+ updateShopSettingsOpts.data
+ .shopDomainUpdate.errors,
+ []
+ ),
+ ...maybe(
() =>
- addAuthorizationKeyOpts.data
- .authorizationKeyAdd.errors,
+ updateShopSettingsOpts.data
+ .shopSettingsUpdate.errors,
[]
- )}
- initial={{
- key: "",
- password: "",
- type: AuthorizationKeyType.FACEBOOK
- }}
- open={openedAddKeyDialog}
- onClose={toggleAddKeyDialog}
- onSubmit={handleAuthenticationKeyAdd}
- />
- </>
- );
- }}
- </TypedShopSettingsUpdate>
+ )
+ ];
+ const loading =
+ siteSettings.loading ||
+ addAuthorizationKeyOpts.loading ||
+ updateShopSettingsOpts.loading;
+
+ const handleAuthenticationKeyAdd = (
+ data: SiteSettingsKeyDialogForm
+ ) =>
+ addAuthorizationKey({
+ variables: {
+ input: {
+ key: data.key,
+ password: data.password
+ },
+ keyType: data.type
+ }
+ });
+ const handleUpdateShopSettings = (
+ data: SiteSettingsPageFormData
+ ) =>
+ updateShopSettings({
+ variables: {
+ shopDomainInput: {
+ domain: data.domain,
+ name: data.name
+ },
+ shopSettingsInput: {
+ description: data.description
+ }
+ }
+ });
+ return (
+ <>
+ <SiteSettingsPage
+ disabled={loading}
+ errors={errors}
+ shop={maybe(() => siteSettings.data.shop)}
+ onBack={() =>
+ navigate(configurationMenuUrl)
+ }
+ onKeyAdd={toggleAddKeyDialog}
+ onKeyRemove={keyType =>
+ deleteAuthorizationKey({
+ variables: { keyType }
+ })
+ }
+ onSubmit={handleUpdateShopSettings}
+ />
+ <SiteSettingsKeyDialog
+ errors={maybe(
+ () =>
+ addAuthorizationKeyOpts.data
+ .authorizationKeyAdd.errors,
+ []
+ )}
+ initial={{
+ key: "",
+ password: "",
+ type: AuthorizationKeyType.FACEBOOK
+ }}
+ open={openedAddKeyDialog}
+ onClose={toggleAddKeyDialog}
+ onSubmit={handleAuthenticationKeyAdd}
+ />
+ </>
+ );
+ }}
+ </TypedShopSettingsUpdate>
+ )}
+ </TypedAuthorizationKeyDelete>
)}
- </TypedAuthorizationKeyDelete>
+ </TypedAuthorizationKeyAdd>
)}
- </TypedAuthorizationKeyAdd>
- )}
- </TypedSiteSettingsQuery>
- );
- }}
- </Toggle>
+ </TypedSiteSettingsQuery>
+ );
+ }}
+ </Toggle>
+ )}
+ </Messages>
)}
- </Messages>
+ </Navigator>
);
export default SiteSettings;
diff --git a/saleor/static/dashboard-next/storybook/stories/siteSettings/SiteSettingsPage.tsx b/saleor/static/dashboard-next/storybook/stories/siteSettings/SiteSettingsPage.tsx
index 3df89e5a68..2b0c2b25e0 100644
--- a/saleor/static/dashboard-next/storybook/stories/siteSettings/SiteSettingsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/siteSettings/SiteSettingsPage.tsx
@@ -11,6 +11,7 @@ import { formError } from "../../misc";
const props: SiteSettingsPageProps = {
disabled: false,
errors: [],
+ onBack: () => undefined,
onKeyAdd: () => undefined,
onKeyRemove: () => undefined,
onSubmit: () => undefined,