Skip to content

Commit f8ac6df

Browse files
chore: add workspace switcher login A/B testing flow (hoppscotch#4053)
Co-authored-by: Andrew Bastin <[email protected]>
1 parent 7d2d335 commit f8ac6df

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

packages/hoppscotch-common/src/components/app/Header.vue

+35-14
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@
4343
@click="invokeAction('modals.support.toggle')"
4444
/>
4545
</div>
46-
<div class="flex">
46+
<div
47+
class="flex"
48+
:class="{
49+
'flex-row-reverse gap-2':
50+
workspaceSelectorFlagEnabled && !currentUser,
51+
}"
52+
>
4753
<div
4854
v-if="currentUser === null"
4955
class="inline-flex items-center space-x-2"
5056
>
5157
<HoppButtonSecondary
58+
v-if="!workspaceSelectorFlagEnabled"
5259
:icon="IconUploadCloud"
5360
:label="t('header.save_workspace')"
5461
class="!focus-visible:text-emerald-600 !hover:text-emerald-600 hidden h-8 border border-emerald-600/25 bg-emerald-500/10 !text-emerald-500 hover:border-emerald-600/20 hover:bg-emerald-600/20 focus-visible:border-emerald-600/20 focus-visible:bg-emerald-600/20 md:flex"
@@ -60,18 +67,22 @@
6067
@click="invokeAction('modals.login.toggle')"
6168
/>
6269
</div>
63-
<div v-else class="inline-flex items-center space-x-2">
64-
<TeamsMemberStack
65-
v-if="
66-
workspace.type === 'team' &&
67-
selectedTeam &&
68-
selectedTeam.teamMembers.length > 1
69-
"
70-
:team-members="selectedTeam.teamMembers"
71-
show-count
72-
class="mx-2"
73-
@handle-click="handleTeamEdit()"
74-
/>
70+
<TeamsMemberStack
71+
v-else-if="
72+
currentUser !== null &&
73+
workspace.type === 'team' &&
74+
selectedTeam &&
75+
selectedTeam.teamMembers.length > 1
76+
"
77+
:team-members="selectedTeam.teamMembers"
78+
show-count
79+
class="mx-2"
80+
@handle-click="handleTeamEdit()"
81+
/>
82+
<div
83+
v-if="workspaceSelectorFlagEnabled || currentUser"
84+
class="inline-flex items-center space-x-2"
85+
>
7586
<div
7687
class="flex h-8 divide-x divide-emerald-600/25 rounded border border-emerald-600/25 bg-emerald-500/10 focus-within:divide-emerald-600/20 focus-within:border-emerald-600/20 focus-within:bg-emerald-600/20 hover:divide-emerald-600/20 hover:border-emerald-600/20 hover:bg-emerald-600/20"
7788
>
@@ -84,6 +95,7 @@
8495
/>
8596
<HoppButtonSecondary
8697
v-if="
98+
currentUser &&
8799
workspace.type === 'team' &&
88100
selectedTeam &&
89101
selectedTeam?.myRole === 'OWNER'
@@ -124,7 +136,7 @@
124136
</div>
125137
</template>
126138
</tippy>
127-
<span class="px-2">
139+
<span v-if="currentUser" class="px-2">
128140
<tippy
129141
interactive
130142
trigger="click"
@@ -259,6 +271,13 @@ import {
259271
const t = useI18n()
260272
const toast = useToast()
261273
274+
/**
275+
* Feature flag to enable the workspace selector login conversion
276+
*/
277+
const workspaceSelectorFlagEnabled = computed(
278+
() => !!platform.platformFeatureFlags.workspaceSwitcherLogin?.value
279+
)
280+
262281
/**
263282
* Once the PWA code is initialized, this holds a method
264283
* that can be called to show the user the installation
@@ -380,6 +399,8 @@ const inviteTeam = (team: { name: string }, teamID: string) => {
380399
381400
// Show the workspace selected team invite modal if the user is an owner of the team else show the default invite modal
382401
const handleInvite = () => {
402+
if (!currentUser.value) return invokeAction("modals.login.toggle")
403+
383404
if (
384405
workspace.value.type === "team" &&
385406
workspace.value.teamID &&

packages/hoppscotch-common/src/components/workspace/Selector.vue

+7-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
/>
6060
</div>
6161
<div
62-
v-if="!loading && teamListAdapterError"
62+
v-else-if="teamListAdapterError"
6363
class="flex flex-col items-center py-4"
6464
>
6565
<icon-lucide-help-circle class="svg-icons mb-4" />
@@ -85,7 +85,7 @@ import { useColorMode } from "@composables/theming"
8585
import { GetMyTeamsQuery } from "~/helpers/backend/graphql"
8686
import IconDone from "~icons/lucide/check"
8787
import { useLocalState } from "~/newstore/localstate"
88-
import { defineActionHandler } from "~/helpers/actions"
88+
import { defineActionHandler, invokeAction } from "~/helpers/actions"
8989
import { WorkspaceService } from "~/services/workspace.service"
9090
import { useService } from "dioc/vue"
9191
import { useElementVisibility, useIntervalFn } from "@vueuse/core"
@@ -157,8 +157,8 @@ const switchToTeamWorkspace = (team: GetMyTeamsQuery["myTeams"][number]) => {
157157
workspaceService.changeWorkspace({
158158
teamID: team.id,
159159
teamName: team.name,
160-
role: team.myRole,
161160
type: "team",
161+
role: team.myRole,
162162
})
163163
}
164164
@@ -174,12 +174,16 @@ watch(
174174
(user) => {
175175
if (!user) {
176176
switchToPersonalWorkspace()
177+
teamListadapter.dispose()
177178
}
178179
}
179180
)
180181
181182
const displayModalAdd = (shouldDisplay: boolean) => {
183+
if (!currentUser.value) return invokeAction("modals.login.toggle")
184+
182185
showModalAdd.value = shouldDisplay
186+
teamListadapter.fetchList()
183187
}
184188
185189
defineActionHandler("modals.team.new", () => {

packages/hoppscotch-common/src/helpers/teams/TeamListAdapter.ts

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default class TeamListAdapter {
5050
}
5151

5252
public dispose() {
53+
this.teamList$.next([])
5354
this.isDispose = true
5455
clearTimeout(this.timeoutHandle as any)
5556
this.timeoutHandle = null

packages/hoppscotch-common/src/platform/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { InspectorsPlatformDef } from "./inspectors"
1111
import { ServiceClassInstance } from "dioc"
1212
import { IOPlatformDef } from "./io"
1313
import { SpotlightPlatformDef } from "./spotlight"
14+
import { Ref } from "vue"
1415

1516
export type PlatformDef = {
1617
ui?: UIPlatformDef
@@ -45,6 +46,11 @@ export type PlatformDef = {
4546
* If a value is not given, then the value is assumed to be true
4647
*/
4748
promptAsUsingCookies?: boolean
49+
50+
/**
51+
* Whether to show the A/B testing workspace switcher click login flow or not
52+
*/
53+
workspaceSwitcherLogin?: Ref<boolean>
4854
}
4955
}
5056

0 commit comments

Comments
 (0)