diff --git a/web-app/src/api/account.ts b/web-app/src/api/account.ts index 601d903..d7e69b4 100644 --- a/web-app/src/api/account.ts +++ b/web-app/src/api/account.ts @@ -1,3 +1,4 @@ +import { type RouteLocation } from 'vue-router' import { ApiClient } from './base' import type { Currency } from './data' import type { Page, PageRequest } from './pagination' @@ -125,9 +126,9 @@ export interface AccountHistoryJournalEntryItem extends AccountHistoryItem { export class AccountApiClient extends ApiClient { readonly path: string - constructor() { + constructor(route: RouteLocation) { super() - this.path = `/profiles/${getSelectedProfile()}/accounts` + this.path = `/profiles/${getSelectedProfile(route)}/accounts` } getAccounts(): Promise { diff --git a/web-app/src/api/profile.ts b/web-app/src/api/profile.ts index 8d41562..ef2e171 100644 --- a/web-app/src/api/profile.ts +++ b/web-app/src/api/profile.ts @@ -1,4 +1,4 @@ -import { useRoute, type RouteLocation } from 'vue-router' +import { type RouteLocation } from 'vue-router' import { ApiClient } from './base' export interface Profile { @@ -35,11 +35,10 @@ export class ProfileApiClient extends ApiClient { /** * Gets the currently selected profile. Throws an error in any case where * the route doesn't contain profile name information. - * @param route The route to get the profile from. Defaults to getting it from - * Vue's `useRoute()` which is available in component contexts. + * @param route The route to get the profile from. * @returns The currently selected profile name, via the current route. */ -export function getSelectedProfile(route: RouteLocation = useRoute()): string { +export function getSelectedProfile(route: RouteLocation): string { if (!('profileName' in route.params)) { throw new Error('No "profileName" route property available.') } diff --git a/web-app/src/api/transaction.ts b/web-app/src/api/transaction.ts index e3c4400..9c45165 100644 --- a/web-app/src/api/transaction.ts +++ b/web-app/src/api/transaction.ts @@ -1,7 +1,6 @@ import { ApiClient } from './base' import type { Currency } from './data' import { type Page, type PageRequest } from './pagination' -import { getSelectedProfile } from './profile' export interface TransactionVendor { id: number @@ -144,9 +143,9 @@ export interface CreateCategoryPayload { export class TransactionApiClient extends ApiClient { readonly path: string - constructor() { + constructor(profileName: string) { super() - this.path = `/profiles/${getSelectedProfile()}` + this.path = `/profiles/${profileName}` } getVendors(): Promise { diff --git a/web-app/src/components/AddValueRecordModal.vue b/web-app/src/components/AddValueRecordModal.vue index 05072da..23f198b 100644 --- a/web-app/src/components/AddValueRecordModal.vue +++ b/web-app/src/components/AddValueRecordModal.vue @@ -8,7 +8,9 @@ import AppButton from './AppButton.vue'; import { AccountApiClient, AccountValueRecordType, type Account, type AccountValueRecord, type AccountValueRecordCreationPayload } from '@/api/account'; import { datetimeLocalToISO, getDatetimeLocalValueForNow } from '@/util/time'; import FileSelector from './FileSelector.vue'; +import { useRoute } from 'vue-router'; +const route = useRoute() const props = defineProps<{ account: Account }>() const modal = useTemplateRef('modal') const savedValueRecord: Ref = ref(undefined) @@ -36,7 +38,7 @@ async function addValueRecord() { type: AccountValueRecordType.BALANCE, value: amount.value } - const api = new AccountApiClient() + const api = new AccountApiClient(route) try { savedValueRecord.value = await api.createValueRecord(props.account.id, payload, attachments.value) modal.value?.close('saved') diff --git a/web-app/src/components/AppButton.vue b/web-app/src/components/AppButton.vue index e4eb125..3de1e53 100644 --- a/web-app/src/components/AppButton.vue +++ b/web-app/src/components/AppButton.vue @@ -1,17 +1,35 @@