Skip to content

Commit

Permalink
fix: hide remove button when default service is not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
dd060606 committed Aug 14, 2022
1 parent 2e74584 commit 7d4455b
Showing 1 changed file with 61 additions and 29 deletions.
90 changes: 61 additions & 29 deletions src/components/ManageSlideOver/index.tsx
Expand Up @@ -13,8 +13,10 @@ import { IssueStatus } from '../../../server/constants/issue';
import {
MediaRequestStatus,
MediaStatus,
MediaType,
} from '../../../server/constants/media';
import { MediaWatchDataResponse } from '../../../server/interfaces/api/mediaInterfaces';
import { RadarrSettings, SonarrSettings } from '../../../server/lib/settings';
import { MovieDetails } from '../../../server/models/Movie';
import { TvDetails } from '../../../server/models/Tv';
import useSettings from '../../hooks/useSettings';
Expand Down Expand Up @@ -91,6 +93,12 @@ const ManageSlideOver: React.FC<
? `/api/v1/media/${data.mediaInfo.id}/watch_data`
: null
);
const { data: radarrData } = useSWR<RadarrSettings[]>(
'/api/v1/settings/radarr'
);
const { data: sonarrData } = useSWR<SonarrSettings[]>(
'/api/v1/settings/sonarr'
);

const deleteMedia = async () => {
if (data.mediaInfo) {
Expand All @@ -106,6 +114,27 @@ const ManageSlideOver: React.FC<
}
};

const isDefaultService = () => {
if (data.mediaInfo) {
if (data.mediaInfo.mediaType === MediaType.MOVIE) {
return (
radarrData?.find(
(radarr) =>
radarr.isDefault && radarr.id === data.mediaInfo?.serviceId
) !== undefined
);
} else {
return (
sonarrData?.find(
(sonarr) =>
sonarr.isDefault && sonarr.id === data.mediaInfo?.serviceId
) !== undefined
);
}
}
return false;
};

const markAvailable = async (is4k = false) => {
if (data.mediaInfo) {
await axios.post(`/api/v1/media/${data.mediaInfo?.id}/available`, {
Expand Down Expand Up @@ -336,7 +365,8 @@ const ManageSlideOver: React.FC<
)}

{hasPermission(Permission.ADMIN) &&
data?.mediaInfo?.serviceUrl && (
data?.mediaInfo?.serviceUrl &&
isDefaultService() && (
<div>
<ConfirmButton
onClick={() => deleteMediaFile()}
Expand Down Expand Up @@ -482,35 +512,37 @@ const ManageSlideOver: React.FC<
</span>
</Button>
</a>
<div>
<ConfirmButton
onClick={() => deleteMediaFile()}
confirmText={intl.formatMessage(
globalMessages.areyousure
)}
className="w-full"
>
<TrashIcon />
<span>
{intl.formatMessage(messages.removearr4k, {
arr: mediaType === 'movie' ? 'Radarr' : 'Sonarr',
})}
</span>
</ConfirmButton>
<div className="mt-1 text-xs text-gray-400">
{intl.formatMessage(
messages.manageModalRemoveMediaWarning,
{
mediaType: intl.formatMessage(
mediaType === 'movie'
? messages.movie
: messages.tvshow
),
arr: mediaType === 'movie' ? 'Radarr' : 'Sonarr',
}
)}
{isDefaultService() && (
<div>
<ConfirmButton
onClick={() => deleteMediaFile()}
confirmText={intl.formatMessage(
globalMessages.areyousure
)}
className="w-full"
>
<TrashIcon />
<span>
{intl.formatMessage(messages.removearr4k, {
arr: mediaType === 'movie' ? 'Radarr' : 'Sonarr',
})}
</span>
</ConfirmButton>
<div className="mt-1 text-xs text-gray-400">
{intl.formatMessage(
messages.manageModalRemoveMediaWarning,
{
mediaType: intl.formatMessage(
mediaType === 'movie'
? messages.movie
: messages.tvshow
),
arr: mediaType === 'movie' ? 'Radarr' : 'Sonarr',
}
)}
</div>
</div>
</div>
)}
</>
)}
</div>
Expand Down

0 comments on commit 7d4455b

Please sign in to comment.