import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { ToggleGroup, ToggleGroupItem, } from '@patternfly/react-core'; import { noop } from 'foremanReact/common/helpers'; import CdnTypeForm from './CdnTypeForm'; import ExportSyncForm from './ExportSyncForm'; import NetworkSyncForm from './NetworkSyncForm'; import './CdnConfigurationForm.scss'; import { CDN_URL, CDN, EXPORT_SYNC, NETWORK_SYNC, CDN_CONFIGURATION_TYPES } from './CdnConfigurationConstants'; const CdnConfigurationForm = (props) => { const { contentCredentials, cdnConfiguration, onUpdate, } = props; const [type, setType] = useState(cdnConfiguration.type); const updateType = (connectionType) => { if (type !== connectionType) { setType(connectionType); } }; const cdnUrl = type !== cdnConfiguration.type ? CDN_URL : cdnConfiguration.url; return (
updateType(CDN)} /> updateType(NETWORK_SYNC)} /> updateType(EXPORT_SYNC)} /> { type === NETWORK_SYNC && } { type === CDN && } { type === EXPORT_SYNC && }
); }; CdnConfigurationForm.propTypes = { contentCredentials: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.number, name: PropTypes.string, })), cdnConfiguration: PropTypes.shape({ type: PropTypes.string, url: PropTypes.string, username: PropTypes.string, upstream_organization_label: PropTypes.string, upstream_content_view_label: PropTypes.string, upstream_lifecycle_environment_label: PropTypes.string, ssl_ca_credential_id: PropTypes.number, password_exists: PropTypes.bool, }), onUpdate: PropTypes.func, }; CdnConfigurationForm.defaultProps = { contentCredentials: [], cdnConfiguration: {}, onUpdate: noop, }; export default CdnConfigurationForm;