cal/packages/app-store/_components/DynamicComponent.tsx
GitStart-Cal.com 2dbc73c75b
chore: fix all Typescript warnings (#8618)
* [CAL-1517] fix all Typescript warnings

* solve conflicts

* Update stripeCheckoutSession.handler.ts

Parse is a guard, so even though the variable is unused the parse itself is needed.

* Update ToolbarPlugin.tsx

Don't change dependency tree

---------

Co-authored-by: gitstart-calcom <gitstart@users.noreply.github.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
2023-06-06 11:59:57 +00:00

21 lines
595 B
TypeScript

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function DynamicComponent<T extends Record<string, React.ComponentType<any>>>(props: {
componentMap: T;
slug: string;
wrapperClassName?: string;
}) {
const { componentMap, slug, wrapperClassName, ...rest } = props;
const dirName = slug === "stripe" ? "stripepayment" : slug;
// There can be apps with no matching component
if (!componentMap[slug]) return null;
const Component = componentMap[dirName];
return (
<div className={wrapperClassName || ""}>
<Component {...rest} />
</div>
);
}