mirror of
				https://github.com/lingble/twenty.git
				synced 2025-10-30 20:27:55 +00:00 
			
		
		
		
	o365 calendar sync (#8044)
Implemented: * Account Connect * Calendar sync via delta ids then requesting single events I think I would split the messaging part into a second pr - that's a step more complex then the calendar :) --------- Co-authored-by: bosiraphael <raphael.bosi@gmail.com>
This commit is contained in:
		| @@ -0,0 +1,69 @@ | ||||
| import { AppPath } from '@/types/AppPath'; | ||||
| import { useCallback } from 'react'; | ||||
|  | ||||
| import { REACT_APP_SERVER_BASE_URL } from '~/config'; | ||||
| import { | ||||
|   CalendarChannelVisibility, | ||||
|   MessageChannelVisibility, | ||||
|   useGenerateTransientTokenMutation, | ||||
| } from '~/generated/graphql'; | ||||
|  | ||||
| const getProviderUrl = (provider: string) => { | ||||
|   switch (provider) { | ||||
|     case 'google': | ||||
|       return 'google-apis'; | ||||
|     case 'microsoft': | ||||
|       return 'microsoft-apis'; | ||||
|     default: | ||||
|       throw new Error(`Provider ${provider} is not supported`); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| export const useTriggerApisOAuth = () => { | ||||
|   const [generateTransientToken] = useGenerateTransientTokenMutation(); | ||||
|  | ||||
|   const triggerApisOAuth = useCallback( | ||||
|     async ( | ||||
|       provider: string, | ||||
|       { | ||||
|         redirectLocation, | ||||
|         messageVisibility, | ||||
|         calendarVisibility, | ||||
|         loginHint, | ||||
|       }: { | ||||
|         redirectLocation?: AppPath | string; | ||||
|         messageVisibility?: MessageChannelVisibility; | ||||
|         calendarVisibility?: CalendarChannelVisibility; | ||||
|         loginHint?: string; | ||||
|       } = {}, | ||||
|     ) => { | ||||
|       const authServerUrl = REACT_APP_SERVER_BASE_URL; | ||||
|  | ||||
|       const transientToken = await generateTransientToken(); | ||||
|  | ||||
|       const token = | ||||
|         transientToken.data?.generateTransientToken.transientToken.token; | ||||
|  | ||||
|       let params = `transientToken=${token}`; | ||||
|  | ||||
|       params += redirectLocation | ||||
|         ? `&redirectLocation=${encodeURIComponent(redirectLocation)}` | ||||
|         : ''; | ||||
|  | ||||
|       params += calendarVisibility | ||||
|         ? `&calendarVisibility=${calendarVisibility}` | ||||
|         : ''; | ||||
|  | ||||
|       params += messageVisibility | ||||
|         ? `&messageVisibility=${messageVisibility}` | ||||
|         : ''; | ||||
|  | ||||
|       params += loginHint ? `&loginHint=${loginHint}` : ''; | ||||
|  | ||||
|       window.location.href = `${authServerUrl}/auth/${getProviderUrl(provider)}?${params}`; | ||||
|     }, | ||||
|     [generateTransientToken], | ||||
|   ); | ||||
|  | ||||
|   return { triggerApisOAuth }; | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user
	 brendanlaschke
					brendanlaschke