Skip to content

CAS-174 - update my communities section after joining a community#108

Merged
dbslone merged 33 commits intomainfrom
cas-174
Jul 9, 2022
Merged

CAS-174 - update my communities section after joining a community#108
dbslone merged 33 commits intomainfrom
cas-174

Conversation

@germanurrus
Copy link
Copy Markdown
Contributor

@germanurrus germanurrus commented Jul 7, 2022

Depends on #97

  • Use mutations for adding and removing users from communities.
  • Updates home screen when user is added as member

@germanurrus germanurrus changed the title CAS-174: update my communities section after joining a community CAS-174 - update my communities section after joining a community Jul 7, 2022
</Router>
</NotificationModalProvider>
</Web3Provider>
{isLocalDevMode && <ReactQueryDevtools />}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables the react-query debugger:
Screen Shot 2022-07-07 at 17 34 57

@germanurrus germanurrus requested review from CJamesKeller, dbslone and jbluks and removed request for dbslone July 7, 2022 21:17

const createCommunityUser = useCallback(
async (communityId, user, injectedProvider) => {
const { mutateAsync: createCommunityUserMutation } = useMutation(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tu use mutateAsync as opposed to mutate because of the way the hook is used in the component. The component is expecting to get a result from the mutation like here: https://github.com/DapperCollectives/CAST/pull/108/files#diff-ba7b9f47b489056dd6b487fee2e4bf14d1d836b8f8de40956a83cd57e1e84b39R34

In the docs: https://react-query.tanstack.com/reference/useMutation retuning the mutate function seems the way to go, they we could use something like:

const { mutate, data, error, isLoading } = useSomeWrapperFunctionMutation(mutate, 
{
   onSuccess: () => {
        manage side effects here; general ones like some query invalidation adding data to loaded queries and so on
   }
});
   
then we can call
mutate(payload);

or if we have specific side effects:
mutate(payload, {
   onSuccess: (data, variables, context) => {
     // something we need to happen on the component that triggered the update
   },
   onError: (error, variables, context) => {
     // same here
   },
   onSettled: (data, error, variables, context) => {
     // same here
   },
 })

Comment on lines -27 to -29
// setting this to null and then to a valid address retriggers query to get memberState
setAddr(null);
setAddr(user.addr);
Copy link
Copy Markdown
Contributor Author

@germanurrus germanurrus Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially this was done to make useUserRoleOnCommunity to reload and update memberState.
But becase useUserRoleOnCommunity() uses inside useUserCommunities() that uses onSuccess here to invalidate the query and refetch from the API we don't need to re-trigger the query by reseting one of it's params

@germanurrus germanurrus marked this pull request as ready for review July 7, 2022 22:08
Copy link
Copy Markdown
Collaborator

@jbluks jbluks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

dbslone added 3 commits July 8, 2022 15:19
… cas-174

# Conflicts:
#	frontend/packages/client/src/App.js
#	frontend/packages/client/src/hooks/useUserCommunities.js
#	frontend/packages/client/src/pages/Home.js
@dbslone dbslone merged commit cf64097 into main Jul 9, 2022
@dbslone dbslone deleted the cas-174 branch July 9, 2022 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants