appointments.js
1 year ago
attendees.js
1 year ago
colorManipulation.js
3 years ago
customer.js
1 year ago
date.js
1 year ago
defaultCustomize.js
1 year ago
employee.js
1 year ago
events.js
1 year ago
formFieldsTemplates.js
3 years ago
formatting.js
1 year ago
helper.js
1 year ago
image.js
1 year ago
integrationApple.js
1 year ago
integrationGoogle.js
1 year ago
integrationOutlook.js
1 year ago
integrationStripe.js
1 year ago
integrationZoom.js
1 year ago
licence.js
2 years ago
objectAndArrayManipulation.js
3 years ago
pricing.js
1 year ago
recurring.js
1 year ago
responsive.js
1 year ago
scrollElements.js
4 years ago
settings.js
1 year ago
translationsElementPlus.js
1 year ago
integrationGoogle.js
80 lines
| 1 | import httpClient from "../../../plugins/axios"; |
| 2 | import {useRemoveUrlParameter, useUrlQueryParams} from "./helper"; |
| 3 | import {useAuthorizationHeaderObject} from "../public/panel"; |
| 4 | |
| 5 | function useGoogleSync (code, successCallback) { |
| 6 | let redirectURL = useRemoveUrlParameter( |
| 7 | useRemoveUrlParameter( |
| 8 | useRemoveUrlParameter( |
| 9 | window.location.href, |
| 10 | 'code' |
| 11 | ), |
| 12 | 'state' |
| 13 | ), |
| 14 | 'scope' |
| 15 | ) |
| 16 | |
| 17 | httpClient.post( |
| 18 | '/google/authorization/token', |
| 19 | { |
| 20 | authCode: code, |
| 21 | userId: useUrlQueryParams(window.location.href)['state'], |
| 22 | redirectUri: redirectURL |
| 23 | } |
| 24 | ).then(() => { |
| 25 | history.pushState(null, null, redirectURL) |
| 26 | }).catch((error) => { |
| 27 | console.log(error) |
| 28 | }).finally(() => { |
| 29 | successCallback() |
| 30 | }) |
| 31 | } |
| 32 | |
| 33 | function useGoogleConnect (store) { |
| 34 | if (!store.getters['auth/getGoogleLoading']) { |
| 35 | store.commit('auth/setGoogleLoading', true) |
| 36 | |
| 37 | httpClient.get( |
| 38 | '/google/authorization/url/' + store.getters['employee/getId'], |
| 39 | Object.assign( |
| 40 | { |
| 41 | 'redirectUri': window.location.href.split('?')[0], |
| 42 | }, |
| 43 | useAuthorizationHeaderObject(store) |
| 44 | ) |
| 45 | ).then((response) => { |
| 46 | window.location.href = response.data.data.authUrl.replace( |
| 47 | /redirect_uri=.+?&/, |
| 48 | 'redirect_uri=' + window.location.href + '&' |
| 49 | ) |
| 50 | }).catch((error) => { |
| 51 | console.log(error) |
| 52 | |
| 53 | store.commit('auth/setGoogleLoading', false) |
| 54 | }) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | function useGoogleDisconnect (store) { |
| 59 | store.commit('auth/setGoogleLoading', true) |
| 60 | |
| 61 | httpClient.post( |
| 62 | '/google/disconnect/' + store.getters['employee/getId'] |
| 63 | ).then(() => { |
| 64 | store.commit('employee/setGoogleId', null) |
| 65 | store.commit('employee/setGoogleCalendarId', '') |
| 66 | store.commit('employee/setGoogleToken', null) |
| 67 | store.commit('auth/setGoogleCalendars', []) |
| 68 | }).catch((error) => { |
| 69 | console.log(error) |
| 70 | }).finally(() => { |
| 71 | store.commit('auth/setGoogleLoading', false) |
| 72 | }) |
| 73 | } |
| 74 | |
| 75 | export { |
| 76 | useGoogleSync, |
| 77 | useGoogleConnect, |
| 78 | useGoogleDisconnect, |
| 79 | } |
| 80 |