Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
feat: Path change to use /{{ Institution Name }}/...
Browse files Browse the repository at this point in the history
  • Loading branch information
C4RR0T02 committed Jul 5, 2023
1 parent e3a8487 commit 642e87e
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 12 deletions.
34 changes: 34 additions & 0 deletions composables/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export const useAuthStore = defineStore('auth', () => {
const pointsAwardedResetTime = ref(new Date(Date.now()))
const godMode = ref(false)

const institutionName = ref('')
const institutionShortName = ref('')
const institutionDescription = ref('')

const authenticated = computed(() => !!email.value)

/**
Expand All @@ -31,6 +35,24 @@ export const useAuthStore = defineStore('auth', () => {
: undefined,
})
populate(res)
await getuserinstitution(cookie)
}
catch (e) {
console.error('[composables/user.ts] failed to init store', e)
return parseError(e)
}
}

async function getuserinstitution(cookie?: string) {
try {
const res = await $api<Institution>('/auth/myinstitution', {
headers: cookie
? {
cookie,
}
: undefined,
})
populateInst(res)
}
catch (e) {
console.error('[composables/user.ts] failed to init store', e)
Expand All @@ -53,6 +75,7 @@ export const useAuthStore = defineStore('auth', () => {
},
})
populate(res)
await getuserinstitution()
}
catch (e) {
console.error('[composables/user.ts] failed to login', e)
Expand Down Expand Up @@ -83,6 +106,7 @@ export const useAuthStore = defineStore('auth', () => {
},
})
populate(res)
await getuserinstitution()
}
catch (e) {
console.error('[composables/user.ts] failed to register', e)
Expand Down Expand Up @@ -116,6 +140,12 @@ export const useAuthStore = defineStore('auth', () => {
}
}

function populateInst(data: Institution) {
institutionName.value = data.name
institutionShortName.value = data.shortName
institutionDescription.value = data.description
}

return {
firstName,
lastName,
Expand All @@ -125,6 +155,10 @@ export const useAuthStore = defineStore('auth', () => {
pointsAwardedResetTime,
godMode,

institutionName,
institutionShortName,
institutionDescription,

authenticated,

init,
Expand Down
2 changes: 1 addition & 1 deletion layouts/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ useAsyncData(async () => {
<header>
<div mx-auto container>
<div flex items-center justify-between px5 py8>
<NuxtLink to="/">
<NuxtLink :to="`/@${auth.institutionShortName}/dashboard`">
<CommonAppLogo h-8 />
</NuxtLink>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ definePageMeta({
middleware: 'god-mode',
})
const router = useRouter()
const group = useGroupStore()
const headers = useRequestHeaders(['cookie'])
useAsyncData(async () => {
Expand All @@ -20,14 +19,14 @@ useAsyncData(async () => {
const groupsMenu = computed(() => {
const i: MenuItem[] = group.groups.map(grp => ({
label: `${grp.name} (${grp.shortName})`,
to: `/dashboard/admin/groups/${grp.shortName}`,
to: `${grp.shortName}`,
}))
i.push({ separator: true })
return i
})
function toCreate() {
router.push('/dashboard/admin/groups')
navigateTo('new')
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ definePageMeta({
const route = useRoute()
const router = useRouter()
const toast = useToast()
const auth = useAuthStore()
const group = useGroupStore()
onMounted(async () => {
Expand Down Expand Up @@ -74,7 +75,7 @@ async function update() {
summary: 'Success',
detail: 'Group updated',
})
navigateTo(`/dashboard/admin/groups/${formData.value.shortName}`)
navigateTo(`/@${auth.institutionShortName}/manage/groups/${formData.value.shortName}`)
}
}
Expand All @@ -89,7 +90,7 @@ async function del() {
summary: 'Success',
detail: 'Group deleted',
})
navigateTo('/dashboard/admin/groups')
navigateTo(`/@${auth.institutionShortName}/manage/groups`)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ definePageMeta({
const toast = useToast()
const auth = useAuthStore()
const group = useGroupStore()
const headers = useRequestHeaders(['cookie'])
useAsyncData(async () => {
Expand Down Expand Up @@ -45,7 +46,7 @@ async function create() {
summary: 'Success',
detail: 'Group created',
})
navigateTo(`/dashboard/admin/groups/${formData.value.shortName}`)
navigateTo(`/@${auth.institutionShortName}/manage/groups/${formData.value.shortName}`)
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ interface AdminPages {
const adminPages = [
{
text: 'Manage Group',
link: '/dashboard/admin/groups',
link: 'manage/groups/new',
},
{
text: 'View available Pet Accessories and Vouchers',
link: '/dashboard/admin/rewards',
link: 'manage/rewards',
},
{
text: 'Modify Pet Accessories and Vouchers',
link: '/dashboard/admin/add-rewards',
link: 'manage/add-rewards',
},
] satisfies AdminPages[]
</script>
Expand Down
2 changes: 1 addition & 1 deletion pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function login() {
formData.isLoading = true
const err = await auth.login(formData.email, formData.password)
if (!err)
return navigateTo('/dashboard')
return navigateTo(`/@${auth.institutionShortName}/dashboard`)
formData.error = err
formData.isLoading = false
}
Expand Down
2 changes: 1 addition & 1 deletion pages/s/[code].vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function register() {
formData.firstName, formData.lastName, formData.email, formData.password,
)
if (!err)
return navigateTo('/dashboard')
return navigateTo(`/@${data.value?.institution.shortName}/dashboard`)
formData.error = err
formData.isLoading = false
}
Expand Down

0 comments on commit 642e87e

Please sign in to comment.