feat: display error snackbars for Object and Field creation/edition (#2708)
This commit is contained in:
@ -9,6 +9,7 @@ import { Section } from '@/ui/layout/section/components/Section';
|
|||||||
|
|
||||||
type SettingsObjectFieldFormSectionProps = {
|
type SettingsObjectFieldFormSectionProps = {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
disableNameEdition?: boolean;
|
||||||
name?: string;
|
name?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
iconKey?: string;
|
iconKey?: string;
|
||||||
@ -30,6 +31,7 @@ const StyledInputsContainer = styled.div`
|
|||||||
|
|
||||||
export const SettingsObjectFieldFormSection = ({
|
export const SettingsObjectFieldFormSection = ({
|
||||||
disabled,
|
disabled,
|
||||||
|
disableNameEdition,
|
||||||
name = '',
|
name = '',
|
||||||
description = '',
|
description = '',
|
||||||
iconKey = 'IconUsers',
|
iconKey = 'IconUsers',
|
||||||
@ -55,7 +57,7 @@ export const SettingsObjectFieldFormSection = ({
|
|||||||
onChange?.({ label: value });
|
onChange?.({ label: value });
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
disabled={disabled}
|
disabled={disabled || disableNameEdition}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
</StyledInputsContainer>
|
</StyledInputsContainer>
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import {
|
|||||||
import { SettingsObjectIconSection } from '@/settings/data-model/object-edit/SettingsObjectIconSection';
|
import { SettingsObjectIconSection } from '@/settings/data-model/object-edit/SettingsObjectIconSection';
|
||||||
import { IconSettings } from '@/ui/display/icon';
|
import { IconSettings } from '@/ui/display/icon';
|
||||||
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
||||||
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||||
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
||||||
import { Section } from '@/ui/layout/section/components/Section';
|
import { Section } from '@/ui/layout/section/components/Section';
|
||||||
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
||||||
@ -23,6 +24,7 @@ export const SettingsNewObject = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [selectedObjectType, setSelectedObjectType] =
|
const [selectedObjectType, setSelectedObjectType] =
|
||||||
useState<NewObjectType>('Standard');
|
useState<NewObjectType>('Standard');
|
||||||
|
const { enqueueSnackBar } = useSnackBar();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
activateObjectMetadataItem: activateObject,
|
activateObjectMetadataItem: activateObject,
|
||||||
@ -66,6 +68,7 @@ export const SettingsNewObject = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (selectedObjectType === 'Custom') {
|
if (selectedObjectType === 'Custom') {
|
||||||
|
try {
|
||||||
const createdObject = await createObject({
|
const createdObject = await createObject({
|
||||||
labelPlural: customFormValues.labelPlural,
|
labelPlural: customFormValues.labelPlural,
|
||||||
labelSingular: customFormValues.labelSingular,
|
labelSingular: customFormValues.labelSingular,
|
||||||
@ -80,6 +83,11 @@ export const SettingsNewObject = () => {
|
|||||||
)}`
|
)}`
|
||||||
: '/settings/objects',
|
: '/settings/objects',
|
||||||
);
|
);
|
||||||
|
} catch (error) {
|
||||||
|
enqueueSnackBar((error as Error).message, {
|
||||||
|
variant: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import { SettingsObjectIconSection } from '@/settings/data-model/object-edit/Set
|
|||||||
import { AppPath } from '@/types/AppPath';
|
import { AppPath } from '@/types/AppPath';
|
||||||
import { IconArchive, IconSettings } from '@/ui/display/icon';
|
import { IconArchive, IconSettings } from '@/ui/display/icon';
|
||||||
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
||||||
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||||
import { Button } from '@/ui/input/button/components/Button';
|
import { Button } from '@/ui/input/button/components/Button';
|
||||||
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
||||||
import { Section } from '@/ui/layout/section/components/Section';
|
import { Section } from '@/ui/layout/section/components/Section';
|
||||||
@ -18,6 +19,7 @@ import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
|||||||
|
|
||||||
export const SettingsObjectEdit = () => {
|
export const SettingsObjectEdit = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { enqueueSnackBar } = useSnackBar();
|
||||||
|
|
||||||
const { objectSlug = '' } = useParams();
|
const { objectSlug = '' } = useParams();
|
||||||
const {
|
const {
|
||||||
@ -73,9 +75,15 @@ export const SettingsObjectEdit = () => {
|
|||||||
...formValues,
|
...formValues,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
await editObjectMetadataItem(editedObjectMetadataItem);
|
await editObjectMetadataItem(editedObjectMetadataItem);
|
||||||
|
|
||||||
navigate(`/settings/objects/${getObjectSlug(editedObjectMetadataItem)}`);
|
navigate(`/settings/objects/${getObjectSlug(editedObjectMetadataItem)}`);
|
||||||
|
} catch (error) {
|
||||||
|
enqueueSnackBar((error as Error).message, {
|
||||||
|
variant: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDisable = async () => {
|
const handleDisable = async () => {
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import { useFieldMetadataForm } from '@/settings/data-model/hooks/useFieldMetada
|
|||||||
import { AppPath } from '@/types/AppPath';
|
import { AppPath } from '@/types/AppPath';
|
||||||
import { IconArchive, IconSettings } from '@/ui/display/icon';
|
import { IconArchive, IconSettings } from '@/ui/display/icon';
|
||||||
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
import { H2Title } from '@/ui/display/typography/components/H2Title';
|
||||||
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||||
import { Button } from '@/ui/input/button/components/Button';
|
import { Button } from '@/ui/input/button/components/Button';
|
||||||
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
||||||
import { Section } from '@/ui/layout/section/components/Section';
|
import { Section } from '@/ui/layout/section/components/Section';
|
||||||
@ -22,6 +23,7 @@ import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|||||||
|
|
||||||
export const SettingsObjectFieldEdit = () => {
|
export const SettingsObjectFieldEdit = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { enqueueSnackBar } = useSnackBar();
|
||||||
|
|
||||||
const { objectSlug = '', fieldSlug = '' } = useParams();
|
const { objectSlug = '', fieldSlug = '' } = useParams();
|
||||||
const { findActiveObjectMetadataItemBySlug } =
|
const { findActiveObjectMetadataItemBySlug } =
|
||||||
@ -93,6 +95,7 @@ export const SettingsObjectFieldEdit = () => {
|
|||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (!validatedFormValues) return;
|
if (!validatedFormValues) return;
|
||||||
|
|
||||||
|
try {
|
||||||
if (
|
if (
|
||||||
validatedFormValues.type === FieldMetadataType.Relation &&
|
validatedFormValues.type === FieldMetadataType.Relation &&
|
||||||
relationFieldMetadataItem?.id &&
|
relationFieldMetadataItem?.id &&
|
||||||
@ -115,6 +118,11 @@ export const SettingsObjectFieldEdit = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
navigate(`/settings/objects/${objectSlug}`);
|
navigate(`/settings/objects/${objectSlug}`);
|
||||||
|
} catch (error) {
|
||||||
|
enqueueSnackBar((error as Error).message, {
|
||||||
|
variant: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDisable = async () => {
|
const handleDisable = async () => {
|
||||||
@ -146,6 +154,7 @@ export const SettingsObjectFieldEdit = () => {
|
|||||||
</SettingsHeaderContainer>
|
</SettingsHeaderContainer>
|
||||||
<SettingsObjectFieldFormSection
|
<SettingsObjectFieldFormSection
|
||||||
disabled={!activeMetadataField.isCustom}
|
disabled={!activeMetadataField.isCustom}
|
||||||
|
disableNameEdition
|
||||||
name={formValues.label}
|
name={formValues.label}
|
||||||
description={formValues.description}
|
description={formValues.description}
|
||||||
iconKey={formValues.icon}
|
iconKey={formValues.icon}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import { SettingsObjectFieldTypeSelectSection } from '@/settings/data-model/comp
|
|||||||
import { useFieldMetadataForm } from '@/settings/data-model/hooks/useFieldMetadataForm';
|
import { useFieldMetadataForm } from '@/settings/data-model/hooks/useFieldMetadataForm';
|
||||||
import { AppPath } from '@/types/AppPath';
|
import { AppPath } from '@/types/AppPath';
|
||||||
import { IconSettings } from '@/ui/display/icon';
|
import { IconSettings } from '@/ui/display/icon';
|
||||||
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||||
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
||||||
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
||||||
import { View } from '@/views/types/View';
|
import { View } from '@/views/types/View';
|
||||||
@ -24,6 +25,7 @@ import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|||||||
export const SettingsObjectNewFieldStep2 = () => {
|
export const SettingsObjectNewFieldStep2 = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { objectSlug = '' } = useParams();
|
const { objectSlug = '' } = useParams();
|
||||||
|
const { enqueueSnackBar } = useSnackBar();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
findActiveObjectMetadataItemBySlug,
|
findActiveObjectMetadataItemBySlug,
|
||||||
@ -108,6 +110,7 @@ export const SettingsObjectNewFieldStep2 = () => {
|
|||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (!validatedFormValues) return;
|
if (!validatedFormValues) return;
|
||||||
|
|
||||||
|
try {
|
||||||
if (validatedFormValues.type === FieldMetadataType.Relation) {
|
if (validatedFormValues.type === FieldMetadataType.Relation) {
|
||||||
const createdRelation = await createOneRelationMetadata({
|
const createdRelation = await createOneRelationMetadata({
|
||||||
relationType: validatedFormValues.relation.type,
|
relationType: validatedFormValues.relation.type,
|
||||||
@ -165,6 +168,11 @@ export const SettingsObjectNewFieldStep2 = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
navigate(`/settings/objects/${objectSlug}`);
|
navigate(`/settings/objects/${objectSlug}`);
|
||||||
|
} catch (error) {
|
||||||
|
enqueueSnackBar((error as Error).message, {
|
||||||
|
variant: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user