Feat/error boundaries (#2779)
* - Changed to objectNameSingular always defined - Added ErrorCatchAll * - Added mock mode for companies logged out - Added a proper ErrorBoundary component * Removed react-error-boundary * Implemented proper ErrorBoundary * Fixes * Change strategy about mocks --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
co-authored by
Charles Bochet
parent
a301f451f9
commit
74b077f3ca
@@ -31,7 +31,7 @@ export const useFieldPreview = ({
|
||||
|
||||
const { value: firstRecordFieldValue } = useFieldPreviewValue({
|
||||
fieldName: fieldName || '',
|
||||
objectNamePlural: objectMetadataItem?.namePlural || '',
|
||||
objectNamePlural: objectMetadataItem?.namePlural ?? '',
|
||||
skip:
|
||||
!fieldName ||
|
||||
!objectMetadataItem ||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural';
|
||||
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
||||
import { assertNotNull } from '~/utils/assert';
|
||||
|
||||
@@ -10,8 +11,12 @@ export const useFieldPreviewValue = ({
|
||||
objectNamePlural: string;
|
||||
skip?: boolean;
|
||||
}) => {
|
||||
const { records } = useFindManyRecords({
|
||||
const { objectNameSingular } = useObjectNameSingularFromPlural({
|
||||
objectNamePlural,
|
||||
});
|
||||
|
||||
const { records } = useFindManyRecords({
|
||||
objectNameSingular,
|
||||
skip,
|
||||
});
|
||||
|
||||
|
||||
@@ -10,12 +10,13 @@ export const useRelationFieldPreviewValue = ({
|
||||
}) => {
|
||||
const { findObjectMetadataItemById } = useObjectMetadataItemForSettings();
|
||||
|
||||
// TODO: make this impossible to be undefined
|
||||
const relationObjectMetadataItem = relationObjectMetadataId
|
||||
? findObjectMetadataItemById(relationObjectMetadataId)
|
||||
: undefined;
|
||||
|
||||
const { records: relationObjects } = useFindManyRecords({
|
||||
objectNamePlural: relationObjectMetadataItem?.namePlural,
|
||||
objectNameSingular: relationObjectMetadataItem?.nameSingular ?? '',
|
||||
skip: skip || !relationObjectMetadataItem,
|
||||
});
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ export const SettingsObjectItemTableRow = ({
|
||||
const theme = useTheme();
|
||||
|
||||
const { records } = useFindManyRecords({
|
||||
objectNamePlural: objectItem.namePlural,
|
||||
objectNameSingular: objectItem.nameSingular,
|
||||
});
|
||||
|
||||
const { Icon } = useLazyLoadIcon(objectItem.icon ?? '');
|
||||
|
||||
@@ -40,7 +40,7 @@ export const NameFields = ({
|
||||
currentWorkspaceMember?.name?.lastName ?? '',
|
||||
);
|
||||
|
||||
const { updateOneRecord, objectMetadataItemNotFound } = useUpdateOneRecord({
|
||||
const { updateOneRecord } = useUpdateOneRecord({
|
||||
objectNameSingular: 'workspaceMember',
|
||||
});
|
||||
|
||||
@@ -58,9 +58,6 @@ export const NameFields = ({
|
||||
}
|
||||
|
||||
if (autoSave) {
|
||||
if (!updateOneRecord || objectMetadataItemNotFound) {
|
||||
throw new Error('Object not found in metadata');
|
||||
}
|
||||
await updateOneRecord({
|
||||
idToUpdate: currentWorkspaceMember?.id,
|
||||
input: {
|
||||
|
||||
@@ -19,7 +19,7 @@ export const ProfilePictureUploader = () => {
|
||||
useState<AbortController | null>(null);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
|
||||
const { updateOneRecord, objectMetadataItemNotFound } = useUpdateOneRecord({
|
||||
const { updateOneRecord } = useUpdateOneRecord({
|
||||
objectNameSingular: 'workspaceMember',
|
||||
});
|
||||
|
||||
@@ -54,9 +54,7 @@ export const ProfilePictureUploader = () => {
|
||||
if (!avatarUrl) {
|
||||
throw new Error('Avatar URL not found');
|
||||
}
|
||||
if (!updateOneRecord || objectMetadataItemNotFound) {
|
||||
throw new Error('Object not found in metadata');
|
||||
}
|
||||
|
||||
await updateOneRecord({
|
||||
idToUpdate: currentWorkspaceMember?.id,
|
||||
input: {
|
||||
@@ -80,12 +78,10 @@ export const ProfilePictureUploader = () => {
|
||||
};
|
||||
|
||||
const handleRemove = async () => {
|
||||
if (!updateOneRecord || objectMetadataItemNotFound) {
|
||||
throw new Error('Object not found in metadata');
|
||||
}
|
||||
if (!currentWorkspaceMember?.id) {
|
||||
throw new Error('User is not logged in');
|
||||
}
|
||||
|
||||
await updateOneRecord({
|
||||
idToUpdate: currentWorkspaceMember?.id,
|
||||
input: {
|
||||
|
||||
Reference in New Issue
Block a user