@@ -17,6 +17,7 @@ export class DecisionFormComponent implements OnInit {
1717 isEditMode = false ;
1818 decisionId : string | null = null ;
1919 isLoading = false ;
20+ workspaceId : string | null = null ;
2021
2122 constructor (
2223 private fb : FormBuilder ,
@@ -32,13 +33,7 @@ export class DecisionFormComponent implements OnInit {
3233 }
3334
3435 ngOnInit ( ) : void {
35- // Get workspaceId from parent
36- this . route . parent ?. paramMap . subscribe ( params => {
37- const workspaceId = params . get ( 'id' ) ;
38- if ( workspaceId ) {
39- this . decisionForm . patchValue ( { workspaceId } ) ;
40- }
41- } ) ;
36+ this . workspaceId = this . getWorkspaceIdFromRoute ( ) ;
4237
4338 // Get decisionId from current route
4439 this . route . paramMap . subscribe ( params => {
@@ -78,11 +73,23 @@ export class DecisionFormComponent implements OnInit {
7873 this . router . navigate ( [ '../../' ] , { relativeTo : this . route } ) ;
7974 } ) ;
8075 } else {
81- // Include workspaceId from parent route if available
82- const workspaceId = this . route . parent ?. snapshot . paramMap . get ( 'id' ) ;
83- this . decisionService . createDecision ( { ...formValue , workspaceId } ) . subscribe ( ( ) => {
76+ if ( ! this . workspaceId ) {
77+ return ;
78+ }
79+
80+ this . decisionService . createDecision ( { ...formValue , workspaceId : this . workspaceId } ) . subscribe ( ( ) => {
8481 this . router . navigate ( [ '../' ] , { relativeTo : this . route } ) ;
8582 } ) ;
8683 }
8784 }
85+
86+ private getWorkspaceIdFromRoute ( ) : string | null {
87+ for ( const route of this . route . pathFromRoot ) {
88+ const id = route . snapshot . paramMap . get ( 'id' ) ;
89+ if ( id ) {
90+ return id ;
91+ }
92+ }
93+ return null ;
94+ }
8895}
0 commit comments