Skip to content

Commit

Permalink
Merge pull request #339 from codescalers/development_1.1_vacation_rules
Browse files Browse the repository at this point in the history
Add vacation rules
  • Loading branch information
zaelgohary authored Feb 1, 2024
2 parents d7fbeec + 2b0630b commit d6e1231
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
9 changes: 5 additions & 4 deletions client/src/components/SetUserVacations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
v-model="vacation.annual_leaves"
label="Annual Leaves"
type="number"
:rules="requiredRules"
:rules="vacationRules"
></v-text-field>
<v-text-field
v-model="vacation.leave_excuses"
label="Leave Excuses"
type="number"
:rules="requiredRules"
:rules="vacationRules"
></v-text-field>
<v-text-field
v-model="vacation.emergency_leaves"
label="Emergency Leaves"
type="number"
:rules="requiredRules"
:rules="vacationRules"
></v-text-field>
<v-btn
color="primary"
Expand All @@ -53,7 +53,7 @@
<script lang="ts">
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'
Expand Down Expand Up @@ -120,6 +120,7 @@ export default {
vacation,
requiredStringRules,
requiredRules,
vacationRules,
isLoading,
execute
}
Expand Down
9 changes: 5 additions & 4 deletions client/src/components/SetVacations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
v-model="office_balance.annual_leaves"
type="number"
label="Annual Leaves"
:rules="requiredRules"
:rules="vacationRules"
></v-text-field>
<v-text-field
v-model="office_balance.leave_excuses"
type="number"
label="Leave Excuses"
:rules="requiredRules"
:rules="vacationRules"
></v-text-field>
<v-text-field
v-model="office_balance.emergency_leaves"
type="number"
label="Emergency Leaves"
:rules="requiredRules"
:rules="vacationRules"
></v-text-field>
<v-text-field
v-model="formattedDates"
Expand Down Expand Up @@ -74,7 +74,7 @@
import { $api } from '@/clients'
import type { Api } from '@/types'
import { computed, onMounted, ref } from 'vue'
import { requiredRules } from '@/utils'
import { requiredRules, vacationRules } from '@/utils'
import { formatDate } from '@/utils'
import { useAsyncState } from '@vueuse/core'
Expand Down Expand Up @@ -150,6 +150,7 @@ export default {
selectedDates,
requiredRules,
isLoading,
vacationRules,
toggleDatePicker,
execute
}
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/UpdateOfficeVacations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
v-model="vacation.value"
label="Vacation Type"
type="text"
:rules="requiredStringRules"
:rules="vacationRules"
></v-text-field>
<v-btn
color="primary"
Expand All @@ -46,7 +46,7 @@
<script lang="ts">
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'
Expand Down Expand Up @@ -94,7 +94,7 @@ export default {
reasons,
selectedReason,
user,
requiredStringRules,
vacationRules,
isLoading,
execute
}
Expand Down
6 changes: 6 additions & 0 deletions client/src/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ 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. ',
(v: string) => /^(?!00)\d{1,2}$/.test(v) || 'Invalid value.'
]

0 comments on commit d6e1231

Please sign in to comment.