2022-10-15 17:08:01 +00:00
|
|
|
export function DynamicComponent<T extends Record<string, any>>(props: {
|
|
|
|
componentMap: T;
|
|
|
|
slug: string;
|
|
|
|
wrapperClassName?: string;
|
|
|
|
}) {
|
2022-05-11 04:58:10 +00:00
|
|
|
const { componentMap, slug, ...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 (
|
|
|
|
<div className={props.wrapperClassName || ""}>
|
|
|
|
<Component {...rest} />
|
|
|
|
</div>
|
|
|
|
);
|
2022-05-11 04:58:10 +00:00
|
|
|
}
|