Refactoring du tableau de bord et ajout du panel pour les DADs

This commit is contained in:
2020-07-31 17:36:10 +02:00
parent c0ee95234d
commit ac41b301a9
10 changed files with 292 additions and 95 deletions

View File

@ -0,0 +1,32 @@
import { gql, useQuery } from '@apollo/client';
import { DecisionSupportFile } from '../../types/decision';
import { useState, useEffect } from 'react';
import { useGraphQLData } from './helper';
const QUERY_DECISIONS = gql`
query decisions($filter: DecisionFilter) {
decisions(filter: $filter) {
id,
title,
sections
createdAt,
closedAt,
votedAt,
workgroup {
id,
name
}
}
}
`;
export function useDecisionsQuery(options = {}) {
return useQuery(QUERY_DECISIONS, options);
}
export function useDecisions() {
const { data, loading, error } = useGraphQLData<DecisionSupportFile[]>(
QUERY_DECISIONS, 'decicions', []
);
return { decisions: data, loading, error };
}

View File

@ -0,0 +1,11 @@
import { useQuery, DocumentNode } from "@apollo/client";
import { useState, useEffect } from "react";
export function useGraphQLData<T>(q: DocumentNode, key: string, defaultValue: T) {
const query = useQuery(q);
const [ data, setData ] = useState<T>(defaultValue);
useEffect(() => {
setData(query.data ? query.data[key] as T : defaultValue);
}, [query.loading, query.data]);
return { data, loading: query.loading, error: query.error };
}

View File

@ -1,4 +1,7 @@
import { gql, useQuery } from '@apollo/client';
import { User } from '../../types/user';
import { useState, useEffect } from 'react';
import { useGraphQLData } from './helper';
const QUERY_USER_PROFILE = gql`
query userProfile {
@ -13,4 +16,11 @@ query userProfile {
export function useUserProfileQuery() {
return useQuery(QUERY_USER_PROFILE);
}
export function useUserProfile() {
const { data, loading, error } = useGraphQLData<User>(
QUERY_USER_PROFILE, 'userProfile', {id: '', email: ''}
);
return { user: data, loading, error };
}

View File

@ -1,4 +1,6 @@
import { gql, useQuery } from '@apollo/client';
import { Workgroup } from '../../types/workgroup';
import { useGraphQLData } from './helper';
const QUERY_WORKGROUP = gql`
query workgroups($filter: WorkgroupsFilter) {
@ -18,4 +20,11 @@ const QUERY_WORKGROUP = gql`
export function useWorkgroupsQuery(options = {}) {
return useQuery(QUERY_WORKGROUP, options);
}
export function useWorkgroups() {
const { data, loading, error } = useGraphQLData<Workgroup[]>(
QUERY_WORKGROUP, 'workgroups', []
);
return { workgroups: data, loading, error };
}