@@ -112,12 +112,15 @@ function AddNewTitleModal({
112112
113113 // live teamCode validity (using QSTTeamCodes list)
114114 useEffect ( ( ) => {
115+ const codeValue = ( titleData . teamCode || '' ) . trim ( ) ;
116+
115117 setIsValidTeamCode (
116- titleData . teamCode === '' ||
118+ codeValue === '' ||
117119 ( Array . isArray ( QSTTeamCodes ) &&
118- QSTTeamCodes . some ( code => code ?. value === titleData . teamCode ) )
120+ QSTTeamCodes . some ( code => code ?. value === codeValue ) )
119121 ) ;
120122 } , [ titleData . teamCode , QSTTeamCodes ] ) ;
123+
121124
122125 // ----------------- canonical lists for validation ------------------------
123126
@@ -161,7 +164,10 @@ function AddNewTitleModal({
161164
162165 const selectTeamCode = teamCode => {
163166 onSelectTeamCode ( teamCode ) ;
164- setTitleData ( prev => ( { ...prev , teamCode } ) ) ;
167+ setTitleData ( prev => ( {
168+ ...prev ,
169+ teamCode : teamCode || '' ,
170+ } ) ) ;
165171 } ;
166172
167173 const cleanProjectAssign = ( ) => {
@@ -238,29 +244,32 @@ function AddNewTitleModal({
238244 // ------------------- submit ----------------------------------------------
239245
240246 const confirmOnClick = ( ) => {
241- // validate team name (no-op if empty/optional)
242247 if ( ! onTeamNameValidation ( titleData . teamAssiged ) ) return ;
243-
244- // normalize team and build payload
248+
245249 const safeTeams = allTeamsArray ;
246250 const team = normalizeTeam ( titleData . teamAssiged , safeTeams ) ;
251+
252+ // normalize teamCode to a pure string
253+ const teamCodeValue = ( titleData . teamCode || '' ) . trim ( ) ;
247254
248255 const payload = {
249256 id : titleData . id ,
250257 titleName : titleData . titleName ?. trim ( ) || '' ,
251258 titleCode : titleData . titleCode ?. trim ( ) || '' ,
252259 mediaFolder : titleData . mediaFolder ?. trim ( ) || '' ,
253- teamCode : titleData . teamCode ?. trim ( ) || '' ,
260+ teamCode : teamCodeValue , // now a non-empty string
254261 projectAssigned : titleData . projectAssigned || '' ,
255262 } ;
256-
263+
257264 if ( team && team . _id ) {
258- payload . teamAssiged = team ; // {_id, teamName}
259- payload . teamName = team . teamName ; // some endpoints check this flat prop
265+ payload . teamAssiged = team ;
266+ payload . teamName = team . teamName ;
260267 }
261-
268+
262269 const run = editMode ? editTitle : addTitle ;
263-
270+
271+ console . log ( 'Title update payload:' , payload ) ; // <--- use this once to inspect
272+
264273 run ( payload )
265274 . then ( resp => {
266275 if ( resp . status !== 200 ) {
@@ -273,12 +282,12 @@ function AddNewTitleModal({
273282 }
274283 } )
275284 . catch ( e => {
276- // eslint-disable-next-line no-console
277285 console . log ( e ) ;
278286 setWarningMessage ( { title : 'Error' , content : 'Unexpected error' } ) ;
279287 setShowMessage ( true ) ;
280288 } ) ;
281289 } ;
290+
282291
283292 // ------------------- render ----------------------------------------------
284293
0 commit comments