Skip to content

Commit

Permalink
fix: fixed staff account id redirection (#45)
Browse files Browse the repository at this point in the history
* fix: fixed staff account id redirection

* removed commented code

* changed page titles based on if staff or not

* fixed unit tests

* fixed lint + typing issue

* added comments

* moved to /account/[orgId] + added middleware

* fixed comment

* fixed isStaffOrSbcStaff check

* fixed unit tests by using the computed property

* DRY

* removed unnecessary div

* handle intermittent page 404 not found
  • Loading branch information
JazzarKarim authored Jan 8, 2025
1 parent 4605151 commit 13897c7
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
<BusinessLookup class="-mt-4" />
<TableAffiliatedEntity class="mt-6" />
</div>
</template>
11 changes: 7 additions & 4 deletions business-registry-dashboard/app/layouts/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ const config = useRuntimeConfig().public
const { isAuthenticated } = useKeycloak()
useHead({
title: t('page.home.title')
title: accountStore.isStaffOrSbcStaff ? t('page.home.titleStaff') : t('page.home.title')
})
setBreadcrumbs([
{ to: `${config.registryHomeURL}dashboard?accountid=${accountStore.currentAccount.id}`, label: t('labels.bcRegDashboard') },
{ label: t('page.home.h1') }
{
to: `${config.registryHomeURL}dashboard?accountid=${accountStore.currentAccount.id}`,
label: accountStore.isStaffOrSbcStaff ? t('labels.bcRegStaffDashboard') : t('labels.bcRegDashboard')
},
{ label: accountStore.isStaffOrSbcStaff ? t('page.home.h1Staff') : t('page.home.h1') }
])
onMounted(() => {
Expand All @@ -28,7 +31,7 @@ onMounted(() => {
<div class="flex flex-col gap-4 md:flex-row md:justify-between">
<div class="flex flex-col gap-4 md:flex-1">
<h1 class="text-[32px]">
{{ $t('page.home.h1') }}
{{ accountStore.isStaffOrSbcStaff ? t('page.home.h1Staff') : t('page.home.h1') }}
</h1>

<p class="text-gray-700">
Expand Down
5 changes: 4 additions & 1 deletion business-registry-dashboard/app/locales/en-CA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ export default {
resendEmail: 'Resend Email',
removeFromList: 'Remove From List',
removeBusiness: 'Remove Business',
bcRegDashboard: 'BC Registries Dashboard'
bcRegDashboard: 'BC Registries Dashboard',
bcRegStaffDashboard: 'Staff Dashboard'
},
links: {
busCorpAct: {
Expand Down Expand Up @@ -610,7 +611,9 @@ export default {
},
home: {
title: 'My Business Registry',
titleStaff: 'My Staff Business Registry',
h1: 'My Business Registry',
h1Staff: 'My Staff Business Registry',
intro: 'Start B.C. based businesses and keep business records up to date.',
busOrNRSearch: {
label: 'Retrieve an existing business or active Name Request to manage:',
Expand Down
5 changes: 4 additions & 1 deletion business-registry-dashboard/app/locales/fr-CA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ export default {
resendEmail: 'Renvoyer le Courriel',
removeFromList: 'Supprimer de la Liste',
removeBusiness: "Supprimer l'Entreprise",
bcRegDashboard: 'Tableau de Bord des Registres de la CB'
bcRegDashboard: 'Tableau de Bord des Registres de la CB',
bcRegStaffDashboard: 'Tableau de Bord du Personnel'
},
links: {
busCorpAct: {
Expand Down Expand Up @@ -600,7 +601,9 @@ export default {
},
home: {
title: "Mon Registre d'Entreprise",
titleStaff: 'Registre des Entreprises de mon Personnel',
h1: "Mon Registre d'Entreprise",
h1Staff: 'Registre des Entreprises de mon Personnel',
intro: 'Commencer la CB entreprises basées et tenir à jour les dossiers commerciaux.',
busOrNRSearch: {
label: 'Rechercher une Entreprise Existante ou une Demande de Nom Active à Gérer:',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default defineNuxtRouteMiddleware((to) => {
// Check if the route is an account link without locale prefix
if (to.path.startsWith('/account')) {
// Construct the full URL with the en-CA locale prefix
const newUrl = `/en-CA${to.path}`
// Force a full page reload with the new URL to ensure proper locale handling
window.location.href = newUrl

// Prevent Nuxt from handling the navigation since we're doing a full page reload
return abortNavigation()
}
})
10 changes: 10 additions & 0 deletions business-registry-dashboard/app/pages/[...slug].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup lang="ts">
// This is a catch-all route that will handle any undefined routes
// This will handle the intermittent page 404 not found until the middleware is loaded
</script>

<template>
<NuxtLayout name="dashboard">
<DashboardContent />
</NuxtLayout>
</template>
5 changes: 5 additions & 0 deletions business-registry-dashboard/app/pages/account/[orgId].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<NuxtLayout name="dashboard">
<DashboardContent />
</NuxtLayout>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ const parseUrlAndAddAffiliation = async (token: any, base64Token: string) => {
</script>
<template>
<NuxtLayout name="dashboard">
<div>
<BusinessLookup class="-mt-4" />
<TableAffiliatedEntity class="mt-6" />
</div>
<DashboardContent />
</NuxtLayout>
</template>
3 changes: 1 addition & 2 deletions business-registry-dashboard/app/pages/incorporateNow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ onMounted(async () => {
<div>
<SbcLoadingSpinner v-if="isLoading" :overlay="true" />
<template v-else>
<BusinessLookup class="-mt-4" />
<TableAffiliatedEntity class="mt-6" />
<DashboardContent />
</template>
</div>
</NuxtLayout>
Expand Down
5 changes: 1 addition & 4 deletions business-registry-dashboard/app/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ definePageMeta({
</script>
<template>
<NuxtLayout name="dashboard">
<div>
<BusinessLookup class="-mt-4" />
<TableAffiliatedEntity class="mt-6" />
</div>
<DashboardContent />
</NuxtLayout>
</template>
13 changes: 12 additions & 1 deletion business-registry-dashboard/app/stores/affiliations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,18 @@ export const useAffiliationsStore = defineStore('brd-affiliations-store', () =>
affiliations.loading = true

if (!accountStore.currentAccount.id || !$keycloak.authenticated) { return }
const response = await $authApi<{ entities: AffiliationResponse[] }>(`/orgs/${accountStore.currentAccount.id}/affiliations?new=true`)

const route = useRoute()
// Use route param if staff, otherwise use current account
const orgId = (isStaffOrSbcStaff.value && route.params.orgId)
? route.params.orgId
: accountStore.currentAccount.id

if (!orgId) { return }

const response = await $authApi<{ entities: AffiliationResponse[] }>(
`/orgs/${orgId}/affiliations?new=true`
)

let affiliatedEntities: Business[] = []

Expand Down
2 changes: 1 addition & 1 deletion business-registry-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "business-registry-dashboard",
"private": true,
"type": "module",
"version": "0.0.14",
"version": "0.0.15",
"scripts": {
"build-check": "nuxt build",
"build": "nuxt generate",
Expand Down
5 changes: 2 additions & 3 deletions business-registry-dashboard/tests/unit/pages/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { describe, it, expect } from 'vitest'
import { BusinessLookup, TableAffiliatedEntity } from '#components'
import { DashboardContent } from '#components'
import Dashboard from '~/layouts/dashboard.vue'
import { enI18n } from '~~/tests/mocks/i18n'
import Index from '~/pages/index.vue'
Expand All @@ -26,7 +26,6 @@ describe('Index Page', () => {

it('should render child components correctly', async () => {
const wrapper = await mountPage()
expect(wrapper.findComponent(BusinessLookup).exists()).toBe(true)
expect(wrapper.findComponent(TableAffiliatedEntity).exists()).toBe(true)
expect(wrapper.findComponent(DashboardContent).exists()).toBe(true)
})
})
33 changes: 31 additions & 2 deletions business-registry-dashboard/tests/unit/stores/affiliations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ mockNuxtImport('useConnectLaunchdarklyStore', () => {
)
})

// Add mock for useRoute
const mockRoute = { params: {} }
mockNuxtImport('useRoute', () => {
return () => mockRoute
})

describe('useAffiliationsStore', () => {
let store: any

Expand All @@ -169,6 +175,7 @@ describe('useAffiliationsStore', () => {
vi.clearAllMocks()
vi.resetAllMocks()
mockAuthenticated = true
mockRoute.params = {} // Reset route params after each test
})

describe('loadAffiliations', () => {
Expand All @@ -183,11 +190,33 @@ describe('useAffiliationsStore', () => {
const affStore = useAffiliationsStore()

await affStore.loadAffiliations()
await flushPromises()

// Should use accountStore.currentAccount.id since not staff
expect(mockAuthApi).toHaveBeenCalledWith('/orgs/123/affiliations?new=true')
// results mapped to business object
expect(affStore.affiliations.results).toEqual(processedAffiliations)
expect(affStore.affiliations.count).toEqual(4)
})

it('should use route param orgId when user is staff', async () => {
store.currentAccount.accountType = 'STAFF' // Make user staff
mockRoute.params = { orgId: '456' } // Set route param

// wait for getAffiliatedEntities to finish
mockGetStoredFlag.mockReturnValue(true)
mockAuthApi
.mockResolvedValueOnce(mockEntities)
.mockResolvedValueOnce({
affiliationInvitations: []
})

const affStore = useAffiliationsStore()

await affStore.loadAffiliations()
await flushPromises()

expect(mockAuthApi).toHaveBeenCalledTimes(2) // once for affiliations and another for invitations
// Should use route.params.orgId since user is staff
expect(mockAuthApi).toHaveBeenCalledWith('/orgs/456/affiliations?new=true')
// results mapped to business object
expect(affStore.affiliations.results).toEqual(processedAffiliations)
expect(affStore.affiliations.count).toEqual(4)
Expand Down

0 comments on commit 13897c7

Please sign in to comment.