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

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