Skip to content

Commit

Permalink
Merge pull request #325 from codescalers/development_1.1_offices_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
maayarosama authored Feb 1, 2024
2 parents 2cf9cb1 + 970b01c commit 2ec311f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
43 changes: 24 additions & 19 deletions client/src/components/filters.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<v-row class="ma-1">
<v-row class="ma-1">
<v-col cols="12" class="px-2">
<v-alert color="warning"
>You can change the selected office to discover the team in other offices.</v-alert
Expand All @@ -12,40 +12,45 @@
<h4 class="font-weight-medium">Select Office</h4>
</v-col>
<v-col cols="12" sm="12" md="12" class="pa-1">
<div>
<v-autocomplete
clearable
v-model="office"
:items="offices"
label="Office"
@update:model-value="handleOfficeChange"
return-object
item-title="country"
>
</v-autocomplete>
</div>
</v-col>
<div>
<v-autocomplete clearable v-model="office" :items="offices.state.value" label="Office"
@update:model-value="handleOfficeChange" return-object item-title="country">
</v-autocomplete>
</div>
</v-col>
</v-row>
</div>
</template>

<script lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import type { Country } from '@/types'
import type { Api } from '@/types'
export default {
name: 'officeFilters',
props: ['offices'],
setup() {
setup(props) {
const $router = useRouter()
const office = ref<Country>()
const office = ref<Api.Inputs.Office>()
const $route = useRoute()
const handleOfficeChange = () => {
$router.push({ path: '/users', query: { location_id: office.value?.id } })
}
watch(
() => props.offices.state.value,
async (newValue) => {
if ($route.query.location_id && props.offices.state.value) {
office.value = props.offices.state.value.find((office: any) => office.id === Number($route.query.location_id));
}
},
);
return {
office,
handleOfficeChange
Expand Down
1 change: 1 addition & 0 deletions client/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ export module Api {
}

export type Office = {
id?: number
name: string
country: string
weekend: string
Expand Down
29 changes: 15 additions & 14 deletions client/src/views/UsersView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<script lang="ts">
import type { Api, Country } from '@/types'
import { ref, watch } from 'vue'
import { onMounted, ref, watch } from 'vue'
import { $api } from '@/clients'
import UserCard from '@/components/userCard.vue'
import officeFilters from '@/components/filters.vue'
Expand All @@ -50,36 +50,33 @@ export default {
officeFilters
},
setup() {
const offices = ref<Country[]>([])
const offices = useAsyncState($api.office.list(), [], { immediate: true })
const $route = useRoute()
let isFirstLoad = true
const page = ref(1)
const count = ref<number>(0)
function setCount(data: any) {
if (data?.count) {
count.value = Math.ceil(data?.count / 10)
} else {
count.value = 0
}
}
useAsyncState(
$api.users.list({ location_id: $route.query.location_id, page: page.value }),
undefined,
{
onSuccess(data) {
if (data?.count) {
count.value = data.count / 10
count.value = Math.ceil(data.count / 10)
}
setCount(data)
users.execute(undefined, data?.results || [])
}
}
)
const users = useAsyncState(
async (users: Api.User[]) => {
if (isFirstLoad) {
offices.value = Array.from(new Set(users.map((user) => user.location.id))).map((id) => {
const user = users.find((u) => u.location.id === id)
return { id: user?.location.id ?? 0, country: user?.location.country ?? '' }
})
}
isFirstLoad = false
return users
},
[],
Expand All @@ -95,6 +92,7 @@ export default {
undefined,
{
onSuccess(data) {
setCount(data)
users.execute(undefined, data?.results || [])
}
}
Expand All @@ -110,13 +108,16 @@ export default {
undefined,
{
onSuccess(data) {
setCount(data)
users.execute(undefined, data?.results || [])
}
}
)
}
)
return {
users,
page,
Expand Down

0 comments on commit 2ec311f

Please sign in to comment.