mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-18 21:22:15 +01:00
fix billable rate input field, fixes ST-203
This commit is contained in:
@@ -5,14 +5,14 @@ import {
|
|||||||
getOrganizationCurrencyString,
|
getOrganizationCurrencyString,
|
||||||
getOrganizationCurrencySymbol,
|
getOrganizationCurrencySymbol,
|
||||||
} from '../../utils/money';
|
} from '../../utils/money';
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
name: string;
|
name: string;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const model = defineModel({
|
const model = defineModel<number | null>({
|
||||||
default: null,
|
default: null,
|
||||||
type: Number,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function cleanUpDecimalValue(value: string) {
|
function cleanUpDecimalValue(value: string) {
|
||||||
@@ -38,15 +38,29 @@ function updateRate(value: string) {
|
|||||||
value = cleanUpDecimalValue(value);
|
value = cleanUpDecimalValue(value);
|
||||||
model.value = parseInt(value);
|
model.value = parseInt(value);
|
||||||
}
|
}
|
||||||
|
} else if (value === '') {
|
||||||
|
model.value = 0;
|
||||||
} else {
|
} else {
|
||||||
// if it doesn't contain a comma or a dot, it's probably a whole number so let's convert it to cents
|
// if it doesn't contain a comma or a dot, it's probably a whole number so let's convert it to cents
|
||||||
model.value = parseInt(cleanUpDecimalValue(value)) * 100;
|
const parsedValue = parseInt(cleanUpDecimalValue(value)) * 100;
|
||||||
|
if (parsedValue) {
|
||||||
|
model.value = parsedValue;
|
||||||
|
} else {
|
||||||
|
model.value = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function formatValue(modelValue: number) {
|
inputValue.value = formatValue(model.value);
|
||||||
const formattedValue = formatCents(modelValue);
|
}
|
||||||
|
function formatValue(modelValue: number | null) {
|
||||||
|
const formattedValue = formatCents(modelValue ?? 0);
|
||||||
return formattedValue.replace(getOrganizationCurrencySymbol(), '').trim();
|
return formattedValue.replace(getOrganizationCurrencySymbol(), '').trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(model, (newValue) => {
|
||||||
|
inputValue.value = formatValue(newValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
const inputValue = ref(formatValue(model.value));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -54,7 +68,7 @@ function formatValue(modelValue: number) {
|
|||||||
<TextInput
|
<TextInput
|
||||||
:id="name"
|
:id="name"
|
||||||
ref="projectMemberRateInput"
|
ref="projectMemberRateInput"
|
||||||
:modelValue="formatValue(model)"
|
v-model="inputValue"
|
||||||
@blur="updateRate($event.target.value)"
|
@blur="updateRate($event.target.value)"
|
||||||
type="text"
|
type="text"
|
||||||
:name="name"
|
:name="name"
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const project = ref<CreateProjectBody>({
|
|||||||
name: '',
|
name: '',
|
||||||
color: getRandomColor(),
|
color: getRandomColor(),
|
||||||
client_id: null,
|
client_id: null,
|
||||||
|
billable_rate: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
@@ -35,6 +36,7 @@ async function submit() {
|
|||||||
name: '',
|
name: '',
|
||||||
color: getRandomColor(),
|
color: getRandomColor(),
|
||||||
client_id: null,
|
client_id: null,
|
||||||
|
billable_rate: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
|
|
||||||
defineProps({
|
defineProps<{
|
||||||
modelValue: String,
|
name?: string;
|
||||||
name: String,
|
}>();
|
||||||
});
|
|
||||||
|
|
||||||
const input = ref<HTMLInputElement | null>(null);
|
const input = ref<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
@@ -15,21 +14,13 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
defineExpose({ focus: () => input.value?.focus() });
|
defineExpose({ focus: () => input.value?.focus() });
|
||||||
|
const model = defineModel();
|
||||||
const emit = defineEmits(['update:modelValue']);
|
|
||||||
|
|
||||||
function updateValue(event: Event) {
|
|
||||||
if (event.target && 'value' in event.target) {
|
|
||||||
emit('update:modelValue', event?.target?.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<input
|
<input
|
||||||
ref="input"
|
ref="input"
|
||||||
class="border-input-border border bg-input-background text-white focus:ring-input-border-active focus:ring-0 focus-visible:border-input-border-active rounded-md shadow-sm"
|
class="border-input-border border bg-input-background text-white focus:ring-input-border-active focus:ring-0 focus-visible:border-input-border-active rounded-md shadow-sm"
|
||||||
:value="modelValue"
|
v-model="model"
|
||||||
:name="name"
|
:name="name" />
|
||||||
@input="updateValue" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user