mirror of
https://github.com/strapi/strapi.git
synced 2025-09-17 20:40:17 +00:00
Chore: Cleanup advanced settings and email templates
This commit is contained in:
parent
c696619b98
commit
86a45d30ed
@ -20,6 +20,8 @@ import {
|
|||||||
GenericInput,
|
GenericInput,
|
||||||
LoadingIndicatorPage,
|
LoadingIndicatorPage,
|
||||||
SettingsPageTitle,
|
SettingsPageTitle,
|
||||||
|
useAPIErrorHandler,
|
||||||
|
useFetchClient,
|
||||||
useFocusWhenNavigate,
|
useFocusWhenNavigate,
|
||||||
useNotification,
|
useNotification,
|
||||||
useOverlayBlocker,
|
useOverlayBlocker,
|
||||||
@ -33,7 +35,6 @@ import { useMutation, useQuery, useQueryClient } from 'react-query';
|
|||||||
import { PERMISSIONS } from '../../constants';
|
import { PERMISSIONS } from '../../constants';
|
||||||
import { getTrad } from '../../utils';
|
import { getTrad } from '../../utils';
|
||||||
|
|
||||||
import { fetchData, putAdvancedSettings } from './utils/api';
|
|
||||||
import layout from './utils/layout';
|
import layout from './utils/layout';
|
||||||
import schema from './utils/schema';
|
import schema from './utils/schema';
|
||||||
|
|
||||||
@ -49,6 +50,9 @@ const AdvancedSettingsPage = () => {
|
|||||||
const { lockApp, unlockApp } = useOverlayBlocker();
|
const { lockApp, unlockApp } = useOverlayBlocker();
|
||||||
const { notifyStatus } = useNotifyAT();
|
const { notifyStatus } = useNotifyAT();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const { get, put } = useFetchClient();
|
||||||
|
const { formatAPIError } = useAPIErrorHandler();
|
||||||
|
|
||||||
useFocusWhenNavigate();
|
useFocusWhenNavigate();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -56,28 +60,37 @@ const AdvancedSettingsPage = () => {
|
|||||||
allowedActions: { canUpdate },
|
allowedActions: { canUpdate },
|
||||||
} = useRBAC({ update: PERMISSIONS.updateAdvancedSettings });
|
} = useRBAC({ update: PERMISSIONS.updateAdvancedSettings });
|
||||||
|
|
||||||
const { status: isLoadingData, data } = useQuery('advanced', () => fetchData(), {
|
const { isLoading: isLoadingData, data } = useQuery(
|
||||||
onSuccess() {
|
['users-permissions', 'advanced'],
|
||||||
notifyStatus(
|
async () => {
|
||||||
formatMessage({
|
const { data } = await get('/users-permissions/advanced');
|
||||||
id: getTrad('Form.advancedSettings.data.loaded'),
|
|
||||||
defaultMessage: 'Advanced settings data has been loaded',
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onError() {
|
|
||||||
toggleNotification({
|
|
||||||
type: 'warning',
|
|
||||||
message: { id: getTrad('notification.error'), defaultMessage: 'An error occured' },
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const isLoading = isLoadingForPermissions || isLoadingData !== 'success';
|
return data;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess() {
|
||||||
|
notifyStatus(
|
||||||
|
formatMessage({
|
||||||
|
id: getTrad('Form.advancedSettings.data.loaded'),
|
||||||
|
defaultMessage: 'Advanced settings data has been loaded',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onError() {
|
||||||
|
toggleNotification({
|
||||||
|
type: 'warning',
|
||||||
|
message: { id: getTrad('notification.error'), defaultMessage: 'An error occured' },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const submitMutation = useMutation((body) => putAdvancedSettings(body), {
|
const isLoading = isLoadingForPermissions || isLoadingData;
|
||||||
|
|
||||||
|
const submitMutation = useMutation((body) => put('/users-permissions/advanced', body), {
|
||||||
async onSuccess() {
|
async onSuccess() {
|
||||||
await queryClient.invalidateQueries('advanced');
|
await queryClient.invalidateQueries(['users-permissions', 'advanced']);
|
||||||
|
|
||||||
toggleNotification({
|
toggleNotification({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: { id: getTrad('notification.success.saved'), defaultMessage: 'Saved' },
|
message: { id: getTrad('notification.success.saved'), defaultMessage: 'Saved' },
|
||||||
@ -85,11 +98,12 @@ const AdvancedSettingsPage = () => {
|
|||||||
|
|
||||||
unlockApp();
|
unlockApp();
|
||||||
},
|
},
|
||||||
onError() {
|
onError(error) {
|
||||||
toggleNotification({
|
toggleNotification({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
message: { id: getTrad('notification.error'), defaultMessage: 'An error occured' },
|
message: formatAPIError(error),
|
||||||
});
|
});
|
||||||
|
|
||||||
unlockApp();
|
unlockApp();
|
||||||
},
|
},
|
||||||
refetchActive: true,
|
refetchActive: true,
|
||||||
@ -100,9 +114,12 @@ const AdvancedSettingsPage = () => {
|
|||||||
const handleSubmit = async (body) => {
|
const handleSubmit = async (body) => {
|
||||||
lockApp();
|
lockApp();
|
||||||
|
|
||||||
const urlConfirmation = body.email_confirmation ? body.email_confirmation_redirection : '';
|
submitMutation.mutate({
|
||||||
|
...body,
|
||||||
await submitMutation.mutateAsync({ ...body, email_confirmation_redirection: urlConfirmation });
|
email_confirmation_redirection: body.email_confirmation
|
||||||
|
? body.email_confirmation_redirection
|
||||||
|
: '',
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
import { getFetchClient } from '@strapi/helper-plugin';
|
|
||||||
|
|
||||||
const fetchData = async () => {
|
|
||||||
const { get } = getFetchClient();
|
|
||||||
const { data } = await get('/users-permissions/advanced');
|
|
||||||
|
|
||||||
return data;
|
|
||||||
};
|
|
||||||
|
|
||||||
const putAdvancedSettings = (body) => {
|
|
||||||
const { put } = getFetchClient();
|
|
||||||
|
|
||||||
return put('/users-permissions/advanced', body);
|
|
||||||
};
|
|
||||||
|
|
||||||
export { fetchData, putAdvancedSettings };
|
|
@ -1,10 +1,12 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import { ContentLayout, HeaderLayout, Main, useNotifyAT } from '@strapi/design-system';
|
import { ContentLayout, HeaderLayout, Main, useNotifyAT } from '@strapi/design-system';
|
||||||
import {
|
import {
|
||||||
CheckPagePermissions,
|
CheckPagePermissions,
|
||||||
LoadingIndicatorPage,
|
LoadingIndicatorPage,
|
||||||
SettingsPageTitle,
|
SettingsPageTitle,
|
||||||
|
useAPIErrorHandler,
|
||||||
|
useFetchClient,
|
||||||
useFocusWhenNavigate,
|
useFocusWhenNavigate,
|
||||||
useNotification,
|
useNotification,
|
||||||
useOverlayBlocker,
|
useOverlayBlocker,
|
||||||
@ -19,7 +21,6 @@ import { getTrad } from '../../utils';
|
|||||||
|
|
||||||
import EmailForm from './components/EmailForm';
|
import EmailForm from './components/EmailForm';
|
||||||
import EmailTable from './components/EmailTable';
|
import EmailTable from './components/EmailTable';
|
||||||
import { fetchData, putEmailTemplate } from './utils/api';
|
|
||||||
|
|
||||||
const ProtectedEmailTemplatesPage = () => (
|
const ProtectedEmailTemplatesPage = () => (
|
||||||
<CheckPagePermissions permissions={PERMISSIONS.readEmailTemplates}>
|
<CheckPagePermissions permissions={PERMISSIONS.readEmailTemplates}>
|
||||||
@ -33,36 +34,46 @@ const EmailTemplatesPage = () => {
|
|||||||
const { notifyStatus } = useNotifyAT();
|
const { notifyStatus } = useNotifyAT();
|
||||||
const toggleNotification = useNotification();
|
const toggleNotification = useNotification();
|
||||||
const { lockApp, unlockApp } = useOverlayBlocker();
|
const { lockApp, unlockApp } = useOverlayBlocker();
|
||||||
const trackUsageRef = useRef(trackUsage);
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const { get, put } = useFetchClient();
|
||||||
|
const { formatAPIError } = useAPIErrorHandler();
|
||||||
|
|
||||||
useFocusWhenNavigate();
|
useFocusWhenNavigate();
|
||||||
|
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = React.useState(false);
|
||||||
const [templateToEdit, setTemplateToEdit] = useState(null);
|
const [templateToEdit, setTemplateToEdit] = React.useState(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isLoading: isLoadingForPermissions,
|
isLoading: isLoadingForPermissions,
|
||||||
allowedActions: { canUpdate },
|
allowedActions: { canUpdate },
|
||||||
} = useRBAC({ update: PERMISSIONS.updateEmailTemplates });
|
} = useRBAC({ update: PERMISSIONS.updateEmailTemplates });
|
||||||
|
|
||||||
const { status: isLoadingData, data } = useQuery('email-templates', () => fetchData(), {
|
const { isLoading: isLoadingData, data } = useQuery(
|
||||||
onSuccess() {
|
['users-permissions', 'email-templates'],
|
||||||
notifyStatus(
|
async () => {
|
||||||
formatMessage({
|
const { data } = await get('/users-permissions/email-templates');
|
||||||
id: getTrad('Email.template.data.loaded'),
|
|
||||||
defaultMessage: 'Email templates has been loaded',
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onError() {
|
|
||||||
toggleNotification({
|
|
||||||
type: 'warning',
|
|
||||||
message: { id: 'notification.error', defaultMessage: 'An error occured' },
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const isLoading = isLoadingForPermissions || isLoadingData !== 'success';
|
return data;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess() {
|
||||||
|
notifyStatus(
|
||||||
|
formatMessage({
|
||||||
|
id: getTrad('Email.template.data.loaded'),
|
||||||
|
defaultMessage: 'Email templates has been loaded',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onError(error) {
|
||||||
|
toggleNotification({
|
||||||
|
type: 'warning',
|
||||||
|
message: formatAPIError(error),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const isLoading = isLoadingForPermissions || isLoadingData;
|
||||||
|
|
||||||
const handleToggle = () => {
|
const handleToggle = () => {
|
||||||
setIsModalOpen((prev) => !prev);
|
setIsModalOpen((prev) => !prev);
|
||||||
@ -73,34 +84,38 @@ const EmailTemplatesPage = () => {
|
|||||||
handleToggle();
|
handleToggle();
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitMutation = useMutation((body) => putEmailTemplate({ 'email-templates': body }), {
|
const submitMutation = useMutation(
|
||||||
async onSuccess() {
|
(body) => put('/users-permissions/email-templates', { 'email-templates': body }),
|
||||||
await queryClient.invalidateQueries('email-templates');
|
{
|
||||||
|
async onSuccess() {
|
||||||
|
await queryClient.invalidateQueries(['users-permissions', 'email-templates']);
|
||||||
|
|
||||||
toggleNotification({
|
toggleNotification({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: { id: 'notification.success.saved', defaultMessage: 'Saved' },
|
message: { id: 'notification.success.saved', defaultMessage: 'Saved' },
|
||||||
});
|
});
|
||||||
|
|
||||||
trackUsageRef.current('didEditEmailTemplates');
|
trackUsage('didEditEmailTemplates');
|
||||||
|
|
||||||
unlockApp();
|
unlockApp();
|
||||||
handleToggle();
|
handleToggle();
|
||||||
},
|
},
|
||||||
onError() {
|
onError(error) {
|
||||||
toggleNotification({
|
toggleNotification({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
message: { id: 'notification.error', defaultMessage: 'An error occured' },
|
message: formatAPIError(error),
|
||||||
});
|
});
|
||||||
unlockApp();
|
|
||||||
},
|
unlockApp();
|
||||||
refetchActive: true,
|
},
|
||||||
});
|
refetchActive: true,
|
||||||
const { isLoading: isSubmittingForm } = submitMutation;
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const handleSubmit = (body) => {
|
const handleSubmit = (body) => {
|
||||||
lockApp();
|
lockApp();
|
||||||
trackUsageRef.current('willEditEmailTemplates');
|
|
||||||
|
trackUsage('willEditEmailTemplates');
|
||||||
|
|
||||||
const editedTemplates = { ...data, [templateToEdit]: body };
|
const editedTemplates = { ...data, [templateToEdit]: body };
|
||||||
submitMutation.mutate(editedTemplates);
|
submitMutation.mutate(editedTemplates);
|
||||||
@ -129,7 +144,7 @@ const EmailTemplatesPage = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Main aria-busy={isSubmittingForm}>
|
<Main aria-busy={submitMutation.isLoading}>
|
||||||
<SettingsPageTitle
|
<SettingsPageTitle
|
||||||
name={formatMessage({
|
name={formatMessage({
|
||||||
id: getTrad('HeaderNav.link.emailTemplates'),
|
id: getTrad('HeaderNav.link.emailTemplates'),
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
import { getFetchClient } from '@strapi/helper-plugin';
|
|
||||||
|
|
||||||
const fetchData = async () => {
|
|
||||||
const { get } = getFetchClient();
|
|
||||||
const { data } = await get('/users-permissions/email-templates');
|
|
||||||
|
|
||||||
return data;
|
|
||||||
};
|
|
||||||
|
|
||||||
const putEmailTemplate = (body) => {
|
|
||||||
const { put } = getFetchClient();
|
|
||||||
|
|
||||||
return put('/users-permissions/email-templates', body);
|
|
||||||
};
|
|
||||||
|
|
||||||
export { fetchData, putEmailTemplate };
|
|
Loading…
x
Reference in New Issue
Block a user