1
1
import {
2
+ Avatar ,
2
3
Button ,
3
4
Modal ,
4
5
ModalBody ,
5
6
ModalContent ,
6
7
useDisclosure ,
7
8
} from '@nextui-org/react' ;
8
- import { Image } from '@nextui-org/image' ;
9
9
import { BiPlus } from 'react-icons/bi' ;
10
10
import { NotionFileModal } from '@/components/knowledge/Notion' ;
11
11
import { isNotionConfigured , runNotionSync } from '@/actions/knowledge/notion' ;
12
12
import { useState } from 'react' ;
13
+ import { OnedriveFileModal } from '@/components/knowledge/OneDrive' ;
14
+ import {
15
+ isOneDriveConfigured ,
16
+ runOneDriveSync ,
17
+ } from '@/actions/knowledge/onedrive' ;
13
18
14
19
interface FileModalProps {
15
20
isOpen : boolean ;
@@ -19,9 +24,12 @@ interface FileModalProps {
19
24
20
25
const FileModal = ( { isOpen, onClose, handleAddFile } : FileModalProps ) => {
21
26
const notionModal = useDisclosure ( ) ;
27
+ const onedriveModal = useDisclosure ( ) ;
22
28
const [ isSyncing , setIsSyncing ] = useState ( false ) ;
23
29
const [ notionConfigured , setNotionConfigured ] = useState ( false ) ;
24
30
const [ notionSyncError , setNotionSyncError ] = useState ( '' ) ;
31
+ const [ oneDriveConfigured , setOneDriveConfigured ] = useState ( false ) ;
32
+ const [ oneDriveSyncError , setOneDriveSyncError ] = useState ( '' ) ;
25
33
26
34
const onClickNotion = async ( ) => {
27
35
onClose ( ) ;
@@ -40,6 +48,23 @@ const FileModal = ({ isOpen, onClose, handleAddFile }: FileModalProps) => {
40
48
}
41
49
} ;
42
50
51
+ const onClickOnedrive = async ( ) => {
52
+ onClose ( ) ;
53
+ onedriveModal . onOpen ( ) ;
54
+ const isConfigured = await isOneDriveConfigured ( ) ;
55
+ if ( ! isConfigured ) {
56
+ setIsSyncing ( true ) ;
57
+ try {
58
+ await runOneDriveSync ( false ) ;
59
+ setOneDriveConfigured ( true ) ;
60
+ } catch ( e ) {
61
+ setOneDriveSyncError ( ( e as Error ) . toString ( ) ) ;
62
+ } finally {
63
+ setIsSyncing ( false ) ;
64
+ }
65
+ }
66
+ } ;
67
+
43
68
return (
44
69
< >
45
70
< Modal
@@ -68,11 +93,30 @@ const FileModal = ({ isOpen, onClose, handleAddFile }: FileModalProps) => {
68
93
onClick = { onClickNotion }
69
94
className = "flex w-full items-center justify-center gap-3 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus-visible:ring-transparent hover:cursor-pointer"
70
95
>
71
- < Image className = "h-5 w-5" src = "notion.svg" alt = "Notion Icon" />
96
+ < Avatar
97
+ size = "sm"
98
+ src = "notion.svg"
99
+ alt = "Notion Icon"
100
+ classNames = { { base : 'p-1.5 bg-white' } }
101
+ />
72
102
< span className = "text-sm font-semibold leading-6" >
73
103
Sync From Notion
74
104
</ span >
75
105
</ Button >
106
+ < Button
107
+ onClick = { onClickOnedrive }
108
+ className = "flex w-full items-center justify-center gap-3 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus-visible:ring-transparent hover:cursor-pointer"
109
+ >
110
+ < Avatar
111
+ size = "sm"
112
+ src = "onedrive.svg"
113
+ alt = "OneDrive Icon"
114
+ classNames = { { base : 'p-1.5 bg-white' } }
115
+ />
116
+ < span className = "text-sm font-semibold leading-6" >
117
+ Sync From OneDrive
118
+ </ span >
119
+ </ Button >
76
120
</ ModalBody >
77
121
</ ModalContent >
78
122
</ Modal >
@@ -86,6 +130,16 @@ const FileModal = ({ isOpen, onClose, handleAddFile }: FileModalProps) => {
86
130
syncError = { notionSyncError }
87
131
setSyncError = { setNotionSyncError }
88
132
/>
133
+ < OnedriveFileModal
134
+ isOpen = { onedriveModal . isOpen }
135
+ onClose = { onedriveModal . onClose }
136
+ isSyncing = { isSyncing }
137
+ setIsSyncing = { setIsSyncing }
138
+ onedriveConfigured = { oneDriveConfigured }
139
+ setOnedriveConfigured = { setOneDriveConfigured }
140
+ syncError = { oneDriveSyncError }
141
+ setSyncError = { setOneDriveSyncError }
142
+ />
89
143
</ >
90
144
) ;
91
145
} ;
0 commit comments