fix dashboards and add empty state

This commit is contained in:
João Geonizeli
2022-07-27 22:41:22 -03:00
parent 7489cab78e
commit 89f39f93e9
4 changed files with 29 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
import React, {FC,} from 'react' import React from 'react'
import {DashboardProvider} from './DashboardContext' import {DashboardProvider} from './DashboardContext'
import { import {
@@ -9,7 +9,7 @@ import {
} from './charts' } from './charts'
import {Filters} from './Filters' import {Filters} from './Filters'
export const Dashboard: FC = () => ( export const Dashboard = () => (
<DashboardProvider> <DashboardProvider>
<main className="max-h-screen sm:px-8 gap-2 pt-2 sm:pt-4"> <main className="max-h-screen sm:px-8 gap-2 pt-2 sm:pt-4">
<Filters/> <Filters/>

View File

@@ -31,7 +31,11 @@ export const whereDefaultState = (userContext: UserContext) => (
userContext.isOnlyTeacher ? {userId: userContext.user?.id} : {} userContext.isOnlyTeacher ? {userId: userContext.user?.id} : {}
) )
export const DashboardProvider: FC = ({children}) => { type DashboardProviderProps = {
children: React.ReactNode
}
export const DashboardProvider = ({children}: DashboardProviderProps) => {
const userContext = useCurrentUser() const userContext = useCurrentUser()
const [where, setWhere] = useState<QuestionWhereInput>(whereDefaultState(userContext)) const [where, setWhere] = useState<QuestionWhereInput>(whereDefaultState(userContext))
const providerValue = useMemo(() => ({where, setWhere}), [ const providerValue = useMemo(() => ({where, setWhere}), [

View File

@@ -17,22 +17,26 @@ export const Pie: FC<Props> = ({title, data}) => {
style={{ height: '36rem', width: '36rem' }} style={{ height: '36rem', width: '36rem' }}
> >
<h3 className="text-lg leading-6 font-medium text-gray-900">{title}</h3> <h3 className="text-lg leading-6 font-medium text-gray-900">{title}</h3>
<ResponsivePie {data.length ? (
data={data} <ResponsivePie
margin={{top: 40, right: 80, bottom: 80, left: 80}} data={data}
innerRadius={0.5} margin={{top: 40, right: 80, bottom: 80, left: 80}}
padAngle={0.7} innerRadius={0.5}
cornerRadius={3} padAngle={0.7}
activeOuterRadiusOffset={8} cornerRadius={3}
borderWidth={1} activeOuterRadiusOffset={8}
borderColor={{from: 'color', modifiers: [['darker', 0.2]]}} borderWidth={1}
arcLinkLabelsSkipAngle={10} borderColor={{from: 'color', modifiers: [['darker', 0.2]]}}
arcLinkLabelsTextColor="#333333" arcLinkLabelsSkipAngle={10}
arcLinkLabelsThickness={2} arcLinkLabelsTextColor="#333333"
arcLinkLabelsColor={{from: 'color'}} arcLinkLabelsThickness={2}
arcLabelsSkipAngle={10} arcLinkLabelsColor={{from: 'color'}}
arcLabelsTextColor={{from: 'color', modifiers: [['darker', 2]]}} arcLabelsSkipAngle={10}
/> arcLabelsTextColor={{from: 'color', modifiers: [['darker', 2]]}}
/>
) : (
<div className='grid items-center text-center h-full'>Não existem dados disponíveis.</div>
)}
</div> </div>
) )
} }

View File

@@ -24,5 +24,7 @@ class Subject < ApplicationRecord
belongs_to :category belongs_to :category
belongs_to :axis belongs_to :axis
has_many :questions
validates :name, presence: true, uniqueness: true validates :name, presence: true, uniqueness: true
end end