mirror of
https://github.com/optim-enterprises-bv/OptimCloud-gw-ui.git
synced 2025-10-31 18:27:45 +00:00
New copy to clipboard component. Alignment fixes
This commit is contained in:
36
src/components/CopyToClipboardButton/index.js
Normal file
36
src/components/CopyToClipboardButton/index.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import CIcon from '@coreui/icons-react';
|
||||||
|
import { cilClone } from '@coreui/icons';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { CButton, CPopover } from '@coreui/react';
|
||||||
|
|
||||||
|
const CopyToClipboardButton = ({content, size}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [result, setResult] = useState('');
|
||||||
|
|
||||||
|
const copyToClipboard = () => {
|
||||||
|
navigator.clipboard.writeText(content);
|
||||||
|
setResult(t('common.copied'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CPopover content={t('common.copy_to_clipboard')}>
|
||||||
|
<CButton onClick={copyToClipboard} size={size}>
|
||||||
|
<CIcon content={cilClone} />
|
||||||
|
{' '}{result || ''}
|
||||||
|
</CButton>
|
||||||
|
</CPopover>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyToClipboardButton.propTypes = {
|
||||||
|
content: PropTypes.string.isRequired,
|
||||||
|
size: PropTypes.string
|
||||||
|
};
|
||||||
|
|
||||||
|
CopyToClipboardButton.defaultProps = {
|
||||||
|
size: 'sm',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CopyToClipboardButton;
|
||||||
@@ -17,10 +17,11 @@ import {
|
|||||||
} from '@coreui/react';
|
} from '@coreui/react';
|
||||||
import CIcon from '@coreui/icons-react';
|
import CIcon from '@coreui/icons-react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { cilWindowMaximize, cilClone } from '@coreui/icons';
|
import { cilWindowMaximize } from '@coreui/icons';
|
||||||
import { prettyDate } from 'utils/helper';
|
import { prettyDate } from 'utils/helper';
|
||||||
import axiosInstance from 'utils/axiosInstance';
|
import axiosInstance from 'utils/axiosInstance';
|
||||||
import { getToken } from 'utils/authHelper';
|
import { getToken } from 'utils/authHelper';
|
||||||
|
import CopyToClipboardButton from 'components/CopyToClipboardButton';
|
||||||
import DeviceConfigurationModal from './DeviceConfigurationModal';
|
import DeviceConfigurationModal from './DeviceConfigurationModal';
|
||||||
import styles from './index.module.scss';
|
import styles from './index.module.scss';
|
||||||
|
|
||||||
@@ -29,7 +30,6 @@ const DeviceConfiguration = ({ selectedDeviceId }) => {
|
|||||||
const [collapse, setCollapse] = useState(false);
|
const [collapse, setCollapse] = useState(false);
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
const [device, setDevice] = useState(null);
|
const [device, setDevice] = useState(null);
|
||||||
const [copyPasswordSuccess, setCopyPasswordSuccess] = useState('');
|
|
||||||
|
|
||||||
const toggle = (e) => {
|
const toggle = (e) => {
|
||||||
setCollapse(!collapse);
|
setCollapse(!collapse);
|
||||||
@@ -40,12 +40,6 @@ const DeviceConfiguration = ({ selectedDeviceId }) => {
|
|||||||
setShowModal(!showModal);
|
setShowModal(!showModal);
|
||||||
};
|
};
|
||||||
|
|
||||||
const copyPasswordToClipboard = () => {
|
|
||||||
const password = device.devicePassword === '' ? 'openwifi' : device.devicePassword;
|
|
||||||
navigator.clipboard.writeText(password);
|
|
||||||
setCopyPasswordSuccess(t('common.copied'));
|
|
||||||
};
|
|
||||||
|
|
||||||
const getDevice = () => {
|
const getDevice = () => {
|
||||||
const options = {
|
const options = {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -64,7 +58,6 @@ const DeviceConfiguration = ({ selectedDeviceId }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedDeviceId) getDevice();
|
if (selectedDeviceId) getDevice();
|
||||||
setCopyPasswordSuccess(null);
|
|
||||||
}, [selectedDeviceId]);
|
}, [selectedDeviceId]);
|
||||||
|
|
||||||
if (device) {
|
if (device) {
|
||||||
@@ -106,6 +99,7 @@ const DeviceConfiguration = ({ selectedDeviceId }) => {
|
|||||||
</CCol>
|
</CCol>
|
||||||
<CCol xs="12" md="9">
|
<CCol xs="12" md="9">
|
||||||
{device.serialNumber}
|
{device.serialNumber}
|
||||||
|
<CopyToClipboardButton size="sm" content={device.serialNumber}/>
|
||||||
</CCol>
|
</CCol>
|
||||||
</CFormGroup>
|
</CFormGroup>
|
||||||
<CFormGroup row>
|
<CFormGroup row>
|
||||||
@@ -149,17 +143,12 @@ const DeviceConfiguration = ({ selectedDeviceId }) => {
|
|||||||
</CCol>
|
</CCol>
|
||||||
</CFormGroup>
|
</CFormGroup>
|
||||||
<CFormGroup row>
|
<CFormGroup row>
|
||||||
<CCol md="3">
|
<CCol md="3" className={styles.topPadding}>
|
||||||
<CLabel>{t('configuration.device_password')} : </CLabel>
|
<CLabel>{t('configuration.device_password')} : </CLabel>
|
||||||
</CCol>
|
</CCol>
|
||||||
<CCol xs="12" md="9">
|
<CCol xs="12" md="9">
|
||||||
{device.devicePassword === '' ? 'openwifi' : device.devicePassword}
|
{device.devicePassword === '' ? 'openwifi' : device.devicePassword}
|
||||||
<CPopover content={t('common.copy_to_clipboard')}>
|
<CopyToClipboardButton size="sm" content={device?.devicePassword === '' ? 'openwifi' : device.devicePassword}/>
|
||||||
<CButton onClick={copyPasswordToClipboard} size="sm">
|
|
||||||
<CIcon content={cilClone} />
|
|
||||||
</CButton>
|
|
||||||
</CPopover>
|
|
||||||
{copyPasswordSuccess}
|
|
||||||
</CCol>
|
</CCol>
|
||||||
</CFormGroup>
|
</CFormGroup>
|
||||||
<CCollapse show={collapse}>
|
<CCollapse show={collapse}>
|
||||||
|
|||||||
@@ -9,3 +9,7 @@
|
|||||||
.modalTitle {
|
.modalTitle {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.topPadding {
|
||||||
|
padding-top: 5px;
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,3 +5,7 @@
|
|||||||
.spacedColumn {
|
.spacedColumn {
|
||||||
margin-top: 7px;
|
margin-top: 7px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.spacedDate {
|
||||||
|
margin-top: 7px;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user