import React from 'react'; import BaseButton from '../BaseButton'; import BaseIcon from '../BaseIcon'; import * as icons from '@mdi/js'; import { useAppDispatch, useAppSelector } from '../../stores/hooks'; import { fetchWidgets, removeWidget } from '../../stores/roles/rolesSlice'; import { WidgetChartType, WidgetType } from './models/widget.model'; import { BarChart } from './components/BarChart'; import { PieChart } from './components/PieChart'; import { AreaChart } from './components/AreaChart'; import { LineChart } from './components/LineChart'; export const SmartWidget = ({ widget, userId, admin, roleId }) => { const dispatch = useAppDispatch(); const corners = useAppSelector((state) => state.style.corners); const cardsStyle = useAppSelector((state) => state.style.cardsStyle); const deleteWidget = async () => { await dispatch( removeWidget({ id: userId, widgetId: widget.widget_id, roleId }), ); await dispatch(fetchWidgets(roleId)); }; return (
{widget.label}
{admin && ( )}
{widget.value ? ( widget.widget_type === WidgetType.chart ? ( widget.chart_type === WidgetChartType.bar ? ( ) : widget.chart_type === WidgetChartType.line ? ( ) : widget.chart_type === WidgetChartType.pie ? ( ) : widget.chart_type === WidgetChartType.area ? ( ) : widget.chart_type === WidgetChartType.funnel ? ( ) : null ) : (
{widget.value}
) ) : (
Something went wrong, please try again or use a different query.
)}
{widget.type === WidgetType.scalar && widget.mdiIcon && (
)}
); };