Skip to content

Commit

Permalink
refactor: init agent-list-view
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Nov 26, 2024
1 parent e2d4ee9 commit 982b48f
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 126 deletions.
122 changes: 0 additions & 122 deletions desk/src/pages/desk/agent/AgentList.vue

This file was deleted.

105 changes: 105 additions & 0 deletions desk/src/pages/desk/agent/Agents.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<div class="flex flex-col">
<LayoutHeader>
<template #left-header>
<div class="text-lg font-medium text-gray-900">Agents</div>
</template>
<template #right-header>
<Button
label="New agent"
theme="gray"
variant="solid"
@click="isDialogVisible = !isDialogVisible"
>
<template #prefix>
<LucidePlus class="h-4 w-4" />
</template>
</Button>
</template>
</LayoutHeader>
<!-- <ViewControls
:filter="{ filters: filters, filterableFields: filterableFields.data }"
:sort="{ sorts: sorts, sortableFields: sortableFields.data }"
:column="{
fields: fields,
columns: columns,
}"
/> -->
<AddNewAgentsDialog
:show="isDialogVisible"
@close="isDialogVisible = false"
/>
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { usePageMeta, Avatar, Badge } from "frappe-ui";
import AddNewAgentsDialog from "@/components/desk/global/AddNewAgentsDialog.vue";
import LayoutHeader from "@/components/LayoutHeader.vue";
import { createResource } from "frappe-ui";
// import ViewControls from "@/components/ViewControls.vue";
const isDialogVisible = ref(false);
const agents = createResource({
url: "helpdesk.api.doc.get_list_data",
params: {
doctype: "HD Agent",
},
auto: true,
onSuccess: (response) => {
console.log(response);
},
});
const filterableFields = createResource({
url: "helpdesk.api.doc.get_filterable_fields",
cache: ["DocField", "HD Agent"],
auto: true,
params: {
doctype: "HD Agent",
append_assign: true,
},
transform: (data) => {
return data
.sort((fieldA, fieldB) => {
const labelA = fieldA.label.toUpperCase();
const labelB = fieldB.label.toUpperCase();
if (labelA < labelB) {
return -1;
}
if (labelA > labelB) {
return 1;
}
return 0;
})
.map((field) => {
return {
label: field.label,
value: field.fieldname,
...field,
};
});
},
onSuccess: (response) => {
console.log("FIL FIELDS", response);
},
});
const sortableFields = createResource({
url: "helpdesk.api.doc.sort_options",
auto: true,
params: {
doctype: "HD Agent",
},
onSuccess: (response) => {
console.log("SORT FIELDS", response);
},
});
usePageMeta(() => {
return {
title: "Agents",
};
});
</script>
2 changes: 1 addition & 1 deletion desk/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const routes = [
{
path: "agents",
name: AGENT_PORTAL_AGENT_LIST,
component: () => import("@/pages/desk/agent/AgentList.vue"),
component: () => import("@/pages/desk/agent/Agents.vue"),
},
{
path: "teams",
Expand Down
6 changes: 5 additions & 1 deletion helpdesk/api/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ def get_list_data(
# flake8: noqa
if is_default:
if hasattr(list, "default_list_data"):
columns = list.default_list_data(show_customer_portal_fields).get("columns")
columns = (
list.default_list_data(show_customer_portal_fields).get("columns")
if doctype == "HD Ticket"
else list.default_list_data().get("columns")
)
rows = list.default_list_data().get("rows")

# check if rows has all keys from columns if not add them
Expand Down
33 changes: 31 additions & 2 deletions helpdesk/helpdesk/doctype/hd_agent/hd_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,41 @@ def before_save(self):

def set_user_roles(self):
user = frappe.get_doc("User", self.user)

for role in ["Agent"]:
user.append("roles", {"role": role})

user.save()

@staticmethod
def default_list_data():
columns = [
{
"label": "Name",
"key": "name",
"width": "w-80",
},
{
"label": "Email",
"key": "email",
"width": "w-80",
},
{
"label": "Username",
"key": "user.username",
"width": "w-80",
},
]
rows = [
"name",
"is_active",
"user.full_name",
"user.user_image",
"user.email",
"user.username",
"modified",
"creation",
]
return {"columns": columns, "rows": rows}


@frappe.whitelist()
def create_hd_agent(first_name, last_name, email, signature, team):
Expand Down

0 comments on commit 982b48f

Please sign in to comment.