mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import React from "react";
|
|
import { useLocation } from "@remix-run/react";
|
|
import { useResource } from "@refinedev/core";
|
|
|
|
type RefineRoutesProps = {
|
|
children?: (
|
|
renderedRoute: JSX.Element | undefined,
|
|
pathname: string | undefined,
|
|
) => JSX.Element;
|
|
};
|
|
|
|
export const RefineRoutes = ({ children }: RefineRoutesProps) => {
|
|
const { resource, action } = useResource();
|
|
const { pathname } = useLocation();
|
|
|
|
const resourceAction = resource && action ? resource[action] : undefined;
|
|
|
|
const ResourceActionComponent =
|
|
typeof resourceAction === "function"
|
|
? resourceAction
|
|
: typeof resourceAction === "object"
|
|
? resourceAction.component
|
|
: undefined;
|
|
|
|
return (
|
|
<>
|
|
{children ? (
|
|
children(
|
|
ResourceActionComponent ? (
|
|
<ResourceActionComponent />
|
|
) : undefined,
|
|
pathname ?? undefined,
|
|
)
|
|
) : ResourceActionComponent ? (
|
|
<ResourceActionComponent />
|
|
) : undefined}
|
|
</>
|
|
);
|
|
};
|