feat(notif): add "Media Automatically Approved" notification type (#1137)

This commit is contained in:
TheCatLady
2021-03-11 21:42:06 -05:00
committed by GitHub
parent 1be97fe7fb
commit f7d2723fab
19 changed files with 284 additions and 102 deletions

View File

@@ -8,16 +8,19 @@ const messages = defineMessages({
'Sends a notification when media is requested and requires approval.',
mediaapproved: 'Media Approved',
mediaapprovedDescription:
'Sends a notification when media is approved.\
By default, automatically approved requests will not trigger notifications.',
'Sends a notification when requested media is manually approved.',
mediaAutoApproved: 'Media Automatically Approved',
mediaAutoApprovedDescription:
'Sends a notification when requested media is automatically approved.',
mediaavailable: 'Media Available',
mediaavailableDescription:
'Sends a notification when media becomes available.',
'Sends a notification when requested media becomes available.',
mediafailed: 'Media Failed',
mediafailedDescription:
'Sends a notification when media fails to be added to Radarr or Sonarr.',
'Sends a notification when requested media fails to be added to Radarr or Sonarr.',
mediadeclined: 'Media Declined',
mediadeclinedDescription: 'Sends a notification when a request is declined.',
mediadeclinedDescription:
'Sends a notification when a media request is declined.',
});
export const hasNotificationType = (
@@ -46,6 +49,7 @@ export enum Notification {
MEDIA_FAILED = 16,
TEST_NOTIFICATION = 32,
MEDIA_DECLINED = 64,
MEDIA_AUTO_APPROVED = 128,
}
export interface NotificationItem {
@@ -74,6 +78,12 @@ const NotificationTypeSelector: React.FC<NotificationTypeSelectorProps> = ({
description: intl.formatMessage(messages.mediarequestedDescription),
value: Notification.MEDIA_PENDING,
},
{
id: 'media-auto-approved',
name: intl.formatMessage(messages.mediaAutoApproved),
description: intl.formatMessage(messages.mediaAutoApprovedDescription),
value: Notification.MEDIA_AUTO_APPROVED,
},
{
id: 'media-approved',
name: intl.formatMessage(messages.mediaapproved),

View File

@@ -32,10 +32,13 @@ const messages = defineMessages({
senderName: 'Sender Name',
notificationtypes: 'Notification Types',
validationEmail: 'You must provide a valid email address',
emailNotificationTypesAlert: 'Notification Email Recipients',
emailNotificationTypesAlert: 'Email Notification Recipients',
emailNotificationTypesAlertDescription:
'For the "Media Requested" and "Media Failed" notification types,\
notifications will only be sent to users with the "Manage Requests" permission.',
'<strong>Media Requested</strong>, <strong>Media Automatically Approved</strong>, and <strong>Media Failed</strong>\
email notifications are sent to all users with the <strong>Manage Requests</strong> permission.',
emailNotificationTypesAlertDescriptionPt2:
'<strong>Media Approved</strong>, <strong>Media Declined</strong>, and <strong>Media Available</strong>\
email notifications are sent to the user who submitted the request.',
});
const NotificationsEmail: React.FC = () => {
@@ -134,9 +137,34 @@ const NotificationsEmail: React.FC = () => {
title={intl.formatMessage(messages.emailNotificationTypesAlert)}
type="info"
>
{intl.formatMessage(
messages.emailNotificationTypesAlertDescription
)}
<p className="mb-2">
{intl.formatMessage(
messages.emailNotificationTypesAlertDescription,
{
strong: function strong(msg) {
return (
<strong className="font-normal text-indigo-100">
{msg}
</strong>
);
},
}
)}
</p>
<p>
{intl.formatMessage(
messages.emailNotificationTypesAlertDescriptionPt2,
{
strong: function strong(msg) {
return (
<strong className="font-normal text-indigo-100">
{msg}
</strong>
);
},
}
)}
</p>
</Alert>
<Form className="section">
<div className="form-row">

View File

@@ -27,7 +27,7 @@ const messages = defineMessages({
settinguptelegramDescription:
'To configure Telegram notifications, you will need to <CreateBotLink>create a bot</CreateBotLink> and get the bot API key.\
Additionally, you will need the chat ID for the chat to which you would like to send notifications.\
You can get this by adding <GetIdBotLink>@get_id_bot</GetIdBotLink> to the chat.',
You can find this by adding <GetIdBotLink>@get_id_bot</GetIdBotLink> to the chat and issuing the <code>/my_id</code> command.',
notificationtypes: 'Notification Types',
sendSilently: 'Send Silently',
sendSilentlyTip: 'Send notifications with no sound',
@@ -143,6 +143,9 @@ const NotificationsTelegram: React.FC = () => {
</a>
);
},
code: function code(msg) {
return <code className="bg-opacity-50">{msg}</code>;
},
})}
</Alert>
<Form className="section">

View File

@@ -28,7 +28,6 @@ const messages = defineMessages({
notificationsettingssaved: 'Notification settings saved successfully!',
notificationsettingsfailed: 'Notification settings failed to save.',
enablenotifications: 'Enable Notifications',
autoapprovedrequests: 'Enable Notifications for Automatic Approvals',
email: 'Email',
webhook: 'Webhook',
});
@@ -187,14 +186,12 @@ const SettingsNotifications: React.FC = ({ children }) => {
<Formik
initialValues={{
enabled: data.enabled,
autoapprovalEnabled: data.autoapprovalEnabled,
}}
enableReinitialize
onSubmit={async (values) => {
try {
await axios.post('/api/v1/settings/notifications', {
enabled: values.enabled,
autoapprovalEnabled: values.autoapprovalEnabled,
});
addToast(intl.formatMessage(messages.notificationsettingssaved), {
appearance: 'success',
@@ -233,26 +230,6 @@ const SettingsNotifications: React.FC = ({ children }) => {
/>
</div>
</div>
<div className="form-row">
<label htmlFor="name" className="checkbox-label">
<span>
{intl.formatMessage(messages.autoapprovedrequests)}
</span>
</label>
<div className="form-input">
<Field
type="checkbox"
id="autoapprovalEnabled"
name="autoapprovalEnabled"
onChange={() => {
setFieldValue(
'autoapprovalEnabled',
!values.autoapprovalEnabled
);
}}
/>
</div>
</div>
<div className="actions">
<div className="flex justify-end">
<span className="inline-flex ml-3 rounded-md shadow-sm">