Compare commits

...

2 Commits

Author SHA1 Message Date
Nikhil Soni
cbb30cb60e fix: handle legacy alert type values on patch 2026-05-07 13:51:53 +05:30
Deepak Mardi
078b82e957 fix(frontend): simplify password matching logic (#11174)
Some checks are pending
build-staging / prepare (push) Waiting to run
build-staging / js-build (push) Blocked by required conditions
build-staging / go-build (push) Blocked by required conditions
build-staging / staging (push) Blocked by required conditions
Release Drafter / update_release_draft (push) Waiting to run
* fix(frontend): simplify password matching logic

* fix(frontend): address review comments on validation feedback

* refactor(signup): remove redundant password mismatch check
2026-05-06 21:51:08 +00:00
3 changed files with 26 additions and 54 deletions

View File

@@ -8,7 +8,7 @@ import afterLogin from 'AppRoutes/utils';
import AuthError from 'components/AuthError/AuthError';
import AuthPageContainer from 'components/AuthPageContainer';
import { useNotifications } from 'hooks/useNotifications';
import { ArrowRight, CircleAlert } from 'lucide-react';
import { ArrowRight } from 'lucide-react';
import APIError from 'types/api/error';
import tvUrl from '@/assets/svgs/tv.svg';
@@ -28,9 +28,8 @@ type FormValues = {
function SignUp(): JSX.Element {
const [loading, setLoading] = useState(false);
const [confirmPasswordTouched, setConfirmPasswordTouched] = useState(false);
const [confirmPasswordError, setConfirmPasswordError] =
useState<boolean>(false);
const [formError, setFormError] = useState<APIError | null>();
const { notifications } = useNotifications();
@@ -84,35 +83,10 @@ function SignUp(): JSX.Element {
})();
};
const handleValuesChange: (changedValues: Partial<FormValues>) => void = (
changedValues,
) => {
// Clear error if passwords match while typing (but don't set error until blur)
if ('password' in changedValues || 'confirmPassword' in changedValues) {
const { password, confirmPassword } = form.getFieldsValue();
const isPasswordMismatch =
Boolean(confirmPassword) && password !== confirmPassword;
if (password && confirmPassword && password === confirmPassword) {
setConfirmPasswordError(false);
}
}
};
const handlePasswordBlur = (): void => {
const { password, confirmPassword } = form.getFieldsValue();
// Only validate if confirm password has a value
if (confirmPassword) {
const isSamePassword = password === confirmPassword;
setConfirmPasswordError(!isSamePassword);
}
};
const handleConfirmPasswordBlur = (): void => {
const { password, confirmPassword } = form.getFieldsValue();
if (password && confirmPassword) {
const isSamePassword = password === confirmPassword;
setConfirmPasswordError(!isSamePassword);
}
};
const showPasswordMismatchError = confirmPasswordTouched && isPasswordMismatch;
const isValidForm = useMemo(
(): boolean =>
@@ -120,8 +94,8 @@ function SignUp(): JSX.Element {
Boolean(email?.trim()) &&
Boolean(password?.trim()) &&
Boolean(confirmPassword?.trim()) &&
!confirmPasswordError,
[loading, email, password, confirmPassword, confirmPasswordError],
password === confirmPassword,
[loading, email, password, confirmPassword],
);
return (
@@ -140,12 +114,7 @@ function SignUp(): JSX.Element {
</Typography.Paragraph>
</div>
<FormContainer
onFinish={handleSubmit}
onValuesChange={handleValuesChange}
form={form}
className="signup-form"
>
<FormContainer onFinish={handleSubmit} form={form} className="signup-form">
<div className="signup-form-container">
<div className="signup-form-fields">
<div className="signup-field-container">
@@ -175,7 +144,6 @@ function SignUp(): JSX.Element {
placeholder="Enter new password"
disabled={loading}
className="signup-antd-input"
onBlur={handlePasswordBlur}
/>
</FormContainer.Item>
</div>
@@ -185,6 +153,12 @@ function SignUp(): JSX.Element {
<FormContainer.Item
name="confirmPassword"
validateTrigger="onBlur"
validateStatus={showPasswordMismatchError ? 'error' : undefined}
help={
showPasswordMismatchError
? "Passwords don't match. Please try again."
: undefined
}
rules={[{ required: true, message: 'Please enter confirm password!' }]}
>
<AntdInput.Password
@@ -193,7 +167,7 @@ function SignUp(): JSX.Element {
placeholder="Confirm your new password"
disabled={loading}
className="signup-antd-input"
onBlur={handleConfirmPasswordBlur}
onBlur={() => setConfirmPasswordTouched(true)}
/>
</FormContainer.Item>
</div>
@@ -205,19 +179,7 @@ function SignUp(): JSX.Element {
your admin for an invite link
</Callout>
{confirmPasswordError && (
<Callout
type="error"
size="small"
showIcon
icon={<CircleAlert size={12} />}
className="signup-error-callout"
>
Passwords don&apos;t match. Please try again.
</Callout>
)}
{formError && !confirmPasswordError && <AuthError error={formError} />}
{formError && <AuthError error={formError} />}
<div className="signup-form-actions">
<Button

View File

@@ -952,6 +952,7 @@ func (m *Manager) PatchRule(ctx context.Context, ruleStr string, id valuer.UUID)
m.logger.ErrorContext(ctx, "failed to unmarshal rule from db", slog.String("rule.id", id.StringValue()), errors.Attr(err))
return nil, err
}
storedRule.NormalizeAlertType()
if err := json.Unmarshal([]byte(ruleStr), &storedRule); err != nil {
m.logger.ErrorContext(ctx, "failed to unmarshal patched rule with given id", slog.String("rule.id", id.StringValue()), errors.Attr(err))

View File

@@ -36,6 +36,15 @@ func (AlertType) Enum() []any {
}
}
// NormalizeAlertType corrects known legacy alert type values that were stored
// before strict validation was introduced. The corrected value is persisted on
// the next write, so the DB self-heals without a migration.
func (r *PostableRule) NormalizeAlertType() {
if r.AlertType == "LOG_BASED_ALERT" {
r.AlertType = AlertTypeLogs
}
}
const (
DefaultSchemaVersion = "v1"
SchemaVersionV2Alpha1 = "v2alpha1"