Skip to content

The open alternative to Salesforce, designed for AI.

Use the existing banner and field error components for validation rule messages (#27906)

Thomas Trompetted8a78342594d
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx
index 11924ec75c9..d8da696bd13 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx
@@ -8,6 +8,7 @@ import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
import { type ValidationRuleViolation } from '@/validation-rules/types/ValidationRuleViolation';
import { styled } from '@linaria/react';
import { type JsonValue } from 'type-fest';
+import { Field } from 'twenty-ui/primitives/input';
import { themeCssVariables } from 'twenty-ui/theme';
const StyledFieldList = styled.div`
@@ -16,12 +17,6 @@ const StyledFieldList = styled.div`
gap: ${themeCssVariables.spacing[3]};
`;
-const StyledFieldViolation = styled.div`
- color: ${themeCssVariables.font.color.danger};
- font-size: ${themeCssVariables.font.size.xs};
- margin-top: ${themeCssVariables.spacing[0.5]};
-`;
-
type RecordFormFieldInputsProps = {
objectMetadataItem: EnrichedObjectMetadataItem;
fieldMetadataItems: FieldMetadataItem[];
@@ -47,7 +42,7 @@ export const RecordFormFieldInputs = ({
const gqlFieldName = getFieldMetadataItemGqlFieldName(fieldMetadataItem);
return (
- <div key={fieldMetadataItem.id}>
+ <Field.Root key={fieldMetadataItem.id}>
<FormFieldInput
field={formatFieldMetadataItemAsFieldDefinition({
field: fieldMetadataItem,
@@ -63,11 +58,11 @@ export const RecordFormFieldInputs = ({
validationRuleViolationsByFieldMetadataId[fieldMetadataItem.id] ??
[]
).map((violation) => (
- <StyledFieldViolation key={violation.ruleId} role="alert">
+ <Field.Error key={violation.ruleId} match role="alert">
{violation.message}
- </StyledFieldViolation>
+ </Field.Error>
))}
- </div>
+ </Field.Root>
);
})}
</StyledFieldList>
diff --git a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx
index 96638662a0a..ff6f7497996 100644
--- a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx
+++ b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx
@@ -36,7 +36,7 @@ import { Key } from 'ts-key-enum';
import { type JsonValue } from 'type-fest';
import { PermissionFlagType } from 'twenty-shared/constants';
import { isDefined } from 'twenty-shared/utils';
-import { useToast } from 'twenty-ui/components/feedback';
+import { InlineBanner, useToast } from 'twenty-ui/components/feedback';
import { LightButton } from 'twenty-ui/components/input';
import { IconChevronDown, IconChevronUp, IconPlus } from 'twenty-ui/icon';
import { Button } from 'twenty-ui/primitives/input';
@@ -48,14 +48,6 @@ const StyledContainer = styled.div`
height: 100%;
`;
-const StyledValidationRuleError = styled.div`
- background: ${themeCssVariables.background.danger};
- border-radius: ${themeCssVariables.border.radius.sm};
- color: ${themeCssVariables.font.color.danger};
- font-size: ${themeCssVariables.font.size.sm};
- padding: ${themeCssVariables.spacing[2]} ${themeCssVariables.spacing[3]};
-`;
-
const StyledValidationRuleErrors = styled.div`
display: flex;
flex-direction: column;
@@ -351,9 +343,9 @@ const SidePanelRecordCreationForm = ({
{recordViolations.length > 0 && (
<StyledValidationRuleErrors>
{recordViolations.map((violation) => (
- <StyledValidationRuleError key={violation.ruleId} role="alert">
+ <InlineBanner key={violation.ruleId} status="error" role="alert">
{violation.message}
- </StyledValidationRuleError>
+ </InlineBanner>
))}
</StyledValidationRuleErrors>
)}
diff --git a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx
index e37deb8fe50..bca3194d443 100644
--- a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx
+++ b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx
@@ -13,6 +13,7 @@ import {
compileValidationRuleExpression,
isDefined,
} from 'twenty-shared/utils';
+import { Field } from 'twenty-ui/primitives/input';
import { Card } from 'twenty-ui/primitives/surfaces';
import { themeCssVariables } from 'twenty-ui/theme';
@@ -43,10 +44,9 @@ const StyledAskAiButtonContainer = styled.div`
top: ${themeCssVariables.spacing[1]};
`;
-const StyledEditorContent = styled.div`
+const StyledEditorContent = styled(Field.Root)`
display: flex;
flex-direction: column;
- gap: ${themeCssVariables.spacing[2]};
`;
const StyledEditor = styled.div<{ hasError: boolean }>`
@@ -109,11 +109,6 @@ const StyledEditor = styled.div<{ hasError: boolean }>`
}
`;
-const StyledError = styled.div`
- color: ${themeCssVariables.font.color.danger};
- font-size: ${themeCssVariables.font.size.sm};
-`;
-
type SettingsValidationRuleExpressionEditorProps = {
value: string;
fields: ValidationRuleFieldDescriptor[];
@@ -287,7 +282,9 @@ export const SettingsValidationRuleExpressionEditor = ({
</StyledAskAiButtonContainer>
</StyledEditor>
{isDefined(errorMessage) && (
- <StyledError role="alert">{errorMessage}</StyledError>
+ <Field.Error match role="alert">
+ {errorMessage}
+ </Field.Error>
)}
</StyledEditorContent>
</Card.Content>