0

41 lines
966 B
TypeScript
Raw Normal View History

2022-05-05 15:01:23 -07:00
import { Button } from 'antd';
2022-05-09 15:34:02 -07:00
import { useState } from 'react';
import Modal from '../ui/Modal/Modal';
2022-05-11 23:31:31 -07:00
import { ExternalAction } from '../../interfaces/external-action';
2022-05-07 16:13:06 -07:00
import s from './ActionButton.module.scss';
2022-05-05 15:01:23 -07:00
interface Props {
action: ExternalAction;
}
2022-05-22 14:19:39 +02:00
export default function ActionButton({action: { url, title, description, icon, openExternally }}: Props) {
2022-05-09 15:34:02 -07:00
const [showModal, setShowModal] = useState(false);
2022-05-05 15:01:23 -07:00
2022-05-09 15:34:02 -07:00
const buttonClicked = () => {
if (openExternally) {
window.open(url, '_blank');
} else {
setShowModal(true);
}
};
2022-05-05 15:01:23 -07:00
return (
2022-05-09 15:34:02 -07:00
<>
<Button
type="primary"
className={`${s.button}`}
onClick={buttonClicked}
>
<img src={icon} className={`${s.icon}`} alt={description} />
{title}
</Button>
<Modal
title={description || title}
url={url}
visible={showModal}
handleCancel={() => setShowModal(false)}
/>
</>
2022-05-05 15:01:23 -07:00
);
}