From ce6cdb51d3a82cbc26b0416f7411acc712a8cfb5 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Sat, 22 Feb 2025 09:32:17 +0100 Subject: [PATCH] add constant, remove some unused code --- .../Contributions/ContributionForm.vue | 10 +++-- .../ContributionListItem.spec.js | 6 --- .../Contributions/ContributionListItem.vue | 10 ++--- .../Contributions/OpenCreationsAmount.vue | 43 +++++++++---------- frontend/src/constants.js | 1 + frontend/src/pages/Community.vue | 3 +- 6 files changed, 33 insertions(+), 40 deletions(-) create mode 100644 frontend/src/constants.js diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index d879b7676..19540c514 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -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) diff --git a/frontend/src/components/Contributions/ContributionListItem.spec.js b/frontend/src/components/Contributions/ContributionListItem.spec.js index 6140a9147..5abb1f8b6 100644 --- a/frontend/src/components/Contributions/ContributionListItem.spec.js +++ b/frontend/src/components/Contributions/ContributionListItem.spec.js @@ -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(() => { diff --git a/frontend/src/components/Contributions/ContributionListItem.vue b/frontend/src/components/Contributions/ContributionListItem.vue index 6c80a9439..a08af2e4c 100644 --- a/frontend/src/components/Contributions/ContributionListItem.vue +++ b/frontend/src/components/Contributions/ContributionListItem.vue @@ -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, diff --git a/frontend/src/components/Contributions/OpenCreationsAmount.vue b/frontend/src/components/Contributions/OpenCreationsAmount.vue index fe49a01a7..2b15bdc52 100644 --- a/frontend/src/components/Contributions/OpenCreationsAmount.vue +++ b/frontend/src/components/Contributions/OpenCreationsAmount.vue @@ -32,32 +32,29 @@ -