R
Refine

ask-any-question

Can we use different resources for detail and update?

Nnational-gold12/6/2022
I have a requirement where my resources details comes from /endpoint and I should update or patch to another api endpoint /s/endpoint. So, how can I use one endpoint to fetch the detail data and while submitting a form send to a different endpoint?
Uunwilling-turquoise12/6/2022
Hi @dipbazz, For example, if you wanna update categories resource from post resource, u can give resource name to any data provider's hook. you can use this https://refine.dev/docs/api-reference/core/hooks/data/useUpdate/ resource: "/s/endpoint" But if u need completly custom, you can use https://refine.dev/docs/api-reference/core/hooks/data/useCustomMutation/ but don't forget please, you should manually invalidate queries. For example: https://refine.dev/docs/faq/#how-can-i-change-the-form-data-before-submitting-it-to-the-api Instead of calling onFinish() from useForm() You can call useCustom 's mutation()
Nnational-gold12/6/2022
I have used useOne to get the detail and useForm with a different resource for a patch but now I have a problem with redirect. How can I redirect to a list page that has a different resource not same as useForm. What I have done is:
const { data } = useOne({
resource: 'posts',
id
})
const { data } = useOne({
resource: 'posts',
id
})
const { formProps, saveButtonProps, onFinish } = useForm<IPost>({
resource: 's/posts',
id,
queryOptions: {
enabled: false
},
onMutationSuccess: () => {
invalidate({
resource: 'posts',
invalidates: ['list']
})
invalidate({
resource: 'posts',
invalidates: ['detail'],
id
})
}
});
const { formProps, saveButtonProps, onFinish } = useForm<IPost>({
resource: 's/posts',
id,
queryOptions: {
enabled: false
},
onMutationSuccess: () => {
invalidate({
resource: 'posts',
invalidates: ['list']
})
invalidate({
resource: 'posts',
invalidates: ['detail'],
id
})
}
});
After submitting a form the page is redirected to s/posts but I have a list of posts in /posts so how to redirect to /posts page after successful mutation?
Uunwilling-turquoise12/6/2022
Unfortunately the redirect only goes to the resource used. You can change only view type. list | show | edit or you can disable with false you can give redirect:false to useForm(), after onMutationSuccess you can redirect programmaticly. https://refine.dev/docs/api-reference/core/hooks/navigation/useNavigation/

Looking for more? Join the community!

R
Refine

ask-any-question

Join Server
Recommended Posts
nested query in meta datametaData: { fields: [ "id", "org_unit_id", "created_at", { santd form.itemI have a form with 4 form items but i just want to post 3 items to table in hasura while submittingWhy warnWhenUnsavedChanges show when I shift to different tabs?I need help. I have a big form which compose of tabs to make it more user friendly. My issues: WhUncaught TypeError date.locale is not a functionI am using ant design `TimePicker` component on my form. While creating a form it doesn't have a proIs there a way to submit a Timepicker form value as a string?I am using ant design `TimePicker` component and when I submit the form the submitted data is an dayuse router v6 with search paramsHello 👋 i am trying to programmatically redirect to the create view of a resource and passing sooperators for crudFilters- contains v. containssIs there a difference between 'contains' v. 'containss'Using react-router-dom hooksI want to use react-router-dom hooks but I get: `useLocation() may be used only in the context of a duplicate value i dont want to posti am having a form and i posting name . so i dont i want to post duplicate name another time . it shCan I display a list of posts within a category?In this format: `categories/1/posts` I see only option: `categories/posts` https://refine.dev/docs/aHow are supabase tables supposed to be created?I did not find any explanation in the documentation who manages the database, or at least informatioHow to transform form data before passing it to data provider?I have an edit page that should only send changed fields to the server instead of the whole form dat