import React, { useState } from 'react'; import { defineMessages, FormattedMessage } from 'react-intl'; import Badge from '../Common/Badge'; import Button from '../Common/Button'; import useSWR from 'swr'; import type { RadarrSettings, SonarrSettings, } from '../../../server/lib/settings'; import LoadingSpinner from '../Common/LoadingSpinner'; import RadarrModal from './RadarrModal'; import Modal from '../Common/Modal'; import Transition from '../Transition'; import axios from 'axios'; import SonarrModal from './SonarrModal'; const messages = defineMessages({ radarrsettings: 'Radarr Settings', radarrSettingsDescription: 'Configure your Radarr connection below. You can have multiple Radarr configurations but only two can be active as defaults at any time (one for standard HD and one for 4K). Administrations can override a titles connection to use in the manage title screen.', sonarrsettings: 'Sonarr Settings', sonarrSettingsDescription: 'Configure your Sonarr connection below. You can have multiple Sonarr configurations but only two can be active as defaults at any time (one for standard HD and one for 4K). Administrations can override a titles connection to use in the manage title screen.', deleteserverconfirm: 'Are you sure you want to delete this server?', edit: 'Edit', delete: 'Delete', ssl: 'SSL', default: 'Default', default4k: 'Default 4K', address: 'Address', activeProfile: 'Active Profile', addradarr: 'Add Radarr Server', addsonarr: 'Add Sonarr Server', }); interface ServerInstanceProps { name: string; isDefault?: boolean; isDefault4K?: boolean; address: string; isSSL?: boolean; profileName: string; isSonarr?: boolean; onEdit: () => void; onDelete: () => void; } const ServerInstance: React.FC = ({ name, address, profileName, isDefault4K = false, isDefault = false, isSSL = false, isSonarr = false, onEdit, onDelete, }) => { return (
  • {name}

    {isDefault && ( )} {isDefault4K && ( )} {isSSL && ( )}

    {address}

    {' '} {profileName}

  • ); }; const SettingsServices: React.FC = () => { const { data: radarrData, error: radarrError, revalidate: revalidateRadarr, } = useSWR('/api/v1/settings/radarr'); const { data: sonarrData, error: sonarrError, revalidate: revalidateSonarr, } = useSWR('/api/v1/settings/sonarr'); const [editRadarrModal, setEditRadarrModal] = useState<{ open: boolean; radarr: RadarrSettings | null; }>({ open: false, radarr: null, }); const [editSonarrModal, setEditSonarrModal] = useState<{ open: boolean; sonarr: SonarrSettings | null; }>({ open: false, sonarr: null, }); const [deleteServerModal, setDeleteServerModal] = useState<{ open: boolean; type: 'radarr' | 'sonarr'; serverId: number | null; }>({ open: false, type: 'radarr', serverId: null, }); const deleteServer = async () => { await axios.delete( `/api/v1/settings/${deleteServerModal.type}/${deleteServerModal.serverId}` ); setDeleteServerModal({ open: false, serverId: null, type: 'radarr' }); revalidateRadarr(); revalidateSonarr(); }; return ( <>

    {editRadarrModal.open && ( setEditRadarrModal({ open: false, radarr: null })} onSave={() => { revalidateRadarr(); setEditRadarrModal({ open: false, radarr: null }); }} /> )} {editSonarrModal.open && ( setEditSonarrModal({ open: false, sonarr: null })} onSave={() => { revalidateSonarr(); setEditSonarrModal({ open: false, sonarr: null }); }} /> )} deleteServer()} onCancel={() => setDeleteServerModal({ open: false, serverId: null, type: 'radarr', }) } title="Delete Server" >
    {!radarrData && !radarrError && } {radarrData && !radarrError && (
      {radarrData.map((radarr) => ( setEditRadarrModal({ open: true, radarr })} onDelete={() => setDeleteServerModal({ open: true, serverId: radarr.id, type: 'radarr', }) } /> ))}
    )}

    {!sonarrData && !sonarrError && } {sonarrData && !sonarrError && (
      {sonarrData.map((sonarr) => ( setEditSonarrModal({ open: true, sonarr })} onDelete={() => setDeleteServerModal({ open: true, serverId: sonarr.id, type: 'sonarr', }) } /> ))}
    )}
    ); }; export default SettingsServices;