5c1c998b97
Render front components in a widget. https://github.com/user-attachments/assets/1ae130a4-070d-498e-88f7-80cee847e2fa --------- Co-authored-by: Charles Bochet <charles@twenty.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { useState } from 'react';
|
|
|
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
|
import { t } from '@lingui/core/macro';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { getMockFrontComponentUrl } from '@/front-components/utils/mockFrontComponent';
|
|
import { FrontComponentRenderer as SharedFrontComponentRenderer } from 'twenty-shared/front-component';
|
|
|
|
type FrontComponentRendererProps = {
|
|
frontComponentId: string;
|
|
};
|
|
|
|
export const FrontComponentRenderer = ({
|
|
frontComponentId: _frontComponentId,
|
|
}: FrontComponentRendererProps) => {
|
|
const [hasError, setHasError] = useState(false);
|
|
|
|
const { enqueueErrorSnackBar } = useSnackBar();
|
|
|
|
const handleError = (error?: Error) => {
|
|
if (isDefined(error)) {
|
|
const errorMessage = error.message;
|
|
|
|
enqueueErrorSnackBar({
|
|
message: t`Failed to load front component: ${errorMessage}`,
|
|
});
|
|
}
|
|
setHasError(true);
|
|
};
|
|
|
|
if (hasError) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<SharedFrontComponentRenderer
|
|
componentUrl={getMockFrontComponentUrl()}
|
|
onError={handleError}
|
|
/>
|
|
);
|
|
};
|