Skip to content

Commit fb2a45f

Browse files
author
anaisberg
committed
✨ open modal to inpu dans save api key
1 parent ab6d617 commit fb2a45f

File tree

1 file changed

+52
-3
lines changed
  • src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks

1 file changed

+52
-3
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/DatabaseBlock.tsx

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* eslint-disable react-hooks/rules-of-hooks */
22
import { defaultProps, insertOrUpdateBlock } from '@blocknote/core';
33
import { BlockTypeSelectItem, createReactBlockSpec } from '@blocknote/react';
4+
import { Button, Input, Modal, ModalSize } from '@openfun/cunningham-react';
45
import { TFunction } from 'i18next';
5-
import { set } from 'lodash';
66
import React, { useEffect, useState } from 'react';
7+
import { useTranslation } from 'react-i18next';
78

8-
import { Box, Icon } from '@/components';
9+
import { Box, Icon, Text } from '@/components';
910

1011
import { DocsBlockNoteEditor } from '../../types';
1112

@@ -26,10 +27,21 @@ export const DatabaseBlock = createReactBlockSpec(
2627
const getGristApiKey = (): string | null => {
2728
return localStorage.getItem('grist_api_key');
2829
};
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();
2938

3039
const [gristApiKeyModal, setGristApiKey] = useState<string | null>(
3140
getGristApiKey,
3241
);
42+
const [openGristApiKeyModal, setOpenGristApiKeyModal] = useState<boolean>(
43+
gristApiKeyModal === null,
44+
);
3345

3446
useEffect(() => {
3547
if (
@@ -50,7 +62,44 @@ export const DatabaseBlock = createReactBlockSpec(
5062
}}
5163
>
5264
<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+
)}
54103
</Box>
55104
);
56105
},

0 commit comments

Comments
 (0)