Skip to content

Commit

Permalink
fix: add search functionality single team page
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Jan 30, 2025
1 parent 94cb074 commit 2639ebb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
67 changes: 48 additions & 19 deletions desk/src/pages/desk/team/TeamSingle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@
<Dialog v-model="showDelete" :options="deleteDialogOptions" />
<Dialog v-model="showAddMember" :options="addMemberDialogOptions">
<template #body-content>
<div class="space-y-2">
<div v-if="agentStore.agents.data.length === 0">
<div class="space-y-4">
<FormControl
type="text"
v-model="query"
placeholder="Search agents"
@input="searchMembers()"
/>
<div v-if="_agents.length === 0">
<p class="text-base text-gray-600">
No agents found, please add
<span
Expand All @@ -103,25 +109,30 @@
in the system.
</p>
</div>
<div
v-for="agent in agentStore.agents.data"
v-else
:key="agent.name"
class="flex items-center justify-between"
>
<div class="flex items-center gap-2">
<Avatar :label="agent.agent_name" :image="agent.user_image" />
<div class="text-base">
{{ agent.agent_name }}
<div v-else class="flex flex-col gap-4">
<div class="flex flex-col gap-2">
<div
v-for="agent in _agents"
:key="agent.name"
class="flex items-center justify-between"
>
<div class="flex items-center gap-2">
<Avatar :label="agent.agent_name" :image="agent.user_image" />
<div class="text-base">
{{ agent.agent_name }}
</div>
</div>
<Button
:disabled="
!!team.doc?.users.find((u) => u.user === agent.user)
"
label="Add"
theme="gray"
variant="outline"
@click="addMember(agent.user)"
/>
</div>
</div>
<Button
:disabled="!!team.doc?.users.find((u) => u.user === agent.user)"
label="Add"
theme="gray"
variant="outline"
@click="addMember(agent.user)"
/>
</div>
</div>
</template>
Expand Down Expand Up @@ -151,6 +162,7 @@ import IconMoreHorizontal from "~icons/lucide/more-horizontal";
import IconPlus from "~icons/lucide/plus";
import Pill from "@/components/Pill.vue";
import LayoutHeader from "@/components/LayoutHeader.vue";
import { onMounted } from "vue";
const props = defineProps({
teamId: {
Expand Down Expand Up @@ -262,6 +274,23 @@ function addMember(user: string) {
});
}
// Search members
const query = ref("");
const searchedAgents = ref([]);
const _agents = computed(() => {
return searchedAgents.value.length || query.value.length
? searchedAgents.value
: agentStore.agents.data;
});
function searchMembers() {
const filteredAgents = agentStore.searchAgents(query.value);
searchedAgents.value = filteredAgents;
}
onMounted(() => {
agentStore.agents.reload();
});
function removeMember(member: string) {
const users = team.doc.users.filter((u) => u.user !== member);
team.setValue.submit({
Expand Down
8 changes: 7 additions & 1 deletion desk/src/stores/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const useAgentStore = defineStore("agent", () => {
doctype: "HD Agent",
fields: ["name", "agent_name", "user", "user.user_image"],
filters: { is_active: 1 },
auto: true,
pageLength: 99999,
});

Expand All @@ -18,8 +17,15 @@ export const useAgentStore = defineStore("agent", () => {
}))
);

function searchAgents(query: string) {
return agents.data.filter((a) =>
a.user?.toLowerCase().includes(query.toLowerCase())
);
}

return {
dropdown,
agents,
searchAgents,
};
});

0 comments on commit 2639ebb

Please sign in to comment.