Add role switcher (Client/Seller) in navigation menu
All checks were successful
Build Docker Image / build (push) Successful in 4m20s
All checks were successful
Build Docker Image / build (push) Successful in 4m20s
- Add role switcher buttons after Explore/Quote/Кабинет with separator - Dynamic center tabs based on role: BUYER shows orders/addresses, SELLER shows offers - Redirect to appropriate page when switching role in client area - Add localization for roles.client and roles.seller
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
:theme="theme"
|
||||
:user-data="userData"
|
||||
:is-seller="isSeller"
|
||||
:has-buyer-team="hasBuyerTeam"
|
||||
:has-seller-team="hasSellerTeam"
|
||||
:current-role="currentRole"
|
||||
:active-tokens="activeTokens"
|
||||
:available-chips="availableChips"
|
||||
:select-mode="selectMode"
|
||||
@@ -36,6 +39,7 @@
|
||||
@sign-out="onClickSignOut"
|
||||
@sign-in="signIn()"
|
||||
@switch-team="switchToTeam"
|
||||
@switch-role="switchToRole"
|
||||
@start-select="startSelect"
|
||||
@cancel-select="cancelSelect"
|
||||
@edit-token="editFilter"
|
||||
@@ -129,7 +133,7 @@ const userData = useState<{
|
||||
avatarId?: string
|
||||
activeTeam?: { name?: string; teamType?: string; logtoOrgId?: string; selectedLocation?: SelectedLocation | null }
|
||||
activeTeamId?: string
|
||||
teams?: Array<{ id?: string; name?: string; logtoOrgId?: string }>
|
||||
teams?: Array<{ id?: string; name?: string; logtoOrgId?: string; teamType?: string }>
|
||||
} | null>('me', () => null)
|
||||
|
||||
const sessionChecked = ref(false)
|
||||
@@ -140,6 +144,19 @@ const isSeller = computed(() => {
|
||||
return userData.value?.activeTeam?.teamType === 'SELLER'
|
||||
})
|
||||
|
||||
// Role switching support
|
||||
const buyerTeam = computed(() =>
|
||||
userData.value?.teams?.find(t => t?.teamType === 'BUYER')
|
||||
)
|
||||
const sellerTeam = computed(() =>
|
||||
userData.value?.teams?.find(t => t?.teamType === 'SELLER')
|
||||
)
|
||||
const hasBuyerTeam = computed(() => !!buyerTeam.value)
|
||||
const hasSellerTeam = computed(() => !!sellerTeam.value)
|
||||
const currentRole = computed(() =>
|
||||
userData.value?.activeTeam?.teamType || 'BUYER'
|
||||
)
|
||||
|
||||
const isLoggedIn = computed(() => loggedIn.value || !!userData.value?.id)
|
||||
|
||||
const userName = computed(() => {
|
||||
@@ -252,7 +269,7 @@ watch(userData, () => {
|
||||
await fetchSession().catch(() => {})
|
||||
sessionChecked.value = true
|
||||
|
||||
const switchToTeam = async (team: { id?: string; logtoOrgId?: string; name?: string }) => {
|
||||
const switchToTeam = async (team: { id?: string; logtoOrgId?: string; name?: string; teamType?: string }) => {
|
||||
if (!team?.id) return
|
||||
|
||||
try {
|
||||
@@ -271,6 +288,20 @@ const switchToTeam = async (team: { id?: string; logtoOrgId?: string; name?: str
|
||||
}
|
||||
}
|
||||
|
||||
const switchToRole = async (role: 'BUYER' | 'SELLER') => {
|
||||
const targetTeam = role === 'SELLER' ? sellerTeam.value : buyerTeam.value
|
||||
if (targetTeam?.id) {
|
||||
await switchToTeam(targetTeam)
|
||||
// Redirect to appropriate page when in client area
|
||||
if (isClientArea.value) {
|
||||
const targetPath = role === 'SELLER'
|
||||
? '/clientarea/offers'
|
||||
: '/clientarea/orders'
|
||||
await navigateTo(localePath(targetPath))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const onClickSignOut = () => {
|
||||
signOut(siteUrl)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user