Skip to content

Commit

Permalink
Validate symbols and number in first charater of project name during …
Browse files Browse the repository at this point in the history
…edit
  • Loading branch information
royallsilwallz committed May 7, 2024
1 parent 532d84a commit ec2a3fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions frontend/src/components/projectEdit/messages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { defineMessages } from 'react-intl';

import projectCreateMessages from '../projectCreate/messages';

/**
* Internationalized messages for use on project edit.
*/
Expand Down Expand Up @@ -439,6 +441,7 @@ export default defineMessages({
id: 'projects.formInputs.name',
defaultMessage: 'Name of the project',
},
projectNameValidationError: { ...projectCreateMessages.projectNameValidationError },
dueDate: {
id: 'projects.formInputs.dueDate',
defaultMessage: 'Due date',
Expand Down
20 changes: 19 additions & 1 deletion frontend/src/views/projectEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,17 @@ export function ProjectEdit() {
) {
missingFields.push({ type: 'noTeamsAssigned' });
}

// validate name
if (!missingFields?.[0]?.fields?.includes('name')) {
const projectName = defaultLocaleInfo.name;
if (!/^[a-zA-Z]/.test(projectName)) {
missingFields.push({
locale: projectInfo.defaultLocale,
fields: ['projectNameValidationError'],
type: 'nameValidationError',
});
}
}
if (missingFields.length > 0) {
setError(missingFields);
return new Promise((resolve, reject) => reject());
Expand Down Expand Up @@ -351,6 +361,14 @@ const ErrorTitle = ({ locale, numberOfMissingFields, type, projectInfo }) => {
/>
);
}
if (type === 'nameValidationError') {
return (
<FormattedMessage
id="management.projects.create.errors.project_name_validation_error"
defaultMessage="Project Name Validation Error"
/>
);
}
if (locale === null) {
return (
<FormattedMessage {...messages.missingFields} values={{ number: numberOfMissingFields }} />
Expand Down

0 comments on commit ec2a3fc

Please sign in to comment.