From e990184a0b43e4dcdd53c757607c7c2277529932 Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 23 Jul 2020 08:25:19 +0200 Subject: [PATCH] Clore un groupe de travail --- .../components/HomePage/WorkgroupsPanel.tsx | 6 ++--- .../components/WorkgroupPage/MembersPanel.tsx | 2 +- .../WorkgroupPage/WorkgroupPage.tsx | 22 ++++++++++++++----- client/src/gql/mutations/workgroups.tsx | 19 ++++++++++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/client/src/components/HomePage/WorkgroupsPanel.tsx b/client/src/components/HomePage/WorkgroupsPanel.tsx index b59a601..439b931 100644 --- a/client/src/components/HomePage/WorkgroupsPanel.tsx +++ b/client/src/components/HomePage/WorkgroupsPanel.tsx @@ -17,9 +17,9 @@ export function WorkgroupsPanel() { const filterTabs = [ { - label: "Mes groupes", + label: "Mes groupes en cours", filter: workgroups => workgroups.filter((wg: Workgroup) => { - return wg.members.some((u: User) => u.id === (userProfile ? userProfile.id : '')); + return wg.closedAt === null && wg.members.some((u: User) => u.id === (userProfile ? userProfile.id : '')); }) }, { @@ -27,7 +27,7 @@ export function WorkgroupsPanel() { filter: workgroups => workgroups.filter((wg: Workgroup) => !wg.closedAt) }, { - label: "Clôs", + label: "Clos", filter: workgroups => workgroups.filter((wg: Workgroup) => !!wg.closedAt) } ]; diff --git a/client/src/components/WorkgroupPage/MembersPanel.tsx b/client/src/components/WorkgroupPage/MembersPanel.tsx index 1cdd85f..7092ace 100644 --- a/client/src/components/WorkgroupPage/MembersPanel.tsx +++ b/client/src/components/WorkgroupPage/MembersPanel.tsx @@ -18,7 +18,7 @@ export const MembersPanel: FunctionComponent = ({ users }) => - {`${ u.name ? u.name : '' } - `}{`${u.email}`} + {`${ u.name ? (u.name + ' - ') : '' }`}{`${u.email}`} ); }) diff --git a/client/src/components/WorkgroupPage/WorkgroupPage.tsx b/client/src/components/WorkgroupPage/WorkgroupPage.tsx index 7d93c6c..a0a114c 100644 --- a/client/src/components/WorkgroupPage/WorkgroupPage.tsx +++ b/client/src/components/WorkgroupPage/WorkgroupPage.tsx @@ -8,7 +8,7 @@ import { MembersPanel } from './MembersPanel'; import { User } from '../../types/user'; import { InfoPanel } from './InfoPanel'; import { Workgroup } from '../../types/workgroup'; -import { useJoinWorkgroupMutation, useLeaveWorkgroupMutation } from '../../gql/mutations/workgroups'; +import { useJoinWorkgroupMutation, useLeaveWorkgroupMutation, useCloseWorkgroupMutation } from '../../gql/mutations/workgroups'; export function WorkgroupPage() { const { id } = useParams(); @@ -22,6 +22,7 @@ export function WorkgroupPage() { const userProfileQuery = useUserProfileQuery(); const [ joinWorkgroup, joinWorkgroupMutation ] = useJoinWorkgroupMutation(); const [ leaveWorkgroup, leaveWorkgroupMutation ] = useLeaveWorkgroupMutation(); + const [ closeWorkgroup, closeWorkgroupMutation ] = useCloseWorkgroupMutation(); const [ state, setState ] = useState({ userProfileId: '', workgroup: { @@ -59,8 +60,17 @@ export function WorkgroupPage() { }); } + const onCloseWorkgroupClick = () => { + closeWorkgroup({ + variables: { + workgroupId: state.workgroup.id, + } + }); + } + const isNew = state.workgroup.id === ''; const isWorkgroupMember = state.workgroup.members.some(u => u.id === state.userProfileId); + const isClosed = state.workgroup.closedAt !== null; return ( @@ -79,7 +89,7 @@ export function WorkgroupPage() {

{state.workgroup.name}

-

Groupe de travail

+

Groupe de travail { isClosed ? '(clos)' : null }

} @@ -87,17 +97,17 @@ export function WorkgroupPage() {
{ - isNew ? null : + isNew || isClosed ? null : { isWorkgroupMember ? - : diff --git a/client/src/gql/mutations/workgroups.tsx b/client/src/gql/mutations/workgroups.tsx index 9b5ad58..b9f6770 100644 --- a/client/src/gql/mutations/workgroups.tsx +++ b/client/src/gql/mutations/workgroups.tsx @@ -74,4 +74,23 @@ mutation leaveWorkgroup($workgroupId: ID!) { export function useLeaveWorkgroupMutation() { return useMutation(MUTATION_LEAVE_WORKGROUP); +} + +const MUTATION_CLOSE_WORKGROUP = gql` +mutation closeWorkgroup($workgroupId: ID!) { + closeWorkgroup(workgroupId: $workgroupId) { + id, + name, + createdAt, + closedAt, + members { + id, + name, + email + } + } +}`; + +export function useCloseWorkgroupMutation() { + return useMutation(MUTATION_CLOSE_WORKGROUP); } \ No newline at end of file