From add0450b97d94e632d6d1768620706c5ae3c5148 Mon Sep 17 00:00:00 2001 From: royallsilwallz Date: Wed, 1 May 2024 10:26:56 +0545 Subject: [PATCH 1/2] Validate empty project name while creating project --- frontend/src/components/projectCreate/index.js | 4 ++++ frontend/src/components/projectCreate/messages.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/frontend/src/components/projectCreate/index.js b/frontend/src/components/projectCreate/index.js index d5cb5cb31c..7d50966494 100644 --- a/frontend/src/components/projectCreate/index.js +++ b/frontend/src/components/projectCreate/index.js @@ -191,6 +191,10 @@ const ProjectCreate = () => { const handleCreate = useCallback( (cloneProjectData) => { + if (!metadata.projectName.trim()) { + setErr({ error: true, message: intl.formatMessage(messages.noProjectName) }); + throw new Error('Missing project name.'); + } if (!metadata.geom) { setErr({ error: true, message: intl.formatMessage(messages.noGeometry) }); throw new Error('Missing geom.'); diff --git a/frontend/src/components/projectCreate/messages.js b/frontend/src/components/projectCreate/messages.js index 2b57df0e1d..d574727764 100644 --- a/frontend/src/components/projectCreate/messages.js +++ b/frontend/src/components/projectCreate/messages.js @@ -123,6 +123,10 @@ export default defineMessages({ id: 'management.projects.create.errors.closed_linestring', defaultMessage: 'Points do not form a closed linestring', }, + noProjectName: { + id: 'management.projects.create.errors.no_project_name', + defaultMessage: 'Name is a required field.', + }, noGeometry: { id: 'management.projects.create.errors.no_geometry', defaultMessage: "You need to define the project's area of interest.", From 4d338a81900f2a49e9860d729cdf962a3afc35d2 Mon Sep 17 00:00:00 2001 From: royallsilwallz Date: Wed, 1 May 2024 10:27:25 +0545 Subject: [PATCH 2/2] Validate symbols and number in first charater of project name --- frontend/src/components/projectCreate/index.js | 4 ++++ frontend/src/components/projectCreate/messages.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/frontend/src/components/projectCreate/index.js b/frontend/src/components/projectCreate/index.js index 7d50966494..066c66b914 100644 --- a/frontend/src/components/projectCreate/index.js +++ b/frontend/src/components/projectCreate/index.js @@ -195,6 +195,10 @@ const ProjectCreate = () => { setErr({ error: true, message: intl.formatMessage(messages.noProjectName) }); throw new Error('Missing project name.'); } + if (!/^[a-zA-Z]/.test(metadata.projectName)) { + setErr({ error: true, message: intl.formatMessage(messages.projectNameValidationError) }); + throw new Error('Project name validation error.'); + } if (!metadata.geom) { setErr({ error: true, message: intl.formatMessage(messages.noGeometry) }); throw new Error('Missing geom.'); diff --git a/frontend/src/components/projectCreate/messages.js b/frontend/src/components/projectCreate/messages.js index d574727764..5b82a8a31d 100644 --- a/frontend/src/components/projectCreate/messages.js +++ b/frontend/src/components/projectCreate/messages.js @@ -127,6 +127,10 @@ export default defineMessages({ id: 'management.projects.create.errors.no_project_name', defaultMessage: 'Name is a required field.', }, + projectNameValidationError: { + id: 'management.projects.create.errors.project_name_validation_error', + defaultMessage: 'Project name should start with an alphabet.', + }, noGeometry: { id: 'management.projects.create.errors.no_geometry', defaultMessage: "You need to define the project's area of interest.",