0

I have show page and this page should load data from it's resource but this page shouldn't update this resource. Instead of updating current resource's item this page should make different mutation. So for example i have users resource and i have mywebsite.com/users/uniq-user-id/show page. I can see user on this page. But when i press button - request shouldn't go to user's resource and shouldn't mutate users resource. Instead of it this mutation should go to (musics for example) and execute mutation there. I can use useMutation hook but i'm not sure that using this hook and putting it onPress to button - is the best solution. Does react-admin have already created components for this specific case?

Link
  • 669
  • 7
  • 20

1 Answers1

1

I think react-admin doesn't have such custom components, and agree about useMutation.

You can intercept dataProvider requests by proxing it, and re-routing users mutation:

v2

import { UPDATE, UPDATE_MANY } from 'react-admin'

const routerDataProvider = dataProvider => (verb, resource, params) => {
    if ((verb === UPDATE || verb === UPDATE_MANY) && resource === 'users') {
        resource === 'music'
        //transform params to match music resource expected format 
    }
    return dataProvider(verb, resource, params)
}

v3

const routerDataProvider = dataProvider => ({
    ...dataProvider,
    update: (resource, params) => 
        dataProvider(resource === 'users' ? 'music' : resource, params),
    updateMany: (resource, params) =>
        dataProvider(resource === 'users' ? 'music' : resource, params),
})
gstvg
  • 889
  • 4
  • 10
  • Thank you for helping! The solution which was made is to create page with react-final-form and manually gather data. – Link May 07 '20 at 20:43