@strapi/email 0.0.0 → 5.0.0-beta.10
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.
- package/README.md +3 -1
- package/dist/_chunks/Settings-DPpUcr9n.js +300 -0
- package/dist/_chunks/Settings-DPpUcr9n.js.map +1 -0
- package/dist/_chunks/Settings-DwGRZXNs.mjs +281 -0
- package/dist/_chunks/Settings-DwGRZXNs.mjs.map +1 -0
- package/dist/_chunks/ar-Bf9XlLLo.mjs +5 -0
- package/dist/_chunks/ar-Bf9XlLLo.mjs.map +1 -0
- package/dist/_chunks/ar-C_tQu1XS.js +5 -0
- package/dist/_chunks/ar-C_tQu1XS.js.map +1 -0
- package/dist/_chunks/cs-B0QZJTah.mjs +5 -0
- package/dist/_chunks/cs-B0QZJTah.mjs.map +1 -0
- package/dist/_chunks/cs-CPKIUWLp.js +5 -0
- package/dist/_chunks/cs-CPKIUWLp.js.map +1 -0
- package/dist/_chunks/de-B9kiAC-s.mjs +5 -0
- package/dist/_chunks/de-B9kiAC-s.mjs.map +1 -0
- package/dist/_chunks/de-K6IYQk2d.js +5 -0
- package/dist/_chunks/de-K6IYQk2d.js.map +1 -0
- package/dist/_chunks/dk-31mOPYpI.js +26 -0
- package/dist/_chunks/dk-31mOPYpI.js.map +1 -0
- package/dist/_chunks/dk-DqrbgSkv.mjs +26 -0
- package/dist/_chunks/dk-DqrbgSkv.mjs.map +1 -0
- package/dist/_chunks/en-BCu4d6-o.js +29 -0
- package/dist/_chunks/en-BCu4d6-o.js.map +1 -0
- package/dist/_chunks/en-DF4KtAAC.mjs +29 -0
- package/dist/_chunks/en-DF4KtAAC.mjs.map +1 -0
- package/dist/_chunks/es-BNo7eLLJ.mjs +26 -0
- package/dist/_chunks/es-BNo7eLLJ.mjs.map +1 -0
- package/dist/_chunks/es-Dl2HVmwz.js +26 -0
- package/dist/_chunks/es-Dl2HVmwz.js.map +1 -0
- package/dist/_chunks/fr-C8Qw4iPZ.js +5 -0
- package/dist/_chunks/fr-C8Qw4iPZ.js.map +1 -0
- package/dist/_chunks/fr-hkSxFuzl.mjs +5 -0
- package/dist/_chunks/fr-hkSxFuzl.mjs.map +1 -0
- package/dist/_chunks/id-CHtAzAUz.mjs +5 -0
- package/dist/_chunks/id-CHtAzAUz.mjs.map +1 -0
- package/dist/_chunks/id-CvE5f0zz.js +5 -0
- package/dist/_chunks/id-CvE5f0zz.js.map +1 -0
- package/dist/_chunks/index-BL_YuIzh.mjs +81 -0
- package/dist/_chunks/index-BL_YuIzh.mjs.map +1 -0
- package/dist/_chunks/index-D6q3fYgO.js +80 -0
- package/dist/_chunks/index-D6q3fYgO.js.map +1 -0
- package/dist/_chunks/it-C7z82V3g.mjs +5 -0
- package/dist/_chunks/it-C7z82V3g.mjs.map +1 -0
- package/dist/_chunks/it-DYpuAHa5.js +5 -0
- package/dist/_chunks/it-DYpuAHa5.js.map +1 -0
- package/dist/_chunks/ja-CiekkoEN.mjs +26 -0
- package/dist/_chunks/ja-CiekkoEN.mjs.map +1 -0
- package/dist/_chunks/ja-PL3WilO7.js +26 -0
- package/dist/_chunks/ja-PL3WilO7.js.map +1 -0
- package/dist/_chunks/ko-CJBkZ375.mjs +26 -0
- package/dist/_chunks/ko-CJBkZ375.mjs.map +1 -0
- package/dist/_chunks/ko-CL2BB_w_.js +26 -0
- package/dist/_chunks/ko-CL2BB_w_.js.map +1 -0
- package/dist/_chunks/ms-BGlHkuJz.js +5 -0
- package/dist/_chunks/ms-BGlHkuJz.js.map +1 -0
- package/dist/_chunks/ms-C1wNkEQw.mjs +5 -0
- package/dist/_chunks/ms-C1wNkEQw.mjs.map +1 -0
- package/dist/_chunks/nl-BuofSsmb.js +5 -0
- package/dist/_chunks/nl-BuofSsmb.js.map +1 -0
- package/dist/_chunks/nl-C79CwB4e.mjs +5 -0
- package/dist/_chunks/nl-C79CwB4e.mjs.map +1 -0
- package/dist/_chunks/pl-DXcJCevg.mjs +26 -0
- package/dist/_chunks/pl-DXcJCevg.mjs.map +1 -0
- package/dist/_chunks/pl-DdtXf3SH.js +26 -0
- package/dist/_chunks/pl-DdtXf3SH.js.map +1 -0
- package/dist/_chunks/pt-BR-B_ii8U63.js +5 -0
- package/dist/_chunks/pt-BR-B_ii8U63.js.map +1 -0
- package/dist/_chunks/pt-BR-DjINUWGk.mjs +5 -0
- package/dist/_chunks/pt-BR-DjINUWGk.mjs.map +1 -0
- package/dist/_chunks/pt-CzRDvk6c.js +29 -0
- package/dist/_chunks/pt-CzRDvk6c.js.map +1 -0
- package/dist/_chunks/pt-DEVCt2mt.mjs +29 -0
- package/dist/_chunks/pt-DEVCt2mt.mjs.map +1 -0
- package/dist/_chunks/ru-C_7wBr9e.mjs +5 -0
- package/dist/_chunks/ru-C_7wBr9e.mjs.map +1 -0
- package/dist/_chunks/ru-Dc-rSPqb.js +5 -0
- package/dist/_chunks/ru-Dc-rSPqb.js.map +1 -0
- package/dist/_chunks/sk-Cnpb4YOK.js +5 -0
- package/dist/_chunks/sk-Cnpb4YOK.js.map +1 -0
- package/dist/_chunks/sk-i1gQKUBN.mjs +5 -0
- package/dist/_chunks/sk-i1gQKUBN.mjs.map +1 -0
- package/dist/_chunks/th-BXTLF08M.js +5 -0
- package/dist/_chunks/th-BXTLF08M.js.map +1 -0
- package/dist/_chunks/th-D-MxpWKr.mjs +5 -0
- package/dist/_chunks/th-D-MxpWKr.mjs.map +1 -0
- package/dist/_chunks/tr-BXu41MLY.mjs +29 -0
- package/dist/_chunks/tr-BXu41MLY.mjs.map +1 -0
- package/dist/_chunks/tr-DwBySNgJ.js +29 -0
- package/dist/_chunks/tr-DwBySNgJ.js.map +1 -0
- package/dist/_chunks/uk-C_1qrLRM.mjs +5 -0
- package/dist/_chunks/uk-C_1qrLRM.mjs.map +1 -0
- package/dist/_chunks/uk-CxIePjBD.js +5 -0
- package/dist/_chunks/uk-CxIePjBD.js.map +1 -0
- package/dist/_chunks/vi-B4uqmjm6.js +5 -0
- package/dist/_chunks/vi-B4uqmjm6.js.map +1 -0
- package/dist/_chunks/vi-BfZkgFxI.mjs +5 -0
- package/dist/_chunks/vi-BfZkgFxI.mjs.map +1 -0
- package/dist/_chunks/zh-BS-XJCSt.mjs +29 -0
- package/dist/_chunks/zh-BS-XJCSt.mjs.map +1 -0
- package/dist/_chunks/zh-DsMIjTgu.js +29 -0
- package/dist/_chunks/zh-DsMIjTgu.js.map +1 -0
- package/dist/_chunks/zh-Hans-BLEEaLoN.mjs +21 -0
- package/dist/_chunks/zh-Hans-BLEEaLoN.mjs.map +1 -0
- package/dist/_chunks/zh-Hans-CmL3sY9o.js +21 -0
- package/dist/_chunks/zh-Hans-CmL3sY9o.js.map +1 -0
- package/dist/admin/index.js +4 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/index.mjs +5 -0
- package/dist/admin/index.mjs.map +1 -0
- package/dist/admin/src/constants.d.ts +6 -0
- package/dist/admin/src/index.d.ts +3 -0
- package/dist/admin/src/pages/Settings.d.ts +1 -0
- package/dist/admin/src/utils/getYupInnerErrors.d.ts +7 -0
- package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
- package/dist/admin/src/utils/schema.d.ts +8 -0
- package/dist/server/index.js +209 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +191 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/src/bootstrap.d.ts +5 -0
- package/dist/server/src/bootstrap.d.ts.map +1 -0
- package/dist/server/src/config.d.ts +3 -0
- package/dist/server/src/config.d.ts.map +1 -0
- package/dist/server/src/controllers/email.d.ts +13 -0
- package/dist/server/src/controllers/email.d.ts.map +1 -0
- package/dist/server/src/controllers/index.d.ts +9 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +49 -0
- package/dist/server/src/index.d.ts.map +1 -0
- package/dist/server/src/routes/admin.d.ts +18 -0
- package/dist/server/src/routes/admin.d.ts.map +1 -0
- package/dist/server/src/routes/content-api.d.ts +10 -0
- package/dist/server/src/routes/content-api.d.ts.map +1 -0
- package/dist/server/src/routes/index.d.ts +27 -0
- package/dist/server/src/routes/index.d.ts.map +1 -0
- package/dist/server/src/services/email.d.ts +8 -0
- package/dist/server/src/services/email.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +8 -0
- package/dist/server/src/services/index.d.ts.map +1 -0
- package/dist/server/src/types.d.ts +38 -0
- package/dist/server/src/types.d.ts.map +1 -0
- package/dist/shared/types.d.ts +11 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/package.json +80 -3
- package/strapi-server.js +3 -0
package/README.md
CHANGED
|
@@ -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 styledComponents = require("styled-components");
|
|
11
|
+
const yup = require("yup");
|
|
12
|
+
const index = require("./index-D6q3fYgO.js");
|
|
13
|
+
function _interopNamespace(e) {
|
|
14
|
+
if (e && e.__esModule)
|
|
15
|
+
return e;
|
|
16
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
17
|
+
if (e) {
|
|
18
|
+
for (const k in e) {
|
|
19
|
+
if (k !== "default") {
|
|
20
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: () => e[k]
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
n.default = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
|
32
|
+
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
33
|
+
const extractValuesFromYupError = (errorType, errorParams) => {
|
|
34
|
+
if (!errorType || !errorParams) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
[errorType]: errorParams[errorType]
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const getYupInnerErrors = (error) => (error?.inner || []).reduce((acc, currentError) => {
|
|
42
|
+
if (currentError.path) {
|
|
43
|
+
acc[currentError.path.split("[").join(".").split("]").join("")] = {
|
|
44
|
+
id: currentError.message,
|
|
45
|
+
defaultMessage: currentError.message,
|
|
46
|
+
values: extractValuesFromYupError(currentError?.type, currentError?.params)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
const schema = yup__namespace.object().shape({
|
|
52
|
+
email: yup__namespace.string().email(strapiAdmin.translatedErrors.email.id).required(strapiAdmin.translatedErrors.required.id)
|
|
53
|
+
});
|
|
54
|
+
const DocumentationLink = styledComponents.styled.a`
|
|
55
|
+
color: ${({ theme }) => theme.colors.primary600};
|
|
56
|
+
`;
|
|
57
|
+
const ProtectedSettingsPage = () => /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Protect, { permissions: index.PERMISSIONS.settings, children: /* @__PURE__ */ jsxRuntime.jsx(SettingsPage, {}) });
|
|
58
|
+
const SettingsPage = () => {
|
|
59
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
|
60
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
61
|
+
const { get, post } = strapiAdmin.useFetchClient();
|
|
62
|
+
const [testAddress, setTestAddress] = React__namespace.useState("");
|
|
63
|
+
const [isTestAddressValid, setIsTestAddressValid] = React__namespace.useState(false);
|
|
64
|
+
const [formErrors, setFormErrors] = React__namespace.useState({});
|
|
65
|
+
const { data, isLoading } = reactQuery.useQuery(["email", "settings"], async () => {
|
|
66
|
+
const res = await get("/email/settings");
|
|
67
|
+
const {
|
|
68
|
+
data: { config }
|
|
69
|
+
} = res;
|
|
70
|
+
return config;
|
|
71
|
+
});
|
|
72
|
+
const mutation = reactQuery.useMutation(
|
|
73
|
+
async (body) => {
|
|
74
|
+
await post("/email/test", body);
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
onError() {
|
|
78
|
+
toggleNotification({
|
|
79
|
+
type: "danger",
|
|
80
|
+
message: formatMessage(
|
|
81
|
+
{
|
|
82
|
+
id: "email.Settings.email.plugin.notification.test.error",
|
|
83
|
+
defaultMessage: "Failed to send a test mail to {to}"
|
|
84
|
+
},
|
|
85
|
+
{ to: testAddress }
|
|
86
|
+
)
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
onSuccess() {
|
|
90
|
+
toggleNotification({
|
|
91
|
+
type: "success",
|
|
92
|
+
message: formatMessage(
|
|
93
|
+
{
|
|
94
|
+
id: "email.Settings.email.plugin.notification.test.success",
|
|
95
|
+
defaultMessage: "Email test succeeded, check the {to} mailbox"
|
|
96
|
+
},
|
|
97
|
+
{ to: testAddress }
|
|
98
|
+
)
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
retry: false
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
React__namespace.useEffect(() => {
|
|
105
|
+
schema.validate({ email: testAddress }, { abortEarly: false }).then(() => setIsTestAddressValid(true)).catch(() => setIsTestAddressValid(false));
|
|
106
|
+
}, [testAddress]);
|
|
107
|
+
const handleChange = (event) => {
|
|
108
|
+
setTestAddress(() => event.target.value);
|
|
109
|
+
};
|
|
110
|
+
const handleSubmit = async (event) => {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
try {
|
|
113
|
+
await schema.validate({ email: testAddress }, { abortEarly: false });
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (error instanceof yup.ValidationError) {
|
|
116
|
+
setFormErrors(getYupInnerErrors(error));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
mutation.mutate({ to: testAddress });
|
|
120
|
+
};
|
|
121
|
+
if (isLoading) {
|
|
122
|
+
return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
|
|
123
|
+
}
|
|
124
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Page.Main, { labelledBy: "title", "aria-busy": isLoading || mutation.isLoading, children: [
|
|
125
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Title, { children: formatMessage(
|
|
126
|
+
{ id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
|
|
127
|
+
{
|
|
128
|
+
name: formatMessage({
|
|
129
|
+
id: "email.Settings.email.plugin.title",
|
|
130
|
+
defaultMessage: "Configuration"
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
) }),
|
|
134
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
135
|
+
strapiAdmin.Layouts.Header,
|
|
136
|
+
{
|
|
137
|
+
id: "title",
|
|
138
|
+
title: formatMessage({
|
|
139
|
+
id: "email.Settings.email.plugin.title",
|
|
140
|
+
defaultMessage: "Configuration"
|
|
141
|
+
}),
|
|
142
|
+
subtitle: formatMessage({
|
|
143
|
+
id: "email.Settings.email.plugin.subTitle",
|
|
144
|
+
defaultMessage: "Test the settings for the Email plugin"
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
/* @__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: [
|
|
149
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
150
|
+
designSystem.Box,
|
|
151
|
+
{
|
|
152
|
+
background: "neutral0",
|
|
153
|
+
hasRadius: true,
|
|
154
|
+
shadow: "filterShadow",
|
|
155
|
+
paddingTop: 6,
|
|
156
|
+
paddingBottom: 6,
|
|
157
|
+
paddingLeft: 7,
|
|
158
|
+
paddingRight: 7,
|
|
159
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
160
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
161
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h2", children: formatMessage({
|
|
162
|
+
id: "email.Settings.email.plugin.title.config",
|
|
163
|
+
defaultMessage: "Configuration"
|
|
164
|
+
}) }),
|
|
165
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: formatMessage(
|
|
166
|
+
{
|
|
167
|
+
id: "email.Settings.email.plugin.text.configuration",
|
|
168
|
+
defaultMessage: "The plugin is configured through the {file} file, checkout this {link} for the documentation."
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
file: "./config/plugins.js",
|
|
172
|
+
link: /* @__PURE__ */ jsxRuntime.jsx(
|
|
173
|
+
DocumentationLink,
|
|
174
|
+
{
|
|
175
|
+
href: "https://docs.strapi.io/developer-docs/latest/plugins/email.html",
|
|
176
|
+
target: "_blank",
|
|
177
|
+
rel: "noopener noreferrer",
|
|
178
|
+
children: formatMessage({
|
|
179
|
+
id: "email.link",
|
|
180
|
+
defaultMessage: "Link"
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
) })
|
|
186
|
+
] }),
|
|
187
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 5, children: [
|
|
188
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, s: 12, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "shipper-email", children: [
|
|
189
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
|
|
190
|
+
id: "email.Settings.email.plugin.label.defaultFrom",
|
|
191
|
+
defaultMessage: "Default sender email"
|
|
192
|
+
}) }),
|
|
193
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
194
|
+
designSystem.TextInput,
|
|
195
|
+
{
|
|
196
|
+
placeholder: formatMessage({
|
|
197
|
+
id: "email.Settings.email.plugin.placeholder.defaultFrom",
|
|
198
|
+
defaultMessage: "ex: Strapi No-Reply '<'no-reply@strapi.io'>'"
|
|
199
|
+
}),
|
|
200
|
+
disabled: true,
|
|
201
|
+
value: data.settings.defaultFrom
|
|
202
|
+
}
|
|
203
|
+
)
|
|
204
|
+
] }) }),
|
|
205
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, s: 12, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "response-email", children: [
|
|
206
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
|
|
207
|
+
id: "email.Settings.email.plugin.label.defaultReplyTo",
|
|
208
|
+
defaultMessage: "Default response email"
|
|
209
|
+
}) }),
|
|
210
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
211
|
+
designSystem.TextInput,
|
|
212
|
+
{
|
|
213
|
+
placeholder: formatMessage({
|
|
214
|
+
id: "email.Settings.email.plugin.placeholder.defaultReplyTo",
|
|
215
|
+
defaultMessage: `ex: Strapi '<'example@strapi.io'>'`
|
|
216
|
+
}),
|
|
217
|
+
disabled: true,
|
|
218
|
+
value: data.settings.defaultReplyTo
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
] }) }),
|
|
222
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, s: 12, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "email-provider", children: [
|
|
223
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
|
|
224
|
+
id: "email.Settings.email.plugin.label.provider",
|
|
225
|
+
defaultMessage: "Email provider"
|
|
226
|
+
}) }),
|
|
227
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelect, { disabled: true, value: data.provider, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: data.provider, children: data.provider }) })
|
|
228
|
+
] }) })
|
|
229
|
+
] })
|
|
230
|
+
] })
|
|
231
|
+
}
|
|
232
|
+
),
|
|
233
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
234
|
+
designSystem.Flex,
|
|
235
|
+
{
|
|
236
|
+
alignItems: "stretch",
|
|
237
|
+
background: "neutral0",
|
|
238
|
+
direction: "column",
|
|
239
|
+
gap: 4,
|
|
240
|
+
hasRadius: true,
|
|
241
|
+
shadow: "filterShadow",
|
|
242
|
+
paddingTop: 6,
|
|
243
|
+
paddingBottom: 6,
|
|
244
|
+
paddingLeft: 7,
|
|
245
|
+
paddingRight: 7,
|
|
246
|
+
children: [
|
|
247
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h2", children: formatMessage({
|
|
248
|
+
id: "email.Settings.email.plugin.title.test",
|
|
249
|
+
defaultMessage: "Test email delivery"
|
|
250
|
+
}) }),
|
|
251
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 5, children: [
|
|
252
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, s: 12, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
253
|
+
designSystem.Field.Root,
|
|
254
|
+
{
|
|
255
|
+
name: "test-address",
|
|
256
|
+
error: formErrors.email?.id && formatMessage({
|
|
257
|
+
id: `email.${formErrors.email?.id}`,
|
|
258
|
+
defaultMessage: "This is not a valid email"
|
|
259
|
+
}),
|
|
260
|
+
children: [
|
|
261
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
|
|
262
|
+
id: "email.Settings.email.plugin.label.testAddress",
|
|
263
|
+
defaultMessage: "Recipient email"
|
|
264
|
+
}) }),
|
|
265
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
266
|
+
designSystem.TextInput,
|
|
267
|
+
{
|
|
268
|
+
onChange: handleChange,
|
|
269
|
+
value: testAddress,
|
|
270
|
+
placeholder: formatMessage({
|
|
271
|
+
id: "email.Settings.email.plugin.placeholder.testAddress",
|
|
272
|
+
defaultMessage: "ex: developer@example.com"
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
)
|
|
276
|
+
]
|
|
277
|
+
}
|
|
278
|
+
) }),
|
|
279
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { 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-DPpUcr9n.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Settings-DPpUcr9n.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 SingleSelectOption,\n SingleSelect,\n TextInput,\n Typography,\n Field,\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\" tag=\"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.Root gap={5}>\n <Grid.Item col={6} s={12}>\n <Field.Root name=\"shipper-email\">\n <Field.Label>\n {formatMessage({\n id: 'email.Settings.email.plugin.label.defaultFrom',\n defaultMessage: 'Default sender email',\n })}\n </Field.Label>\n <TextInput\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 </Field.Root>\n </Grid.Item>\n\n <Grid.Item col={6} s={12}>\n <Field.Root name=\"response-email\">\n <Field.Label>\n {formatMessage({\n id: 'email.Settings.email.plugin.label.defaultReplyTo',\n defaultMessage: 'Default response email',\n })}\n </Field.Label>\n <TextInput\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 </Field.Root>\n </Grid.Item>\n\n <Grid.Item col={6} s={12}>\n <Field.Root name=\"email-provider\">\n <Field.Label>\n {formatMessage({\n id: 'email.Settings.email.plugin.label.provider',\n defaultMessage: 'Email provider',\n })}\n </Field.Label>\n <SingleSelect disabled value={data.provider}>\n <SingleSelectOption value={data.provider}>\n {data.provider}\n </SingleSelectOption>\n </SingleSelect>\n </Field.Root>\n </Grid.Item>\n </Grid.Root>\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\" tag=\"h2\">\n {formatMessage({\n id: 'email.Settings.email.plugin.title.test',\n defaultMessage: 'Test email delivery',\n })}\n </Typography>\n\n <Grid.Root gap={5}>\n <Grid.Item col={6} s={12}>\n <Field.Root\n name=\"test-address\"\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 >\n <Field.Label>\n {formatMessage({\n id: 'email.Settings.email.plugin.label.testAddress',\n defaultMessage: 'Recipient email',\n })}\n </Field.Label>\n <TextInput\n onChange={handleChange}\n value={testAddress}\n placeholder={formatMessage({\n id: 'email.Settings.email.plugin.placeholder.testAddress',\n defaultMessage: 'ex: developer@example.com',\n })}\n />\n </Field.Root>\n </Grid.Item>\n <Grid.Item 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 </Grid.Item>\n </Grid.Root>\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","Field","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,iBAAO,OAAA;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,uBA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ACX,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,281 @@
|
|
|
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, Field, 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-BL_YuIzh.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", tag: "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.Root, { gap: 5, children: [
|
|
167
|
+
/* @__PURE__ */ jsx(Grid.Item, { col: 6, s: 12, children: /* @__PURE__ */ jsxs(Field.Root, { name: "shipper-email", children: [
|
|
168
|
+
/* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
|
|
169
|
+
id: "email.Settings.email.plugin.label.defaultFrom",
|
|
170
|
+
defaultMessage: "Default sender email"
|
|
171
|
+
}) }),
|
|
172
|
+
/* @__PURE__ */ jsx(
|
|
173
|
+
TextInput,
|
|
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
|
+
] }) }),
|
|
184
|
+
/* @__PURE__ */ jsx(Grid.Item, { col: 6, s: 12, children: /* @__PURE__ */ jsxs(Field.Root, { name: "response-email", children: [
|
|
185
|
+
/* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
|
|
186
|
+
id: "email.Settings.email.plugin.label.defaultReplyTo",
|
|
187
|
+
defaultMessage: "Default response email"
|
|
188
|
+
}) }),
|
|
189
|
+
/* @__PURE__ */ jsx(
|
|
190
|
+
TextInput,
|
|
191
|
+
{
|
|
192
|
+
placeholder: formatMessage({
|
|
193
|
+
id: "email.Settings.email.plugin.placeholder.defaultReplyTo",
|
|
194
|
+
defaultMessage: `ex: Strapi '<'example@strapi.io'>'`
|
|
195
|
+
}),
|
|
196
|
+
disabled: true,
|
|
197
|
+
value: data.settings.defaultReplyTo
|
|
198
|
+
}
|
|
199
|
+
)
|
|
200
|
+
] }) }),
|
|
201
|
+
/* @__PURE__ */ jsx(Grid.Item, { col: 6, s: 12, children: /* @__PURE__ */ jsxs(Field.Root, { name: "email-provider", children: [
|
|
202
|
+
/* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
|
|
203
|
+
id: "email.Settings.email.plugin.label.provider",
|
|
204
|
+
defaultMessage: "Email provider"
|
|
205
|
+
}) }),
|
|
206
|
+
/* @__PURE__ */ jsx(SingleSelect, { disabled: true, value: data.provider, children: /* @__PURE__ */ jsx(SingleSelectOption, { value: data.provider, children: data.provider }) })
|
|
207
|
+
] }) })
|
|
208
|
+
] })
|
|
209
|
+
] })
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
/* @__PURE__ */ jsxs(
|
|
213
|
+
Flex,
|
|
214
|
+
{
|
|
215
|
+
alignItems: "stretch",
|
|
216
|
+
background: "neutral0",
|
|
217
|
+
direction: "column",
|
|
218
|
+
gap: 4,
|
|
219
|
+
hasRadius: true,
|
|
220
|
+
shadow: "filterShadow",
|
|
221
|
+
paddingTop: 6,
|
|
222
|
+
paddingBottom: 6,
|
|
223
|
+
paddingLeft: 7,
|
|
224
|
+
paddingRight: 7,
|
|
225
|
+
children: [
|
|
226
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", tag: "h2", children: formatMessage({
|
|
227
|
+
id: "email.Settings.email.plugin.title.test",
|
|
228
|
+
defaultMessage: "Test email delivery"
|
|
229
|
+
}) }),
|
|
230
|
+
/* @__PURE__ */ jsxs(Grid.Root, { gap: 5, children: [
|
|
231
|
+
/* @__PURE__ */ jsx(Grid.Item, { col: 6, s: 12, children: /* @__PURE__ */ jsxs(
|
|
232
|
+
Field.Root,
|
|
233
|
+
{
|
|
234
|
+
name: "test-address",
|
|
235
|
+
error: formErrors.email?.id && formatMessage({
|
|
236
|
+
id: `email.${formErrors.email?.id}`,
|
|
237
|
+
defaultMessage: "This is not a valid email"
|
|
238
|
+
}),
|
|
239
|
+
children: [
|
|
240
|
+
/* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
|
|
241
|
+
id: "email.Settings.email.plugin.label.testAddress",
|
|
242
|
+
defaultMessage: "Recipient email"
|
|
243
|
+
}) }),
|
|
244
|
+
/* @__PURE__ */ jsx(
|
|
245
|
+
TextInput,
|
|
246
|
+
{
|
|
247
|
+
onChange: handleChange,
|
|
248
|
+
value: testAddress,
|
|
249
|
+
placeholder: formatMessage({
|
|
250
|
+
id: "email.Settings.email.plugin.placeholder.testAddress",
|
|
251
|
+
defaultMessage: "ex: developer@example.com"
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
) }),
|
|
258
|
+
/* @__PURE__ */ jsx(Grid.Item, { col: 7, s: 12, children: /* @__PURE__ */ jsx(
|
|
259
|
+
Button,
|
|
260
|
+
{
|
|
261
|
+
loading: mutation.isLoading,
|
|
262
|
+
disabled: !isTestAddressValid,
|
|
263
|
+
type: "submit",
|
|
264
|
+
startIcon: /* @__PURE__ */ jsx(Mail, {}),
|
|
265
|
+
children: formatMessage({
|
|
266
|
+
id: "email.Settings.email.plugin.button.test-email",
|
|
267
|
+
defaultMessage: "Send test email"
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
) })
|
|
271
|
+
] })
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
] }) }) })
|
|
276
|
+
] });
|
|
277
|
+
};
|
|
278
|
+
export {
|
|
279
|
+
ProtectedSettingsPage
|
|
280
|
+
};
|
|
281
|
+
//# sourceMappingURL=Settings-DwGRZXNs.mjs.map
|