This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dex 1341 - add collaboration from user page (#464)
* Update user collaboration cards * Update MyCollaborationsCard columns to fix no-unstable-nested-components error * Add AddCollaboratorButton shell * Add logic to AddCollaboratorButton * Internationalize default error message for handleAxiosError * Remove 'limit' and 'offset' from useGetUsers * Fix useMutation error handling * Rename prefixApiURL to prefixApiUrl * Rename useHandleAxiosError to useHandleRequestError and update logic * Inline handleSubmitCollaborator * Rename axiosUtils.js to requestUtils and prefixApiUrl to withApiPrefix
- Loading branch information
Showing
10 changed files
with
421 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import axios from 'axios'; | ||
import { get } from 'lodash-es'; | ||
import { useMutation, useQueryClient } from 'react-query'; | ||
|
||
import Card from '@material-ui/core/Card'; | ||
import CardActions from '@material-ui/core/CardActions'; | ||
import CardContent from '@material-ui/core/CardContent'; | ||
|
||
import { withApiPrefix } from '../../utils/requestUtils'; | ||
import { getUserQueryKey } from '../../constants/queryKeys'; | ||
import AddCollaboratorButton from './collaborations/AddCollaboratorButton'; | ||
import UserManagerCollaborationEditTable from '../UserManagerCollaborationEditTable'; | ||
import useHandleRequestError from '../../hooks/useHandleRequestError'; | ||
|
||
export default function UserManagerCollaborationsCard({ userData }) { | ||
const queryClient = useQueryClient(); | ||
const collaborations = get(userData, ['collaborations'], []); | ||
const handleRequestError = useHandleRequestError(); | ||
|
||
const userGuid = userData?.guid; | ||
|
||
async function mutationFn({ userGuid: secondUserGuid }) { | ||
try { | ||
const result = await axios.request({ | ||
url: withApiPrefix('/collaborations/'), | ||
method: 'POST', | ||
data: { | ||
user_guid: userGuid, | ||
second_user_guid: secondUserGuid, | ||
}, | ||
}); | ||
return result; | ||
} catch (error) { | ||
return handleRequestError(error); | ||
} | ||
} | ||
|
||
const mutation = useMutation(mutationFn, { | ||
onSuccess: async () => | ||
queryClient.invalidateQueries(getUserQueryKey(userGuid)), | ||
}); | ||
|
||
return ( | ||
<Card> | ||
<CardContent> | ||
<UserManagerCollaborationEditTable | ||
inputData={collaborations} | ||
/> | ||
</CardContent> | ||
<CardActions> | ||
<AddCollaboratorButton | ||
userData={userData} | ||
mutation={mutation} | ||
/> | ||
</CardActions> | ||
</Card> | ||
); | ||
} |
Oops, something went wrong.