66 * https://electronjs.org/docs/latest/tutorial/process-model
77 *
88 */
9- import " ./index.css" ;
10- import * as React from " react" ;
11- import { useState } from " react" ;
12- import { SpiffCommerceClient , WorkflowExperience } from " @spiffcommerce/core" ;
13- import { SpiffCommerce3DPreviewService } from " @spiffcommerce/preview" ;
9+ import ' ./index.css' ;
10+ import * as React from ' react' ;
11+ import { useState } from ' react' ;
12+ import { SpiffCommerceClient , WorkflowExperience } from ' @spiffcommerce/core' ;
13+ import { SpiffCommerce3DPreviewService } from ' @spiffcommerce/preview' ;
1414
15- console . log (
16- '👋 This message is being logged by "App.tsx"'
17- ) ;
15+ console . log ( '👋 This message is being logged by "App.tsx"' ) ;
1816
1917/**
2018 * This is the main wrapper component for the App editor.
2119 * See app in src/index.tsx for usage.
2220 */
2321const App : React . FunctionComponent < {
24- /**
25- * The workflow to be used.
26- */
27- workflowId : string ;
28- /**
29- * The integration product associated to the workflow being run.
30- */
31- integrationProductId : string ;
22+ /**
23+ * The workflow to be used.
24+ */
25+ workflowId : string ;
26+ /**
27+ * The integration product associated to the workflow being run.
28+ */
29+ integrationProductId : string ;
3230} > = ( { workflowId, integrationProductId } ) => {
33- const canvasRef = React . useRef < HTMLCanvasElement > ( null ) ;
34- const [ workflowExperience , setWorkflowExperience ] = useState <
35- WorkflowExperience | undefined
36- > ( undefined ) ;
31+ const canvasRef = React . useRef < HTMLCanvasElement > ( null ) ;
32+ const [ workflowExperience , setWorkflowExperience ] = useState < WorkflowExperience | undefined > ( undefined ) ;
3733
38- // This effect handles initialize of the workflow experience when the user first arrives at the page. Loading
39- // saved designs will be handled within App seperately.
40- React . useEffect ( ( ) => {
41- if ( ! canvasRef . current ) return ;
42- const init = async ( ) => {
43- const client = new SpiffCommerceClient ( { } ) ;
44- await client . initFromIntegrationProduct ( integrationProductId ) ;
45- const experience = await client . getWorkflowExperience (
46- workflowId ,
47- undefined ,
48- ( workflow ) => {
49- const canvas = document . createElement ( "canvas" ) ;
50- return new SpiffCommerce3DPreviewService (
51- canvas ,
52- workflow . globalPreviewConfig
53- ) ;
54- }
55- ) ;
56- experience
57- . getWorkflowManager ( )
58- . getPreviewService ( )
59- . registerView ( canvasRef . current ) ;
60- setWorkflowExperience ( experience ) ;
61- } ;
62- init ( ) . then ( ( ) => console . log ( "Workflow Experience Initialized" ) ) ;
63- // We only want this to run when the parameters passed in change. The workflow experience
64- // changing internally due to saved designs etc.. Should not trigger this.
65- // eslint-disable-next-line react-hooks/exhaustive-deps
66- } , [ canvasRef , integrationProductId , workflowId ] ) ;
34+ // This effect handles initialize of the workflow experience when the user first arrives at the page. Loading
35+ // saved designs will be handled within App seperately.
36+ React . useEffect ( ( ) => {
37+ if ( ! canvasRef . current ) return ;
38+ const init = async ( ) => {
39+ const client = new SpiffCommerceClient ( { } ) ;
40+ await client . initFromIntegrationProduct ( integrationProductId ) ;
41+ const experience = await client . getWorkflowExperience (
42+ undefined ,
43+ undefined ,
44+ ( workflow ) => {
45+ return new SpiffCommerce3DPreviewService ( workflow . globalPreviewConfig ) ;
46+ } ,
47+ {
48+ type : 'integration' ,
49+ integrationProductId : integrationProductId ,
50+ workflowId : workflowId ,
51+ } ,
52+ ) ;
53+ experience . getWorkflowManager ( ) . getPreviewService ( ) . registerView ( canvasRef . current ) ;
54+ setWorkflowExperience ( experience ) ;
55+ } ;
56+ init ( ) . then ( ( ) => console . log ( 'Workflow Experience Initialized' ) ) ;
57+ // We only want this to run when the parameters passed in change. The workflow experience
58+ // changing internally due to saved designs etc.. Should not trigger this.
59+ // eslint-disable-next-line react-hooks/exhaustive-deps
60+ } , [ canvasRef , integrationProductId , workflowId ] ) ;
6761
68- return (
69- < div
70- style = { {
71- width : " 100%" ,
72- height : " 100%" ,
73- overflow : " hidden" ,
74- } }
75- >
76- < canvas
77- id = "3D-preview-canvas"
78- ref = { canvasRef }
79- style = { { width : " 100%" , height : " 100%" , outline : " none" } }
80- width = "100%"
81- height = "100%"
82- />
83- </ div >
84- ) ;
62+ return (
63+ < div
64+ style = { {
65+ width : ' 100%' ,
66+ height : ' 100%' ,
67+ overflow : ' hidden' ,
68+ } }
69+ >
70+ < canvas
71+ id = "3D-preview-canvas"
72+ ref = { canvasRef }
73+ style = { { width : ' 100%' , height : ' 100%' , outline : ' none' } }
74+ width = "100%"
75+ height = "100%"
76+ />
77+ </ div >
78+ ) ;
8579} ;
8680
87- export default App ;
81+ export default App ;
0 commit comments