diff --git a/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx b/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx index d2a767c..5683bc6 100644 --- a/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx +++ b/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx @@ -1,31 +1,70 @@ -import React, { FunctionComponent, useState } from 'react'; -import { DecisionSupportFile } from '../../types/decision'; +import React, { FunctionComponent, useState, ChangeEvent, useEffect } from 'react'; +import { DecisionSupportFileUpdaterProps } from './DecisionSupportFileUpdaterProps'; -export interface ClarificationSectionProps { - dsf: DecisionSupportFile, -}; +export interface ClarificationSectionProps extends DecisionSupportFileUpdaterProps {}; + +const ClarificationSectionName = 'clarification'; + +export const ClarificationSection: FunctionComponent = ({ dsf, updateDSF }) => { + const [ section, setSection ] = useState({ + objectives: '', + motivations: '', + scope: '', + nature: '', + deadline: undefined, + hasDeadline: false, + }); + + useEffect(() => { + updateDSF({ ...dsf, sections: { ...dsf.sections, [ClarificationSectionName]: { ...section }} }) + }, [section]); + + const onTitleChange = (evt: ChangeEvent) => { + const title = (evt.currentTarget).value; + updateDSF({ ...dsf, title }); + }; + + const onSectionAttrChange = (attrName: string, evt: ChangeEvent) => { + const target = evt.currentTarget; + const value = target.hasOwnProperty('checked') ? target.checked : target.value; + setSection(section => ({ ...section, [attrName]: value })); + }; + + const onDeadlineChange = (evt: ChangeEvent) => { + const deadline = evt.currentTarget.valueAsDate; + setSection(section => ({ ...section, deadline })); + }; -export const ClarificationSection: FunctionComponent = ({ dsf }) => { return (
- +
- +

Ne pas essayer de rentrer trop dans les détails ici. Préférer l'utilisation des annexes et y faire référence.

- +

Penser à indiquer si des obligations légales pèsent sur cette prise de décision.

@@ -33,11 +72,13 @@ export const ClarificationSection: FunctionComponent
- - - - + + +
@@ -46,19 +87,33 @@ export const ClarificationSection: FunctionComponent
- - - - + + +
-
- -
- + +
+
+ +
+
+ +
+
diff --git a/client/src/components/DecisionSupportFilePage/DecisionSupportFilePage.tsx b/client/src/components/DecisionSupportFilePage/DecisionSupportFilePage.tsx index 02f23da..7aea3e9 100644 --- a/client/src/components/DecisionSupportFilePage/DecisionSupportFilePage.tsx +++ b/client/src/components/DecisionSupportFilePage/DecisionSupportFilePage.tsx @@ -4,15 +4,42 @@ import { ClarificationSection } from './ClarificationSection'; import { OptionsSection } from './OptionsSection'; import { MetadataPanel } from './MetadataPanel'; import { AppendixPanel } from './AppendixPanel'; +import { DecisionSupportFile, newDecisionSupportFile, DecisionSupportFileStatus } from '../../types/decision'; +import { useParams } from 'react-router'; +import { useDecisions } from '../../gql/queries/decisions'; export interface DecisionSupportFilePageProps { }; export const DecisionSupportFilePage: FunctionComponent = () => { - const [ state, setState ] = useState({ dsf: null }); - const isNew = true; - const isClosed = false; + const { id } = useParams(); + const { decisions } = useDecisions({ + variables:{ + filter: { + ids: [id], + } + } + }); + + const [ state, setState ] = useState({ + dsf: decisions.length > 0 ? decisions[0] : newDecisionSupportFile(), + selectedTabIndex: 0 + }); + + const isNew = state.dsf.id === ''; + const isClosed = state.dsf.status === DecisionSupportFileStatus.Closed; + + const selectTab = (tabIndex: number) => { + setState(state => ({ ...state, selectedTabIndex: tabIndex })); + }; + + const updateDSF = (dsf: DecisionSupportFile) => { + setState(state => ({...state, dsf})); + }; + + console.log(state.dsf); + return (
@@ -39,21 +66,24 @@ export const DecisionSupportFilePage: FunctionComponent
-
diff --git a/client/src/components/DecisionSupportFilePage/DecisionSupportFileUpdaterProps.tsx b/client/src/components/DecisionSupportFilePage/DecisionSupportFileUpdaterProps.tsx new file mode 100644 index 0000000..5c065f9 --- /dev/null +++ b/client/src/components/DecisionSupportFilePage/DecisionSupportFileUpdaterProps.tsx @@ -0,0 +1,6 @@ +import { DecisionSupportFile } from "../../types/decision"; + +export interface DecisionSupportFileUpdaterProps { + dsf: DecisionSupportFile + updateDSF: (dsf: DecisionSupportFile) => void +} \ No newline at end of file diff --git a/client/src/components/HomePage/DecisionSupportFilePanel.tsx b/client/src/components/HomePage/DecisionSupportFilePanel.tsx index e6b69b1..cf3c80b 100644 --- a/client/src/components/HomePage/DecisionSupportFilePanel.tsx +++ b/client/src/components/HomePage/DecisionSupportFilePanel.tsx @@ -14,12 +14,12 @@ export function DecisionSupportFilePanel() { label: 'Mes dossiers en cours', itemFilter: (item: Item) => { const dsf = item as DecisionSupportFile; - return dsf.status === DecisionSupportFileStatus.Opened && inWorkgroup(user, dsf.workgroup); + return (dsf.status === DecisionSupportFileStatus.Draft || dsf.status === DecisionSupportFileStatus.Ready) && inWorkgroup(user, dsf.workgroup); } }, { - label: 'Ouverts', - itemFilter: (item: Item) => (item as DecisionSupportFile).status === DecisionSupportFileStatus.Opened + label: 'Brouillons', + itemFilter: (item: Item) => (item as DecisionSupportFile).status === DecisionSupportFileStatus.Draft }, { label: 'Clos', diff --git a/client/src/gql/queries/decisions.tsx b/client/src/gql/queries/decisions.tsx index 599faee..4450a52 100644 --- a/client/src/gql/queries/decisions.tsx +++ b/client/src/gql/queries/decisions.tsx @@ -24,9 +24,9 @@ export function useDecisionsQuery(options = {}) { return useQuery(QUERY_DECISIONS, options); } -export function useDecisions() { +export function useDecisions(options = {}) { const { data, loading, error } = useGraphQLData( - QUERY_DECISIONS, 'decicions', [] + QUERY_DECISIONS, 'decisions', [], options ); return { decisions: data, loading, error }; } \ No newline at end of file diff --git a/client/src/gql/queries/helper.ts b/client/src/gql/queries/helper.ts index f159356..586791a 100644 --- a/client/src/gql/queries/helper.ts +++ b/client/src/gql/queries/helper.ts @@ -1,8 +1,8 @@ import { useQuery, DocumentNode } from "@apollo/client"; import { useState, useEffect } from "react"; -export function useGraphQLData(q: DocumentNode, key: string, defaultValue: T) { - const query = useQuery(q); +export function useGraphQLData(q: DocumentNode, key: string, defaultValue: T, options = {}) { + const query = useQuery(q, options); const [ data, setData ] = useState(defaultValue); useEffect(() => { setData(query.data ? query.data[key] as T : defaultValue); diff --git a/client/src/gql/queries/workgroups.tsx b/client/src/gql/queries/workgroups.tsx index 0965799..00efc69 100644 --- a/client/src/gql/queries/workgroups.tsx +++ b/client/src/gql/queries/workgroups.tsx @@ -22,9 +22,10 @@ export function useWorkgroupsQuery(options = {}) { return useQuery(QUERY_WORKGROUP, options); } -export function useWorkgroups() { +export function useWorkgroups(options = {}) { const { data, loading, error } = useGraphQLData( - QUERY_WORKGROUP, 'workgroups', [] + QUERY_WORKGROUP, 'workgroups', [], + options ); return { workgroups: data, loading, error }; } \ No newline at end of file diff --git a/client/src/types/decision.tsx b/client/src/types/decision.tsx index d38c619..9a86d44 100644 --- a/client/src/types/decision.tsx +++ b/client/src/types/decision.tsx @@ -1,23 +1,35 @@ import { Workgroup } from "./workgroup"; export enum DecisionSupportFileStatus { - Opened = "opened", + Draft = "draft", + Ready = "ready", Voted = "voted", Closed = "closed", } export interface DecisionSupportFileSection { - id: string + name: string } // aka Dossier d'aide à la décision export interface DecisionSupportFile { id: string title: string - sections: DecisionSupportFileSection[] + sections: {[name: string]: any} status: DecisionSupportFileStatus - workgroup: Workgroup, + workgroup?: Workgroup, createdAt: Date votedAt?: Date closedAt?: Date +} + +export function newDecisionSupportFile(): DecisionSupportFile { + return { + id: '', + title: '', + sections: {}, + status: DecisionSupportFileStatus.Draft, + workgroup: null, + createdAt: new Date(), + }; } \ No newline at end of file