Skip to content

Commit 00c0ff6

Browse files
author
puranban
committed
Fix project name validation
1 parent 037a19f commit 00c0ff6

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

firebase/functions/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,14 @@ exports.addProjectTopicKey = functions.https.onRequest(async (_, res) => {
355355
res.status(404).send('No projects found');
356356
}
357357

358-
if (!isEmptyProject && data) {
358+
if (data) {
359359
const newProjectData: {[key: string]: string} = {};
360360

361361
Object.keys(data).forEach((id) => {
362-
if (data[id]?.projectTopic) {
363-
const newProjectTopicKey = formatProjectTopic(data[id].projectTopic);
362+
const projectData = data[id];
363+
364+
if (projectData.name) {
365+
const newProjectTopicKey = formatProjectTopic(projectData.name);
364366
newProjectData[`v2/projects/${id}/projectTopicKey`] = newProjectTopicKey;
365367
}
366368
});

manager-dashboard/app/views/NewProject/BasicProjectInfoForm/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function BasicProjectInfoForm(props: Props<PartialProjectFormType>) {
126126
hint="We will generate you project name based on your inputs above."
127127
readOnly
128128
placeholder="[Project Topic] - [Project Region] ([Task Number]) [Requesting Organisation]"
129-
// error={error?.name}
129+
error={error?.name}
130130
disabled={disabled}
131131
/>
132132
<div className={styles.inputGroup}>

manager-dashboard/app/views/NewProject/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function NewProject(props: Props) {
275275
visibility,
276276
filter,
277277
filterText,
278-
projectTopic,
278+
name,
279279
...valuesToCopy
280280
} = finalValues;
281281

@@ -331,8 +331,7 @@ function NewProject(props: Props) {
331331
// NOTE: All the user don't have permission to access draft project
332332
// FIXME: The firebase rules need to be changed to perform this on draft project
333333
const database = getDatabase();
334-
const projectTopicKeyLowercase = (projectTopic?.trim())?.toLowerCase() as string;
335-
const projectTopicKey = formatProjectTopic(projectTopicKeyLowercase);
334+
const projectTopicKey = formatProjectTopic(name);
336335
const projectRef = databaseRef(database, 'v2/projects/');
337336

338337
const prevProjectNameQuery = query(
@@ -350,7 +349,7 @@ function NewProject(props: Props) {
350349
setError((prevErr) => ({
351350
...getErrorObject(prevErr),
352351
[nonFieldError]: 'A project with this name already exists, please use a different project name (Please note that the name comparison is not case sensitive)',
353-
projectTopic: 'A project with this name already exists',
352+
name: 'A project with this name already exists',
354353
}));
355354
setProjectSubmissionStatus(undefined);
356355
return;
@@ -369,7 +368,7 @@ function NewProject(props: Props) {
369368

370369
const uploadData = {
371370
...valuesToCopy,
372-
projectTopic,
371+
name,
373372
projectTopicKey,
374373
filter: finalFilter,
375374
image: downloadUrl,

0 commit comments

Comments
 (0)