mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-05 09:10:26 +00:00
add currency setting support (UI)
This commit is contained in:
parent
d88494af24
commit
01dd5db2ee
3 changed files with 67 additions and 20 deletions
|
@ -2,6 +2,7 @@ package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/repo"
|
"github.com/hay-kot/homebox/backend/internal/repo"
|
||||||
|
@ -36,7 +37,7 @@ func (ctrl *V1Controller) HandleGroupGet() http.HandlerFunc {
|
||||||
|
|
||||||
group, err := ctrl.svc.Group.Get(ctx)
|
group, err := ctrl.svc.Group.Get(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to get group")
|
log.Err(err).Msg("failed to get group")
|
||||||
server.RespondError(w, http.StatusInternalServerError, err)
|
server.RespondError(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -67,10 +68,11 @@ func (ctrl *V1Controller) HandleGroupUpdate() http.HandlerFunc {
|
||||||
|
|
||||||
group, err := ctrl.svc.Group.UpdateGroup(ctx, data)
|
group, err := ctrl.svc.Group.UpdateGroup(ctx, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Err(err).Msg("failed to update group")
|
||||||
server.RespondError(w, http.StatusInternalServerError, err)
|
server.RespondError(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
group.Currency = strings.ToUpper(group.Currency) // TODO: Hack to fix the currency enums being lower case
|
||||||
server.Respond(w, http.StatusOK, group)
|
server.Respond(w, http.StatusOK, group)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/repo"
|
"github.com/hay-kot/homebox/backend/internal/repo"
|
||||||
|
@ -25,6 +26,8 @@ func (svc *GroupService) UpdateGroup(ctx Context, data repo.GroupUpdate) (repo.G
|
||||||
return repo.Group{}, errors.New("currency cannot be empty")
|
return repo.Group{}, errors.New("currency cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.Currency = strings.ToLower(data.Currency)
|
||||||
|
|
||||||
return svc.repos.Groups.GroupUpdate(ctx.Context, ctx.GID, data)
|
return svc.repos.Groups.GroupUpdate(ctx.Context, ctx.GID, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,60 @@
|
||||||
title: "Homebox | Profile",
|
title: "Homebox | Profile",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const api = useUserApi();
|
||||||
|
const confirm = useConfirm();
|
||||||
|
const notify = useNotifier();
|
||||||
|
|
||||||
|
// Currency Selection
|
||||||
|
const currency = ref<Currency>(currencies[0]);
|
||||||
|
|
||||||
|
watch(currency, () => {
|
||||||
|
if (group.value) {
|
||||||
|
group.value.currency = currency.value.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(group.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
const currencyExample = computed(() => {
|
||||||
|
const formatter = new Intl.NumberFormat("en-US", {
|
||||||
|
style: "currency",
|
||||||
|
currency: currency.value ? currency.value.code : "USD",
|
||||||
|
});
|
||||||
|
|
||||||
|
return formatter.format(1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: group } = useAsyncData(async () => {
|
||||||
|
const { data } = await api.group.get();
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sync Initial Currency
|
||||||
|
watch(group, () => {
|
||||||
|
if (group.value) {
|
||||||
|
const found = currencies.find(c => c.code === group.value.currency);
|
||||||
|
if (found) {
|
||||||
|
currency.value = found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function updateGroup() {
|
||||||
|
const { data, error } = await api.group.update({
|
||||||
|
name: group.value.name,
|
||||||
|
currency: group.value.currency,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
notify.error("Failed to update group");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
group.value = data;
|
||||||
|
notify.success("Group updated");
|
||||||
|
}
|
||||||
|
|
||||||
const pubApi = usePublicApi();
|
const pubApi = usePublicApi();
|
||||||
const { data: status } = useAsyncData(async () => {
|
const { data: status } = useAsyncData(async () => {
|
||||||
const { data } = await pubApi.status();
|
const { data } = await pubApi.status();
|
||||||
|
@ -35,10 +89,6 @@
|
||||||
] as Detail[];
|
] as Detail[];
|
||||||
});
|
});
|
||||||
|
|
||||||
const api = useUserApi();
|
|
||||||
const confirm = useConfirm();
|
|
||||||
const notify = useNotifier();
|
|
||||||
|
|
||||||
async function deleteProfile() {
|
async function deleteProfile() {
|
||||||
const result = await confirm.open(
|
const result = await confirm.open(
|
||||||
"Are you sure you want to delete your account? If you are the last member in your group all your data will be deleted. This action cannot be undone."
|
"Are you sure you want to delete your account? If you are the last member in your group all your data will be deleted. This action cannot be undone."
|
||||||
|
@ -113,18 +163,6 @@
|
||||||
passwordChange.current = "";
|
passwordChange.current = "";
|
||||||
passwordChange.loading = false;
|
passwordChange.loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currency Selection
|
|
||||||
const currency = ref<Currency>(currencies[1]);
|
|
||||||
|
|
||||||
const currencyExample = computed(() => {
|
|
||||||
const formatter = new Intl.NumberFormat("en-US", {
|
|
||||||
style: "currency",
|
|
||||||
currency: currency.value ? currency.value.code : "USD",
|
|
||||||
});
|
|
||||||
|
|
||||||
return formatter.format(1000);
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -185,9 +223,13 @@
|
||||||
</BaseSectionHeader>
|
</BaseSectionHeader>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="p-5 pt-0 max-w-lg">
|
<div v-if="group" class="p-5 pt-0">
|
||||||
<FormSelect v-model="currency" label="Currency Format" :items="currencies" />
|
<FormSelect v-model="currency" value="code" label="Currency Format" :items="currencies" />
|
||||||
<p class="m-2 text-sm">Example: {{ currencyExample }}</p>
|
<p class="m-2 text-sm">Example: {{ currencyExample }}</p>
|
||||||
|
|
||||||
|
<div class="mt-4 flex justify-end">
|
||||||
|
<BaseButton @click="updateGroup"> Update Group </BaseButton>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</BaseCard>
|
</BaseCard>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue