mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-22 00:25:43 +00:00
implement selecting dynamic currency options
This commit is contained in:
parent
fa676d6351
commit
b4151f03c8
3 changed files with 34 additions and 5 deletions
|
@ -133,6 +133,10 @@ func run(cfg *config.Config) error {
|
|||
}
|
||||
|
||||
if cfg.CurrencyConfig != "" {
|
||||
log.Info().
|
||||
Str("path", cfg.CurrencyConfig).
|
||||
Msg("loading currency config file")
|
||||
|
||||
content, err := os.ReadFile(cfg.CurrencyConfig)
|
||||
if err != nil {
|
||||
log.Fatal().
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
import { BaseAPI, route } from "../base";
|
||||
import { Group, GroupInvitation, GroupInvitationCreate, GroupUpdate } from "../types/data-contracts";
|
||||
import {
|
||||
CurrenciesCurrency,
|
||||
Group,
|
||||
GroupInvitation,
|
||||
GroupInvitationCreate,
|
||||
GroupUpdate,
|
||||
} from "../types/data-contracts";
|
||||
|
||||
export class GroupApi extends BaseAPI {
|
||||
createInvitation(data: GroupInvitationCreate) {
|
||||
|
@ -21,4 +27,10 @@ export class GroupApi extends BaseAPI {
|
|||
url: route("/groups"),
|
||||
});
|
||||
}
|
||||
|
||||
currencies() {
|
||||
return this.http.get<CurrenciesCurrency[]>({
|
||||
url: route("/currencies"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { Detail } from "~~/components/global/DetailsSection/types";
|
||||
import { themes } from "~~/lib/data/themes";
|
||||
import { currencies, Currency } from "~~/lib/data/currency";
|
||||
import { NotifierCreate, NotifierOut } from "~~/lib/api/types/data-contracts";
|
||||
|
||||
definePageMeta({
|
||||
|
@ -15,9 +14,23 @@
|
|||
const confirm = useConfirm();
|
||||
const notify = useNotifier();
|
||||
|
||||
// Currency Selection
|
||||
const currency = ref<Currency>(currencies[0]);
|
||||
const currencies = computedAsync(async () => {
|
||||
const resp = await api.group.currencies();
|
||||
if (resp.error) {
|
||||
notify.error("Failed to get currencies");
|
||||
return [];
|
||||
}
|
||||
|
||||
return resp.data;
|
||||
});
|
||||
|
||||
// Currency Selection
|
||||
const currency = ref<typeof currencies.value[number]>({
|
||||
code: "USD",
|
||||
name: "United States Dollar",
|
||||
local: "en-US",
|
||||
symbol: "$",
|
||||
});
|
||||
watch(currency, () => {
|
||||
if (group.value) {
|
||||
group.value.currency = currency.value.code;
|
||||
|
@ -45,7 +58,7 @@
|
|||
}
|
||||
|
||||
// @ts-expect-error - typescript is stupid, it should know group.value is not null
|
||||
const found = currencies.find(c => c.code === group.value.currency);
|
||||
const found = currencies.value.find(c => c.code === group.value.currency);
|
||||
if (found) {
|
||||
currency.value = found;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue