1
1
/* eslint-disable react-hooks/rules-of-hooks */
2
2
import { defaultProps , insertOrUpdateBlock } from '@blocknote/core' ;
3
3
import { BlockTypeSelectItem , createReactBlockSpec } from '@blocknote/react' ;
4
+ import { Button , Input , Modal , ModalSize } from '@openfun/cunningham-react' ;
4
5
import { TFunction } from 'i18next' ;
5
- import { set } from 'lodash' ;
6
6
import React , { useEffect , useState } from 'react' ;
7
+ import { useTranslation } from 'react-i18next' ;
7
8
8
- import { Box , Icon } from '@/components' ;
9
+ import { Box , Icon , Text } from '@/components' ;
9
10
10
11
import { DocsBlockNoteEditor } from '../../types' ;
11
12
@@ -26,10 +27,21 @@ export const DatabaseBlock = createReactBlockSpec(
26
27
const getGristApiKey = ( ) : string | null => {
27
28
return localStorage . getItem ( 'grist_api_key' ) ;
28
29
} ;
30
+ const validateGristApiKey = ( ) : void => {
31
+ if ( gristApiKeyModal !== null ) {
32
+ localStorage . setItem ( 'grist_api_key' , gristApiKeyModal ) ;
33
+ }
34
+ setOpenGristApiKeyModal ( false ) ;
35
+ } ;
36
+
37
+ const { t : translation } = useTranslation ( ) ;
29
38
30
39
const [ gristApiKeyModal , setGristApiKey ] = useState < string | null > (
31
40
getGristApiKey ,
32
41
) ;
42
+ const [ openGristApiKeyModal , setOpenGristApiKeyModal ] = useState < boolean > (
43
+ gristApiKeyModal === null ,
44
+ ) ;
33
45
34
46
useEffect ( ( ) => {
35
47
if (
@@ -50,7 +62,44 @@ export const DatabaseBlock = createReactBlockSpec(
50
62
} }
51
63
>
52
64
< Box as = "p" > 🏗️ Database block is in development</ Box >
53
- { gristApiKeyModal === null && < p > modal open</ p > }
65
+ { openGristApiKeyModal && (
66
+ < Modal
67
+ isOpen = { openGristApiKeyModal }
68
+ closeOnClickOutside
69
+ data-testid = "doc-share-modal"
70
+ aria-label = { translation ( 'Configure Grist API Key' ) }
71
+ size = { ModalSize . SMALL }
72
+ onClose = { ( ) => setOpenGristApiKeyModal ( false ) }
73
+ title = {
74
+ < Box $align = "flex-start" > { translation ( 'Base de données' ) } </ Box >
75
+ }
76
+ >
77
+ < Box >
78
+ < Text >
79
+ Pour synchroniser vos données avec Grist vous devez fournir
80
+ une clé API.
81
+ </ Text >
82
+ < Text style = { { fontWeight : 'bold' } } >
83
+ Comment obtenir votre clé API :
84
+ </ Text >
85
+ < Text > 1. Connectez-vous à votre compte Grist</ Text >
86
+ < Text >
87
+ 2. Allez dans Paramètres du compte { '>' } API { '>' } Clé API
88
+ </ Text >
89
+ < Text > 3. Créez une nouvelle clé et copiez-la</ Text >
90
+ </ Box >
91
+ < Input
92
+ label = "Grist API key"
93
+ onChange = { ( event ) => {
94
+ const value = event . target . value ;
95
+ setGristApiKey ( value ) ;
96
+ } }
97
+ />
98
+ < Button onClick = { validateGristApiKey } >
99
+ { translation ( 'Valider la clé API' ) }
100
+ </ Button >
101
+ </ Modal >
102
+ ) }
54
103
</ Box >
55
104
) ;
56
105
} ,
0 commit comments