add constant, remove some unused code

This commit is contained in:
einhornimmond 2025-02-22 09:32:17 +01:00
parent 1ab8f75a68
commit ce6cdb51d3
6 changed files with 33 additions and 40 deletions

View File

@ -45,7 +45,7 @@
class="mt-3"
name="amount"
:label="$t('form.amount')"
placeholder="20"
:placeholder="GDD_PER_HOUR"
readonly
type="text"
trim
@ -86,6 +86,7 @@ import ValidatedInput from '@/components/Inputs/ValidatedInput'
import LabeledInput from '@/components/Inputs/LabeledInput'
import { memo as memoSchema } from '@/validationSchemas'
import { object, date as dateSchema, number } from 'yup'
import { GDD_PER_HOUR } from '../../constants'
const props = defineProps({
modelValue: { type: Object, required: true },
@ -123,7 +124,7 @@ const validationSchema = computed(() => {
const maxAmounts = Number(
isThisMonth.value ? parseFloat(props.maxGddThisMonth) : parseFloat(props.maxGddLastMonth),
)
const maxHours = parseFloat(Number(maxAmounts / 20).toFixed(2))
const maxHours = parseFloat(Number(maxAmounts / GDD_PER_HOUR).toFixed(2))
return object({
// The date field is required and needs to be a valid date
@ -143,7 +144,7 @@ const validationSchema = computed(() => {
if (value === undefined || value === null) return true
return /^\d+(\.\d{0,2})?$/.test(value.toString())
}),
amount: number().max(maxAmounts),
amount: number().min(0.01).max(maxAmounts),
})
})
@ -168,7 +169,8 @@ const updateField = (newValue, name) => {
if (typeof name === 'string' && name.length) {
form[name] = newValue
if (name === 'hours') {
form.amount = form.hours ? (form.hours * 20).toFixed(2).toString() : '20'
const amount = form.hours ? (form.hours * GDD_PER_HOUR).toFixed(2) : GDD_PER_HOUR
form.amount = amount.toString()
}
}
emit('update:modelValue', form)

View File

@ -99,12 +99,6 @@ describe('ContributionListItem', () => {
})
})
describe('date', () => {
it('is equal to createdAt', () => {
expect(wrapper.vm.date).toBe(wrapper.vm.createdAt)
})
})
describe('delete contribution', () => {
describe('edit contribution', () => {
beforeEach(() => {

View File

@ -125,8 +125,9 @@ import ContributionMessagesList from '@/components/ContributionMessages/Contribu
import { listContributionMessages } from '@/graphql/queries'
import { useAppToast } from '@/composables/useToast'
import { useI18n } from 'vue-i18n'
import { useLazyQuery, useQuery } from '@vue/apollo-composable'
import { useLazyQuery } from '@vue/apollo-composable'
import AppAvatar from '@/components/AppAvatar.vue'
import { GDD_PER_HOUR } from '../../constants'
const props = defineProps({
id: {
@ -201,10 +202,9 @@ const props = defineProps({
},
})
const { toastError, toastSuccess } = useAppToast()
const { toastError } = useAppToast()
const { t } = useI18n()
const inProcess = ref(true)
const messagesGet = ref([])
const visible = ref(false)
@ -224,8 +224,6 @@ const icon = computed(() => {
return 'bell-fill'
})
const date = computed(() => props.createdAt)
const collapseId = computed(() => 'collapse' + String(props.id))
const username = computed(() => ({
@ -233,7 +231,7 @@ const username = computed(() => ({
initials: `${props.firstName[0]}${props.lastName[0]}`,
}))
const hours = computed(() => parseFloat((props.amount / 20).toFixed(2)))
const hours = computed(() => parseFloat((props.amount / GDD_PER_HOUR).toFixed(2)))
watch(
() => visible.value,

View File

@ -32,32 +32,29 @@
</div>
</div>
</template>
<script>
<script setup>
import { computed } from 'vue'
import { GDD_PER_HOUR } from '../../constants'
const props = defineProps({
minimalDate: { type: Date, required: true },
maxGddLastMonth: { type: Number, required: true },
maxGddThisMonth: { type: Number, required: true },
})
function afterComma(input) {
return parseFloat(input.toFixed(2)).toString()
}
export default {
name: 'OpenCreationsAmount',
props: {
minimalDate: { type: Date, required: true },
maxGddLastMonth: { type: Number, required: true },
maxGddThisMonth: { type: Number, required: true },
},
computed: {
hoursSubmittedThisMonth() {
return afterComma((1000 - this.maxGddThisMonth) / 20)
},
hoursSubmittedLastMonth() {
return afterComma((1000 - this.maxGddLastMonth) / 20)
},
hoursAvailableThisMonth() {
return afterComma(this.maxGddThisMonth / 20)
},
hoursAvailableLastMonth() {
return afterComma(this.maxGddLastMonth / 20)
},
},
}
const hoursSubmittedThisMonth = computed(() =>
afterComma((1000 - props.maxGddThisMonth) / GDD_PER_HOUR),
)
const hoursSubmittedLastMonth = computed(() =>
afterComma((1000 - props.maxGddLastMonth) / GDD_PER_HOUR),
)
const hoursAvailableThisMonth = computed(() => afterComma(props.maxGddThisMonth / GDD_PER_HOUR))
const hoursAvailableLastMonth = computed(() => afterComma(props.maxGddLastMonth / GDD_PER_HOUR))
</script>
<style lang="scss" scoped>

View File

@ -0,0 +1 @@
export const GDD_PER_HOUR = 20

View File

@ -68,6 +68,7 @@ import { createContribution, updateContribution, deleteContribution } from '@/gr
import { listContributions, listAllContributions, openCreations } from '@/graphql/queries'
import { useAppToast } from '@/composables/useToast'
import { useI18n } from 'vue-i18n'
import { GDD_PER_HOUR } from '../constants'
const COMMUNITY_TABS = ['contribute', 'contributions', 'community']
@ -93,7 +94,7 @@ const form = ref({
date: undefined,
memo: '',
hours: '',
amount: 20,
amount: GDD_PER_HOUR,
})
const originalContributionDate = ref('')
const updateAmount = ref('')