Sonarr/frontend/src/Settings/DownloadClients/RemotePathMappings/EditRemotePathMappingModalC...

154 lines
4.4 KiB
JavaScript
Raw Normal View History

2018-01-13 02:01:27 +00:00
import PropTypes from 'prop-types';
import React from 'react';
2022-05-20 04:15:43 +00:00
import Form from 'Components/Form/Form';
import FormGroup from 'Components/Form/FormGroup';
import FormInputGroup from 'Components/Form/FormInputGroup';
import FormLabel from 'Components/Form/FormLabel';
2018-01-13 02:01:27 +00:00
import Button from 'Components/Link/Button';
import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton';
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
import ModalBody from 'Components/Modal/ModalBody';
2022-05-20 04:15:43 +00:00
import ModalContent from 'Components/Modal/ModalContent';
2018-01-13 02:01:27 +00:00
import ModalFooter from 'Components/Modal/ModalFooter';
2022-05-20 04:15:43 +00:00
import ModalHeader from 'Components/Modal/ModalHeader';
import { inputTypes, kinds } from 'Helpers/Props';
import { stringSettingShape } from 'Helpers/Props/Shapes/settingShape';
2023-07-22 19:14:33 +00:00
import translate from 'Utilities/String/translate';
2018-01-13 02:01:27 +00:00
import styles from './EditRemotePathMappingModalContent.css';
function EditRemotePathMappingModalContent(props) {
const {
id,
isFetching,
error,
isSaving,
saveError,
item,
downloadClientHosts,
onInputChange,
onSavePress,
onModalClose,
onDeleteRemotePathMappingPress,
...otherProps
} = props;
const {
host,
remotePath,
localPath
} = item;
return (
<ModalContent onModalClose={onModalClose}>
<ModalHeader>
2023-07-22 19:14:33 +00:00
{id ? translate('EditRemotePathMapping') : translate('AddRemotePathMapping')}
2018-01-13 02:01:27 +00:00
</ModalHeader>
<ModalBody className={styles.body}>
{
isFetching &&
<LoadingIndicator />
}
{
!isFetching && !!error &&
2023-07-22 19:14:33 +00:00
<div>
{translate('AddRemotePathMappingError')}
</div>
2018-01-13 02:01:27 +00:00
}
{
!isFetching && !error &&
<Form {...otherProps}>
2018-01-13 02:01:27 +00:00
<FormGroup>
2023-07-22 19:14:33 +00:00
<FormLabel>{translate('Host')}</FormLabel>
2018-01-13 02:01:27 +00:00
<FormInputGroup
type={inputTypes.SELECT}
2018-01-13 02:01:27 +00:00
name="host"
2023-07-22 19:14:33 +00:00
helpText={translate('RemotePathMappingHostHelpText')}
2018-01-13 02:01:27 +00:00
{...host}
values={downloadClientHosts}
onChange={onInputChange}
/>
</FormGroup>
<FormGroup>
2023-07-22 19:14:33 +00:00
<FormLabel>{translate('RemotePath')}</FormLabel>
2018-01-13 02:01:27 +00:00
<FormInputGroup
type={inputTypes.TEXT}
name="remotePath"
2023-07-22 19:14:33 +00:00
helpText={translate('RemotePathMappingRemotePathHelpText')}
2018-01-13 02:01:27 +00:00
{...remotePath}
onChange={onInputChange}
/>
</FormGroup>
<FormGroup>
2023-07-22 19:14:33 +00:00
<FormLabel>{translate('LocalPath')}</FormLabel>
2018-01-13 02:01:27 +00:00
<FormInputGroup
type={inputTypes.PATH}
name="localPath"
2023-07-22 19:14:33 +00:00
helpText={translate('RemotePathMappingLocalPathHelpText')}
2018-01-13 02:01:27 +00:00
{...localPath}
onChange={onInputChange}
/>
</FormGroup>
</Form>
}
</ModalBody>
<ModalFooter>
{
id &&
<Button
className={styles.deleteButton}
kind={kinds.DANGER}
onPress={onDeleteRemotePathMappingPress}
>
2023-07-22 19:14:33 +00:00
{translate('Delete')}
2018-01-13 02:01:27 +00:00
</Button>
}
<Button
onPress={onModalClose}
>
2023-07-22 19:14:33 +00:00
{translate('Cancel')}
2018-01-13 02:01:27 +00:00
</Button>
<SpinnerErrorButton
isSpinning={isSaving}
error={saveError}
onPress={onSavePress}
>
2023-07-22 19:14:33 +00:00
{translate('Save')}
2018-01-13 02:01:27 +00:00
</SpinnerErrorButton>
</ModalFooter>
</ModalContent>
);
}
const remotePathMappingShape = {
host: PropTypes.shape(stringSettingShape).isRequired,
remotePath: PropTypes.shape(stringSettingShape).isRequired,
localPath: PropTypes.shape(stringSettingShape).isRequired
};
EditRemotePathMappingModalContent.propTypes = {
id: PropTypes.number,
isFetching: PropTypes.bool.isRequired,
error: PropTypes.object,
isSaving: PropTypes.bool.isRequired,
saveError: PropTypes.object,
item: PropTypes.shape(remotePathMappingShape).isRequired,
downloadClientHosts: PropTypes.arrayOf(PropTypes.object).isRequired,
2018-01-13 02:01:27 +00:00
onInputChange: PropTypes.func.isRequired,
onSavePress: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired,
onDeleteRemotePathMappingPress: PropTypes.func
};
export default EditRemotePathMappingModalContent;