|
1 | 1 | <template> |
2 | | - <app-twitter-connect-modal |
3 | | - v-model="modalVisible" |
| 2 | + <app-twitter-connect-drawer |
| 3 | + v-if="hasSettings && drawerVisible" |
| 4 | + v-model="drawerVisible" |
| 5 | + :hashtags="hashtags" |
| 6 | + :connect-url="connectUrl" |
4 | 7 | /> |
5 | 8 | <slot |
6 | | - :connect="connect" |
| 9 | + :connect="isTwitterEnabled ? connect : upgradePlan" |
| 10 | + :settings="settings" |
| 11 | + :has-settings="true" |
| 12 | + :has-integration="isTwitterEnabled" |
7 | 13 | /> |
8 | 14 | </template> |
9 | 15 |
|
10 | 16 | <script setup> |
| 17 | +import { useStore } from 'vuex'; |
11 | 18 | import { |
12 | | - ref, |
| 19 | + defineProps, computed, ref, onMounted, |
13 | 20 | } from 'vue'; |
14 | | -import AppTwitterConnectModal from '@/integrations/twitter/components/twitter-connect-modal.vue'; |
| 21 | +import { useRouter, useRoute } from 'vue-router'; |
| 22 | +import config from '@/config'; |
| 23 | +import { AuthToken } from '@/modules/auth/auth-token'; |
| 24 | +import Message from '@/shared/message/message'; |
| 25 | +import AppTwitterConnectDrawer from '@/integrations/twitter/components/twitter-connect-drawer.vue'; |
| 26 | +import { FeatureFlag } from '@/utils/featureFlag'; |
15 | 27 |
|
16 | | -const modalVisible = ref(false); |
| 28 | +const route = useRoute(); |
| 29 | +const router = useRouter(); |
| 30 | +const isTwitterEnabled = ref(false); |
| 31 | +
|
| 32 | +const props = defineProps({ |
| 33 | + integration: { |
| 34 | + type: Object, |
| 35 | + default: () => {}, |
| 36 | + }, |
| 37 | +}); |
| 38 | +const store = useStore(); |
| 39 | +const drawerVisible = ref(false); |
| 40 | +
|
| 41 | +onMounted(() => { |
| 42 | + const isConnectionSuccessful = route.query.success; |
| 43 | +
|
| 44 | + if (isConnectionSuccessful) { |
| 45 | + router.replace({ query: null }); |
| 46 | + Message.success('Integration updated successfuly'); |
| 47 | + } |
| 48 | +}); |
| 49 | +
|
| 50 | +onMounted(async () => { |
| 51 | + isTwitterEnabled.value = FeatureFlag.isFlagEnabled( |
| 52 | + FeatureFlag.flags.twitter, |
| 53 | + ); |
| 54 | +}); |
| 55 | +
|
| 56 | +// Only render twitter drawer and settings button, if integration has settings |
| 57 | +const hasSettings = computed(() => !!props.integration.settings); |
| 58 | +const hashtags = computed(() => props.integration.settings?.hashtags || []); |
| 59 | +
|
| 60 | +// Create an url for the connection without the hashtags |
| 61 | +// This will allow to be reused by the twitter drawer component |
| 62 | +// and override the current configured hashtag |
| 63 | +const connectUrl = computed(() => { |
| 64 | + const redirectUrl = `${window.location.protocol}//${window.location.host}${window.location.pathname}?success=true`; |
| 65 | +
|
| 66 | + return `${config.backendUrl}/twitter/${ |
| 67 | + store.getters['auth/currentTenant'].id |
| 68 | + }/connect?redirectUrl=${redirectUrl}&crowdToken=${AuthToken.get()}`; |
| 69 | +}); |
17 | 70 |
|
18 | 71 | const connect = () => { |
19 | | - modalVisible.value = true; |
| 72 | + // Add the already configured hashtags to the connectUrl |
| 73 | + const encodedHashtags = hashtags.value.length > 0 |
| 74 | + ? `&hashtags[]=${hashtags.value[hashtags.value.length - 1]}` |
| 75 | + : ''; |
| 76 | +
|
| 77 | + window.open(`${connectUrl.value}${encodedHashtags}`, '_self'); |
| 78 | +}; |
| 79 | +
|
| 80 | +const upgradePlan = () => { |
| 81 | + router.push('/settings?activeTab=plans'); |
| 82 | +}; |
| 83 | +
|
| 84 | +const settings = () => { |
| 85 | + drawerVisible.value = true; |
20 | 86 | }; |
21 | 87 | </script> |
22 | 88 |
|
|
0 commit comments