From 098ead8da6f6703d6c9539ed6f4a4cdbda1da087 Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Tue, 13 May 2025 18:51:36 +0200 Subject: [PATCH] change billable rate input to use shadcn component --- .../Common/Member/MemberEditModal.vue | 1 - .../Common/Project/ProjectEditModal.vue | 4 +- .../ui/src/Input/BillableRateInput.vue | 98 +++++-------------- .../ui/src/Project/ProjectCreateModal.vue | 2 +- .../Project/ProjectEditBillableSection.vue | 4 +- 5 files changed, 29 insertions(+), 80 deletions(-) diff --git a/resources/js/Components/Common/Member/MemberEditModal.vue b/resources/js/Components/Common/Member/MemberEditModal.vue index 93a98faf..39e5270c 100644 --- a/resources/js/Components/Common/Member/MemberEditModal.vue +++ b/resources/js/Components/Common/Member/MemberEditModal.vue @@ -154,7 +154,6 @@ const roleDescription = computed(() => { class="flex-1"> +
-import TextInput from '@/packages/ui/src/Input/TextInput.vue'; -import { formatCents } from '@/packages/ui/src/utils/money'; -import { ref, watch, inject, type ComputedRef } from 'vue'; +import { ref } from 'vue'; import { useFocus } from '@vueuse/core'; -import type { Organization } from '@/packages/api/src'; +import { + NumberField, + NumberFieldContent, + NumberFieldDecrement, + NumberFieldIncrement, + NumberFieldInput, +} from '@/Components/ui/number-field'; const props = defineProps<{ name: string; @@ -11,8 +15,6 @@ const props = defineProps<{ currency: string; }>(); -const organization = inject>('organization'); - const model = defineModel({ default: null, }); @@ -20,82 +22,32 @@ const model = defineModel({ const billableRateInput = ref(null); useFocus(billableRateInput, { initialValue: props.focus }); -function cleanUpDecimalValue(value: string) { - value = value.replace(/,/g, ''); - value = value.replace(props.currency, ''); - return value.replace(/\./g, ''); -} - -function updateRate(value: string) { - value = value.trim(); - if (value.includes(',')) { - const parts = value.split(','); - const lastPart = (parts[parts.length - 1] = parts[parts.length - 1]); - if (lastPart.length === 2) { - // we detected a decimal number with 2 digits after the comma - value = cleanUpDecimalValue(value); - model.value = parseInt(value); - } - } else if (value.includes('.')) { - const parts = value.split('.'); - const lastPart = (parts[parts.length - 1] = parts[parts.length - 1]); - if (lastPart.length === 2) { - value = cleanUpDecimalValue(value); - model.value = parseInt(value); - } - } else if (value === '') { - model.value = 0; - } else { - // if it doesn't contain a comma or a dot, it's probably a whole number so let's convert it to cents - const parsedValue = parseInt(cleanUpDecimalValue(value)) * 100; - if (parsedValue) { - model.value = parsedValue; - } else { - model.value = 0; - } - } - inputValue.value = formatValue(model.value); -} - function formatValue(modelValue: number | null) { - const formattedValue = formatCents( - modelValue ?? 0, - props.currency, - organization?.value?.currency_format, - organization?.value?.currency_symbol, - organization?.value?.number_format - ); - return formattedValue - ?.replace(organization?.value?.currency_symbol ?? '', '') - .trim(); + return modelValue ? modelValue / 100 : 0; } - -watch(model, (newValue) => { - inputValue.value = formatValue(newValue); -}); - -const inputValue = ref(formatValue(model.value)); diff --git a/resources/js/packages/ui/src/Project/ProjectCreateModal.vue b/resources/js/packages/ui/src/Project/ProjectCreateModal.vue index 8c88b971..869c7c95 100644 --- a/resources/js/packages/ui/src/Project/ProjectCreateModal.vue +++ b/resources/js/packages/ui/src/Project/ProjectCreateModal.vue @@ -128,7 +128,7 @@ const currentClientName = computed(() => {
-
+
-
+