mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: Update ResetPassword.tsx to improve password confirmation validation
This commit is contained in:
@@ -68,11 +68,12 @@ const RegisterPage: () => JSX.Element = () => {
|
||||
placeholder: 'New Password',
|
||||
title: 'New Password',
|
||||
required: true,
|
||||
showEvenIfPermissionDoesNotExist: true,
|
||||
},
|
||||
{
|
||||
field: {
|
||||
password: true,
|
||||
},
|
||||
confirmPassword: true,
|
||||
} as any,
|
||||
validation: {
|
||||
minLength: 6,
|
||||
toMatchField: 'password',
|
||||
@@ -82,6 +83,7 @@ const RegisterPage: () => JSX.Element = () => {
|
||||
title: 'Confirm Password',
|
||||
overrideFieldKey: 'confirmPassword',
|
||||
required: true,
|
||||
showEvenIfPermissionDoesNotExist: true,
|
||||
},
|
||||
]}
|
||||
createOrUpdateApiUrl={apiUrl}
|
||||
|
||||
@@ -67,7 +67,7 @@ export default interface Field<TEntity> {
|
||||
validation?: {
|
||||
minLength?: number | undefined;
|
||||
maxLength?: number | undefined;
|
||||
toMatchField?: string | undefined;
|
||||
toMatchField?: keyof TEntity | undefined;
|
||||
noSpaces?: boolean | undefined;
|
||||
noSpecialCharacters?: boolean;
|
||||
noNumbers?: boolean | undefined;
|
||||
|
||||
@@ -134,7 +134,7 @@ export default class Validation {
|
||||
public static validateMatchField<T extends GenericObject>(
|
||||
content: string | undefined,
|
||||
field: Field<T>,
|
||||
entity: JSONObject
|
||||
entity: FormValues<T>
|
||||
): string | null {
|
||||
if (
|
||||
content &&
|
||||
@@ -144,7 +144,9 @@ export default class Validation {
|
||||
.toString()
|
||||
.trim() !== content.trim()
|
||||
) {
|
||||
return `${field.title} should match ${field.validation?.toMatchField}`;
|
||||
return `${field.title} should match ${
|
||||
field.validation?.toMatchField as string
|
||||
}`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -239,7 +241,7 @@ export default class Validation {
|
||||
currentFormStepId?: string | null | undefined;
|
||||
}): Dictionary<string> {
|
||||
const errors: JSONObject = {};
|
||||
const entries: JSONObject = { ...args.values } as JSONObject;
|
||||
const entries: FormValues<T> = { ...args.values };
|
||||
|
||||
for (const field of args.formFields) {
|
||||
if (
|
||||
@@ -256,7 +258,9 @@ export default class Validation {
|
||||
const name: string = field.name;
|
||||
|
||||
if (name in entries) {
|
||||
const content: string | undefined = entries[name]?.toString();
|
||||
const content: string | undefined = (entries as JSONObject)[
|
||||
name
|
||||
]?.toString();
|
||||
|
||||
// Check Required fields.
|
||||
const resultRequired: string | null = this.validateRequired(
|
||||
|
||||
@@ -2,6 +2,7 @@ import DashboardNavigation from '../../Utils/Navigation';
|
||||
import PageComponentProps from '../PageComponentProps';
|
||||
import FormFieldSchemaType from 'CommonUI/src/Components/Forms/Types/FormFieldSchemaType';
|
||||
import CardModelDetail from 'CommonUI/src/Components/ModelDetail/CardModelDetail';
|
||||
import Navigation from 'CommonUI/src/Utils/Navigation';
|
||||
import Project from 'Model/Models/Project';
|
||||
import React, { Fragment, FunctionComponent, ReactElement } from 'react';
|
||||
|
||||
@@ -32,6 +33,9 @@ const Settings: FunctionComponent<PageComponentProps> = (
|
||||
},
|
||||
},
|
||||
]}
|
||||
onSaveSuccess={() => {
|
||||
Navigation.reload();
|
||||
}}
|
||||
modelDetailProps={{
|
||||
modelType: Project,
|
||||
id: 'model-detail-project',
|
||||
|
||||
@@ -133,8 +133,8 @@ const ResetPassword: FunctionComponent<ComponentProps> = (
|
||||
},
|
||||
{
|
||||
field: {
|
||||
password: true,
|
||||
},
|
||||
confirmPassword: true,
|
||||
} as any,
|
||||
validation: {
|
||||
minLength: 6,
|
||||
toMatchField: 'password',
|
||||
|
||||
Reference in New Issue
Block a user