enable passing of free-form urls to apiUrl (#6012)

This commit is contained in:
Matthias Mair 2023-12-02 12:35:12 +01:00 committed by GitHub
parent fb42878c11
commit bbf4d2f206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -60,7 +60,7 @@ export interface ApiFormAction {
* @param onFormError : A callback function to call when the form is submitted with errors.
*/
export interface ApiFormProps {
url: ApiPaths;
url: ApiPaths | string;
pk?: number | string | undefined;
pathParams?: PathParams;
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';

View File

@ -19,7 +19,7 @@ import { generateUniqueId } from './uid';
* Construct an API url from the provided ApiFormProps object
*/
export function constructFormUrl(
url: ApiPaths,
url: ApiPaths | string,
pk?: string | number,
pathParams?: PathParams
): string {

View File

@ -196,11 +196,14 @@ export type PathParams = Record<string, string | number>;
* Construct an API URL with an endpoint and (optional) pk value
*/
export function apiUrl(
path: ApiPaths,
path: ApiPaths | string,
pk?: any,
pathParams?: PathParams
): string {
let _url = apiEndpoint(path);
let _url = path;
if (Object.values(ApiPaths).includes(path as ApiPaths)) {
_url = apiEndpoint(path as ApiPaths);
}
// If the URL does not start with a '/', add the API prefix
if (!_url.startsWith('/')) {