Skip to content

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

Extract add key dialog to route

dominik-zeglen66372d387b2b
diff --git a/saleor/static/dashboard-next/siteSettings/urls.ts b/saleor/static/dashboard-next/siteSettings/urls.ts
index a3bee06967..f3a6050615 100644
--- a/saleor/static/dashboard-next/siteSettings/urls.ts
+++ b/saleor/static/dashboard-next/siteSettings/urls.ts
@@ -1 +1,5 @@
-export const siteSettingsUrl = "/siteSettings";
+import * as urlJoin from "url-join";
+
+const siteSettingsSection = "/siteSettings";
+export const siteSettingsUrl = siteSettingsSection;
+export const siteSettingsAddKeyUrl = urlJoin(siteSettingsSection, "addKey");
diff --git a/saleor/static/dashboard-next/siteSettings/views/index.tsx b/saleor/static/dashboard-next/siteSettings/views/index.tsx
index 7147839c8d..85b9e24331 100644
--- a/saleor/static/dashboard-next/siteSettings/views/index.tsx
+++ b/saleor/static/dashboard-next/siteSettings/views/index.tsx
@@ -1,8 +1,8 @@
import * as React from "react";
+import { Route } from "react-router-dom";
import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
-import Toggle from "../../components/Toggle";
import { WindowTitle } from "../../components/WindowTitle";
import { configurationMenuUrl } from "../../configuration";
import i18n from "../../i18n";
@@ -23,135 +23,135 @@ import { TypedSiteSettingsQuery } from "../queries";
import { AuthorizationKeyAdd } from "../types/AuthorizationKeyAdd";
import { AuthorizationKeyDelete } from "../types/AuthorizationKeyDelete";
import { ShopSettingsUpdate } from "../types/ShopSettingsUpdate";
+import { siteSettingsAddKeyUrl, siteSettingsUrl } from "../urls";
export const SiteSettings: React.StatelessComponent<{}> = () => (
<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 (
- (!data.shopDomainUpdate.errors ||
- data.shopDomainUpdate.errors.length === 0) &&
- (!data.shopSettingsUpdate.errors ||
- data.shopSettingsUpdate.errors.length === 0)
- ) {
- pushMessage({
- text: i18n.t("Site settings updated", {
- context: "notification"
- })
- });
- }
- };
- return (
- <TypedSiteSettingsQuery>
- {siteSettings => (
- <TypedAuthorizationKeyAdd onCompleted={handleAddKeySuccess}>
- {(addAuthorizationKey, addAuthorizationKeyOpts) => (
- <TypedAuthorizationKeyDelete
- onCompleted={handleDeleteKeySuccess}
+ {pushMessage => {
+ const handleAddKeySuccess = (data: AuthorizationKeyAdd) => {
+ if (!maybe(() => data.authorizationKeyAdd.errors.length)) {
+ pushMessage({
+ text: i18n.t("Authorization key added", {
+ context: "notification"
+ })
+ });
+ navigate(siteSettingsUrl);
+ }
+ };
+ 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 (
+ (!data.shopDomainUpdate.errors ||
+ data.shopDomainUpdate.errors.length === 0) &&
+ (!data.shopSettingsUpdate.errors ||
+ data.shopSettingsUpdate.errors.length === 0)
+ ) {
+ pushMessage({
+ text: i18n.t("Site settings updated", {
+ context: "notification"
+ })
+ });
+ }
+ };
+ return (
+ <TypedSiteSettingsQuery>
+ {siteSettings => (
+ <TypedAuthorizationKeyAdd onCompleted={handleAddKeySuccess}>
+ {(addAuthorizationKey, addAuthorizationKeyOpts) => (
+ <TypedAuthorizationKeyDelete
+ onCompleted={handleDeleteKeySuccess}
+ >
+ {(deleteAuthorizationKey, _) => (
+ <TypedShopSettingsUpdate
+ onCompleted={handleSiteSettingsSuccess}
>
- {(deleteAuthorizationKey, _) => (
- <TypedShopSettingsUpdate
- onCompleted={handleSiteSettingsSuccess}
- >
- {(updateShopSettings, updateShopSettingsOpts) => {
- const errors = [
- ...maybe(
- () =>
- updateShopSettingsOpts.data
- .shopDomainUpdate.errors,
- []
- ),
- ...maybe(
- () =>
- updateShopSettingsOpts.data
- .shopSettingsUpdate.errors,
- []
- )
- ];
- const loading =
- siteSettings.loading ||
- addAuthorizationKeyOpts.loading ||
- updateShopSettingsOpts.loading;
+ {(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 (
- <>
- <WindowTitle
- title={i18n.t("Site settings")}
- />
- <SiteSettingsPage
- disabled={loading}
- errors={errors}
- shop={maybe(() => siteSettings.data.shop)}
- onBack={() =>
- navigate(configurationMenuUrl)
- }
- onKeyAdd={toggleAddKeyDialog}
- onKeyRemove={keyType =>
- deleteAuthorizationKey({
- variables: { keyType }
- })
- }
- onSubmit={handleUpdateShopSettings}
- />
+ 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 (
+ <>
+ <WindowTitle title={i18n.t("Site settings")} />
+ <SiteSettingsPage
+ disabled={loading}
+ errors={errors}
+ shop={maybe(() => siteSettings.data.shop)}
+ onBack={() => navigate(configurationMenuUrl)}
+ onKeyAdd={() =>
+ navigate(siteSettingsAddKeyUrl)
+ }
+ onKeyRemove={keyType =>
+ deleteAuthorizationKey({
+ variables: { keyType }
+ })
+ }
+ onSubmit={handleUpdateShopSettings}
+ />
+ <Route
+ path={siteSettingsAddKeyUrl}
+ render={({ match }) => (
<SiteSettingsKeyDialog
errors={maybe(
() =>
@@ -164,24 +164,24 @@ export const SiteSettings: React.StatelessComponent<{}> = () => (
password: "",
type: AuthorizationKeyType.FACEBOOK
}}
- open={openedAddKeyDialog}
- onClose={toggleAddKeyDialog}
+ open={!!match}
+ onClose={() => navigate(siteSettingsUrl)}
onSubmit={handleAuthenticationKeyAdd}
/>
- </>
- );
- }}
- </TypedShopSettingsUpdate>
- )}
- </TypedAuthorizationKeyDelete>
+ )}
+ />
+ </>
+ );
+ }}
+ </TypedShopSettingsUpdate>
)}
- </TypedAuthorizationKeyAdd>
+ </TypedAuthorizationKeyDelete>
)}
- </TypedSiteSettingsQuery>
- );
- }}
- </Toggle>
- )}
+ </TypedAuthorizationKeyAdd>
+ )}
+ </TypedSiteSettingsQuery>
+ );
+ }}
</Messages>
)}
</Navigator>