diff --git a/src/searches/useServiceAccountSearch.ts b/src/searches/useServiceAccountSearch.ts index 3b3ed11d8..542e550f3 100644 --- a/src/searches/useServiceAccountSearch.ts +++ b/src/searches/useServiceAccountSearch.ts @@ -13,7 +13,7 @@ export const searchServiceAccount = gql` search: serviceAccounts( after: $after first: $first - filter: { search: $query } + filter: { search: $query, isActive: true } ) { edges { node { diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index ccf779083..1781099b3 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -131353,16 +131353,16 @@ exports[`Storyshots Views / Webhooks / Create webhook default 1`] = ` class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id" >
+

+ Invalid value +

- This URL will receive webhook POST requests + Invalid value

- secret key is used to create a hash signature with each payload. *optional field + Invalid value

@@ -132037,7 +132042,7 @@ exports[`Storyshots Views / Webhooks / Create webhook form errors 1`] = `

- This field is required + Invalid value

@@ -132547,6 +132552,11 @@ exports[`Storyshots Views / Webhooks / Create webhook loading 1`] = ` +

+ Invalid value +

`; +exports[`Storyshots Views / Webhooks / Delete webhook unnamed webhook 1`] = ` +
+`; + exports[`Storyshots Views / Webhooks / Webhook details default 1`] = `

- This URL will receive webhook POST requests + Invalid value

- secret key is used to create a hash signature with each payload. *optional field + Invalid value

@@ -133811,7 +133827,7 @@ exports[`Storyshots Views / Webhooks / Webhook details form errors 1`] = `

- This field is required + Invalid value

@@ -134834,6 +134850,584 @@ exports[`Storyshots Views / Webhooks / Webhook details loading 1`] = ` `; +exports[`Storyshots Views / Webhooks / Webhook details unnamed 1`] = ` +
+
+
+
+
+ Unnamed Webhook Details +
+
+
+
+
+
+
+
+
+ + Webhook Information + +
+
+
+
+
+
+ General Informations +
+
+ +
+ + +
+
+
+
+
+
+ Webhook specific information +
+
+
+ + +
+
+
+
+ +
+ + +
+

+ This URL will receive webhook POST requests +

+
+
+
+ +
+ + +
+

+ secret key is used to create a hash signature with each payload. *optional field +

+
+
+
+
+
+
+
+ + Events + +
+
+
+
+
+
+ Expand or restrict webhooks permissions to register certain events in Saleor system. +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+ + Webhook Status + +
+
+
+
+
+
+ If you want to disable this webhook please uncheck the box below. +
+ +
+
+
+
+
+ +
+`; + exports[`Storyshots Views / Webhooks / Webhook list default 1`] = `
+ + + Unnamed webhook + + + Test Account 2 + + + + + +
diff --git a/src/utils/errors/webhooks.ts b/src/utils/errors/webhooks.ts new file mode 100644 index 000000000..5c9a555a8 --- /dev/null +++ b/src/utils/errors/webhooks.ts @@ -0,0 +1,28 @@ +import { IntlShape } from "react-intl"; + +import { WebhookErrorCode } from "@saleor/types/globalTypes"; +import { commonMessages } from "@saleor/intl"; +import { WebhookErrorFragment } from "@saleor/webhooks/types/WebhookErrorFragment"; +import commonErrorMessages from "./common"; + +function getWebhookErrorMessage( + err: Omit | undefined, + intl: IntlShape +): string { + if (err) { + switch (err.code) { + case WebhookErrorCode.GRAPHQL_ERROR: + return intl.formatMessage(commonErrorMessages.graphqlError); + case WebhookErrorCode.REQUIRED: + return intl.formatMessage(commonMessages.requiredField); + case WebhookErrorCode.INVALID: + return intl.formatMessage(commonErrorMessages.invalid); + default: + return intl.formatMessage(commonErrorMessages.unknownError); + } + } + + return undefined; +} + +export default getWebhookErrorMessage; diff --git a/src/webhooks/components/WebhookCreatePage/WebhookCreatePage.tsx b/src/webhooks/components/WebhookCreatePage/WebhookCreatePage.tsx index 98b23137e..222dbbd5c 100644 --- a/src/webhooks/components/WebhookCreatePage/WebhookCreatePage.tsx +++ b/src/webhooks/components/WebhookCreatePage/WebhookCreatePage.tsx @@ -7,16 +7,15 @@ import Grid from "@saleor/components/Grid"; import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; import { sectionNames } from "@saleor/intl"; -import { maybe } from "@saleor/misc"; import { SearchServiceAccount_search_edges_node } from "@saleor/searches/types/SearchServiceAccount"; import { WebhookEventTypeEnum } from "@saleor/types/globalTypes"; import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler"; import WebhookEvents from "@saleor/webhooks/components/WebhookEvents"; import WebhookInfo from "@saleor/webhooks/components/WebhookInfo"; import WebhookStatus from "@saleor/webhooks/components/WebhookStatus"; -import { WebhookCreate_webhookCreate_webhookErrors } from "@saleor/webhooks/types/WebhookCreate"; import React from "react"; import { useIntl } from "react-intl"; +import { WebhookErrorFragment } from "@saleor/webhooks/types/WebhookErrorFragment"; export interface FormData { events: WebhookEventTypeEnum[]; @@ -30,7 +29,7 @@ export interface FormData { export interface WebhookCreatePageProps { disabled: boolean; - errors: WebhookCreate_webhookCreate_webhookErrors[]; + errors: WebhookErrorFragment[]; services?: SearchServiceAccount_search_edges_node[]; saveButtonBarState: ConfirmButtonTransitionState; fetchServiceAccounts: (data: string) => void; @@ -60,14 +59,11 @@ const WebhookCreatePage: React.FC = ({ const [selectedServiceAcccount, setSelectedServiceAcccount] = React.useState( "" ); - const servicesChoiceList = maybe( - () => - services.map(node => ({ - label: node.name, - value: node.id - })), - [] - ); + const servicesChoiceList = + services?.map(node => ({ + label: node.name, + value: node.id + })) || []; return (
diff --git a/src/webhooks/components/WebhookCreatePage/WebhooksCreatePage.stories.tsx b/src/webhooks/components/WebhookCreatePage/WebhooksCreatePage.stories.tsx index a927deeef..03927625f 100644 --- a/src/webhooks/components/WebhookCreatePage/WebhooksCreatePage.stories.tsx +++ b/src/webhooks/components/WebhookCreatePage/WebhooksCreatePage.stories.tsx @@ -21,15 +21,10 @@ storiesOf("Views / Webhooks / Create webhook", module) .add("form errors", () => ( ({ + errors={["name", "targetUrl", "secretKey", null].map(field => ({ __typename: "WebhookError", - message: "Generic form error", - ...error + code: WebhookErrorCode.INVALID, + field }))} /> )); diff --git a/src/webhooks/components/WebhookDeleteDialog/WebhookDeleteDialog.stories.tsx b/src/webhooks/components/WebhookDeleteDialog/WebhookDeleteDialog.stories.tsx index 1117de287..928ec2a72 100644 --- a/src/webhooks/components/WebhookDeleteDialog/WebhookDeleteDialog.stories.tsx +++ b/src/webhooks/components/WebhookDeleteDialog/WebhookDeleteDialog.stories.tsx @@ -16,4 +16,5 @@ const props: WebhookDeleteDialogProps = { storiesOf("Views / Webhooks / Delete webhook", module) .addDecorator(Decorator) - .add("default", () => ); + .add("default", () => ) + .add("unnamed webhook", () => ); diff --git a/src/webhooks/components/WebhookDeleteDialog/WebhookDeleteDialog.tsx b/src/webhooks/components/WebhookDeleteDialog/WebhookDeleteDialog.tsx index 05700fefc..5c0b5807f 100644 --- a/src/webhooks/components/WebhookDeleteDialog/WebhookDeleteDialog.tsx +++ b/src/webhooks/components/WebhookDeleteDialog/WebhookDeleteDialog.tsx @@ -4,6 +4,7 @@ import { FormattedMessage, useIntl } from "react-intl"; import ActionDialog from "@saleor/components/ActionDialog"; import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton"; +import { getStringOrPlaceholder } from "@saleor/misc"; export interface WebhookDeleteDialogProps { confirmButtonState: ConfirmButtonTransitionState; @@ -35,13 +36,20 @@ const WebhookDeleteDialog: React.FC = ({ variant="delete" > - {name} - }} - /> + {["", null].includes(name) ? ( + + ) : ( + {getStringOrPlaceholder(name)} + }} + /> + )} ); diff --git a/src/webhooks/components/WebhookInfo/WebhookInfo.tsx b/src/webhooks/components/WebhookInfo/WebhookInfo.tsx index d60b7a860..dec1e0ca6 100644 --- a/src/webhooks/components/WebhookInfo/WebhookInfo.tsx +++ b/src/webhooks/components/WebhookInfo/WebhookInfo.tsx @@ -14,14 +14,15 @@ import SingleAutocompleteSelectField, { } from "@saleor/components/SingleAutocompleteSelectField"; import { ChangeEvent } from "@saleor/hooks/useForm"; import { commonMessages } from "@saleor/intl"; -import { WebhookCreate_webhookCreate_webhookErrors } from "@saleor/webhooks/types/WebhookCreate"; -import { getFieldError } from "@saleor/utils/errors"; +import { getFormErrors } from "@saleor/utils/errors"; +import getWebhookErrorMessage from "@saleor/utils/errors/webhooks"; +import { WebhookErrorFragment } from "@saleor/webhooks/types/WebhookErrorFragment"; import { FormData } from "../WebhooksDetailsPage"; interface WebhookInfoProps { data: FormData; disabled: boolean; - errors: WebhookCreate_webhookCreate_webhookErrors[]; + errors: WebhookErrorFragment[]; serviceDisplayValue: string; services: SingleAutocompleteChoiceType[]; onChange: (event: React.ChangeEvent) => void; @@ -55,8 +56,9 @@ const WebhookInfo: React.FC = ({ }) => { const classes = useStyles({}); const intl = useIntl(); - const serviceAccountsError = - errors.filter(error => error.field === null).length > 0; + + const serviceAccountError = errors.find(error => error.field === null); + const formErrors = getFormErrors(["name", "targetUrl", "secretKey"], errors); return ( @@ -72,8 +74,8 @@ const WebhookInfo: React.FC = ({ = ({ label={intl.formatMessage({ defaultMessage: "Assign to Service Account" })} - error={serviceAccountsError} - helperText={ - serviceAccountsError && - intl.formatMessage(commonMessages.requiredField) - } + error={!!serviceAccountError} + helperText={getWebhookErrorMessage(serviceAccountError, intl)} name="serviceAccount" onChange={serviceOnChange} value={data.serviceAccount} @@ -115,9 +114,9 @@ const WebhookInfo: React.FC = ({ = ({ ) + .add("unnamed", () => ( + + )) .add("loading", () => ( ( ({ + errors={["name", "targetUrl", "secretKey", null].map(field => ({ __typename: "WebhookError", - message: "Generic form error", - ...error + code: WebhookErrorCode.INVALID, + field }))} /> )); diff --git a/src/webhooks/components/WebhooksDetailsPage/WebhooksDetailsPage.tsx b/src/webhooks/components/WebhooksDetailsPage/WebhooksDetailsPage.tsx index 77f4e7c36..2bde60fd9 100644 --- a/src/webhooks/components/WebhooksDetailsPage/WebhooksDetailsPage.tsx +++ b/src/webhooks/components/WebhooksDetailsPage/WebhooksDetailsPage.tsx @@ -11,15 +11,16 @@ import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; import useStateFromProps from "@saleor/hooks/useStateFromProps"; import { sectionNames } from "@saleor/intl"; -import { maybe } from "@saleor/misc"; +import { maybe, getStringOrPlaceholder } from "@saleor/misc"; import { SearchServiceAccount_search_edges_node } from "@saleor/searches/types/SearchServiceAccount"; import { WebhookEventTypeEnum } from "@saleor/types/globalTypes"; import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler"; import WebhookEvents from "@saleor/webhooks/components/WebhookEvents"; import WebhookInfo from "@saleor/webhooks/components/WebhookInfo"; import WebhookStatus from "@saleor/webhooks/components/WebhookStatus"; -import { WebhookCreate_webhookCreate_webhookErrors } from "@saleor/webhooks/types/WebhookCreate"; import { WebhookDetails_webhook } from "@saleor/webhooks/types/WebhookDetails"; +import { WebhookErrorFragment } from "@saleor/webhooks/types/WebhookErrorFragment"; +import { isUnnamed } from "@saleor/webhooks/utils"; export interface FormData { events: WebhookEventTypeEnum[]; @@ -33,7 +34,7 @@ export interface FormData { export interface WebhooksDetailsPageProps { disabled: boolean; - errors: WebhookCreate_webhookCreate_webhookErrors[]; + errors: WebhookErrorFragment[]; webhook: WebhookDetails_webhook; services?: SearchServiceAccount_search_edges_node[]; saveButtonBarState: ConfirmButtonTransitionState; @@ -94,15 +95,22 @@ const WebhooksDetailsPage: React.FC = ({ {intl.formatMessage(sectionNames.webhooks)} webhook.name, "...") - } - )} + title={ + isUnnamed(webhook) + ? intl.formatMessage({ + defaultMessage: "Unnamed Webhook Details", + description: "header" + }) + : intl.formatMessage( + { + defaultMessage: "{webhookName} Details", + description: "header" + }, + { + webhookName: getStringOrPlaceholder(webhook?.name) + } + ) + } />
diff --git a/src/webhooks/components/WebhooksList/WebhooksList.tsx b/src/webhooks/components/WebhooksList/WebhooksList.tsx index 14e49bd12..d54ba1fc2 100644 --- a/src/webhooks/components/WebhooksList/WebhooksList.tsx +++ b/src/webhooks/components/WebhooksList/WebhooksList.tsx @@ -8,16 +8,18 @@ import TableRow from "@material-ui/core/TableRow"; import DeleteIcon from "@material-ui/icons/Delete"; import EditIcon from "@material-ui/icons/Edit"; import React from "react"; -import { useIntl } from "react-intl"; +import { useIntl, FormattedMessage } from "react-intl"; +import classNames from "classnames"; import ResponsiveTable from "@saleor/components/ResponsiveTable"; import Skeleton from "@saleor/components/Skeleton"; import TablePagination from "@saleor/components/TablePagination"; -import { maybe, renderCollection, stopPropagation } from "@saleor/misc"; +import { renderCollection, stopPropagation } from "@saleor/misc"; import { ListProps, SortPage } from "@saleor/types"; import { WebhookListUrlSortField } from "@saleor/webhooks/urls"; import TableCellHeader from "@saleor/components/TableCellHeader"; import { getArrowDirection } from "@saleor/utils/sort"; +import { isUnnamed } from "@saleor/webhooks/utils"; import { Webhooks_webhooks_edges_node } from "../../types/Webhooks"; export interface WebhooksListProps @@ -49,6 +51,9 @@ const useStyles = makeStyles( paddingLeft: 0, width: 250 }, + colNameUnnamed: { + color: theme.palette.text.secondary + }, table: { tableLayout: "fixed" }, @@ -143,14 +148,19 @@ const WebhooksList: React.FC = ({ onClick={webhook ? onRowClick(webhook.id) : undefined} key={webhook ? webhook.id : "skeleton"} > - - {maybe(() => webhook.name, )} + + {isUnnamed(webhook) ? ( + + ) : ( + webhook?.name || + )} - {maybe( - () => webhook.serviceAccount.name, - - )} + {webhook?.serviceAccount?.name || } (webhookUpdate); const webhookDelete = gql` + ${webhookErrorFragment} mutation WebhookDelete($id: ID!) { webhookDelete(id: $id) { - errors { - field - message + errors: webhookErrors { + ...WebhookErrorFragment } } } diff --git a/src/webhooks/types/WebhookCreate.ts b/src/webhooks/types/WebhookCreate.ts index 4c4ab1227..dadd24d07 100644 --- a/src/webhooks/types/WebhookCreate.ts +++ b/src/webhooks/types/WebhookCreate.ts @@ -9,15 +9,8 @@ import { WebhookCreateInput, WebhookErrorCode } from "./../../types/globalTypes" // ==================================================== export interface WebhookCreate_webhookCreate_errors { - __typename: "Error"; - field: string | null; - message: string | null; -} - -export interface WebhookCreate_webhookCreate_webhookErrors { __typename: "WebhookError"; code: WebhookErrorCode; - message: string | null; field: string | null; } @@ -38,7 +31,6 @@ export interface WebhookCreate_webhookCreate_webhook { export interface WebhookCreate_webhookCreate { __typename: "WebhookCreate"; errors: WebhookCreate_webhookCreate_errors[]; - webhookErrors: WebhookCreate_webhookCreate_webhookErrors[]; webhook: WebhookCreate_webhookCreate_webhook | null; } diff --git a/src/webhooks/types/WebhookDelete.ts b/src/webhooks/types/WebhookDelete.ts index d04143498..8af582c7a 100644 --- a/src/webhooks/types/WebhookDelete.ts +++ b/src/webhooks/types/WebhookDelete.ts @@ -2,14 +2,16 @@ /* eslint-disable */ // This file was automatically generated and should not be edited. +import { WebhookErrorCode } from "./../../types/globalTypes"; + // ==================================================== // GraphQL mutation operation: WebhookDelete // ==================================================== export interface WebhookDelete_webhookDelete_errors { - __typename: "Error"; + __typename: "WebhookError"; + code: WebhookErrorCode; field: string | null; - message: string | null; } export interface WebhookDelete_webhookDelete { diff --git a/src/webhooks/types/WebhookErrorFragment.ts b/src/webhooks/types/WebhookErrorFragment.ts new file mode 100644 index 000000000..838474806 --- /dev/null +++ b/src/webhooks/types/WebhookErrorFragment.ts @@ -0,0 +1,15 @@ +/* tslint:disable */ +/* eslint-disable */ +// This file was automatically generated and should not be edited. + +import { WebhookErrorCode } from "./../../types/globalTypes"; + +// ==================================================== +// GraphQL fragment: WebhookErrorFragment +// ==================================================== + +export interface WebhookErrorFragment { + __typename: "WebhookError"; + code: WebhookErrorCode; + field: string | null; +} diff --git a/src/webhooks/types/WebhookUpdate.ts b/src/webhooks/types/WebhookUpdate.ts index 065a54e7e..507e433ce 100644 --- a/src/webhooks/types/WebhookUpdate.ts +++ b/src/webhooks/types/WebhookUpdate.ts @@ -9,15 +9,8 @@ import { WebhookUpdateInput, WebhookErrorCode } from "./../../types/globalTypes" // ==================================================== export interface WebhookUpdate_webhookUpdate_errors { - __typename: "Error"; - field: string | null; - message: string | null; -} - -export interface WebhookUpdate_webhookUpdate_webhookErrors { __typename: "WebhookError"; code: WebhookErrorCode; - message: string | null; field: string | null; } @@ -38,7 +31,6 @@ export interface WebhookUpdate_webhookUpdate_webhook { export interface WebhookUpdate_webhookUpdate { __typename: "WebhookUpdate"; errors: WebhookUpdate_webhookUpdate_errors[]; - webhookErrors: WebhookUpdate_webhookUpdate_webhookErrors[]; webhook: WebhookUpdate_webhookUpdate_webhook | null; } diff --git a/src/webhooks/utils.ts b/src/webhooks/utils.ts new file mode 100644 index 000000000..4d056555c --- /dev/null +++ b/src/webhooks/utils.ts @@ -0,0 +1,5 @@ +import { WebhookFragment } from "./types/WebhookFragment"; + +export function isUnnamed(webhook: WebhookFragment): boolean { + return ["", null].includes(webhook?.name); +} diff --git a/src/webhooks/views/WebhookList/WebhookList.tsx b/src/webhooks/views/WebhookList/WebhookList.tsx index 20de84347..fad6d45ec 100644 --- a/src/webhooks/views/WebhookList/WebhookList.tsx +++ b/src/webhooks/views/WebhookList/WebhookList.tsx @@ -10,7 +10,7 @@ import usePaginator, { createPaginationState } from "@saleor/hooks/usePaginator"; import { commonMessages } from "@saleor/intl"; -import { maybe } from "@saleor/misc"; +import { maybe, getStringOrPlaceholder } from "@saleor/misc"; import { ListViews } from "@saleor/types"; import WebhookDeleteDialog from "@saleor/webhooks/components/WebhookDeleteDialog"; import { WebhookDelete } from "@saleor/webhooks/types/WebhookDelete"; @@ -171,7 +171,7 @@ export const WebhooksList: React.FC = ({ params }) => { disabled={loading} settings={settings} sort={getSortParams(params)} - webhooks={maybe(() => data.webhooks.edges.map(edge => edge.node))} + webhooks={data?.webhooks.edges.map(edge => edge.node)} pageInfo={pageInfo} onAdd={() => navigate(webhookAddUrl)} onBack={() => navigate(configurationMenuUrl)} @@ -184,12 +184,10 @@ export const WebhooksList: React.FC = ({ params }) => { /> - data.webhooks.edges.find(edge => edge.node.id === params.id) - .node.name, - "..." - )} + name={ + data?.webhooks.edges.find(edge => edge.node.id === params.id) + ?.node?.name + } onClose={closeModal} onConfirm={handleRemoveConfirm} open={params.action === "remove"} @@ -205,7 +203,7 @@ export const WebhooksList: React.FC = ({ params }) => { confirmButtonState="default" onClose={closeModal} onSubmit={handleTabDelete} - tabName={maybe(() => tabs[currentTab - 1].name, "...")} + tabName={getStringOrPlaceholder(tabs[currentTab - 1]?.name)} /> ); diff --git a/src/webhooks/views/WebhooksCreate.tsx b/src/webhooks/views/WebhooksCreate.tsx index b1b4f3c31..63272b056 100644 --- a/src/webhooks/views/WebhooksCreate.tsx +++ b/src/webhooks/views/WebhooksCreate.tsx @@ -8,7 +8,6 @@ import { WebhookEventTypeEnum } from "@saleor/types/globalTypes"; import { WebhookCreate as WebhookCreateData } from "@saleor/webhooks/types/WebhookCreate"; import React from "react"; import { useIntl } from "react-intl"; -import { maybe } from "../../misc"; import WebhookCreatePage, { FormData } from "../components/WebhookCreatePage"; import { TypedWebhookCreate } from "../mutations"; import { webhookListUrl, WebhookListUrlQueryParams, webhookUrl } from "../urls"; @@ -30,7 +29,7 @@ export const WebhooksCreate: React.FC = () => { }); const onSubmit = (data: WebhookCreateData) => { - if (data.webhookCreate.webhookErrors.length === 0) { + if (data.webhookCreate.errors.length === 0) { notify({ text: intl.formatMessage(commonMessages.savedChanges) }); @@ -69,13 +68,10 @@ export const WebhooksCreate: React.FC = () => { /> webhookCreateOpts.data.webhookCreate.webhookErrors, - [] - )} + errors={webhookCreateOpts.data?.webhookCreate.errors || []} fetchServiceAccounts={searchServiceAccount} - services={maybe(() => - searchServiceAccountOpt.data.search.edges.map(edge => edge.node) + services={searchServiceAccountOpt.data?.search.edges.map( + edge => edge.node )} onBack={handleBack} onSubmit={handleSubmit} diff --git a/src/webhooks/views/WebhooksDetails.tsx b/src/webhooks/views/WebhooksDetails.tsx index e0ede200a..077ae4b14 100644 --- a/src/webhooks/views/WebhooksDetails.tsx +++ b/src/webhooks/views/WebhooksDetails.tsx @@ -13,7 +13,7 @@ import { WebhookDelete } from "@saleor/webhooks/types/WebhookDelete"; import { WebhookUpdate } from "@saleor/webhooks/types/WebhookUpdate"; import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers"; import NotFoundPage from "@saleor/components/NotFoundPage"; -import { maybe, getStringOrPlaceholder } from "../../misc"; +import { getStringOrPlaceholder } from "../../misc"; import WebhooksDetailsPage from "../components/WebhooksDetailsPage"; import { TypedWebhookDelete, TypedWebhookUpdate } from "../mutations"; import { TypedWebhooksDetailsQuery } from "../queries"; @@ -58,14 +58,14 @@ export const WebhooksDetails: React.FC = ({ }; const onWebhookUpdate = (data: WebhookUpdate) => { - const errors = data.webhookUpdate?.webhookErrors; + const errors = data.webhookUpdate?.errors; const webhook = data.webhookUpdate?.webhook; if (errors.length === 0 && webhook) { notify({ text: intl.formatMessage(commonMessages.savedChanges) }); - navigate(webhookUrl(webhook.id)); + closeModal(); } }; @@ -87,7 +87,7 @@ export const WebhooksDetails: React.FC = ({ const webhook = webhookDetails?.data?.webhook; const formErrors = - webhookUpdateOpts.data?.webhookUpdate.webhookErrors || []; + webhookUpdateOpts.data?.webhookUpdate.errors || []; if (webhook === null) { return ; @@ -106,10 +106,8 @@ export const WebhooksDetails: React.FC = ({ saveButtonBarState={webhookUpdateOpts.status} webhook={webhook} fetchServiceAccounts={searchServiceAccount} - services={maybe(() => - searchServiceAccountOpt.data.search.edges.map( - edge => edge.node - ) + services={searchServiceAccountOpt.data?.search.edges.map( + edge => edge.node )} onBack={handleOnBack} onDelete={() => openModal("remove")} @@ -133,7 +131,7 @@ export const WebhooksDetails: React.FC = ({ />