Skip to content

Commit 9ebf03c

Browse files
matts2cantSimonClo
authored andcommitted
✨ Extract DatabaseSelector
1 parent b2a2980 commit 9ebf03c

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
3+
import { Box, Text } from '@/components';
4+
import { Button } from '@openfun/cunningham-react';
5+
import { DatabaseSourceSelector } from '@/docs/doc-editor/components/DatabaseSourceSelector';
6+
7+
type DatabaseSelectorProps = {
8+
onDatabaseSelected: (args: { documentId: string; tableId: string }) => void;
9+
};
10+
11+
export const DatabaseSelector = ({
12+
onDatabaseSelected,
13+
}: DatabaseSelectorProps) => (
14+
<Box
15+
style={{
16+
flexDirection: 'column',
17+
gap: 10,
18+
alignItems: 'center',
19+
justifyContent: 'center',
20+
width: '100%',
21+
}}
22+
>
23+
<Button>Créer une nouvelle base de données vide</Button>
24+
<Text>ou</Text>
25+
<DatabaseSourceSelector onSourceSelected={onDatabaseSelected} />
26+
</Box>
27+
);

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

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/* eslint-disable react-hooks/rules-of-hooks */
22
import { insertOrUpdateBlock } from '@blocknote/core';
33
import { createReactBlockSpec } from '@blocknote/react';
4-
import { Button } from '@openfun/cunningham-react';
54
import { TFunction } from 'i18next';
65
import React from 'react';
76

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

109
import { DocsBlockNoteEditor } from '../../types';
11-
import { DatabaseSourceSelector } from '../DatabaseSourceSelector';
10+
import { DatabaseSelector } from '../DatabaseSelector';
1211

1312
import { DatabaseGrid } from './DatabaseBlock/DatabaseGrid';
1413

@@ -48,25 +47,13 @@ export const DatabaseBlock = createReactBlockSpec(
4847
/>
4948
</Box>
5049
) : (
51-
<Box
52-
style={{
53-
flexDirection: 'column',
54-
gap: 10,
55-
alignItems: 'center',
56-
justifyContent: 'center',
57-
width: '100%',
50+
<DatabaseSelector
51+
onDatabaseSelected={({ documentId, tableId }) => {
52+
editor.updateBlock(block, {
53+
props: { documentId: documentId.toString(), tableId },
54+
});
5855
}}
59-
>
60-
<Button>Créer une nouvelle base de données vide</Button>
61-
<Text>ou</Text>
62-
<DatabaseSourceSelector
63-
onSourceSelected={({ documentId, tableId }) => {
64-
editor.updateBlock(block, {
65-
props: { documentId: documentId.toString(), tableId },
66-
});
67-
}}
68-
/>
69-
</Box>
56+
/>
7057
)}
7158
</Box>
7259
);

0 commit comments

Comments
 (0)