2022-03-02 08:03:50 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import MenuButton from 'components/common/MenuButton';
|
|
|
|
import Gear from 'assets/gear.svg';
|
2022-07-24 08:04:07 +02:00
|
|
|
import useStore, { setDashboard } from 'store/app';
|
2022-07-25 08:25:04 +02:00
|
|
|
import Button from 'components/common/Button';
|
|
|
|
import Check from 'assets/check.svg';
|
|
|
|
import styles from './DashboardSettingsButton.module.css';
|
2022-03-02 08:03:50 +01:00
|
|
|
|
|
|
|
const selector = state => state.dashboard;
|
|
|
|
|
|
|
|
export default function DashboardSettingsButton() {
|
|
|
|
const settings = useStore(selector);
|
|
|
|
|
|
|
|
const menuOptions = [
|
|
|
|
{
|
|
|
|
label: <FormattedMessage id="message.toggle-charts" defaultMessage="Toggle charts" />,
|
|
|
|
value: 'charts',
|
|
|
|
},
|
2022-07-25 08:25:04 +02:00
|
|
|
{
|
|
|
|
label: <FormattedMessage id="message.change-order" defaultMessage="Change order" />,
|
|
|
|
value: 'order',
|
|
|
|
},
|
2022-03-02 08:03:50 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
function handleSelect(value) {
|
|
|
|
if (value === 'charts') {
|
2022-07-24 08:04:07 +02:00
|
|
|
setDashboard({ ...settings, showCharts: !settings.showCharts });
|
2022-03-02 08:03:50 +01:00
|
|
|
}
|
2022-07-25 08:25:04 +02:00
|
|
|
if (value === 'order') {
|
|
|
|
setDashboard({ ...settings, changeOrderMode: !settings.changeOrderMode });
|
|
|
|
}
|
2022-03-02 08:03:50 +01:00
|
|
|
//setDashboard(value);
|
|
|
|
}
|
|
|
|
|
2022-07-25 08:25:04 +02:00
|
|
|
function handleExitChangeOrderMode() {
|
|
|
|
setDashboard({ ...settings, changeOrderMode: !settings.changeOrderMode });
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetWebsiteOrder() {
|
|
|
|
setDashboard({ ...settings, websiteOrdering: {} });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.changeOrderMode)
|
|
|
|
return (
|
|
|
|
<div className={styles.buttonGroup}>
|
|
|
|
<Button onClick={resetWebsiteOrder} size="small">
|
|
|
|
<FormattedMessage id="label.reset-order" defaultMessage="Reset order" />
|
|
|
|
</Button>
|
|
|
|
<Button onClick={handleExitChangeOrderMode} size="small" icon={<Check />}>
|
|
|
|
<FormattedMessage id="label.done" defaultMessage="Done" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2022-03-02 08:03:50 +01:00
|
|
|
return <MenuButton icon={<Gear />} options={menuOptions} onSelect={handleSelect} hideLabel />;
|
|
|
|
}
|