Skip to content

Commit

Permalink
Ajout de l'action permettant d'envoyer une copie (#936)
Browse files Browse the repository at this point in the history
resolves #919
  • Loading branch information
ggrossetie authored Sep 15, 2023
1 parent 77bccfa commit 5c7336a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion front/src/components/Article.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 24 additions & 6 deletions front/src/components/ArticleSendCopy.jsx
Original file line number Diff line number Diff line change
@@ -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])

Expand Down

0 comments on commit 5c7336a

Please sign in to comment.