@@ -9,12 +9,17 @@ import { toast } from "sonner";
9
9
10
10
const backendUrl = import . meta. env . VITE_BACKEND_URL || 'http://localhost:5000' ;
11
11
12
+ interface Tag {
13
+ value : string ;
14
+ label : string ;
15
+ }
16
+
12
17
interface Project {
13
18
id ?: number ;
14
19
title : string ;
15
20
description : string ;
16
21
repoLink : string ;
17
- tags : string [ ] ;
22
+ tags : Tag [ ] ;
18
23
}
19
24
20
25
@@ -76,10 +81,15 @@ const EditProfileForm: React.FC<EditProfileFormProps> = ({ onProjectAdded }) =>
76
81
const handleProjectChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
77
82
const { name, value } = e . target ;
78
83
if ( selectedProject ) {
79
- setSelectedProject ( ( prevProject : Project ) => ( {
80
- ...prevProject ,
81
- [ name ] : value ,
82
- } ) ) ;
84
+ setSelectedProject ( ( prevProject : Project | null ) => {
85
+ if ( prevProject ) {
86
+ return {
87
+ ...prevProject ,
88
+ [ name ] : value ,
89
+ } ;
90
+ }
91
+ return null ; // or return a default Project object if you prefer
92
+ } ) ;
83
93
} else {
84
94
setNewProject ( ( prevProject : Project ) => ( {
85
95
...prevProject ,
@@ -110,15 +120,14 @@ const EditProfileForm: React.FC<EditProfileFormProps> = ({ onProjectAdded }) =>
110
120
const handleAddProject = async ( ) => {
111
121
try {
112
122
console . log ( "Tags:" , newProject . tags ) ;
113
- const tagsString = newProject . tags . map ( tag => tag . value ) . join ( "," ) ;
114
-
123
+ const tagsArray = newProject . tags . map ( tag => ( { value : tag , label : tag } ) ) ; // Convert Tag objects to strings
115
124
116
- console . log ( "Adding project:" , tagsString ) ;
125
+ console . log ( "Adding project:" , tagsArray ) ;
117
126
const response = await axios . post ( `${ backendUrl } /profile/${ username } /projects` , {
118
127
title : newProject . title ,
119
128
description : newProject . description ,
120
129
repo_link : newProject . repoLink ,
121
- tags : tagsString ,
130
+ tags : tagsArray , // Use the formatted tagsArray
122
131
} , { withCredentials : true } ) ;
123
132
if ( response . status === 200 )
124
133
// console.log("Project added successfully:", );
@@ -356,8 +365,8 @@ const EditProfileForm: React.FC<EditProfileFormProps> = ({ onProjectAdded }) =>
356
365
< div >
357
366
< Label > Project Tags</ Label >
358
367
< TagInput
359
- selectedTags = { newProject . tags }
360
- onTagsChange = { ( tags : string [ ] ) => setNewProject ( { ...newProject , tags } ) }
368
+ selectedTags = { newProject . tags } // This should be an array of Tag objects
369
+ onTagsChange = { ( tags : Tag [ ] ) => setNewProject ( { ...newProject , tags } ) } // Ensure tags are of type Tag[]
361
370
/>
362
371
363
372
</ div >
0 commit comments