2023-06-06 11:59:57 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
export function DynamicComponent<T extends Record<string, React.ComponentType<any>>>(props: {
|
2022-10-15 17:08:01 +00:00
|
|
|
componentMap: T;
|
|
|
|
slug: string;
|
|
|
|
wrapperClassName?: string;
|
|
|
|
}) {
|
2023-06-06 11:59:57 +00:00
|
|
|
const { componentMap, slug, wrapperClassName, ...rest } = props;
|
2023-01-18 22:30:25 +00:00
|
|
|
const dirName = slug === "stripe" ? "stripepayment" : slug;
|
2022-05-11 04:58:10 +00:00
|
|
|
|
2023-01-18 22:30:25 +00:00
|
|
|
// There can be apps with no matching component
|
2022-05-11 04:58:10 +00:00
|
|
|
if (!componentMap[slug]) return null;
|
|
|
|
|
2023-01-18 22:30:25 +00:00
|
|
|
const Component = componentMap[dirName];
|
2022-05-11 04:58:10 +00:00
|
|
|
|
2022-10-15 17:08:01 +00:00
|
|
|
return (
|
2023-06-06 11:59:57 +00:00
|
|
|
<div className={wrapperClassName || ""}>
|
2022-10-15 17:08:01 +00:00
|
|
|
<Component {...rest} />
|
|
|
|
</div>
|
|
|
|
);
|
2022-05-11 04:58:10 +00:00
|
|
|
}
|