From 5c7336adba1a98555c08bdbe2c46a77a1f7ecc84 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Fri, 15 Sep 2023 17:28:33 +0200 Subject: [PATCH] Ajout de l'action permettant d'envoyer une copie (#936) resolves #919 --- front/src/components/Article.graphql | 2 +- front/src/components/ArticleSendCopy.jsx | 30 +++++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/front/src/components/Article.graphql b/front/src/components/Article.graphql index c96983752..712ee1632 100644 --- a/front/src/components/Article.graphql +++ b/front/src/components/Article.graphql @@ -50,7 +50,7 @@ query deleteArticle ($article: ID!) { } } -mutation duplicateArticle($user: ID!, $article: ID!, $to: ID!) { +mutation duplicateArticle($user: ID, $article: ID!, $to: ID!) { duplicateArticle(article: $article, to: $to, user: $user) { _id title diff --git a/front/src/components/ArticleSendCopy.jsx b/front/src/components/ArticleSendCopy.jsx index 1c53f5c5a..8f9072564 100644 --- a/front/src/components/ArticleSendCopy.jsx +++ b/front/src/components/ArticleSendCopy.jsx @@ -1,19 +1,37 @@ import React, { useCallback } from 'react' -import styles from './articleSendCopy.module.scss' -import ContactSearch from './ContactSearch.jsx' import { useToasts } from '@geist-ui/core' import { Send } from 'react-feather' +import { + duplicateArticle +} from './Article.graphql' + +import styles from './articleSendCopy.module.scss' +import ContactSearch from './ContactSearch.jsx' +import {useMutation} from '../hooks/graphql.js' + export default function ArticleSendCopy ({ article }) { const { setToast } = useToasts() + const mutation = useMutation() const handleUserUpdated = useCallback(async ({ user, action }) => { if (action === 'select' || action === 'unselect') { - setToast({ - text: `Copie de l'article envoyée à ${user.displayName || user.username}.`, - type: 'success', - }) + try { + await mutation({ + query: duplicateArticle, + variables: {user: null, to: user._id, article: article._id} + }) + setToast({ + text: `Copie de l'article envoyée à ${user.displayName || user.username}.`, + type: 'success', + }) + } catch (err) { + setToast({ + type: 'error', + text: `Unable to send a copy of the article: ${err.message}` + }) + } } }, [article._id])