genetic-orange
genetic-orange13mo ago

Custom create route

How can I add a custom post route for my Create page? Here is my current code:
<Create isLoading={formLoading} saveButtonProps={{ onClick: handleSubmit(onFinishHandler) }}>
<Box
component="form"
sx={{ display: "flex", flexDirection: "column" }}
autoComplete="off"
>
<Controller
<Create isLoading={formLoading} saveButtonProps={{ onClick: handleSubmit(onFinishHandler) }}>
<Box
component="form"
sx={{ display: "flex", flexDirection: "column" }}
autoComplete="off"
>
<Controller
11 Replies
kapa.ai
kapa.ai13mo ago
Hi @.chasel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To add a custom post route for your Create page, you can use the resource prop of the <Create> component. This prop allows you to specify a custom resource for the <Create> component. Here is how you can modify your code:
<Create resource="posts" isLoading={formLoading} saveButtonProps={{ onClick: handleSubmit(onFinishHandler) }}>
<Box
component="form"
sx={{ display: "flex", flexDirection: "column" }}
autoComplete="off"
>
<Controller
<Create resource="posts" isLoading={formLoading} saveButtonProps={{ onClick: handleSubmit(onFinishHandler) }}>
<Box
component="form"
sx={{ display: "flex", flexDirection: "column" }}
autoComplete="off"
>
<Controller
In this example, "posts" is the custom resource that will be used for the <Create> component. You should replace "posts" with the actual resource you want to use. Please note that the <Create> component reads the resource information from the route by default. If you don't specify a resource prop, it will use the resource information from the route. For more information, you can refer to the refine documentation (https://refine.dev/docs/api-reference/antd/components/basic-views/create). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai13mo ago
<@196423433930670080> kapa.ai is still learning and improving, please let us how it did by reacting below
genetic-orange
genetic-orange13mo ago
@kapa.ai specifying resource is not working. I want to post method to go to a specific route
kapa.ai
kapa.ai13mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- In refine, the resource prop in the <Create> component is used to determine the resource information from the route, not to specify a custom route for the POST method. If you want to customize the POST method route, you would need to handle it in your data provider. The data provider is responsible for making the actual API calls, including the POST request when creating a new record. Unfortunately, the provided extracts do not contain specific information on how to customize the POST route in the data provider. For more detailed instructions, you may want to refer to the refine's data provider documentation (https://refine.dev/docs/api-reference/providers/data-provider). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai13mo ago
<@196423433930670080> kapa.ai is still learning and improving, please let us how it did by reacting below
genetic-orange
genetic-orange13mo ago
@kapa.ai I need to custome my saveButtonProps. How can I sepcify the resource to post to in these props
kapa.ai
kapa.ai13mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The saveButtonProps property in the <Create> component is used to customize the save button, not to specify the resource for the POST request. Here is an example of how you can use saveButtonProps to customize the save button:
<Create saveButtonProps={{ size: "small" }}>
<span>Rest of your page here</span>
</Create>
<Create saveButtonProps={{ size: "small" }}>
<span>Rest of your page here</span>
</Create>
In this example, the size of the save button is set to "small". You can replace size: "small" with your own custom properties. If you want to specify a custom resource for the POST request, you would need to handle it in your data provider. The data provider is responsible for making the actual API calls, including the POST request when creating a new record. Unfortunately, the provided extracts do not contain specific information on how to customize the POST route in the data provider. For more detailed instructions, you may want to refer to the refine's data provider documentation (https://refine.dev/docs/api-reference/providers/data-provider). For more information on how to use saveButtonProps, you can refer to the refine documentation (https://refine.dev/docs/api-reference/mui/components/basic-views/create). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai13mo ago
<@196423433930670080> kapa.ai is still learning and improving, please let us how it did by reacting below
genetic-orange
genetic-orange13mo ago
@kapa.ai Then explain how I can customize what route the information is posted to. Where does Create in mui get the route to post information to
kapa.ai
kapa.ai13mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- In refine, the route for the POST request is determined by the data provider you're using. The <Create> component doesn't directly handle the API calls, it delegates this to the data provider. The data provider is a set of functions that define how to interact with your API. When you create a new record, the create method of the data provider is called. The resource prop in the <Create> component is passed to this create method to specify which resource the new record should be created for. If you want to customize the route for the POST request, you would need to customize the create method in your data provider. Unfortunately, the provided extracts do not contain specific information on how to do this. For more detailed instructions, you may want to refer to the refine's data provider documentation (https://refine.dev/docs/api-reference/providers/data-provider). This documentation provides examples of data providers and explains how to customize them. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai13mo ago
<@196423433930670080> kapa.ai is still learning and improving, please let us how it did by reacting below