2020-11-09 15:17:38 +01:00
|
|
|
/**
|
2020-11-24 13:26:15 +01:00
|
|
|
* This component is a template for a modal dialog that wraps the application style
|
2020-11-09 15:17:38 +01:00
|
|
|
*/
|
|
|
|
|
2020-11-24 13:26:15 +01:00
|
|
|
import React, { ReactNode } from 'react';
|
2020-11-09 15:17:38 +01:00
|
|
|
import Modal from 'react-modal';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { Loader } from './loader';
|
2020-11-23 17:36:33 +01:00
|
|
|
import CustomAssetAPI from '../api/custom-asset';
|
2020-11-09 15:17:38 +01:00
|
|
|
|
|
|
|
Modal.setAppElement('body');
|
|
|
|
|
|
|
|
interface FabModalProps {
|
|
|
|
title: string,
|
|
|
|
isOpen: boolean,
|
2020-11-24 13:26:15 +01:00
|
|
|
toggleModal: () => void,
|
|
|
|
confirmButton?: ReactNode
|
2020-11-09 15:17:38 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 17:36:33 +01:00
|
|
|
const blackLogoFile = CustomAssetAPI.get('logo-black-file');
|
2020-11-09 15:17:38 +01:00
|
|
|
|
2020-11-24 13:26:15 +01:00
|
|
|
export const FabModal: React.FC<FabModalProps> = ({ title, isOpen, toggleModal, children, confirmButton }) => {
|
2020-11-09 15:17:38 +01:00
|
|
|
const { t } = useTranslation('shared');
|
|
|
|
const blackLogo = blackLogoFile.read();
|
|
|
|
|
2020-11-24 13:26:15 +01:00
|
|
|
/**
|
|
|
|
* Check if the confirm button should be present
|
|
|
|
*/
|
|
|
|
const hasConfirmButton = (): boolean => {
|
|
|
|
return confirmButton !== undefined;
|
|
|
|
}
|
|
|
|
|
2020-11-09 15:17:38 +01:00
|
|
|
return (
|
|
|
|
<Modal isOpen={isOpen}
|
|
|
|
className="fab-modal"
|
|
|
|
overlayClassName="fab-modal-overlay"
|
|
|
|
onRequestClose={toggleModal}>
|
|
|
|
<div className="fab-modal-header">
|
|
|
|
<Loader>
|
|
|
|
<img src={blackLogo.custom_asset_file_attributes.attachment_url}
|
|
|
|
alt={blackLogo.custom_asset_file_attributes.attachment}
|
|
|
|
className="modal-logo" />
|
|
|
|
</Loader>
|
|
|
|
<h1>{ title }</h1>
|
|
|
|
</div>
|
|
|
|
<div className="fab-modal-content">
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
<div className="fab-modal-footer">
|
|
|
|
<Loader>
|
2020-11-24 13:26:15 +01:00
|
|
|
<button className="modal-btn--close" onClick={toggleModal}>{t('app.shared.buttons.close')}</button>
|
|
|
|
{hasConfirmButton() && <span className="modal-btn--confirm">{confirmButton}</span>}
|
2020-11-09 15:17:38 +01:00
|
|
|
</Loader>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|