@strapi/email 0.0.0-experimental.17b4116f461a49b8ce5386f7c8d79c511d40fb3b

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 (146) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +3 -0
  3. package/dist/_chunks/Settings-C4EFpE_1.js +300 -0
  4. package/dist/_chunks/Settings-C4EFpE_1.js.map +1 -0
  5. package/dist/_chunks/Settings-ZhMskNHr.mjs +279 -0
  6. package/dist/_chunks/Settings-ZhMskNHr.mjs.map +1 -0
  7. package/dist/_chunks/ar-Bf9XlLLo.mjs +5 -0
  8. package/dist/_chunks/ar-Bf9XlLLo.mjs.map +1 -0
  9. package/dist/_chunks/ar-C_tQu1XS.js +5 -0
  10. package/dist/_chunks/ar-C_tQu1XS.js.map +1 -0
  11. package/dist/_chunks/cs-B0QZJTah.mjs +5 -0
  12. package/dist/_chunks/cs-B0QZJTah.mjs.map +1 -0
  13. package/dist/_chunks/cs-CPKIUWLp.js +5 -0
  14. package/dist/_chunks/cs-CPKIUWLp.js.map +1 -0
  15. package/dist/_chunks/de-B9kiAC-s.mjs +5 -0
  16. package/dist/_chunks/de-B9kiAC-s.mjs.map +1 -0
  17. package/dist/_chunks/de-K6IYQk2d.js +5 -0
  18. package/dist/_chunks/de-K6IYQk2d.js.map +1 -0
  19. package/dist/_chunks/dk-31mOPYpI.js +26 -0
  20. package/dist/_chunks/dk-31mOPYpI.js.map +1 -0
  21. package/dist/_chunks/dk-DqrbgSkv.mjs +26 -0
  22. package/dist/_chunks/dk-DqrbgSkv.mjs.map +1 -0
  23. package/dist/_chunks/en-BCu4d6-o.js +29 -0
  24. package/dist/_chunks/en-BCu4d6-o.js.map +1 -0
  25. package/dist/_chunks/en-DF4KtAAC.mjs +29 -0
  26. package/dist/_chunks/en-DF4KtAAC.mjs.map +1 -0
  27. package/dist/_chunks/es-BNo7eLLJ.mjs +26 -0
  28. package/dist/_chunks/es-BNo7eLLJ.mjs.map +1 -0
  29. package/dist/_chunks/es-Dl2HVmwz.js +26 -0
  30. package/dist/_chunks/es-Dl2HVmwz.js.map +1 -0
  31. package/dist/_chunks/fr-C8Qw4iPZ.js +5 -0
  32. package/dist/_chunks/fr-C8Qw4iPZ.js.map +1 -0
  33. package/dist/_chunks/fr-hkSxFuzl.mjs +5 -0
  34. package/dist/_chunks/fr-hkSxFuzl.mjs.map +1 -0
  35. package/dist/_chunks/id-CHtAzAUz.mjs +5 -0
  36. package/dist/_chunks/id-CHtAzAUz.mjs.map +1 -0
  37. package/dist/_chunks/id-CvE5f0zz.js +5 -0
  38. package/dist/_chunks/id-CvE5f0zz.js.map +1 -0
  39. package/dist/_chunks/index-B-caQ2Oe.js +80 -0
  40. package/dist/_chunks/index-B-caQ2Oe.js.map +1 -0
  41. package/dist/_chunks/index-DN0Ma-cQ.mjs +81 -0
  42. package/dist/_chunks/index-DN0Ma-cQ.mjs.map +1 -0
  43. package/dist/_chunks/it-C7z82V3g.mjs +5 -0
  44. package/dist/_chunks/it-C7z82V3g.mjs.map +1 -0
  45. package/dist/_chunks/it-DYpuAHa5.js +5 -0
  46. package/dist/_chunks/it-DYpuAHa5.js.map +1 -0
  47. package/dist/_chunks/ja-CiekkoEN.mjs +26 -0
  48. package/dist/_chunks/ja-CiekkoEN.mjs.map +1 -0
  49. package/dist/_chunks/ja-PL3WilO7.js +26 -0
  50. package/dist/_chunks/ja-PL3WilO7.js.map +1 -0
  51. package/dist/_chunks/ko-CJBkZ375.mjs +26 -0
  52. package/dist/_chunks/ko-CJBkZ375.mjs.map +1 -0
  53. package/dist/_chunks/ko-CL2BB_w_.js +26 -0
  54. package/dist/_chunks/ko-CL2BB_w_.js.map +1 -0
  55. package/dist/_chunks/ms-BGlHkuJz.js +5 -0
  56. package/dist/_chunks/ms-BGlHkuJz.js.map +1 -0
  57. package/dist/_chunks/ms-C1wNkEQw.mjs +5 -0
  58. package/dist/_chunks/ms-C1wNkEQw.mjs.map +1 -0
  59. package/dist/_chunks/nl-BuofSsmb.js +5 -0
  60. package/dist/_chunks/nl-BuofSsmb.js.map +1 -0
  61. package/dist/_chunks/nl-C79CwB4e.mjs +5 -0
  62. package/dist/_chunks/nl-C79CwB4e.mjs.map +1 -0
  63. package/dist/_chunks/pl-DXcJCevg.mjs +26 -0
  64. package/dist/_chunks/pl-DXcJCevg.mjs.map +1 -0
  65. package/dist/_chunks/pl-DdtXf3SH.js +26 -0
  66. package/dist/_chunks/pl-DdtXf3SH.js.map +1 -0
  67. package/dist/_chunks/pt-BR-B_ii8U63.js +5 -0
  68. package/dist/_chunks/pt-BR-B_ii8U63.js.map +1 -0
  69. package/dist/_chunks/pt-BR-DjINUWGk.mjs +5 -0
  70. package/dist/_chunks/pt-BR-DjINUWGk.mjs.map +1 -0
  71. package/dist/_chunks/pt-CzRDvk6c.js +29 -0
  72. package/dist/_chunks/pt-CzRDvk6c.js.map +1 -0
  73. package/dist/_chunks/pt-DEVCt2mt.mjs +29 -0
  74. package/dist/_chunks/pt-DEVCt2mt.mjs.map +1 -0
  75. package/dist/_chunks/ru-C_7wBr9e.mjs +5 -0
  76. package/dist/_chunks/ru-C_7wBr9e.mjs.map +1 -0
  77. package/dist/_chunks/ru-Dc-rSPqb.js +5 -0
  78. package/dist/_chunks/ru-Dc-rSPqb.js.map +1 -0
  79. package/dist/_chunks/sk-Cnpb4YOK.js +5 -0
  80. package/dist/_chunks/sk-Cnpb4YOK.js.map +1 -0
  81. package/dist/_chunks/sk-i1gQKUBN.mjs +5 -0
  82. package/dist/_chunks/sk-i1gQKUBN.mjs.map +1 -0
  83. package/dist/_chunks/th-BXTLF08M.js +5 -0
  84. package/dist/_chunks/th-BXTLF08M.js.map +1 -0
  85. package/dist/_chunks/th-D-MxpWKr.mjs +5 -0
  86. package/dist/_chunks/th-D-MxpWKr.mjs.map +1 -0
  87. package/dist/_chunks/tr-BXu41MLY.mjs +29 -0
  88. package/dist/_chunks/tr-BXu41MLY.mjs.map +1 -0
  89. package/dist/_chunks/tr-DwBySNgJ.js +29 -0
  90. package/dist/_chunks/tr-DwBySNgJ.js.map +1 -0
  91. package/dist/_chunks/uk-C_1qrLRM.mjs +5 -0
  92. package/dist/_chunks/uk-C_1qrLRM.mjs.map +1 -0
  93. package/dist/_chunks/uk-CxIePjBD.js +5 -0
  94. package/dist/_chunks/uk-CxIePjBD.js.map +1 -0
  95. package/dist/_chunks/vi-B4uqmjm6.js +5 -0
  96. package/dist/_chunks/vi-B4uqmjm6.js.map +1 -0
  97. package/dist/_chunks/vi-BfZkgFxI.mjs +5 -0
  98. package/dist/_chunks/vi-BfZkgFxI.mjs.map +1 -0
  99. package/dist/_chunks/zh-BS-XJCSt.mjs +29 -0
  100. package/dist/_chunks/zh-BS-XJCSt.mjs.map +1 -0
  101. package/dist/_chunks/zh-DsMIjTgu.js +29 -0
  102. package/dist/_chunks/zh-DsMIjTgu.js.map +1 -0
  103. package/dist/_chunks/zh-Hans-BLEEaLoN.mjs +21 -0
  104. package/dist/_chunks/zh-Hans-BLEEaLoN.mjs.map +1 -0
  105. package/dist/_chunks/zh-Hans-CmL3sY9o.js +21 -0
  106. package/dist/_chunks/zh-Hans-CmL3sY9o.js.map +1 -0
  107. package/dist/admin/index.js +4 -0
  108. package/dist/admin/index.js.map +1 -0
  109. package/dist/admin/index.mjs +5 -0
  110. package/dist/admin/index.mjs.map +1 -0
  111. package/dist/admin/src/constants.d.ts +6 -0
  112. package/dist/admin/src/index.d.ts +3 -0
  113. package/dist/admin/src/pages/Settings.d.ts +1 -0
  114. package/dist/admin/src/utils/getYupInnerErrors.d.ts +7 -0
  115. package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
  116. package/dist/admin/src/utils/schema.d.ts +8 -0
  117. package/dist/server/index.js +209 -0
  118. package/dist/server/index.js.map +1 -0
  119. package/dist/server/index.mjs +191 -0
  120. package/dist/server/index.mjs.map +1 -0
  121. package/dist/server/src/bootstrap.d.ts +5 -0
  122. package/dist/server/src/bootstrap.d.ts.map +1 -0
  123. package/dist/server/src/config.d.ts +3 -0
  124. package/dist/server/src/config.d.ts.map +1 -0
  125. package/dist/server/src/controllers/email.d.ts +13 -0
  126. package/dist/server/src/controllers/email.d.ts.map +1 -0
  127. package/dist/server/src/controllers/index.d.ts +9 -0
  128. package/dist/server/src/controllers/index.d.ts.map +1 -0
  129. package/dist/server/src/index.d.ts +49 -0
  130. package/dist/server/src/index.d.ts.map +1 -0
  131. package/dist/server/src/routes/admin.d.ts +18 -0
  132. package/dist/server/src/routes/admin.d.ts.map +1 -0
  133. package/dist/server/src/routes/content-api.d.ts +10 -0
  134. package/dist/server/src/routes/content-api.d.ts.map +1 -0
  135. package/dist/server/src/routes/index.d.ts +27 -0
  136. package/dist/server/src/routes/index.d.ts.map +1 -0
  137. package/dist/server/src/services/email.d.ts +8 -0
  138. package/dist/server/src/services/email.d.ts.map +1 -0
  139. package/dist/server/src/services/index.d.ts +8 -0
  140. package/dist/server/src/services/index.d.ts.map +1 -0
  141. package/dist/server/src/types.d.ts +38 -0
  142. package/dist/server/src/types.d.ts.map +1 -0
  143. package/dist/shared/types.d.ts +11 -0
  144. package/dist/shared/types.d.ts.map +1 -0
  145. package/package.json +99 -0
  146. package/strapi-server.js +3 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015-present Strapi Solutions SAS
2
+
3
+ Portions of the Strapi software are licensed as follows:
4
+
5
+ * All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE".
6
+
7
+ * All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
8
+
9
+ MIT Expat License
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Strapi plugin
2
+
3
+ > :warning: The Shipper Email may also need to be changed in the `Email Templates` tab on the admin panel for emails to send properly
@@ -0,0 +1,300 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const strapiAdmin = require("@strapi/admin/strapi-admin");
6
+ const designSystem = require("@strapi/design-system");
7
+ const icons = require("@strapi/icons");
8
+ const reactIntl = require("react-intl");
9
+ const reactQuery = require("react-query");
10
+ const styled = require("styled-components");
11
+ const yup = require("yup");
12
+ const index = require("./index-B-caQ2Oe.js");
13
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
+ function _interopNamespace(e) {
15
+ if (e && e.__esModule)
16
+ return e;
17
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
18
+ if (e) {
19
+ for (const k in e) {
20
+ if (k !== "default") {
21
+ const d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: () => e[k]
25
+ });
26
+ }
27
+ }
28
+ }
29
+ n.default = e;
30
+ return Object.freeze(n);
31
+ }
32
+ const React__namespace = /* @__PURE__ */ _interopNamespace(React);
33
+ const styled__default = /* @__PURE__ */ _interopDefault(styled);
34
+ const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
35
+ const extractValuesFromYupError = (errorType, errorParams) => {
36
+ if (!errorType || !errorParams) {
37
+ return {};
38
+ }
39
+ return {
40
+ [errorType]: errorParams[errorType]
41
+ };
42
+ };
43
+ const getYupInnerErrors = (error) => (error?.inner || []).reduce((acc, currentError) => {
44
+ if (currentError.path) {
45
+ acc[currentError.path.split("[").join(".").split("]").join("")] = {
46
+ id: currentError.message,
47
+ defaultMessage: currentError.message,
48
+ values: extractValuesFromYupError(currentError?.type, currentError?.params)
49
+ };
50
+ }
51
+ return acc;
52
+ }, {});
53
+ const schema = yup__namespace.object().shape({
54
+ email: yup__namespace.string().email(strapiAdmin.translatedErrors.email.id).required(strapiAdmin.translatedErrors.required.id)
55
+ });
56
+ const DocumentationLink = styled__default.default.a`
57
+ color: ${({ theme }) => theme.colors.primary600};
58
+ `;
59
+ const ProtectedSettingsPage = () => /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Protect, { permissions: index.PERMISSIONS.settings, children: /* @__PURE__ */ jsxRuntime.jsx(SettingsPage, {}) });
60
+ const SettingsPage = () => {
61
+ const { toggleNotification } = strapiAdmin.useNotification();
62
+ const { formatMessage } = reactIntl.useIntl();
63
+ const { get, post } = strapiAdmin.useFetchClient();
64
+ const [testAddress, setTestAddress] = React__namespace.useState("");
65
+ const [isTestAddressValid, setIsTestAddressValid] = React__namespace.useState(false);
66
+ const [formErrors, setFormErrors] = React__namespace.useState({});
67
+ const { data, isLoading } = reactQuery.useQuery(["email", "settings"], async () => {
68
+ const res = await get("/email/settings");
69
+ const {
70
+ data: { config }
71
+ } = res;
72
+ return config;
73
+ });
74
+ const mutation = reactQuery.useMutation(
75
+ async (body) => {
76
+ await post("/email/test", body);
77
+ },
78
+ {
79
+ onError() {
80
+ toggleNotification({
81
+ type: "danger",
82
+ message: formatMessage(
83
+ {
84
+ id: "email.Settings.email.plugin.notification.test.error",
85
+ defaultMessage: "Failed to send a test mail to {to}"
86
+ },
87
+ { to: testAddress }
88
+ )
89
+ });
90
+ },
91
+ onSuccess() {
92
+ toggleNotification({
93
+ type: "success",
94
+ message: formatMessage(
95
+ {
96
+ id: "email.Settings.email.plugin.notification.test.success",
97
+ defaultMessage: "Email test succeeded, check the {to} mailbox"
98
+ },
99
+ { to: testAddress }
100
+ )
101
+ });
102
+ },
103
+ retry: false
104
+ }
105
+ );
106
+ React__namespace.useEffect(() => {
107
+ schema.validate({ email: testAddress }, { abortEarly: false }).then(() => setIsTestAddressValid(true)).catch(() => setIsTestAddressValid(false));
108
+ }, [testAddress]);
109
+ const handleChange = (event) => {
110
+ setTestAddress(() => event.target.value);
111
+ };
112
+ const handleSubmit = async (event) => {
113
+ event.preventDefault();
114
+ try {
115
+ await schema.validate({ email: testAddress }, { abortEarly: false });
116
+ } catch (error) {
117
+ if (error instanceof yup.ValidationError) {
118
+ setFormErrors(getYupInnerErrors(error));
119
+ }
120
+ }
121
+ mutation.mutate({ to: testAddress });
122
+ };
123
+ if (isLoading) {
124
+ return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
125
+ }
126
+ return /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Page.Main, { labelledBy: "title", "aria-busy": isLoading || mutation.isLoading, children: [
127
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Title, { children: formatMessage(
128
+ { id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
129
+ {
130
+ name: formatMessage({
131
+ id: "email.Settings.email.plugin.title",
132
+ defaultMessage: "Configuration"
133
+ })
134
+ }
135
+ ) }),
136
+ /* @__PURE__ */ jsxRuntime.jsx(
137
+ strapiAdmin.Layouts.Header,
138
+ {
139
+ id: "title",
140
+ title: formatMessage({
141
+ id: "email.Settings.email.plugin.title",
142
+ defaultMessage: "Configuration"
143
+ }),
144
+ subtitle: formatMessage({
145
+ id: "email.Settings.email.plugin.subTitle",
146
+ defaultMessage: "Test the settings for the Email plugin"
147
+ })
148
+ }
149
+ ),
150
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Layouts.Content, { children: data && /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit: handleSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 7, children: [
151
+ /* @__PURE__ */ jsxRuntime.jsx(
152
+ designSystem.Box,
153
+ {
154
+ background: "neutral0",
155
+ hasRadius: true,
156
+ shadow: "filterShadow",
157
+ paddingTop: 6,
158
+ paddingBottom: 6,
159
+ paddingLeft: 7,
160
+ paddingRight: 7,
161
+ children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
162
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
163
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", as: "h2", children: formatMessage({
164
+ id: "email.Settings.email.plugin.title.config",
165
+ defaultMessage: "Configuration"
166
+ }) }),
167
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: formatMessage(
168
+ {
169
+ id: "email.Settings.email.plugin.text.configuration",
170
+ defaultMessage: "The plugin is configured through the {file} file, checkout this {link} for the documentation."
171
+ },
172
+ {
173
+ file: "./config/plugins.js",
174
+ link: /* @__PURE__ */ jsxRuntime.jsx(
175
+ DocumentationLink,
176
+ {
177
+ href: "https://docs.strapi.io/developer-docs/latest/plugins/email.html",
178
+ target: "_blank",
179
+ rel: "noopener noreferrer",
180
+ children: formatMessage({
181
+ id: "email.link",
182
+ defaultMessage: "Link"
183
+ })
184
+ }
185
+ )
186
+ }
187
+ ) })
188
+ ] }),
189
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid, { gap: 5, children: [
190
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 6, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(
191
+ designSystem.TextInput,
192
+ {
193
+ name: "shipper-email",
194
+ label: formatMessage({
195
+ id: "email.Settings.email.plugin.label.defaultFrom",
196
+ defaultMessage: "Default sender email"
197
+ }),
198
+ placeholder: formatMessage({
199
+ id: "email.Settings.email.plugin.placeholder.defaultFrom",
200
+ defaultMessage: "ex: Strapi No-Reply '<'no-reply@strapi.io'>'"
201
+ }),
202
+ disabled: true,
203
+ value: data.settings.defaultFrom
204
+ }
205
+ ) }),
206
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 6, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(
207
+ designSystem.TextInput,
208
+ {
209
+ name: "response-email",
210
+ label: formatMessage({
211
+ id: "email.Settings.email.plugin.label.defaultReplyTo",
212
+ defaultMessage: "Default response email"
213
+ }),
214
+ placeholder: formatMessage({
215
+ id: "email.Settings.email.plugin.placeholder.defaultReplyTo",
216
+ defaultMessage: `ex: Strapi '<'example@strapi.io'>'`
217
+ }),
218
+ disabled: true,
219
+ value: data.settings.defaultReplyTo
220
+ }
221
+ ) }),
222
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 6, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(
223
+ designSystem.SingleSelect,
224
+ {
225
+ name: "email-provider",
226
+ label: formatMessage({
227
+ id: "email.Settings.email.plugin.label.provider",
228
+ defaultMessage: "Email provider"
229
+ }),
230
+ disabled: true,
231
+ value: data.provider,
232
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: data.provider, children: data.provider })
233
+ }
234
+ ) })
235
+ ] })
236
+ ] })
237
+ }
238
+ ),
239
+ /* @__PURE__ */ jsxRuntime.jsxs(
240
+ designSystem.Flex,
241
+ {
242
+ alignItems: "stretch",
243
+ background: "neutral0",
244
+ direction: "column",
245
+ gap: 4,
246
+ hasRadius: true,
247
+ shadow: "filterShadow",
248
+ paddingTop: 6,
249
+ paddingBottom: 6,
250
+ paddingLeft: 7,
251
+ paddingRight: 7,
252
+ children: [
253
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", as: "h2", children: formatMessage({
254
+ id: "email.Settings.email.plugin.title.test",
255
+ defaultMessage: "Test email delivery"
256
+ }) }),
257
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid, { gap: 5, children: [
258
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 6, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(
259
+ designSystem.TextInput,
260
+ {
261
+ id: "test-address-input",
262
+ name: "test-address",
263
+ onChange: handleChange,
264
+ label: formatMessage({
265
+ id: "email.Settings.email.plugin.label.testAddress",
266
+ defaultMessage: "Recipient email"
267
+ }),
268
+ value: testAddress,
269
+ error: formErrors.email?.id && formatMessage({
270
+ id: `email.${formErrors.email?.id}`,
271
+ defaultMessage: "This is not a valid email"
272
+ }),
273
+ placeholder: formatMessage({
274
+ id: "email.Settings.email.plugin.placeholder.testAddress",
275
+ defaultMessage: "ex: developer@example.com"
276
+ })
277
+ }
278
+ ) }),
279
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 7, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(
280
+ designSystem.Button,
281
+ {
282
+ loading: mutation.isLoading,
283
+ disabled: !isTestAddressValid,
284
+ type: "submit",
285
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Mail, {}),
286
+ children: formatMessage({
287
+ id: "email.Settings.email.plugin.button.test-email",
288
+ defaultMessage: "Send test email"
289
+ })
290
+ }
291
+ ) })
292
+ ] })
293
+ ]
294
+ }
295
+ )
296
+ ] }) }) })
297
+ ] });
298
+ };
299
+ exports.ProtectedSettingsPage = ProtectedSettingsPage;
300
+ //# sourceMappingURL=Settings-C4EFpE_1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Settings-C4EFpE_1.js","sources":["../../admin/src/utils/getYupInnerErrors.ts","../../admin/src/utils/schema.ts","../../admin/src/pages/Settings.tsx"],"sourcesContent":["import type { MessageDescriptor, PrimitiveType } from 'react-intl';\nimport type { ValidationError } from 'yup';\n\ninterface TranslationMessage extends MessageDescriptor {\n values?: Record<string, PrimitiveType>;\n}\n\nconst extractValuesFromYupError = (\n errorType?: string | undefined,\n errorParams?: Record<string, any> | undefined\n) => {\n if (!errorType || !errorParams) {\n return {};\n }\n\n return {\n [errorType]: errorParams[errorType],\n };\n};\n\nconst getYupInnerErrors = (error: ValidationError) =>\n (error?.inner || []).reduce<Record<string, TranslationMessage>>((acc, currentError) => {\n if (currentError.path) {\n acc[currentError.path.split('[').join('.').split(']').join('')] = {\n id: currentError.message,\n defaultMessage: currentError.message,\n values: extractValuesFromYupError(currentError?.type, currentError?.params),\n };\n }\n\n return acc;\n }, {});\n\nexport { getYupInnerErrors };\n","import { translatedErrors } from '@strapi/admin/strapi-admin';\nimport * as yup from 'yup';\n\nexport const schema = yup.object().shape({\n email: yup.string().email(translatedErrors.email.id).required(translatedErrors.required.id),\n});\n","import * as React from 'react';\n\nimport { Page, useNotification, useFetchClient, Layouts } from '@strapi/admin/strapi-admin';\nimport {\n Box,\n Button,\n Flex,\n Grid,\n GridItem,\n SingleSelectOption,\n SingleSelect,\n TextInput,\n Typography,\n} from '@strapi/design-system';\nimport { Mail } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\nimport { useQuery, useMutation } from 'react-query';\nimport styled from 'styled-components';\nimport { ValidationError } from 'yup';\n\nimport { PERMISSIONS } from '../constants';\nimport { getYupInnerErrors } from '../utils/getYupInnerErrors';\nimport { schema } from '../utils/schema';\n\nimport type { EmailSettings } from '../../../shared/types';\n\nconst DocumentationLink = styled.a`\n color: ${({ theme }) => theme.colors.primary600};\n`;\n\ninterface MutationBody {\n to: string;\n}\n\nexport const ProtectedSettingsPage = () => (\n <Page.Protect permissions={PERMISSIONS.settings}>\n <SettingsPage />\n </Page.Protect>\n);\n\nconst SettingsPage = () => {\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const { get, post } = useFetchClient();\n\n const [testAddress, setTestAddress] = React.useState('');\n const [isTestAddressValid, setIsTestAddressValid] = React.useState(false);\n\n // TODO: I'm not sure how to type this. I think it should be Record<string, TranslationMessage> but that type is defined in the helper-plugin\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const [formErrors, setFormErrors] = React.useState<Record<string, any>>({});\n\n const { data, isLoading } = useQuery(['email', 'settings'], async () => {\n const res = await get<EmailSettings>('/email/settings');\n const {\n data: { config },\n } = res;\n\n return config;\n });\n\n const mutation = useMutation<void, Error, MutationBody>(\n async (body) => {\n await post('/email/test', body);\n },\n {\n onError() {\n toggleNotification!({\n type: 'danger',\n message: formatMessage(\n {\n id: 'email.Settings.email.plugin.notification.test.error',\n defaultMessage: 'Failed to send a test mail to {to}',\n },\n { to: testAddress }\n ),\n });\n },\n onSuccess() {\n toggleNotification!({\n type: 'success',\n message: formatMessage(\n {\n id: 'email.Settings.email.plugin.notification.test.success',\n defaultMessage: 'Email test succeeded, check the {to} mailbox',\n },\n { to: testAddress }\n ),\n });\n },\n retry: false,\n }\n );\n\n React.useEffect(() => {\n schema\n .validate({ email: testAddress }, { abortEarly: false })\n .then(() => setIsTestAddressValid(true))\n .catch(() => setIsTestAddressValid(false));\n }, [testAddress]);\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n setTestAddress(() => event.target.value);\n };\n\n const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n\n try {\n await schema.validate({ email: testAddress }, { abortEarly: false });\n } catch (error) {\n if (error instanceof ValidationError) {\n setFormErrors(getYupInnerErrors(error));\n }\n }\n\n mutation.mutate({ to: testAddress });\n };\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n return (\n <Page.Main labelledBy=\"title\" aria-busy={isLoading || mutation.isLoading}>\n <Page.Title>\n {formatMessage(\n { id: 'Settings.PageTitle', defaultMessage: 'Settings - {name}' },\n {\n name: formatMessage({\n id: 'email.Settings.email.plugin.title',\n defaultMessage: 'Configuration',\n }),\n }\n )}\n </Page.Title>\n <Layouts.Header\n id=\"title\"\n title={formatMessage({\n id: 'email.Settings.email.plugin.title',\n defaultMessage: 'Configuration',\n })}\n subtitle={formatMessage({\n id: 'email.Settings.email.plugin.subTitle',\n defaultMessage: 'Test the settings for the Email plugin',\n })}\n />\n\n <Layouts.Content>\n {data && (\n <form onSubmit={handleSubmit}>\n <Flex direction=\"column\" alignItems=\"stretch\" gap={7}>\n <Box\n background=\"neutral0\"\n hasRadius\n shadow=\"filterShadow\"\n paddingTop={6}\n paddingBottom={6}\n paddingLeft={7}\n paddingRight={7}\n >\n <Flex direction=\"column\" alignItems=\"stretch\" gap={4}>\n <Flex direction=\"column\" alignItems=\"stretch\" gap={1}>\n <Typography variant=\"delta\" as=\"h2\">\n {formatMessage({\n id: 'email.Settings.email.plugin.title.config',\n defaultMessage: 'Configuration',\n })}\n </Typography>\n <Typography>\n {formatMessage(\n {\n id: 'email.Settings.email.plugin.text.configuration',\n defaultMessage:\n 'The plugin is configured through the {file} file, checkout this {link} for the documentation.',\n },\n {\n file: './config/plugins.js',\n link: (\n <DocumentationLink\n href=\"https://docs.strapi.io/developer-docs/latest/plugins/email.html\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n {formatMessage({\n id: 'email.link',\n defaultMessage: 'Link',\n })}\n </DocumentationLink>\n ),\n }\n )}\n </Typography>\n </Flex>\n\n <Grid gap={5}>\n <GridItem col={6} s={12}>\n <TextInput\n name=\"shipper-email\"\n label={formatMessage({\n id: 'email.Settings.email.plugin.label.defaultFrom',\n defaultMessage: 'Default sender email',\n })}\n placeholder={formatMessage({\n id: 'email.Settings.email.plugin.placeholder.defaultFrom',\n defaultMessage: \"ex: Strapi No-Reply '<'no-reply@strapi.io'>'\",\n })}\n disabled\n value={data.settings.defaultFrom}\n />\n </GridItem>\n\n <GridItem col={6} s={12}>\n <TextInput\n name=\"response-email\"\n label={formatMessage({\n id: 'email.Settings.email.plugin.label.defaultReplyTo',\n defaultMessage: 'Default response email',\n })}\n placeholder={formatMessage({\n id: 'email.Settings.email.plugin.placeholder.defaultReplyTo',\n defaultMessage: `ex: Strapi '<'example@strapi.io'>'`,\n })}\n disabled\n value={data.settings.defaultReplyTo}\n />\n </GridItem>\n\n <GridItem col={6} s={12}>\n <SingleSelect\n name=\"email-provider\"\n label={formatMessage({\n id: 'email.Settings.email.plugin.label.provider',\n defaultMessage: 'Email provider',\n })}\n disabled\n value={data.provider}\n >\n <SingleSelectOption value={data.provider}>\n {data.provider}\n </SingleSelectOption>\n </SingleSelect>\n </GridItem>\n </Grid>\n </Flex>\n </Box>\n\n <Flex\n alignItems=\"stretch\"\n background=\"neutral0\"\n direction=\"column\"\n gap={4}\n hasRadius\n shadow=\"filterShadow\"\n paddingTop={6}\n paddingBottom={6}\n paddingLeft={7}\n paddingRight={7}\n >\n <Typography variant=\"delta\" as=\"h2\">\n {formatMessage({\n id: 'email.Settings.email.plugin.title.test',\n defaultMessage: 'Test email delivery',\n })}\n </Typography>\n\n <Grid gap={5}>\n <GridItem col={6} s={12}>\n <TextInput\n id=\"test-address-input\"\n name=\"test-address\"\n onChange={handleChange}\n label={formatMessage({\n id: 'email.Settings.email.plugin.label.testAddress',\n defaultMessage: 'Recipient email',\n })}\n value={testAddress}\n error={\n formErrors.email?.id &&\n formatMessage({\n id: `email.${formErrors.email?.id}`,\n defaultMessage: 'This is not a valid email',\n })\n }\n placeholder={formatMessage({\n id: 'email.Settings.email.plugin.placeholder.testAddress',\n defaultMessage: 'ex: developer@example.com',\n })}\n />\n </GridItem>\n <GridItem col={7} s={12}>\n <Button\n loading={mutation.isLoading}\n disabled={!isTestAddressValid}\n type=\"submit\"\n startIcon={<Mail />}\n >\n {formatMessage({\n id: 'email.Settings.email.plugin.button.test-email',\n defaultMessage: 'Send test email',\n })}\n </Button>\n </GridItem>\n </Grid>\n </Flex>\n </Flex>\n </form>\n )}\n </Layouts.Content>\n </Page.Main>\n );\n};\n"],"names":["yup","translatedErrors","styled","jsx","Page","PERMISSIONS","useNotification","useIntl","useFetchClient","React","useQuery","useMutation","ValidationError","jsxs","Layouts","Flex","Box","Typography","Grid","GridItem","TextInput","SingleSelect","SingleSelectOption","Button","Mail"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,4BAA4B,CAChC,WACA,gBACG;AACC,MAAA,CAAC,aAAa,CAAC,aAAa;AAC9B,WAAO;EACT;AAEO,SAAA;AAAA,IACL,CAAC,SAAS,GAAG,YAAY,SAAS;AAAA,EAAA;AAEtC;AAEA,MAAM,oBAAoB,CAAC,WACxB,OAAO,SAAS,CAAA,GAAI,OAA2C,CAAC,KAAK,iBAAiB;AACrF,MAAI,aAAa,MAAM;AACrB,QAAI,aAAa,KAAK,MAAM,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG,EAAE,KAAK,EAAE,CAAC,IAAI;AAAA,MAChE,IAAI,aAAa;AAAA,MACjB,gBAAgB,aAAa;AAAA,MAC7B,QAAQ,0BAA0B,cAAc,MAAM,cAAc,MAAM;AAAA,IAAA;AAAA,EAE9E;AAEO,SAAA;AACT,GAAG,EAAE;AC5BA,MAAM,SAASA,eAAI,OAAO,EAAE,MAAM;AAAA,EACvC,OAAOA,eAAI,OAAO,EAAE,MAAMC,YAAA,iBAAiB,MAAM,EAAE,EAAE,SAASA,6BAAiB,SAAS,EAAE;AAC5F,CAAC;ACqBD,MAAM,oBAAoBC,gBAAO,QAAA;AAAA,WACtB,CAAC,EAAE,MAAA,MAAY,MAAM,OAAO,UAAU;AAAA;AAOpC,MAAA,wBAAwB,MACnCC,2BAAA,IAACC,iBAAK,SAAL,EAAa,aAAaC,kBAAY,UACrC,UAACF,2BAAAA,IAAA,cAAA,CAAA,CAAa,EAChB,CAAA;AAGF,MAAM,eAAe,MAAM;AACnB,QAAA,EAAE,uBAAuBG,YAAAA;AACzB,QAAA,EAAE,kBAAkBC,U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AAA,IAACgB,aAAS,UAAA,EAAA,KAAK,GAAG,GAAG,IACnB,UAAAhB,2BAAA;AAAA,gBAACiB,aAAA;AAAA,gBAAA;AAAA,kBACC,IAAG;AAAA,kBACH,MAAK;AAAA,kBACL,UAAU;AAAA,kBACV,OAAO,cAAc;AAAA,oBACnB,IAAI;AAAA,oBACJ,gBAAgB;AAAA,kBAAA,CACjB;AAAA,kBACD,OAAO;AAAA,kBACP,OACE,WAAW,OAAO,MAClB,cAAc;AAAA,oBACZ,IAAI,SAAS,WAAW,OAAO,EAAE;AAAA,oBACjC,gBAAgB;AAAA,kBAAA,CACjB;AAAA,kBAEH,aAAa,cAAc;AAAA,oBACzB,IAAI;AAAA,oBACJ,gBAAgB;AAAA,kBAAA,CACjB;AAAA,gBAAA;AAAA,cAAA,GAEL;AAAA,cACCjB,2BAAA,IAAAgB,aAAA,UAAA,EAAS,KAAK,GAAG,GAAG,IACnB,UAAAhB,2BAAA;AAAA,gBAACoB,aAAA;AAAA,gBAAA;AAAA,kBACC,SAAS,SAAS;AAAA,kBAClB,UAAU,CAAC;AAAA,kBACX,MAAK;AAAA,kBACL,0CAAYC,MAAK,MAAA,EAAA;AAAA,kBAEhB,UAAc,cAAA;AAAA,oBACb,IAAI;AAAA,oBACJ,gBAAgB;AAAA,kBAAA,CACjB;AAAA,gBAAA;AAAA,cAAA,GAEL;AAAA,YAAA,GACF;AAAA,UAAA;AAAA,QAAA;AAAA,MACF;AAAA,IAAA,EACF,CAAA,EACF,CAAA,GAEJ;AAAA,EACF,EAAA,CAAA;AAEJ;;"}
@@ -0,0 +1,279 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { translatedErrors, Page, useNotification, useFetchClient, Layouts } from "@strapi/admin/strapi-admin";
4
+ import { Flex, Box, Typography, Grid, GridItem, TextInput, SingleSelect, SingleSelectOption, Button } from "@strapi/design-system";
5
+ import { Mail } from "@strapi/icons";
6
+ import { useIntl } from "react-intl";
7
+ import { useQuery, useMutation } from "react-query";
8
+ import styled from "styled-components";
9
+ import * as yup from "yup";
10
+ import { ValidationError } from "yup";
11
+ import { P as PERMISSIONS } from "./index-DN0Ma-cQ.mjs";
12
+ const extractValuesFromYupError = (errorType, errorParams) => {
13
+ if (!errorType || !errorParams) {
14
+ return {};
15
+ }
16
+ return {
17
+ [errorType]: errorParams[errorType]
18
+ };
19
+ };
20
+ const getYupInnerErrors = (error) => (error?.inner || []).reduce((acc, currentError) => {
21
+ if (currentError.path) {
22
+ acc[currentError.path.split("[").join(".").split("]").join("")] = {
23
+ id: currentError.message,
24
+ defaultMessage: currentError.message,
25
+ values: extractValuesFromYupError(currentError?.type, currentError?.params)
26
+ };
27
+ }
28
+ return acc;
29
+ }, {});
30
+ const schema = yup.object().shape({
31
+ email: yup.string().email(translatedErrors.email.id).required(translatedErrors.required.id)
32
+ });
33
+ const DocumentationLink = styled.a`
34
+ color: ${({ theme }) => theme.colors.primary600};
35
+ `;
36
+ const ProtectedSettingsPage = () => /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.settings, children: /* @__PURE__ */ jsx(SettingsPage, {}) });
37
+ const SettingsPage = () => {
38
+ const { toggleNotification } = useNotification();
39
+ const { formatMessage } = useIntl();
40
+ const { get, post } = useFetchClient();
41
+ const [testAddress, setTestAddress] = React.useState("");
42
+ const [isTestAddressValid, setIsTestAddressValid] = React.useState(false);
43
+ const [formErrors, setFormErrors] = React.useState({});
44
+ const { data, isLoading } = useQuery(["email", "settings"], async () => {
45
+ const res = await get("/email/settings");
46
+ const {
47
+ data: { config }
48
+ } = res;
49
+ return config;
50
+ });
51
+ const mutation = useMutation(
52
+ async (body) => {
53
+ await post("/email/test", body);
54
+ },
55
+ {
56
+ onError() {
57
+ toggleNotification({
58
+ type: "danger",
59
+ message: formatMessage(
60
+ {
61
+ id: "email.Settings.email.plugin.notification.test.error",
62
+ defaultMessage: "Failed to send a test mail to {to}"
63
+ },
64
+ { to: testAddress }
65
+ )
66
+ });
67
+ },
68
+ onSuccess() {
69
+ toggleNotification({
70
+ type: "success",
71
+ message: formatMessage(
72
+ {
73
+ id: "email.Settings.email.plugin.notification.test.success",
74
+ defaultMessage: "Email test succeeded, check the {to} mailbox"
75
+ },
76
+ { to: testAddress }
77
+ )
78
+ });
79
+ },
80
+ retry: false
81
+ }
82
+ );
83
+ React.useEffect(() => {
84
+ schema.validate({ email: testAddress }, { abortEarly: false }).then(() => setIsTestAddressValid(true)).catch(() => setIsTestAddressValid(false));
85
+ }, [testAddress]);
86
+ const handleChange = (event) => {
87
+ setTestAddress(() => event.target.value);
88
+ };
89
+ const handleSubmit = async (event) => {
90
+ event.preventDefault();
91
+ try {
92
+ await schema.validate({ email: testAddress }, { abortEarly: false });
93
+ } catch (error) {
94
+ if (error instanceof ValidationError) {
95
+ setFormErrors(getYupInnerErrors(error));
96
+ }
97
+ }
98
+ mutation.mutate({ to: testAddress });
99
+ };
100
+ if (isLoading) {
101
+ return /* @__PURE__ */ jsx(Page.Loading, {});
102
+ }
103
+ return /* @__PURE__ */ jsxs(Page.Main, { labelledBy: "title", "aria-busy": isLoading || mutation.isLoading, children: [
104
+ /* @__PURE__ */ jsx(Page.Title, { children: formatMessage(
105
+ { id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
106
+ {
107
+ name: formatMessage({
108
+ id: "email.Settings.email.plugin.title",
109
+ defaultMessage: "Configuration"
110
+ })
111
+ }
112
+ ) }),
113
+ /* @__PURE__ */ jsx(
114
+ Layouts.Header,
115
+ {
116
+ id: "title",
117
+ title: formatMessage({
118
+ id: "email.Settings.email.plugin.title",
119
+ defaultMessage: "Configuration"
120
+ }),
121
+ subtitle: formatMessage({
122
+ id: "email.Settings.email.plugin.subTitle",
123
+ defaultMessage: "Test the settings for the Email plugin"
124
+ })
125
+ }
126
+ ),
127
+ /* @__PURE__ */ jsx(Layouts.Content, { children: data && /* @__PURE__ */ jsx("form", { onSubmit: handleSubmit, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 7, children: [
128
+ /* @__PURE__ */ jsx(
129
+ Box,
130
+ {
131
+ background: "neutral0",
132
+ hasRadius: true,
133
+ shadow: "filterShadow",
134
+ paddingTop: 6,
135
+ paddingBottom: 6,
136
+ paddingLeft: 7,
137
+ paddingRight: 7,
138
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
139
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
140
+ /* @__PURE__ */ jsx(Typography, { variant: "delta", as: "h2", children: formatMessage({
141
+ id: "email.Settings.email.plugin.title.config",
142
+ defaultMessage: "Configuration"
143
+ }) }),
144
+ /* @__PURE__ */ jsx(Typography, { children: formatMessage(
145
+ {
146
+ id: "email.Settings.email.plugin.text.configuration",
147
+ defaultMessage: "The plugin is configured through the {file} file, checkout this {link} for the documentation."
148
+ },
149
+ {
150
+ file: "./config/plugins.js",
151
+ link: /* @__PURE__ */ jsx(
152
+ DocumentationLink,
153
+ {
154
+ href: "https://docs.strapi.io/developer-docs/latest/plugins/email.html",
155
+ target: "_blank",
156
+ rel: "noopener noreferrer",
157
+ children: formatMessage({
158
+ id: "email.link",
159
+ defaultMessage: "Link"
160
+ })
161
+ }
162
+ )
163
+ }
164
+ ) })
165
+ ] }),
166
+ /* @__PURE__ */ jsxs(Grid, { gap: 5, children: [
167
+ /* @__PURE__ */ jsx(GridItem, { col: 6, s: 12, children: /* @__PURE__ */ jsx(
168
+ TextInput,
169
+ {
170
+ name: "shipper-email",
171
+ label: formatMessage({
172
+ id: "email.Settings.email.plugin.label.defaultFrom",
173
+ defaultMessage: "Default sender email"
174
+ }),
175
+ placeholder: formatMessage({
176
+ id: "email.Settings.email.plugin.placeholder.defaultFrom",
177
+ defaultMessage: "ex: Strapi No-Reply '<'no-reply@strapi.io'>'"
178
+ }),
179
+ disabled: true,
180
+ value: data.settings.defaultFrom
181
+ }
182
+ ) }),
183
+ /* @__PURE__ */ jsx(GridItem, { col: 6, s: 12, children: /* @__PURE__ */ jsx(
184
+ TextInput,
185
+ {
186
+ name: "response-email",
187
+ label: formatMessage({
188
+ id: "email.Settings.email.plugin.label.defaultReplyTo",
189
+ defaultMessage: "Default response email"
190
+ }),
191
+ placeholder: formatMessage({
192
+ id: "email.Settings.email.plugin.placeholder.defaultReplyTo",
193
+ defaultMessage: `ex: Strapi '<'example@strapi.io'>'`
194
+ }),
195
+ disabled: true,
196
+ value: data.settings.defaultReplyTo
197
+ }
198
+ ) }),
199
+ /* @__PURE__ */ jsx(GridItem, { col: 6, s: 12, children: /* @__PURE__ */ jsx(
200
+ SingleSelect,
201
+ {
202
+ name: "email-provider",
203
+ label: formatMessage({
204
+ id: "email.Settings.email.plugin.label.provider",
205
+ defaultMessage: "Email provider"
206
+ }),
207
+ disabled: true,
208
+ value: data.provider,
209
+ children: /* @__PURE__ */ jsx(SingleSelectOption, { value: data.provider, children: data.provider })
210
+ }
211
+ ) })
212
+ ] })
213
+ ] })
214
+ }
215
+ ),
216
+ /* @__PURE__ */ jsxs(
217
+ Flex,
218
+ {
219
+ alignItems: "stretch",
220
+ background: "neutral0",
221
+ direction: "column",
222
+ gap: 4,
223
+ hasRadius: true,
224
+ shadow: "filterShadow",
225
+ paddingTop: 6,
226
+ paddingBottom: 6,
227
+ paddingLeft: 7,
228
+ paddingRight: 7,
229
+ children: [
230
+ /* @__PURE__ */ jsx(Typography, { variant: "delta", as: "h2", children: formatMessage({
231
+ id: "email.Settings.email.plugin.title.test",
232
+ defaultMessage: "Test email delivery"
233
+ }) }),
234
+ /* @__PURE__ */ jsxs(Grid, { gap: 5, children: [
235
+ /* @__PURE__ */ jsx(GridItem, { col: 6, s: 12, children: /* @__PURE__ */ jsx(
236
+ TextInput,
237
+ {
238
+ id: "test-address-input",
239
+ name: "test-address",
240
+ onChange: handleChange,
241
+ label: formatMessage({
242
+ id: "email.Settings.email.plugin.label.testAddress",
243
+ defaultMessage: "Recipient email"
244
+ }),
245
+ value: testAddress,
246
+ error: formErrors.email?.id && formatMessage({
247
+ id: `email.${formErrors.email?.id}`,
248
+ defaultMessage: "This is not a valid email"
249
+ }),
250
+ placeholder: formatMessage({
251
+ id: "email.Settings.email.plugin.placeholder.testAddress",
252
+ defaultMessage: "ex: developer@example.com"
253
+ })
254
+ }
255
+ ) }),
256
+ /* @__PURE__ */ jsx(GridItem, { col: 7, s: 12, children: /* @__PURE__ */ jsx(
257
+ Button,
258
+ {
259
+ loading: mutation.isLoading,
260
+ disabled: !isTestAddressValid,
261
+ type: "submit",
262
+ startIcon: /* @__PURE__ */ jsx(Mail, {}),
263
+ children: formatMessage({
264
+ id: "email.Settings.email.plugin.button.test-email",
265
+ defaultMessage: "Send test email"
266
+ })
267
+ }
268
+ ) })
269
+ ] })
270
+ ]
271
+ }
272
+ )
273
+ ] }) }) })
274
+ ] });
275
+ };
276
+ export {
277
+ ProtectedSettingsPage
278
+ };
279
+ //# sourceMappingURL=Settings-ZhMskNHr.mjs.map