Files
sentinel/static/app/utils/withOrganization.tsx
2024-02-15 17:01:50 +00:00

31 lines
842 B
TypeScript

import type {Organization} from 'sentry/types';
import getDisplayName from 'sentry/utils/getDisplayName';
import useOrganization from './useOrganization';
type InjectedOrganizationProps = {
organization?: Organization;
organizationAllowNull?: undefined | true;
};
function withOrganization<P extends InjectedOrganizationProps>(
WrappedComponent: React.ComponentType<P>
) {
type Props = Omit<P, keyof InjectedOrganizationProps> &
Partial<InjectedOrganizationProps>;
function Wrapper(props: Props) {
const organization = useOrganization({allowNull: props.organizationAllowNull});
const allProps = {organization, ...props} as P;
return <WrappedComponent {...allProps} />;
}
Wrapper.displayName = `withOrganization(${getDisplayName(WrappedComponent)})`;
return Wrapper;
}
export default withOrganization;