node_modules ignore

This commit is contained in:
oier committed 2025-05-08 23:43:47 +02:00
1 parent e19d52f172
commit 4574544c9f
65041 files changed
+10593536

No files matched your search

+361
View File
@@ -0,0 +1,361 @@
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var strapiAdmin = require('@strapi/admin/strapi-admin');
var designSystem = require('@strapi/design-system');
var icons = require('@strapi/icons');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var styledComponents = require('styled-components');
var yup = require('yup');
var constants = require('../constants.js');
var getYupInnerErrors = require('../utils/getYupInnerErrors.js');
var schema = require('../utils/schema.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const DocumentationLink = styledComponents.styled.a`
color: ${({ theme })=>theme.colors.primary600};
`;
const ProtectedSettingsPage = ()=>/*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Protect, {
permissions: constants.PERMISSIONS.settings,
children: /*#__PURE__*/ jsxRuntime.jsx(SettingsPage, {})
});
const SettingsPage = ()=>{
const { toggleNotification } = strapiAdmin.useNotification();
const { formatMessage } = reactIntl.useIntl();
const { get, post } = strapiAdmin.useFetchClient();
const [testAddress, setTestAddress] = React__namespace.useState('');
const [isTestAddressValid, setIsTestAddressValid] = React__namespace.useState(false);
// 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
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [formErrors, setFormErrors] = React__namespace.useState({});
const { data, isLoading } = reactQuery.useQuery([
'email',
'settings'
], async ()=>{
const res = await get('/email/settings');
const { data: { config } } = res;
return config;
});
const mutation = reactQuery.useMutation(async (body)=>{
await post('/email/test', body);
}, {
onError () {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'email.Settings.email.plugin.notification.test.error',
defaultMessage: 'Failed to send a test mail to {to}'
}, {
to: testAddress
})
});
},
onSuccess () {
toggleNotification({
type: 'success',
message: formatMessage({
id: 'email.Settings.email.plugin.notification.test.success',
defaultMessage: 'Email test succeeded, check the {to} mailbox'
}, {
to: testAddress
})
});
},
retry: false
});
React__namespace.useEffect(()=>{
schema.schema.validate({
email: testAddress
}, {
abortEarly: false
}).then(()=>setIsTestAddressValid(true)).catch(()=>setIsTestAddressValid(false));
}, [
testAddress
]);
const handleChange = (event)=>{
setTestAddress(()=>event.target.value);
};
const handleSubmit = async (event)=>{
event.preventDefault();
try {
await schema.schema.validate({
email: testAddress
}, {
abortEarly: false
});
} catch (error) {
if (error instanceof yup.ValidationError) {
setFormErrors(getYupInnerErrors.getYupInnerErrors(error));
}
}
mutation.mutate({
to: testAddress
});
};
if (isLoading) {
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
}
return /*#__PURE__*/ jsxRuntime.jsxs(strapiAdmin.Page.Main, {
labelledBy: "title",
"aria-busy": isLoading || mutation.isLoading,
children: [
/*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Title, {
children: formatMessage({
id: 'Settings.PageTitle',
defaultMessage: 'Settings - {name}'
}, {
name: formatMessage({
id: 'email.Settings.email.plugin.title',
defaultMessage: 'Configuration'
})
})
}),
/*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Layouts.Header, {
id: "title",
title: formatMessage({
id: 'email.Settings.email.plugin.title',
defaultMessage: 'Configuration'
}),
subtitle: formatMessage({
id: 'email.Settings.email.plugin.subTitle',
defaultMessage: 'Test the settings for the Email plugin'
})
}),
/*#__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: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
background: "neutral0",
hasRadius: true,
shadow: "filterShadow",
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 7,
paddingRight: 7,
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
direction: "column",
alignItems: "stretch",
gap: 4,
children: [
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
direction: "column",
alignItems: "stretch",
gap: 1,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
variant: "delta",
tag: "h2",
children: formatMessage({
id: 'email.Settings.email.plugin.title.config',
defaultMessage: 'Configuration'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
children: formatMessage({
id: 'email.Settings.email.plugin.text.configuration',
defaultMessage: 'The plugin is configured through the {file} file, checkout this {link} for the documentation.'
}, {
file: './config/plugins.js',
link: /*#__PURE__*/ jsxRuntime.jsx(DocumentationLink, {
href: "https://docs.strapi.io/developer-docs/latest/plugins/email.html",
target: "_blank",
rel: "noopener noreferrer",
children: formatMessage({
id: 'email.link',
defaultMessage: 'Link'
})
})
})
})
]
}),
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Grid.Root, {
gap: 5,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Grid.Item, {
col: 6,
s: 12,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
name: "shipper-email",
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
children: formatMessage({
id: 'email.Settings.email.plugin.label.defaultFrom',
defaultMessage: 'Default sender email'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.TextInput, {
placeholder: formatMessage({
id: 'email.Settings.email.plugin.placeholder.defaultFrom',
defaultMessage: "ex: Strapi No-Reply '<'no-reply@strapi.io'>'"
}),
disabled: true,
value: data.settings.defaultFrom
})
]
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Grid.Item, {
col: 6,
s: 12,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
name: "response-email",
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
children: formatMessage({
id: 'email.Settings.email.plugin.label.defaultReplyTo',
defaultMessage: 'Default response email'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.TextInput, {
placeholder: formatMessage({
id: 'email.Settings.email.plugin.placeholder.defaultReplyTo',
defaultMessage: `ex: Strapi '<'example@strapi.io'>'`
}),
disabled: true,
value: data.settings.defaultReplyTo
})
]
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Grid.Item, {
col: 6,
s: 12,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
name: "email-provider",
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
children: formatMessage({
id: 'email.Settings.email.plugin.label.provider',
defaultMessage: 'Email provider'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelect, {
disabled: true,
value: data.provider,
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelectOption, {
value: data.provider,
children: data.provider
})
})
]
})
})
]
})
]
})
}),
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
alignItems: "stretch",
background: "neutral0",
direction: "column",
gap: 4,
hasRadius: true,
shadow: "filterShadow",
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 7,
paddingRight: 7,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
variant: "delta",
tag: "h2",
children: formatMessage({
id: 'email.Settings.email.plugin.title.test',
defaultMessage: 'Test email delivery'
})
}),
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Grid.Root, {
gap: 5,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Grid.Item, {
col: 6,
s: 12,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
name: "test-address",
error: formErrors.email?.id && formatMessage({
id: `email.${formErrors.email?.id}`,
defaultMessage: 'This is not a valid email'
}),
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
children: formatMessage({
id: 'email.Settings.email.plugin.label.testAddress',
defaultMessage: 'Recipient email'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.TextInput, {
onChange: handleChange,
value: testAddress,
placeholder: formatMessage({
id: 'email.Settings.email.plugin.placeholder.testAddress',
defaultMessage: 'ex: developer@example.com'
})
})
]
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Grid.Item, {
col: 7,
s: 12,
direction: "column",
alignItems: "start",
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
loading: mutation.isLoading,
disabled: !isTestAddressValid,
type: "submit",
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Mail, {}),
children: formatMessage({
id: 'email.Settings.email.plugin.button.test-email',
defaultMessage: 'Send test email'
})
})
})
]
})
]
})
]
})
})
})
]
});
};
exports.ProtectedSettingsPage = ProtectedSettingsPage;
//# sourceMappingURL=Settings.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Settings.js","sources":["../../../admin/src/pages/Settings.tsx"],"sourcesContent":["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=\"columnLine truncated
+340
View File
@@ -0,0 +1,340 @@
import { jsx, jsxs } from 'react/jsx-runtime';
import * as React from 'react';
import { Page, useNotification, useFetchClient, Layouts } from '@strapi/admin/strapi-admin';
import { Flex, Box, Typography, Grid, Field, TextInput, SingleSelect, SingleSelectOption, Button } from '@strapi/design-system';
import { Mail } from '@strapi/icons';
import { useIntl } from 'react-intl';
import { useQuery, useMutation } from 'react-query';
import { styled } from 'styled-components';
import { ValidationError } from 'yup';
import { PERMISSIONS } from '../constants.mjs';
import { getYupInnerErrors } from '../utils/getYupInnerErrors.mjs';
import { schema } from '../utils/schema.mjs';
const DocumentationLink = styled.a`
color: ${({ theme })=>theme.colors.primary600};
`;
const ProtectedSettingsPage = ()=>/*#__PURE__*/ jsx(Page.Protect, {
permissions: PERMISSIONS.settings,
children: /*#__PURE__*/ jsx(SettingsPage, {})
});
const SettingsPage = ()=>{
const { toggleNotification } = useNotification();
const { formatMessage } = useIntl();
const { get, post } = useFetchClient();
const [testAddress, setTestAddress] = React.useState('');
const [isTestAddressValid, setIsTestAddressValid] = React.useState(false);
// 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
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [formErrors, setFormErrors] = React.useState({});
const { data, isLoading } = useQuery([
'email',
'settings'
], async ()=>{
const res = await get('/email/settings');
const { data: { config } } = res;
return config;
});
const mutation = useMutation(async (body)=>{
await post('/email/test', body);
}, {
onError () {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'email.Settings.email.plugin.notification.test.error',
defaultMessage: 'Failed to send a test mail to {to}'
}, {
to: testAddress
})
});
},
onSuccess () {
toggleNotification({
type: 'success',
message: formatMessage({
id: 'email.Settings.email.plugin.notification.test.success',
defaultMessage: 'Email test succeeded, check the {to} mailbox'
}, {
to: testAddress
})
});
},
retry: false
});
React.useEffect(()=>{
schema.validate({
email: testAddress
}, {
abortEarly: false
}).then(()=>setIsTestAddressValid(true)).catch(()=>setIsTestAddressValid(false));
}, [
testAddress
]);
const handleChange = (event)=>{
setTestAddress(()=>event.target.value);
};
const handleSubmit = async (event)=>{
event.preventDefault();
try {
await schema.validate({
email: testAddress
}, {
abortEarly: false
});
} catch (error) {
if (error instanceof ValidationError) {
setFormErrors(getYupInnerErrors(error));
}
}
mutation.mutate({
to: testAddress
});
};
if (isLoading) {
return /*#__PURE__*/ jsx(Page.Loading, {});
}
return /*#__PURE__*/ jsxs(Page.Main, {
labelledBy: "title",
"aria-busy": isLoading || mutation.isLoading,
children: [
/*#__PURE__*/ jsx(Page.Title, {
children: formatMessage({
id: 'Settings.PageTitle',
defaultMessage: 'Settings - {name}'
}, {
name: formatMessage({
id: 'email.Settings.email.plugin.title',
defaultMessage: 'Configuration'
})
})
}),
/*#__PURE__*/ jsx(Layouts.Header, {
id: "title",
title: formatMessage({
id: 'email.Settings.email.plugin.title',
defaultMessage: 'Configuration'
}),
subtitle: formatMessage({
id: 'email.Settings.email.plugin.subTitle',
defaultMessage: 'Test the settings for the Email plugin'
})
}),
/*#__PURE__*/ jsx(Layouts.Content, {
children: data && /*#__PURE__*/ jsx("form", {
onSubmit: handleSubmit,
children: /*#__PURE__*/ jsxs(Flex, {
direction: "column",
alignItems: "stretch",
gap: 7,
children: [
/*#__PURE__*/ jsx(Box, {
background: "neutral0",
hasRadius: true,
shadow: "filterShadow",
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 7,
paddingRight: 7,
children: /*#__PURE__*/ jsxs(Flex, {
direction: "column",
alignItems: "stretch",
gap: 4,
children: [
/*#__PURE__*/ jsxs(Flex, {
direction: "column",
alignItems: "stretch",
gap: 1,
children: [
/*#__PURE__*/ jsx(Typography, {
variant: "delta",
tag: "h2",
children: formatMessage({
id: 'email.Settings.email.plugin.title.config',
defaultMessage: 'Configuration'
})
}),
/*#__PURE__*/ jsx(Typography, {
children: formatMessage({
id: 'email.Settings.email.plugin.text.configuration',
defaultMessage: 'The plugin is configured through the {file} file, checkout this {link} for the documentation.'
}, {
file: './config/plugins.js',
link: /*#__PURE__*/ jsx(DocumentationLink, {
href: "https://docs.strapi.io/developer-docs/latest/plugins/email.html",
target: "_blank",
rel: "noopener noreferrer",
children: formatMessage({
id: 'email.link',
defaultMessage: 'Link'
})
})
})
})
]
}),
/*#__PURE__*/ jsxs(Grid.Root, {
gap: 5,
children: [
/*#__PURE__*/ jsx(Grid.Item, {
col: 6,
s: 12,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxs(Field.Root, {
name: "shipper-email",
children: [
/*#__PURE__*/ jsx(Field.Label, {
children: formatMessage({
id: 'email.Settings.email.plugin.label.defaultFrom',
defaultMessage: 'Default sender email'
})
}),
/*#__PURE__*/ jsx(TextInput, {
placeholder: formatMessage({
id: 'email.Settings.email.plugin.placeholder.defaultFrom',
defaultMessage: "ex: Strapi No-Reply '<'no-reply@strapi.io'>'"
}),
disabled: true,
value: data.settings.defaultFrom
})
]
})
}),
/*#__PURE__*/ jsx(Grid.Item, {
col: 6,
s: 12,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxs(Field.Root, {
name: "response-email",
children: [
/*#__PURE__*/ jsx(Field.Label, {
children: formatMessage({
id: 'email.Settings.email.plugin.label.defaultReplyTo',
defaultMessage: 'Default response email'
})
}),
/*#__PURE__*/ jsx(TextInput, {
placeholder: formatMessage({
id: 'email.Settings.email.plugin.placeholder.defaultReplyTo',
defaultMessage: `ex: Strapi '<'example@strapi.io'>'`
}),
disabled: true,
value: data.settings.defaultReplyTo
})
]
})
}),
/*#__PURE__*/ jsx(Grid.Item, {
col: 6,
s: 12,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxs(Field.Root, {
name: "email-provider",
children: [
/*#__PURE__*/ jsx(Field.Label, {
children: formatMessage({
id: 'email.Settings.email.plugin.label.provider',
defaultMessage: 'Email provider'
})
}),
/*#__PURE__*/ jsx(SingleSelect, {
disabled: true,
value: data.provider,
children: /*#__PURE__*/ jsx(SingleSelectOption, {
value: data.provider,
children: data.provider
})
})
]
})
})
]
})
]
})
}),
/*#__PURE__*/ jsxs(Flex, {
alignItems: "stretch",
background: "neutral0",
direction: "column",
gap: 4,
hasRadius: true,
shadow: "filterShadow",
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 7,
paddingRight: 7,
children: [
/*#__PURE__*/ jsx(Typography, {
variant: "delta",
tag: "h2",
children: formatMessage({
id: 'email.Settings.email.plugin.title.test',
defaultMessage: 'Test email delivery'
})
}),
/*#__PURE__*/ jsxs(Grid.Root, {
gap: 5,
children: [
/*#__PURE__*/ jsx(Grid.Item, {
col: 6,
s: 12,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxs(Field.Root, {
name: "test-address",
error: formErrors.email?.id && formatMessage({
id: `email.${formErrors.email?.id}`,
defaultMessage: 'This is not a valid email'
}),
children: [
/*#__PURE__*/ jsx(Field.Label, {
children: formatMessage({
id: 'email.Settings.email.plugin.label.testAddress',
defaultMessage: 'Recipient email'
})
}),
/*#__PURE__*/ jsx(TextInput, {
onChange: handleChange,
value: testAddress,
placeholder: formatMessage({
id: 'email.Settings.email.plugin.placeholder.testAddress',
defaultMessage: 'ex: developer@example.com'
})
})
]
})
}),
/*#__PURE__*/ jsx(Grid.Item, {
col: 7,
s: 12,
direction: "column",
alignItems: "start",
children: /*#__PURE__*/ jsx(Button, {
loading: mutation.isLoading,
disabled: !isTestAddressValid,
type: "submit",
startIcon: /*#__PURE__*/ jsx(Mail, {}),
children: formatMessage({
id: 'email.Settings.email.plugin.button.test-email',
defaultMessage: 'Send test email'
})
})
})
]
})
]
})
]
})
})
})
]
});
};
export { ProtectedSettingsPage };
//# sourceMappingURL=Settings.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Settings.mjs","sources":["../../../admin/src/pages/Settings.tsx"],"sourcesContent":["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=\"columLine truncated