PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / v3 / src / assets / js / common / integrationGoogle.js
ameliabooking / v3 / src / assets / js / common Last commit date
appointments.js 1 month ago attendees.js 1 month ago colorManipulation.js 1 month ago customer.js 1 month ago date.js 3 weeks ago defaultCustomize.js 3 weeks ago employee.js 5 days ago events.js 1 month ago formFieldsTemplates.js 1 month ago formatting.js 1 month ago helper.js 5 days ago image.js 1 month ago integrationApple.js 1 month ago integrationGoogle.js 1 month ago integrationOutlook.js 1 month ago integrationStripe.js 1 month ago integrationZoom.js 1 month ago licence.js 1 month ago liveAnnouncer.js 3 weeks ago phone.js 3 weeks ago pricing.js 1 month ago recurring.js 5 days ago responsive.js 1 month ago scrollElements.js 1 month ago settings.js 1 month ago translationsElementPlus.js 1 month ago utilHeaderHeight.js 1 month ago
integrationGoogle.js
165 lines
1 import httpClient from '../../../plugins/axios'
2 import { useRemoveUrlParameter, useUrlQueryParams } from './helper'
3
4 function useGoogleSync(code, successCallback) {
5 let redirectURL = useRemoveUrlParameter(
6 useRemoveUrlParameter(
7 useRemoveUrlParameter(useRemoveUrlParameter(window.location.href, 'code'), 'state'),
8 'scope',
9 ),
10 'iss',
11 )
12
13 httpClient
14 .post('/google/authorization/token', {
15 authCode: code,
16 userId: useUrlQueryParams(window.location.href)['state'],
17 redirectUri: redirectURL,
18 })
19 .then(() => {
20 history.pushState(null, null, redirectURL)
21 })
22 .catch((error) => {
23 console.log(error)
24 })
25 .finally(() => {
26 successCallback()
27 })
28 }
29
30 function useGoogleConnect(store) {
31 const amSettings = store.getters['getSettings']
32 if (!store.getters['auth/getGoogleLoading']) {
33 store.commit('auth/setGoogleLoading', true)
34
35 let cleanUrl = useRemoveUrlParameter(window.location.href, 'iss')
36
37 if (!amSettings.googleCalendar.accessToken) {
38 httpClient
39 .get('/google/authorization/url/' + store.getters['employee/getId'], {
40 redirectUri: cleanUrl.split('?')[0],
41 })
42 .then((response) => {
43 window.location.href = response.data.data.authUrl.replace(
44 /redirect_uri=.+?&/,
45 'redirect_uri=' + cleanUrl + '&',
46 )
47 })
48 .catch((error) => {
49 console.log(error)
50
51 store.commit('auth/setGoogleLoading', false)
52 })
53 }
54
55 if (amSettings.googleCalendar.accessToken) {
56 httpClient
57 .get('/google-calendar/authorization/url/' + store.getters['employee/getId'], {
58 params: {
59 redirectUri: cleanUrl,
60 },
61 })
62 .then((response) => {
63 window.location.href = response.data.data.authUrl
64 })
65 .catch((error) => {
66 console.log(error)
67
68 store.commit('auth/setGoogleLoading', false)
69 })
70 }
71 }
72 }
73
74 async function useGoogleDisconnect(store, accountId = null) {
75 store.commit('auth/setGoogleLoading', true)
76
77 const endpoint = '/google/disconnect/' + store.getters['employee/getId']
78 const data = accountId ? { accountId: accountId } : {}
79
80 await httpClient
81 .post(endpoint, data)
82 .then(async (response) => {
83 if (accountId) {
84 const accounts = store.getters['employee/getGoogleCalendarAccounts'] || []
85
86 const disconnectedAccount = accounts.find((a) => a.id === accountId)
87
88 const updatedAccounts = accounts.filter((account) => account.id !== accountId)
89 store.commit('employee/setGoogleCalendarAccounts', updatedAccounts)
90
91 if (updatedAccounts.length === 0) {
92 store.commit('employee/setGoogleId', null)
93 store.commit('employee/setGoogleCalendarId', '')
94 store.commit('employee/setGoogleToken', null)
95 store.commit('employee/setGoogleCalendarBlockedCalendars', [])
96 store.commit('auth/setGoogleCalendars', [])
97 } else {
98 const remainingCalendarIds = new Set()
99 updatedAccounts.forEach((account) => {
100 if (account.calendarList && account.calendarList.length) {
101 account.calendarList.forEach((cal) => remainingCalendarIds.add(String(cal.id)))
102 }
103 if (account.calendarId) {
104 remainingCalendarIds.add(String(account.calendarId))
105 }
106 })
107
108 const removedCalendarIds = new Set()
109 if (disconnectedAccount) {
110 if (disconnectedAccount.calendarId) {
111 removedCalendarIds.add(String(disconnectedAccount.calendarId))
112 }
113 if (disconnectedAccount.calendarList && disconnectedAccount.calendarList.length) {
114 disconnectedAccount.calendarList.forEach((cal) =>
115 removedCalendarIds.add(String(cal.id)),
116 )
117 }
118 if (
119 disconnectedAccount.blockedCalendars &&
120 disconnectedAccount.blockedCalendars.length
121 ) {
122 disconnectedAccount.blockedCalendars.forEach((id) =>
123 removedCalendarIds.add(String(id)),
124 )
125 }
126 }
127 if (
128 response &&
129 response.data &&
130 response.data.data &&
131 response.data.data.removedCalendarIds
132 ) {
133 response.data.data.removedCalendarIds.forEach((id) =>
134 removedCalendarIds.add(String(id)),
135 )
136 }
137
138 const currentCalendarId = store.getters['employee/getGoogleCalendarId']
139 if (currentCalendarId && !remainingCalendarIds.has(String(currentCalendarId))) {
140 store.commit('employee/setGoogleCalendarId', '')
141 }
142
143 const blocked = store.getters['employee/getGoogleCalendarBlockedCalendars'] || []
144 const cleanedBlocked = blocked.filter((id) => remainingCalendarIds.has(String(id)))
145 store.commit('employee/setGoogleCalendarBlockedCalendars', cleanedBlocked)
146 }
147 } else {
148 store.commit('employee/setGoogleId', null)
149 store.commit('employee/setGoogleCalendarId', '')
150 store.commit('employee/setGoogleToken', null)
151 store.commit('employee/setGoogleCalendarAccounts', [])
152 store.commit('employee/setGoogleCalendarBlockedCalendars', [])
153 store.commit('auth/setGoogleCalendars', [])
154 }
155 })
156 .catch((error) => {
157 console.log(error)
158 })
159 .finally(() => {
160 store.commit('auth/setGoogleLoading', false)
161 })
162 }
163
164 export { useGoogleSync, useGoogleConnect, useGoogleDisconnect }
165