fix: gracefully handle missing object metadata in useObjectNameSingularFromPlural
https://sonarly.com/issue/17092?type=bug When a user navigates to `/objects/quotes` (a custom object that doesn't exist in their workspace metadata), `useObjectNameSingularFromPlural` throws an unhandled error before the redirect to `/not-found` takes effect, causing a React render crash.
This commit is contained in:
+2
-9
@@ -1,12 +1,11 @@
|
||||
import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objectMetadataItemFamilySelector';
|
||||
import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const useObjectNameSingularFromPlural = ({
|
||||
objectNamePlural,
|
||||
}: {
|
||||
objectNamePlural: string;
|
||||
}) => {
|
||||
}): { objectNameSingular: string | undefined } => {
|
||||
const objectMetadataItem = useAtomFamilySelectorValue(
|
||||
objectMetadataItemFamilySelector,
|
||||
{
|
||||
@@ -15,11 +14,5 @@ export const useObjectNameSingularFromPlural = ({
|
||||
},
|
||||
);
|
||||
|
||||
if (!isDefined(objectMetadataItem)) {
|
||||
throw new Error(
|
||||
`Object metadata item not found for ${objectNamePlural} object`,
|
||||
);
|
||||
}
|
||||
|
||||
return { objectNameSingular: objectMetadataItem.nameSingular };
|
||||
return { objectNameSingular: objectMetadataItem?.nameSingular };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user