@strapi/admin 4.11.0-exp.push-transfer-push-stuck → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/admin/src/components/Providers/index.js +32 -32
  2. package/admin/src/components/Theme/index.js +5 -3
  3. package/admin/src/content-manager/components/ComponentIcon/ComponentIcon.js +16 -26
  4. package/admin/src/content-manager/components/ComponentIcon/constants.js +133 -0
  5. package/admin/src/content-manager/components/DynamicTable/BulkActionsBar/index.js +307 -0
  6. package/admin/src/content-manager/components/DynamicTable/index.js +20 -4
  7. package/admin/src/content-manager/components/DynamicZone/components/AddComponentButton.js +32 -95
  8. package/admin/src/content-manager/components/DynamicZone/components/ComponentCard.js +10 -2
  9. package/admin/src/content-manager/components/DynamicZone/components/ComponentCategory.js +63 -15
  10. package/admin/src/content-manager/components/DynamicZone/components/ComponentPicker.js +50 -63
  11. package/admin/src/content-manager/components/DynamicZone/components/DynamicComponent.js +132 -58
  12. package/admin/src/content-manager/components/DynamicZone/components/DynamicZoneLabel.js +29 -37
  13. package/admin/src/content-manager/components/DynamicZone/index.js +131 -83
  14. package/admin/src/content-manager/components/EditViewDataManagerProvider/index.js +31 -8
  15. package/admin/src/content-manager/components/EditViewDataManagerProvider/reducer.js +18 -6
  16. package/admin/src/content-manager/components/EditViewDataManagerProvider/utils/index.js +0 -1
  17. package/admin/src/content-manager/components/Inputs/index.js +18 -11
  18. package/admin/src/content-manager/components/Inputs/utils/index.js +0 -1
  19. package/admin/src/content-manager/pages/EditSettingsView/components/DynamicZoneList.js +7 -1
  20. package/admin/src/content-manager/pages/EditView/index.js +1 -1
  21. package/admin/src/content-manager/pages/ListView/index.js +118 -2
  22. package/admin/src/content-manager/utils/index.js +2 -0
  23. package/admin/src/content-manager/{components/EditViewDataManagerProvider/utils → utils}/schema.js +1 -1
  24. package/admin/src/hooks/useContentTypes/useContentTypes.js +0 -2
  25. package/admin/src/index.js +4 -3
  26. package/admin/src/injectionZones.js +6 -1
  27. package/admin/src/pages/SettingsPage/pages/Users/ListPage/index.js +1 -1
  28. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/EventTable/EventTableCE.js +13 -0
  29. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/EventTable/index.js +3 -0
  30. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/Events/index.js +331 -0
  31. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/HeadersInput/Combobox.js +54 -4
  32. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/HeadersInput/index.js +12 -23
  33. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/WebhookForm/index.js +129 -116
  34. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/WebhookForm/utils/makeWebhookValidationSchema.js +62 -0
  35. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/index.js +59 -64
  36. package/admin/src/translations/ar.json +684 -1
  37. package/admin/src/translations/en.json +12 -1
  38. package/build/3562.e0b1a0b3.chunk.js +50 -0
  39. package/build/371.6e4e2c1f.chunk.js +71 -0
  40. package/build/5297.31c9ffdc.chunk.js +39 -0
  41. package/build/5542.64b623c9.chunk.js +63 -0
  42. package/build/{5563.79950369.chunk.js → 5563.badbffde.chunk.js} +2 -2
  43. package/build/6691.f7a3b5ac.chunk.js +105 -0
  44. package/build/6970.d456705f.chunk.js +1 -0
  45. package/build/{7259.5cc67413.chunk.js → 7259.5d0de931.chunk.js} +1 -1
  46. package/build/8976.0022f5a3.chunk.js +50 -0
  47. package/build/{1657.ca8562dd.chunk.js → 9932.5ef475c5.chunk.js} +54 -62
  48. package/build/Admin-authenticatedApp.ab2b5910.chunk.js +79 -0
  49. package/build/{Admin_InternalErrorPage.96ceaae1.chunk.js → Admin_InternalErrorPage.f25f04f3.chunk.js} +1 -1
  50. package/build/Admin_homePage.05063e43.chunk.js +73 -0
  51. package/build/Admin_marketplace.005d2d5b.chunk.js +55 -0
  52. package/build/Admin_pluginsPage.5d9d4060.chunk.js +6 -0
  53. package/build/{Admin_profilePage.a8fa3a56.chunk.js → Admin_profilePage.ab7b94d7.chunk.js} +2 -2
  54. package/build/Admin_settingsPage.07a6a5f0.chunk.js +79 -0
  55. package/build/{Upload_ConfigureTheView.aa64ed9a.chunk.js → Upload_ConfigureTheView.121deffb.chunk.js} +1 -1
  56. package/build/admin-app.7cc667be.chunk.js +63 -0
  57. package/build/{admin-edit-roles-page.0d12b741.chunk.js → admin-edit-roles-page.bfe3304d.chunk.js} +3 -3
  58. package/build/{admin-edit-users.f9ce7844.chunk.js → admin-edit-users.6efe0382.chunk.js} +2 -2
  59. package/build/admin-roles-list.b2577370.chunk.js +23 -0
  60. package/build/admin-users.4af49ccf.chunk.js +26 -0
  61. package/build/{api-tokens-create-page.973d2816.chunk.js → api-tokens-create-page.65411a36.chunk.js} +1 -1
  62. package/build/{api-tokens-edit-page.29725c5e.chunk.js → api-tokens-edit-page.60312cb6.chunk.js} +1 -1
  63. package/build/{api-tokens-list-page.66c4fbdd.chunk.js → api-tokens-list-page.01a4d5cd.chunk.js} +2 -2
  64. package/build/ar-json.f530bc3f.chunk.js +1 -0
  65. package/build/audit-logs-settings-page.b165679b.chunk.js +16 -0
  66. package/build/content-manager.8cc6c3f9.chunk.js +1094 -0
  67. package/build/content-type-builder-list-view.58f9ed20.chunk.js +211 -0
  68. package/build/{content-type-builder-translation-en-json.af293c9e.chunk.js → content-type-builder-translation-en-json.f592325b.chunk.js} +1 -1
  69. package/build/content-type-builder.baeb0413.chunk.js +132 -0
  70. package/build/email-settings-page.8caad83f.chunk.js +11 -0
  71. package/build/en-json.a8f34002.chunk.js +1 -0
  72. package/build/i18n-settings-page.579d5eab.chunk.js +9 -0
  73. package/build/i18n-translation-en-json.1ec7becf.chunk.js +1 -0
  74. package/build/index.html +1 -1
  75. package/build/main.1d678f7b.js +2926 -0
  76. package/build/{review-workflows-settings.56cab253.chunk.js → review-workflows-settings.3a7bae25.chunk.js} +2 -2
  77. package/build/{runtime~main.adbe36a4.js → runtime~main.9dbd4553.js} +2 -2
  78. package/build/{sso-settings-page.265e3d72.chunk.js → sso-settings-page.4bb073e0.chunk.js} +1 -1
  79. package/build/{transfer-tokens-create-page.170acee6.chunk.js → transfer-tokens-create-page.9ec277d7.chunk.js} +1 -1
  80. package/build/{transfer-tokens-edit-page.6cf23295.chunk.js → transfer-tokens-edit-page.fa5ade14.chunk.js} +1 -1
  81. package/build/{transfer-tokens-list-page.c3fec4c1.chunk.js → transfer-tokens-list-page.5d68d590.chunk.js} +2 -2
  82. package/build/upload-settings.2c1565d6.chunk.js +14 -0
  83. package/build/upload.257b2aef.chunk.js +26 -0
  84. package/build/users-advanced-settings-page.ddd29040.chunk.js +9 -0
  85. package/build/users-email-settings-page.717e2a51.chunk.js +24 -0
  86. package/build/users-providers-settings-page.c7eae829.chunk.js +29 -0
  87. package/build/{users-roles-settings-page.2549794b.chunk.js → users-roles-settings-page.63cf2838.chunk.js} +1 -1
  88. package/build/webhook-edit-page.8576742e.chunk.js +31 -0
  89. package/build/webhook-list-page.abf5747c.chunk.js +63 -0
  90. package/ee/admin/pages/SettingsPage/pages/Webhooks/EditView/components/EventTable/EventTableEE.js +23 -0
  91. package/ee/admin/pages/SettingsPage/pages/Webhooks/EditView/components/EventTable/index.js +3 -0
  92. package/ee/server/services/review-workflows/review-workflows.js +4 -0
  93. package/package.json +22 -24
  94. package/server/controllers/webhooks.js +6 -6
  95. package/admin/src/content-manager/components/DynamicTable/ConfirmDialogDeleteAll/index.js +0 -73
  96. package/admin/src/content-manager/components/DynamicZone/utils/connect.js +0 -12
  97. package/admin/src/content-manager/components/DynamicZone/utils/select.js +0 -53
  98. package/admin/src/content-manager/components/Inputs/utils/getStep.js +0 -13
  99. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/EventInput/EventRow.js +0 -70
  100. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/EventInput/index.js +0 -174
  101. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/HeadersInput/keys.js +0 -39
  102. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/utils/fieldsRegex.js +0 -4
  103. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/utils/schema.js +0 -35
  104. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/reducer.js +0 -100
  105. package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/utils/formatData.js +0 -20
  106. package/build/3081.c2cdfac8.chunk.js +0 -108
  107. package/build/3816.60f858cf.chunk.js +0 -211
  108. package/build/462.a073ff1f.chunk.js +0 -71
  109. package/build/5542.002522eb.chunk.js +0 -71
  110. package/build/617.87b2fe96.chunk.js +0 -155
  111. package/build/6858.85d76858.chunk.js +0 -50
  112. package/build/6970.6a329e15.chunk.js +0 -1
  113. package/build/Admin-authenticatedApp.d425b485.chunk.js +0 -79
  114. package/build/Admin_homePage.107a9fe0.chunk.js +0 -73
  115. package/build/Admin_marketplace.717bd7ca.chunk.js +0 -55
  116. package/build/Admin_pluginsPage.7df6b5a9.chunk.js +0 -6
  117. package/build/Admin_settingsPage.1394aaf2.chunk.js +0 -79
  118. package/build/admin-app.ac5b1f59.chunk.js +0 -63
  119. package/build/admin-roles-list.e8bf9685.chunk.js +0 -31
  120. package/build/admin-users.751b28b2.chunk.js +0 -34
  121. package/build/ar-json.39e54aba.chunk.js +0 -1
  122. package/build/audit-logs-settings-page.3c6cea81.chunk.js +0 -129
  123. package/build/content-manager.70548048.chunk.js +0 -1123
  124. package/build/content-type-builder-list-view.1e821eb9.chunk.js +0 -215
  125. package/build/content-type-builder.b10576e7.chunk.js +0 -126
  126. package/build/email-settings-page.dba83275.chunk.js +0 -11
  127. package/build/en-json.d965e364.chunk.js +0 -1
  128. package/build/i18n-settings-page.55628f74.chunk.js +0 -114
  129. package/build/i18n-translation-en-json.60af6722.chunk.js +0 -1
  130. package/build/main.d9d9ed10.js +0 -2630
  131. package/build/upload-settings.63d99bf5.chunk.js +0 -14
  132. package/build/upload.c50d8c7a.chunk.js +0 -34
  133. package/build/users-advanced-settings-page.4f49ca57.chunk.js +0 -9
  134. package/build/users-email-settings-page.d2429d0a.chunk.js +0 -24
  135. package/build/users-providers-settings-page.50c5ba27.chunk.js +0 -29
  136. package/build/webhook-edit-page.ddd5963d.chunk.js +0 -128
  137. package/build/webhook-list-page.e2fca9f8.chunk.js +0 -71
@@ -1,145 +1,159 @@
1
1
  import React, { useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import { Field, FormikProvider, useFormik } from 'formik';
4
+ import { useIntl } from 'react-intl';
3
5
  import { Form, Link } from '@strapi/helper-plugin';
4
6
  import { ArrowLeft, Check, Play as Publish } from '@strapi/icons';
5
7
  import {
6
- ContentLayout,
7
- HeaderLayout,
8
- Box,
8
+ Grid,
9
+ GridItem,
9
10
  Button,
10
11
  Flex,
11
12
  TextInput,
12
- Grid,
13
- GridItem,
13
+ HeaderLayout,
14
+ ContentLayout,
15
+ Box,
14
16
  } from '@strapi/design-system';
15
- import { Field, Formik } from 'formik';
16
17
 
17
- import { useIntl } from 'react-intl';
18
- import EventInput from '../EventInput';
18
+ import EventTable from 'ee_else_ce/pages/SettingsPage/pages/Webhooks/EditView/components/EventTable';
19
+ import { makeWebhookValidationSchema } from './utils/makeWebhookValidationSchema';
19
20
  import HeadersInput from '../HeadersInput';
20
21
  import TriggerContainer from '../TriggerContainer';
21
- import schema from '../utils/schema';
22
22
 
23
23
  const WebhookForm = ({
24
24
  handleSubmit,
25
- data,
26
25
  triggerWebhook,
27
26
  isCreating,
28
27
  isTriggering,
29
28
  triggerResponse,
30
- isDraftAndPublishEvents,
29
+ data,
31
30
  }) => {
32
31
  const { formatMessage } = useIntl();
33
32
  const [showTriggerResponse, setShowTriggerResponse] = useState(false);
34
33
 
34
+ /**
35
+ * Map the headers into a form that can be used within the formik form
36
+ * @param {Object} headers
37
+ * @returns {Array}
38
+ */
39
+ const mapHeaders = (headers) => {
40
+ if (!Object.keys(headers).length) {
41
+ return [{ key: '', value: '' }];
42
+ }
43
+
44
+ return Object.entries(headers).map(([key, value]) => ({ key, value }));
45
+ };
46
+
47
+ const formik = useFormik({
48
+ initialValues: {
49
+ name: data?.name || '',
50
+ url: data?.url || '',
51
+ headers: mapHeaders(data?.headers || {}),
52
+ events: data?.events || [],
53
+ },
54
+ onSubmit: handleSubmit,
55
+ validationSchema: makeWebhookValidationSchema({ formatMessage }),
56
+ validateOnChange: false,
57
+ validateOnBlur: false,
58
+ });
59
+
35
60
  return (
36
- <Formik
37
- onSubmit={handleSubmit}
38
- initialValues={{
39
- name: data?.name || '',
40
- url: data?.url || '',
41
- headers: Object.keys(data?.headers || []).length
42
- ? Object.entries(data.headers).map(([key, value]) => ({ key, value }))
43
- : [{ key: '', value: '' }],
44
- events: data?.events || [],
45
- }}
46
- validationSchema={schema}
47
- validateOnChange={false}
48
- validateOnBlur={false}
49
- >
50
- {({ handleSubmit, errors }) => (
51
- <Form noValidate>
52
- <HeaderLayout
53
- primaryAction={
54
- <Flex gap={2}>
55
- <Button
56
- onClick={() => {
57
- triggerWebhook();
58
- setShowTriggerResponse(true);
59
- }}
60
- variant="tertiary"
61
- startIcon={<Publish />}
62
- disabled={isCreating || isTriggering}
63
- size="L"
64
- >
65
- {formatMessage({
66
- id: 'Settings.webhooks.trigger',
67
- defaultMessage: 'Trigger',
68
- })}
69
- </Button>
70
- <Button startIcon={<Check />} onClick={handleSubmit} type="submit" size="L">
71
- {formatMessage({
72
- id: 'global.save',
73
- defaultMessage: 'Save',
74
- })}
75
- </Button>
76
- </Flex>
77
- }
78
- title={
79
- isCreating
80
- ? formatMessage({
81
- id: 'Settings.webhooks.create',
82
- defaultMessage: 'Create a webhook',
83
- })
84
- : data?.name
85
- }
86
- navigationAction={
87
- <Link startIcon={<ArrowLeft />} to="/settings/webhooks">
61
+ <FormikProvider value={formik}>
62
+ <Form onSubmit={formik.handleSubmit}>
63
+ <HeaderLayout
64
+ primaryAction={
65
+ <Flex gap={2}>
66
+ <Button
67
+ onClick={() => {
68
+ triggerWebhook();
69
+ setShowTriggerResponse(true);
70
+ }}
71
+ variant="tertiary"
72
+ startIcon={<Publish />}
73
+ disabled={isCreating || isTriggering}
74
+ size="L"
75
+ >
88
76
  {formatMessage({
89
- id: 'global.back',
90
- defaultMessage: 'Back',
77
+ id: 'Settings.webhooks.trigger',
78
+ defaultMessage: 'Trigger',
91
79
  })}
92
- </Link>
93
- }
94
- />
95
- <ContentLayout>
96
- <Flex direction="column" alignItems="stretch" gap={4}>
97
- {showTriggerResponse && (
98
- <div className="trigger-wrapper">
99
- <TriggerContainer
100
- isPending={isTriggering}
101
- response={triggerResponse}
102
- onCancel={() => setShowTriggerResponse(false)}
103
- />
104
- </div>
105
- )}
106
- <Box background="neutral0" padding={8} shadow="filterShadow" hasRadius>
107
- <Flex direction="column" alignItems="stretch" gap={6}>
108
- <Grid gap={6}>
109
- <GridItem col={6}>
110
- <Field
111
- as={TextInput}
112
- name="name"
113
- error={errors.name && formatMessage({ id: errors.name })}
114
- label={formatMessage({
115
- id: 'global.name',
116
- defaultMessage: 'Name',
117
- })}
118
- required
119
- />
120
- </GridItem>
121
- <GridItem col={12}>
122
- <Field
123
- as={TextInput}
124
- name="url"
125
- error={errors.url && formatMessage({ id: errors.url })}
126
- label={formatMessage({
127
- id: 'Settings.roles.form.input.url',
128
- defaultMessage: 'Url',
129
- })}
130
- required
131
- />
132
- </GridItem>
133
- </Grid>
134
- <HeadersInput />
135
- <EventInput isDraftAndPublish={isDraftAndPublishEvents} />
136
- </Flex>
137
- </Box>
80
+ </Button>
81
+ <Button
82
+ startIcon={<Check />}
83
+ type="submit"
84
+ size="L"
85
+ disabled={!formik.dirty}
86
+ loading={formik.isSubmitting}
87
+ >
88
+ {formatMessage({
89
+ id: 'global.save',
90
+ defaultMessage: 'Save',
91
+ })}
92
+ </Button>
138
93
  </Flex>
139
- </ContentLayout>
140
- </Form>
141
- )}
142
- </Formik>
94
+ }
95
+ title={
96
+ isCreating
97
+ ? formatMessage({
98
+ id: 'Settings.webhooks.create',
99
+ defaultMessage: 'Create a webhook',
100
+ })
101
+ : data?.name
102
+ }
103
+ navigationAction={
104
+ <Link startIcon={<ArrowLeft />} to="/settings/webhooks">
105
+ {formatMessage({
106
+ id: 'global.back',
107
+ defaultMessage: 'Back',
108
+ })}
109
+ </Link>
110
+ }
111
+ />
112
+ <ContentLayout>
113
+ <Flex direction="column" alignItems="stretch" gap={4}>
114
+ {showTriggerResponse && (
115
+ <TriggerContainer
116
+ isPending={isTriggering}
117
+ response={triggerResponse}
118
+ onCancel={() => setShowTriggerResponse(false)}
119
+ />
120
+ )}
121
+ <Box background="neutral0" padding={8} shadow="filterShadow" hasRadius>
122
+ <Flex direction="column" alignItems="stretch" gap={6}>
123
+ <Grid gap={6}>
124
+ <GridItem col={6}>
125
+ <Field
126
+ as={TextInput}
127
+ name="name"
128
+ error={formik?.errors?.name && formik.errors.name}
129
+ label={formatMessage({
130
+ id: 'global.name',
131
+ defaultMessage: 'Name',
132
+ })}
133
+ required
134
+ />
135
+ </GridItem>
136
+ <GridItem col={12}>
137
+ <Field
138
+ as={TextInput}
139
+ name="url"
140
+ error={formik?.errors?.url && formik.errors.url}
141
+ label={formatMessage({
142
+ id: 'Settings.roles.form.input.url',
143
+ defaultMessage: 'Url',
144
+ })}
145
+ required
146
+ />
147
+ </GridItem>
148
+ </Grid>
149
+ <HeadersInput />
150
+ <EventTable />
151
+ </Flex>
152
+ </Box>
153
+ </Flex>
154
+ </ContentLayout>
155
+ </Form>
156
+ </FormikProvider>
143
157
  );
144
158
  };
145
159
 
@@ -148,7 +162,6 @@ WebhookForm.propTypes = {
148
162
  handleSubmit: PropTypes.func.isRequired,
149
163
  triggerWebhook: PropTypes.func.isRequired,
150
164
  isCreating: PropTypes.bool.isRequired,
151
- isDraftAndPublishEvents: PropTypes.bool.isRequired,
152
165
  isTriggering: PropTypes.bool.isRequired,
153
166
  triggerResponse: PropTypes.object,
154
167
  };
@@ -0,0 +1,62 @@
1
+ import * as yup from 'yup';
2
+ import { translatedErrors } from '@strapi/helper-plugin';
3
+
4
+ const NAME_REGEX = /(^$)|(^[A-Za-z][_0-9A-Za-z ]*$)/;
5
+ const URL_REGEX = /(^$)|((https?:\/\/.*)(d*)\/?(.*))/;
6
+
7
+ export const makeWebhookValidationSchema = ({ formatMessage }) =>
8
+ yup.object().shape({
9
+ name: yup
10
+ .string()
11
+ .required(
12
+ formatMessage({
13
+ id: 'Settings.webhooks.validation.name',
14
+ defaultMessage: 'Name is required',
15
+ })
16
+ )
17
+ .matches(NAME_REGEX, translatedErrors.regex),
18
+ url: yup
19
+ .string()
20
+ .required(
21
+ formatMessage({
22
+ id: 'Settings.webhooks.validation.url.required',
23
+ defaultMessage: 'Url is required',
24
+ })
25
+ )
26
+ .matches(
27
+ URL_REGEX,
28
+ formatMessage({
29
+ id: translatedErrors.regex,
30
+ defaultMessage: 'The value does not match the regex',
31
+ })
32
+ ),
33
+ headers: yup.lazy((array) => {
34
+ let baseSchema = yup.array();
35
+
36
+ if (array.length === 1) {
37
+ const { key, value } = array[0];
38
+
39
+ if (!key && !value) {
40
+ return baseSchema;
41
+ }
42
+ }
43
+
44
+ return baseSchema.of(
45
+ yup.object().shape({
46
+ key: yup.string().required(
47
+ formatMessage({
48
+ id: 'Settings.webhooks.validation.key',
49
+ defaultMessage: 'Key is required',
50
+ })
51
+ ),
52
+ value: yup.string().required(
53
+ formatMessage({
54
+ id: 'Settings.webhooks.validation.value',
55
+ defaultMessage: 'Value is required',
56
+ })
57
+ ),
58
+ })
59
+ );
60
+ }),
61
+ events: yup.array(),
62
+ });
@@ -1,60 +1,68 @@
1
- /**
2
- *
3
- * EditView
4
- *
5
- */
6
1
  import * as React from 'react';
7
2
  import {
8
3
  LoadingIndicatorPage,
9
4
  SettingsPageTitle,
10
5
  useNotification,
11
- useOverlayBlocker,
12
6
  useFetchClient,
7
+ useAPIErrorHandler,
13
8
  } from '@strapi/helper-plugin';
14
9
  import { Main } from '@strapi/design-system';
15
10
  import { useMutation, useQuery, useQueryClient } from 'react-query';
16
11
  import { useHistory, useRouteMatch } from 'react-router-dom';
17
12
  import { useContentTypes } from '../../../../../hooks/useContentTypes';
18
13
  import WebhookForm from './components/WebhookForm';
19
- import cleanData from './utils/formatData';
14
+
15
+ const cleanData = (data) => ({
16
+ ...data,
17
+ headers: data.headers.reduce((acc, { key, value }) => {
18
+ if (key !== '') {
19
+ acc[key] = value;
20
+ }
21
+
22
+ return acc;
23
+ }, {}),
24
+ });
20
25
 
21
26
  const EditView = () => {
22
27
  const {
23
28
  params: { id },
24
29
  } = useRouteMatch('/settings/webhooks/:id');
30
+ const isCreating = id === 'create';
25
31
 
26
32
  const { replace } = useHistory();
27
- const { lockApp, unlockApp } = useOverlayBlocker();
28
33
  const toggleNotification = useNotification();
34
+ const { formatAPIError } = useAPIErrorHandler();
29
35
  const queryClient = useQueryClient();
30
- const { isLoading: isLoadingForModels, collectionTypes } = useContentTypes();
36
+ const { isLoading: isLoadingForModels } = useContentTypes();
31
37
  const { put, get, post } = useFetchClient();
32
38
 
33
- const isCreating = id === 'create';
34
-
35
- const { isLoading, data } = useQuery(
36
- ['get-webhook', id],
39
+ const {
40
+ isLoading,
41
+ data: webhookData,
42
+ error: webhookError,
43
+ } = useQuery(
44
+ ['webhooks', id],
37
45
  async () => {
38
- try {
39
- const {
40
- data: { data },
41
- } = await get(`/admin/webhooks/${id}`);
46
+ const {
47
+ data: { data },
48
+ } = await get(`/admin/webhooks/${id}`);
42
49
 
43
- return data;
44
- } catch (err) {
45
- toggleNotification({
46
- type: 'warning',
47
- message: { id: 'notification.error' },
48
- });
49
-
50
- return null;
51
- }
50
+ return data;
52
51
  },
53
52
  {
54
53
  enabled: !isCreating,
55
54
  }
56
55
  );
57
56
 
57
+ React.useEffect(() => {
58
+ if (webhookError) {
59
+ toggleNotification({
60
+ type: 'warning',
61
+ message: formatAPIError(webhookError),
62
+ });
63
+ }
64
+ }, [webhookError, toggleNotification, formatAPIError]);
65
+
58
66
  const {
59
67
  isLoading: isTriggering,
60
68
  data: triggerResponse,
@@ -64,10 +72,10 @@ const EditView = () => {
64
72
 
65
73
  const triggerWebhook = () =>
66
74
  mutate(null, {
67
- onError() {
75
+ onError(error) {
68
76
  toggleNotification({
69
77
  type: 'warning',
70
- message: { id: 'notification.error' },
78
+ message: formatAPIError(error),
71
79
  });
72
80
  },
73
81
  });
@@ -78,7 +86,6 @@ const EditView = () => {
78
86
 
79
87
  const handleSubmit = async (data) => {
80
88
  if (isCreating) {
81
- lockApp();
82
89
  createWebhookMutation.mutate(cleanData(data), {
83
90
  onSuccess({ data: result }) {
84
91
  toggleNotification({
@@ -86,48 +93,37 @@ const EditView = () => {
86
93
  message: { id: 'Settings.webhooks.created' },
87
94
  });
88
95
  replace(`/settings/webhooks/${result.data.id}`);
89
- unlockApp();
90
96
  },
91
- onError(e) {
97
+ onError(error) {
92
98
  toggleNotification({
93
99
  type: 'warning',
94
- message: { id: 'notification.error' },
100
+ message: formatAPIError(error),
95
101
  });
96
- console.log(e);
97
- unlockApp();
98
102
  },
99
103
  });
100
- } else {
101
- lockApp();
102
- updateWebhookMutation.mutate(
103
- { id, body: cleanData(data) },
104
- {
105
- onSuccess() {
106
- queryClient.invalidateQueries(['get-webhook', id]);
107
- toggleNotification({
108
- type: 'success',
109
- message: { id: 'notification.form.success.fields' },
110
- });
111
- unlockApp();
112
- },
113
- onError(e) {
114
- toggleNotification({
115
- type: 'warning',
116
- message: { id: 'notification.error' },
117
- });
118
- console.log(e);
119
- unlockApp();
120
- },
121
- }
122
- );
104
+
105
+ return;
123
106
  }
107
+ updateWebhookMutation.mutate(
108
+ { id, body: cleanData(data) },
109
+ {
110
+ onSuccess() {
111
+ queryClient.invalidateQueries(['webhooks', id]);
112
+ toggleNotification({
113
+ type: 'success',
114
+ message: { id: 'notification.form.success.fields' },
115
+ });
116
+ },
117
+ onError(error) {
118
+ toggleNotification({
119
+ type: 'warning',
120
+ message: formatAPIError(error),
121
+ });
122
+ },
123
+ }
124
+ );
124
125
  };
125
126
 
126
- const isDraftAndPublishEvents = React.useMemo(
127
- () => collectionTypes.some((ct) => ct.options.draftAndPublish === true),
128
- [collectionTypes]
129
- );
130
-
131
127
  if (isLoading || isLoadingForModels) {
132
128
  return <LoadingIndicatorPage />;
133
129
  }
@@ -137,14 +133,13 @@ const EditView = () => {
137
133
  <SettingsPageTitle name="Webhooks" />
138
134
  <WebhookForm
139
135
  {...{
136
+ data: webhookData,
140
137
  handleSubmit,
141
- data,
142
138
  triggerWebhook,
143
139
  isCreating,
144
140
  isTriggering,
145
141
  isTriggerIdle,
146
142
  triggerResponse: triggerResponse?.data.data,
147
- isDraftAndPublishEvents,
148
143
  }}
149
144
  />
150
145
  </Main>