@@ -51,6 +51,7 @@ const ConfigScreen = () => {
51
51
const [ richTextFields , setRichTextFields ] = useState < RtfField [ ] > ( [ ] ) ;
52
52
const [ richTextFieldsLoaded , setRichTextFieldsLoaded ] = useState < boolean > ( false ) ;
53
53
const [ isLicensed , setIsLicensed ] = useState ( false ) ;
54
+ const [ isInstalled , setIsInstalled ] = useState ( false ) ;
54
55
55
56
const sdk = useSDK < ConfigAppSDK > ( ) ;
56
57
@@ -109,6 +110,30 @@ const ConfigScreen = () => {
109
110
setRichTextFieldsLoaded ( true ) ;
110
111
} ) ( ) ;
111
112
} , [ sdk ] ) ;
113
+ useEffect ( ( ) => {
114
+ let intervalId : any ;
115
+ ( async ( ) => {
116
+ // Initial check
117
+ const installed = await checkInstallationStatus ( ) ;
118
+ if ( installed ) {
119
+ return ;
120
+ }
121
+ // Polling
122
+ intervalId = setInterval ( async ( ) => {
123
+ if ( await checkInstallationStatus ( ) ) {
124
+ clearInterval ( intervalId ) ;
125
+ }
126
+ } , 2000 ) ;
127
+ } ) ( ) ;
128
+ return ( ) => {
129
+ clearInterval ( intervalId ) ;
130
+ } ;
131
+ } , [ sdk . app ] ) ;
132
+ async function checkInstallationStatus ( ) : Promise < boolean > {
133
+ const installed = await sdk . app . isInstalled ( ) ;
134
+ setIsInstalled ( installed ) ;
135
+ return installed ;
136
+ }
112
137
113
138
async function enableEditorForAllRichTextFields ( ) {
114
139
if ( ! isLicensed && richTextFields . length > 5 ) {
@@ -258,43 +283,49 @@ const ConfigScreen = () => {
258
283
const fieldsCard = (
259
284
< Card >
260
285
< Heading > Configure Rich Text Fields</ Heading >
261
- < p > Select which rich text fields should have Docs to Rich Text enabled</ p >
262
- < br />
263
-
264
- { ! richTextFieldsLoaded && (
265
- < div style = { { display : 'flex' , justifyContent : 'center' } } >
266
- < Spinner variant = "default" />
267
- </ div >
268
- ) }
269
- { richTextFieldsLoaded && (
270
- < div >
271
- < div
272
- style = { {
273
- display : 'flex' ,
274
- justifyContent : 'flex-end' ,
275
- marginBottom : '20px' ,
276
- } } >
277
- { isLicenseLimitReached ? (
278
- < Tooltip content = "Free plan limit reached. Disable another field or upgrade to remove limits" placement = "top" >
279
- < Button variant = "primary" size = "small" style = { { marginRight : '20px' } } isDisabled = { true } >
280
- Enable All
281
- </ Button >
282
- </ Tooltip >
283
- ) : (
284
- < Button
285
- variant = "primary"
286
- size = "small"
287
- style = { { marginRight : '20px' } }
288
- onClick = { async ( ) => {
289
- await enableEditorForAllRichTextFields ( ) ;
290
- } }
291
- isDisabled = { false } >
292
- Enable All
293
- </ Button >
294
- ) }
295
- </ div >
296
- { fieldsTable }
297
- </ div >
286
+ { ! isInstalled ? (
287
+ < p > Install to begin</ p >
288
+ ) : (
289
+ < >
290
+ < p > Select which rich text fields should have Docs to Rich Text enabled</ p >
291
+ < br />
292
+
293
+ { ! richTextFieldsLoaded && (
294
+ < div style = { { display : 'flex' , justifyContent : 'center' } } >
295
+ < Spinner variant = "default" />
296
+ </ div >
297
+ ) }
298
+ { richTextFieldsLoaded && (
299
+ < div >
300
+ < div
301
+ style = { {
302
+ display : 'flex' ,
303
+ justifyContent : 'flex-end' ,
304
+ marginBottom : '20px' ,
305
+ } } >
306
+ { isLicenseLimitReached ? (
307
+ < Tooltip content = "Free plan limit reached. Disable another field or upgrade to remove limits" placement = "top" >
308
+ < Button variant = "primary" size = "small" style = { { marginRight : '20px' } } isDisabled = { true } >
309
+ Enable All
310
+ </ Button >
311
+ </ Tooltip >
312
+ ) : (
313
+ < Button
314
+ variant = "primary"
315
+ size = "small"
316
+ style = { { marginRight : '20px' } }
317
+ onClick = { async ( ) => {
318
+ await enableEditorForAllRichTextFields ( ) ;
319
+ } }
320
+ isDisabled = { false } >
321
+ Enable All
322
+ </ Button >
323
+ ) }
324
+ </ div >
325
+ { fieldsTable }
326
+ </ div >
327
+ ) }
328
+ </ >
298
329
) }
299
330
</ Card >
300
331
) ;
0 commit comments