From f81eea7a9f627e340fb164a91f53bdcb8bb33637 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Thu, 1 Feb 2024 15:00:54 +0200 Subject: [PATCH 1/2] Add vacation rules --- client/src/components/SetUserVacations.vue | 9 +++++---- client/src/components/SetVacations.vue | 9 +++++---- client/src/components/UpdateOfficeVacations.vue | 6 +++--- client/src/utils/validators.ts | 5 +++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/client/src/components/SetUserVacations.vue b/client/src/components/SetUserVacations.vue index 71109175..96deca42 100644 --- a/client/src/components/SetUserVacations.vue +++ b/client/src/components/SetUserVacations.vue @@ -23,19 +23,19 @@ v-model="vacation.annual_leaves" label="Annual Leaves" type="number" - :rules="requiredRules" + :rules="vacationRules" > import { $api } from '@/clients' -import { requiredRules, requiredStringRules } from '@/utils' +import { requiredRules, requiredStringRules, vacationRules } from '@/utils' import { onMounted, ref, watchEffect } from 'vue' import { useAsyncState } from '@vueuse/core' import { ApiClientBase } from '@/clients/api/base' @@ -120,6 +120,7 @@ export default { vacation, requiredStringRules, requiredRules, + vacationRules, isLoading, execute } diff --git a/client/src/components/SetVacations.vue b/client/src/components/SetVacations.vue index b067c91f..5a8f0350 100644 --- a/client/src/components/SetVacations.vue +++ b/client/src/components/SetVacations.vue @@ -20,19 +20,19 @@ v-model="office_balance.annual_leaves" type="number" label="Annual Leaves" - :rules="requiredRules" + :rules="vacationRules" > import { $api } from '@/clients' import { ref } from 'vue' -import { requiredStringRules } from '@/utils' +import { vacationRules } from '@/utils' import { useAsyncState } from '@vueuse/core' import { ApiClientBase } from '@/clients/api/base' @@ -94,7 +94,7 @@ export default { reasons, selectedReason, user, - requiredStringRules, + vacationRules, isLoading, execute } diff --git a/client/src/utils/validators.ts b/client/src/utils/validators.ts index e12a93b8..33d0c0bd 100644 --- a/client/src/utils/validators.ts +++ b/client/src/utils/validators.ts @@ -56,3 +56,8 @@ export const requiredStringRules = [ (v: string) => !!v || 'This field is required.' ] export const requiredRules = [(v: string) => !!v || 'This field is required.'] +export const vacationRules = [ + (v: string) => !!v || 'This field is required.', + (v: string) => +v >= 0 || 'The minimum allowed value is 0. ', + (v: string) => +v <= 80 || 'The maximum allowed value is 80. ' +] From 2b0630b5d2999f78f0ef9f05269fd0f781b98f37 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Thu, 1 Feb 2024 15:23:17 +0200 Subject: [PATCH 2/2] Edit vacation rules --- client/src/utils/validators.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/utils/validators.ts b/client/src/utils/validators.ts index 33d0c0bd..1162d871 100644 --- a/client/src/utils/validators.ts +++ b/client/src/utils/validators.ts @@ -59,5 +59,6 @@ export const requiredRules = [(v: string) => !!v || 'This field is required.'] export const vacationRules = [ (v: string) => !!v || 'This field is required.', (v: string) => +v >= 0 || 'The minimum allowed value is 0. ', - (v: string) => +v <= 80 || 'The maximum allowed value is 80. ' + (v: string) => +v <= 80 || 'The maximum allowed value is 80. ', + (v: string) => /^(?!00)\d{1,2}$/.test(v) || 'Invalid value.' ]