mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
feat(ui): allow admins to edit & approve request from advanced request modal (#2067)
* feat(ui): allow admins to edit & accept request from request modal This changes the "Edit Request" button in the advanced request modal to "Edit & Accept Request" since the only thing an admin would do next is to accept the request. The button would stay the same for users without the manage request permissions; users who are editing their own requests or requesting content. * feat(ui): suggested changes
This commit is contained in:

committed by
GitHub

parent
cc2b2bc7a8
commit
340f1a2119
@@ -23,12 +23,14 @@ const messages = defineMessages({
|
|||||||
requesttitle: 'Request {title}',
|
requesttitle: 'Request {title}',
|
||||||
request4ktitle: 'Request {title} in 4K',
|
request4ktitle: 'Request {title} in 4K',
|
||||||
edit: 'Edit Request',
|
edit: 'Edit Request',
|
||||||
|
approve: 'Approve Request',
|
||||||
cancel: 'Cancel Request',
|
cancel: 'Cancel Request',
|
||||||
pendingrequest: 'Pending Request for {title}',
|
pendingrequest: 'Pending Request for {title}',
|
||||||
pending4krequest: 'Pending 4K Request for {title}',
|
pending4krequest: 'Pending 4K Request for {title}',
|
||||||
requestfrom: "{username}'s request is pending approval.",
|
requestfrom: "{username}'s request is pending approval.",
|
||||||
errorediting: 'Something went wrong while editing the request.',
|
errorediting: 'Something went wrong while editing the request.',
|
||||||
requestedited: 'Request for <strong>{title}</strong> edited successfully!',
|
requestedited: 'Request for <strong>{title}</strong> edited successfully!',
|
||||||
|
requestApproved: 'Request for <strong>{title}</strong> approved!',
|
||||||
requesterror: 'Something went wrong while submitting the request.',
|
requesterror: 'Something went wrong while submitting the request.',
|
||||||
pendingapproval: 'Your request is pending approval.',
|
pendingapproval: 'Your request is pending approval.',
|
||||||
});
|
});
|
||||||
@@ -159,7 +161,7 @@ const MovieRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateRequest = async () => {
|
const updateRequest = async (alsoApproveRequest = false) => {
|
||||||
setIsUpdating(true);
|
setIsUpdating(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -172,14 +174,23 @@ const MovieRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
tags: requestOverrides?.tags,
|
tags: requestOverrides?.tags,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (alsoApproveRequest) {
|
||||||
|
await axios.post(`/api/v1/request/${editRequest?.id}/approve`);
|
||||||
|
}
|
||||||
|
|
||||||
addToast(
|
addToast(
|
||||||
<span>
|
<span>
|
||||||
{intl.formatMessage(messages.requestedited, {
|
{intl.formatMessage(
|
||||||
|
alsoApproveRequest
|
||||||
|
? messages.requestApproved
|
||||||
|
: messages.requestedited,
|
||||||
|
{
|
||||||
title: data?.title,
|
title: data?.title,
|
||||||
strong: function strong(msg) {
|
strong: function strong(msg) {
|
||||||
return <strong>{msg}</strong>;
|
return <strong>{msg}</strong>;
|
||||||
},
|
},
|
||||||
})}
|
}
|
||||||
|
)}
|
||||||
</span>,
|
</span>,
|
||||||
{
|
{
|
||||||
appearance: 'success',
|
appearance: 'success',
|
||||||
@@ -202,12 +213,6 @@ const MovieRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
|
|
||||||
if (editRequest) {
|
if (editRequest) {
|
||||||
const isOwner = editRequest.requestedBy.id === user?.id;
|
const isOwner = editRequest.requestedBy.id === user?.id;
|
||||||
const showEditButton = hasPermission(
|
|
||||||
[Permission.MANAGE_REQUESTS, Permission.REQUEST_ADVANCED],
|
|
||||||
{
|
|
||||||
type: 'or',
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
@@ -218,20 +223,44 @@ const MovieRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
is4k ? messages.pending4krequest : messages.pendingrequest,
|
is4k ? messages.pending4krequest : messages.pendingrequest,
|
||||||
{ title: data?.title }
|
{ title: data?.title }
|
||||||
)}
|
)}
|
||||||
onOk={() => (showEditButton ? updateRequest() : cancelRequest())}
|
onOk={() =>
|
||||||
|
hasPermission(Permission.MANAGE_REQUESTS)
|
||||||
|
? updateRequest(true)
|
||||||
|
: hasPermission(Permission.REQUEST_ADVANCED)
|
||||||
|
? updateRequest()
|
||||||
|
: cancelRequest()
|
||||||
|
}
|
||||||
okDisabled={isUpdating}
|
okDisabled={isUpdating}
|
||||||
okText={
|
okText={
|
||||||
showEditButton
|
hasPermission(Permission.MANAGE_REQUESTS)
|
||||||
|
? intl.formatMessage(messages.approve)
|
||||||
|
: hasPermission(Permission.REQUEST_ADVANCED)
|
||||||
? intl.formatMessage(messages.edit)
|
? intl.formatMessage(messages.edit)
|
||||||
: intl.formatMessage(messages.cancel)
|
: intl.formatMessage(messages.cancel)
|
||||||
}
|
}
|
||||||
okButtonType={showEditButton ? 'primary' : 'danger'}
|
okButtonType={
|
||||||
|
hasPermission(Permission.MANAGE_REQUESTS)
|
||||||
|
? 'success'
|
||||||
|
: hasPermission(Permission.REQUEST_ADVANCED)
|
||||||
|
? 'primary'
|
||||||
|
: 'danger'
|
||||||
|
}
|
||||||
onSecondary={
|
onSecondary={
|
||||||
isOwner && showEditButton ? () => cancelRequest() : undefined
|
isOwner &&
|
||||||
|
hasPermission(
|
||||||
|
[Permission.REQUEST_ADVANCED, Permission.MANAGE_REQUESTS],
|
||||||
|
{ type: 'or' }
|
||||||
|
)
|
||||||
|
? () => cancelRequest()
|
||||||
|
: undefined
|
||||||
}
|
}
|
||||||
secondaryDisabled={isUpdating}
|
secondaryDisabled={isUpdating}
|
||||||
secondaryText={
|
secondaryText={
|
||||||
isOwner && showEditButton
|
isOwner &&
|
||||||
|
hasPermission(
|
||||||
|
[Permission.REQUEST_ADVANCED, Permission.MANAGE_REQUESTS],
|
||||||
|
{ type: 'or' }
|
||||||
|
)
|
||||||
? intl.formatMessage(messages.cancel)
|
? intl.formatMessage(messages.cancel)
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ const messages = defineMessages({
|
|||||||
requesttitle: 'Request {title}',
|
requesttitle: 'Request {title}',
|
||||||
request4ktitle: 'Request {title} in 4K',
|
request4ktitle: 'Request {title} in 4K',
|
||||||
edit: 'Edit Request',
|
edit: 'Edit Request',
|
||||||
|
approve: 'Approve Request',
|
||||||
cancel: 'Cancel Request',
|
cancel: 'Cancel Request',
|
||||||
pendingrequest: 'Pending Request for {title}',
|
pendingrequest: 'Pending Request for {title}',
|
||||||
pending4krequest: 'Pending 4K Request for {title}',
|
pending4krequest: 'Pending 4K Request for {title}',
|
||||||
@@ -46,6 +47,7 @@ const messages = defineMessages({
|
|||||||
extras: 'Extras',
|
extras: 'Extras',
|
||||||
errorediting: 'Something went wrong while editing the request.',
|
errorediting: 'Something went wrong while editing the request.',
|
||||||
requestedited: 'Request for <strong>{title}</strong> edited successfully!',
|
requestedited: 'Request for <strong>{title}</strong> edited successfully!',
|
||||||
|
requestApproved: 'Request for <strong>{title}</strong> approved!',
|
||||||
requestcancelled: 'Request for <strong>{title}</strong> canceled.',
|
requestcancelled: 'Request for <strong>{title}</strong> canceled.',
|
||||||
autoapproval: 'Automatic Approval',
|
autoapproval: 'Automatic Approval',
|
||||||
requesterror: 'Something went wrong while submitting the request.',
|
requesterror: 'Something went wrong while submitting the request.',
|
||||||
@@ -100,7 +102,7 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
selectedSeasons.length +
|
selectedSeasons.length +
|
||||||
(editRequest?.seasons ?? []).length;
|
(editRequest?.seasons ?? []).length;
|
||||||
|
|
||||||
const updateRequest = async () => {
|
const updateRequest = async (alsoApproveRequest = false) => {
|
||||||
if (!editRequest) {
|
if (!editRequest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -121,6 +123,10 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
tags: requestOverrides?.tags,
|
tags: requestOverrides?.tags,
|
||||||
seasons: selectedSeasons,
|
seasons: selectedSeasons,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (alsoApproveRequest) {
|
||||||
|
await axios.post(`/api/v1/request/${editRequest.id}/approve`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await axios.delete(`/api/v1/request/${editRequest.id}`);
|
await axios.delete(`/api/v1/request/${editRequest.id}`);
|
||||||
}
|
}
|
||||||
@@ -128,12 +134,17 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
addToast(
|
addToast(
|
||||||
<span>
|
<span>
|
||||||
{selectedSeasons.length > 0
|
{selectedSeasons.length > 0
|
||||||
? intl.formatMessage(messages.requestedited, {
|
? intl.formatMessage(
|
||||||
|
alsoApproveRequest
|
||||||
|
? messages.requestApproved
|
||||||
|
: messages.requestedited,
|
||||||
|
{
|
||||||
title: data?.name,
|
title: data?.name,
|
||||||
strong: function strong(msg) {
|
strong: function strong(msg) {
|
||||||
return <strong>{msg}</strong>;
|
return <strong>{msg}</strong>;
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
: intl.formatMessage(messages.requestcancelled, {
|
: intl.formatMessage(messages.requestcancelled, {
|
||||||
title: data?.name,
|
title: data?.name,
|
||||||
strong: function strong(msg) {
|
strong: function strong(msg) {
|
||||||
@@ -372,7 +383,13 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
loading={!data && !error}
|
loading={!data && !error}
|
||||||
backgroundClickable
|
backgroundClickable
|
||||||
onCancel={tvdbId ? () => setSearchModal({ show: true }) : onCancel}
|
onCancel={tvdbId ? () => setSearchModal({ show: true }) : onCancel}
|
||||||
onOk={() => (editRequest ? updateRequest() : sendRequest())}
|
onOk={() =>
|
||||||
|
editRequest
|
||||||
|
? hasPermission(Permission.MANAGE_REQUESTS)
|
||||||
|
? updateRequest(true)
|
||||||
|
: updateRequest()
|
||||||
|
: sendRequest()
|
||||||
|
}
|
||||||
title={intl.formatMessage(
|
title={intl.formatMessage(
|
||||||
editRequest
|
editRequest
|
||||||
? is4k
|
? is4k
|
||||||
@@ -387,6 +404,8 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
editRequest
|
editRequest
|
||||||
? selectedSeasons.length === 0
|
? selectedSeasons.length === 0
|
||||||
? intl.formatMessage(messages.cancel)
|
? intl.formatMessage(messages.cancel)
|
||||||
|
: hasPermission(Permission.MANAGE_REQUESTS)
|
||||||
|
? intl.formatMessage(messages.approve)
|
||||||
: intl.formatMessage(messages.edit)
|
: intl.formatMessage(messages.edit)
|
||||||
: getAllRequestedSeasons().length >= getAllSeasons().length
|
: getAllRequestedSeasons().length >= getAllSeasons().length
|
||||||
? intl.formatMessage(messages.alreadyrequested)
|
? intl.formatMessage(messages.alreadyrequested)
|
||||||
@@ -415,11 +434,14 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
|
|||||||
selectedSeasons.length === 0)
|
selectedSeasons.length === 0)
|
||||||
}
|
}
|
||||||
okButtonType={
|
okButtonType={
|
||||||
editRequest &&
|
editRequest
|
||||||
settings.currentSettings.partialRequestsEnabled &&
|
? settings.currentSettings.partialRequestsEnabled &&
|
||||||
selectedSeasons.length === 0
|
selectedSeasons.length === 0
|
||||||
? 'danger'
|
? 'danger'
|
||||||
: `primary`
|
: hasPermission(Permission.MANAGE_REQUESTS)
|
||||||
|
? 'success'
|
||||||
|
: 'primary'
|
||||||
|
: 'primary'
|
||||||
}
|
}
|
||||||
cancelText={
|
cancelText={
|
||||||
editRequest
|
editRequest
|
||||||
|
@@ -322,6 +322,7 @@
|
|||||||
"components.RequestModal.SearchByNameModal.nosummary": "No summary for this title was found.",
|
"components.RequestModal.SearchByNameModal.nosummary": "No summary for this title was found.",
|
||||||
"components.RequestModal.SearchByNameModal.notvdbiddescription": "We couldn't automatically match your request. Please select the correct match from the list below.",
|
"components.RequestModal.SearchByNameModal.notvdbiddescription": "We couldn't automatically match your request. Please select the correct match from the list below.",
|
||||||
"components.RequestModal.alreadyrequested": "Already Requested",
|
"components.RequestModal.alreadyrequested": "Already Requested",
|
||||||
|
"components.RequestModal.approve": "Approve Request",
|
||||||
"components.RequestModal.autoapproval": "Automatic Approval",
|
"components.RequestModal.autoapproval": "Automatic Approval",
|
||||||
"components.RequestModal.cancel": "Cancel Request",
|
"components.RequestModal.cancel": "Cancel Request",
|
||||||
"components.RequestModal.edit": "Edit Request",
|
"components.RequestModal.edit": "Edit Request",
|
||||||
@@ -332,6 +333,7 @@
|
|||||||
"components.RequestModal.pendingapproval": "Your request is pending approval.",
|
"components.RequestModal.pendingapproval": "Your request is pending approval.",
|
||||||
"components.RequestModal.pendingrequest": "Pending Request for {title}",
|
"components.RequestModal.pendingrequest": "Pending Request for {title}",
|
||||||
"components.RequestModal.request4ktitle": "Request {title} in 4K",
|
"components.RequestModal.request4ktitle": "Request {title} in 4K",
|
||||||
|
"components.RequestModal.requestApproved": "Request for <strong>{title}</strong> approved!",
|
||||||
"components.RequestModal.requestCancel": "Request for <strong>{title}</strong> canceled.",
|
"components.RequestModal.requestCancel": "Request for <strong>{title}</strong> canceled.",
|
||||||
"components.RequestModal.requestSuccess": "<strong>{title}</strong> requested successfully!",
|
"components.RequestModal.requestSuccess": "<strong>{title}</strong> requested successfully!",
|
||||||
"components.RequestModal.requestadmin": "This request will be approved automatically.",
|
"components.RequestModal.requestadmin": "This request will be approved automatically.",
|
||||||
|
Reference in New Issue
Block a user