Skip to content

Commit 5ae8129

Browse files
authored
Twitter feature flags (#1858)
1 parent 85f50c1 commit 5ae8129

4 files changed

Lines changed: 76 additions & 93 deletions

File tree

frontend/src/integrations/twitter/components/twitter-connect-2.vue

Lines changed: 0 additions & 83 deletions
This file was deleted.

frontend/src/integrations/twitter/components/twitter-connect.vue

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,88 @@
11
<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"
47
/>
58
<slot
6-
:connect="connect"
9+
:connect="isTwitterEnabled ? connect : upgradePlan"
10+
:settings="settings"
11+
:has-settings="true"
12+
:has-integration="isTwitterEnabled"
713
/>
814
</template>
915

1016
<script setup>
17+
import { useStore } from 'vuex';
1118
import {
12-
ref,
19+
defineProps, computed, ref, onMounted,
1320
} 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';
1527
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+
});
1770
1871
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;
2086
};
2187
</script>
2288

frontend/src/integrations/twitter/config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import config from '@/config';
2-
import TwitterConnect2 from './components/twitter-connect-2.vue';
31
import TwitterConnect from './components/twitter-connect.vue';
42

53
export default {
@@ -11,8 +9,9 @@ export default {
119
'Connect X/Twitter to sync profile information, followers, and relevant tweets.',
1210
image:
1311
'/images/integrations/twitter-x.svg',
14-
connectComponent: config.isTwitterIntegrationEnabled ? TwitterConnect2 : TwitterConnect,
12+
connectComponent: TwitterConnect,
1513
url: ({ username }) => (username ? `https://twitter.com/${username}` : null),
14+
scale: true,
1615
chartColor: '#1D9BF0',
1716
showProfileLink: true,
1817
activityDisplay: {

frontend/src/utils/featureFlag/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const FEATURE_FLAGS = {
1414
logRocket: 'log-rocket',
1515
developerMode: 'developer-mode',
1616
quickstartV2: 'quickstart-v2',
17+
twitter: 'twitter',
1718
};
1819

1920
class FeatureFlagService {

0 commit comments

Comments
 (0)