Updates #6679
Squashed commit of the following:
commit 2e051c9528085182a22ec40a1df11780012a5001
Merge: a001f52ab 56b98080f
Author: Ildar Kamalov <ik@adguard.com>
Date: Thu Feb 8 15:02:22 2024 +0300
Merge branch 'master' into ADG-8179
commit a001f52ab5dadcfc1116ac46da01c0344e51b656
Author: Ildar Kamalov <ik@adguard.com>
Date: Mon Feb 5 18:59:13 2024 +0300
fix changelog
commit 5bac6a2446413b157da6bb404e0e21bb35ac6a10
Author: Ildar Kamalov <ik@adguard.com>
Date: Mon Feb 5 16:01:01 2024 +0300
fix
commit 14a7190ebb18fbed99a897723c27b80144d56825
Author: Ildar Kamalov <ik@adguard.com>
Date: Mon Feb 5 15:59:35 2024 +0300
ADG-8179 add persistent client from query log context menu
103 lines
2.9 KiB
JavaScript
103 lines
2.9 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { Trans, withTranslation } from 'react-i18next';
|
|
import ReactModal from 'react-modal';
|
|
|
|
import { MODAL_TYPE } from '../../../helpers/constants';
|
|
import Form from './Form';
|
|
|
|
const getInitialData = ({
|
|
initial, modalType, clientId, clientName,
|
|
}) => {
|
|
if (initial && initial.blocked_services) {
|
|
const { blocked_services } = initial;
|
|
const blocked = {};
|
|
|
|
blocked_services.forEach((service) => {
|
|
blocked[service] = true;
|
|
});
|
|
|
|
return {
|
|
...initial,
|
|
blocked_services: blocked,
|
|
};
|
|
}
|
|
|
|
if (modalType !== MODAL_TYPE.EDIT_CLIENT && clientId) {
|
|
return {
|
|
...initial,
|
|
name: clientName,
|
|
ids: [clientId],
|
|
};
|
|
}
|
|
|
|
return initial;
|
|
};
|
|
|
|
const Modal = ({
|
|
isModalOpen,
|
|
modalType,
|
|
currentClientData,
|
|
handleSubmit,
|
|
handleClose,
|
|
processingAdding,
|
|
processingUpdating,
|
|
tagsOptions,
|
|
clientId,
|
|
t,
|
|
}) => {
|
|
const initialData = getInitialData({
|
|
initial: currentClientData,
|
|
modalType,
|
|
clientId,
|
|
clientName: t('client_name', { id: clientId }),
|
|
});
|
|
|
|
return (
|
|
<ReactModal
|
|
className="Modal__Bootstrap modal-dialog modal-dialog-centered modal-dialog--clients"
|
|
closeTimeoutMS={0}
|
|
isOpen={isModalOpen}
|
|
onRequestClose={handleClose}
|
|
>
|
|
<div className="modal-content">
|
|
<div className="modal-header">
|
|
<h4 className="modal-title">
|
|
{modalType === MODAL_TYPE.EDIT_CLIENT ? (
|
|
<Trans>client_edit</Trans>
|
|
) : (
|
|
<Trans>client_new</Trans>
|
|
)}
|
|
</h4>
|
|
<button type="button" className="close" onClick={handleClose}>
|
|
<span className="sr-only">Close</span>
|
|
</button>
|
|
</div>
|
|
<Form
|
|
initialValues={{ ...initialData }}
|
|
onSubmit={handleSubmit}
|
|
handleClose={handleClose}
|
|
processingAdding={processingAdding}
|
|
processingUpdating={processingUpdating}
|
|
tagsOptions={tagsOptions}
|
|
/>
|
|
</div>
|
|
</ReactModal>
|
|
);
|
|
};
|
|
|
|
Modal.propTypes = {
|
|
isModalOpen: PropTypes.bool.isRequired,
|
|
modalType: PropTypes.string.isRequired,
|
|
currentClientData: PropTypes.object.isRequired,
|
|
handleSubmit: PropTypes.func.isRequired,
|
|
handleClose: PropTypes.func.isRequired,
|
|
processingAdding: PropTypes.bool.isRequired,
|
|
processingUpdating: PropTypes.bool.isRequired,
|
|
tagsOptions: PropTypes.array.isRequired,
|
|
t: PropTypes.func.isRequired,
|
|
clientId: PropTypes.string,
|
|
};
|
|
|
|
export default withTranslation()(Modal);
|