@@ -5,35 +5,69 @@ import * as React from "react";
5
5
import { CCAModalContent } from "./CCAWizardContent" ;
6
6
import { CCAWizardSteps } from "./CCAWizardSteps" ;
7
7
import { useCCAWizardFooter } from "./CCAWizardUtils" ;
8
- import { useAppDispatch } from "./wizard-store/hooks" ;
9
- import { resetCCAWizard , setPid } from "./wizard-store/reducers/cCAWizardSlice" ;
8
+ import { useAppDispatch , useAppSelector } from "./wizard-store/hooks" ;
9
+ import {
10
+ resetCCAWizard ,
11
+ selectMid ,
12
+ selectPid ,
13
+ setMid ,
14
+ setPid ,
15
+ } from "./wizard-store/reducers/cCAWizardSlice" ;
16
+ import client from "js/slycat-web-client" ;
10
17
11
18
interface CCAWizardParams {
12
19
pid : string ;
20
+ marking ?: string ;
13
21
}
14
22
15
23
export const CCAWizard = ( params : CCAWizardParams ) => {
16
- const { pid } = params ;
24
+ const { pid, marking } = params ;
25
+ const [ modalOpen , setModalOpen ] = React . useState ( true ) ;
17
26
const cCAWizardFooter = useCCAWizardFooter ( ) ;
18
27
const dispatch = useAppDispatch ( ) ;
28
+ const statePid = useAppSelector ( selectPid ) ;
29
+ const stateMid = useAppSelector ( selectMid ) ;
19
30
20
31
React . useEffect ( ( ) => {
21
- dispatch ( setPid ( pid ) ) ;
22
- } , [ dispatch , pid ] )
23
-
32
+ console . log ( "statePid, pid, selectMid" , statePid , pid , stateMid ) ;
33
+ if ( modalOpen ) {
34
+ if ( ! statePid ) {
35
+ dispatch ( setPid ( pid ) ) ;
36
+ }
37
+ if ( ! stateMid && statePid ) {
38
+ // create the model on open so we have something to reference later
39
+ client
40
+ . post_project_models_fetch ( {
41
+ pid : statePid ,
42
+ type : "cca" ,
43
+ name : "" ,
44
+ description : "" ,
45
+ marking : marking ?? "" ,
46
+ } )
47
+ . then ( ( result ) => {
48
+ dispatch ( setMid ( result . id ) ) ;
49
+ } ) ;
50
+ }
51
+ }
52
+ } , [ dispatch , pid , statePid , stateMid ] ) ;
53
+
24
54
return (
25
55
< CCAModalContent
26
56
key = { "slycat-wizard" }
27
57
// slycat-wizard is the standard wizard id from knockout
28
58
modalId = { "slycat-wizard" }
29
- closingCallBack = { ( ) => {
30
- console . log ( "clean and delete model" ) ;
59
+ closingCallBack = { React . useCallback ( ( ) => {
60
+ setModalOpen ( false ) ;
61
+ if ( stateMid ) {
62
+ console . log ( "delete" ) ;
63
+ client . delete_model_fetch ( { mid : stateMid } ) ;
64
+ }
31
65
dispatch ( resetCCAWizard ( ) ) ;
32
- } }
66
+ } , [ stateMid ] ) }
33
67
title = { "New CCA Model" }
34
68
footer = { cCAWizardFooter }
35
69
>
36
70
< CCAWizardSteps key = { "CCA Steps" } />
37
71
</ CCAModalContent >
38
72
) ;
39
- } ;
73
+ } ;
0 commit comments