implement selecting dynamic currency options

This commit is contained in:
Hayden 2024-01-05 11:59:08 -06:00
parent fa676d6351
commit b4151f03c8
No known key found for this signature in database
GPG key ID: 17CF79474E257545
3 changed files with 34 additions and 5 deletions

View file

@ -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().

View file

@ -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"),
});
}
}

View file

@ -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;
}