import React, { FunctionComponent, useState, useEffect, ChangeEvent } from 'react'; import { DecisionSupportFile, DecisionSupportFileStatus } from '../../types/decision'; import { useWorkgroups } from '../../gql/queries/workgroups'; import { useUserProfile } from '../../gql/queries/profile'; import { inWorkgroup } from '../../types/workgroup'; import { DecisionSupportFileUpdaterProps } from './DecisionSupportFileUpdaterProps'; import { asDate } from '../../util/date'; import { Link } from 'react-router-dom'; export interface MetadataPanelProps extends DecisionSupportFileUpdaterProps {}; export const MetadataPanel: FunctionComponent = ({ dsf, updateDSF, readOnly }) => { const { user } = useUserProfile(); const { workgroups } = useWorkgroups(); const [ userOpenedWorkgroups, setUserOpenedWorkgroups ] = useState([]); useEffect(() => { const filtered = workgroups.filter(wg => !wg.closedAt && inWorkgroup(user, wg)); setUserOpenedWorkgroups(filtered); }, [workgroups, user]) const onStatusChanged = (evt: ChangeEvent) => { const status = evt.currentTarget.value as DecisionSupportFileStatus; updateDSF({ ...dsf, status }); }; const onWorkgroupChanged = (evt: ChangeEvent) => { const workgroupId = evt.currentTarget.value; const workgroup = workgroups.find(wg => wg.id === workgroupId); updateDSF({ ...dsf, workgroup }); }; return ( ); };