Skip to content

Commit

Permalink
feat: article page
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad committed Jul 13, 2023
1 parent 5ad7e9b commit e2ff0a0
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 29 deletions.
4 changes: 3 additions & 1 deletion desk/src/components/TopBar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<template>
<div class="flex items-center justify-between gap-2 border-b px-6 py-3">
<div
class="flex items-center justify-between gap-2 border-b bg-white px-6 py-3"
>
<div class="space-y-2">
<div class="flex items-center gap-3">
<IconChevronLeft
Expand Down
157 changes: 157 additions & 0 deletions desk/src/pages/desk/knowledge-base/KnowledgeBaseArticle.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<template>
<div class="flex flex-col">
<TopBar
:back-to="{ name: AGENT_PORTAL_KNOWLEDGE_BASE }"
:title="article.data?.title"
class="sticky top-0"
>
<template #right>
<div class="flex gap-2">
<Button
:label="bLabel"
theme="gray"
variant="solid"
@click="bClick"
/>
<Dropdown :options="dOptions">
<Button theme="gray" variant="ghost">
<template #icon>
<IconMoreHorizontal class="h-4 w-4" />
</template>
</Button>
</Dropdown>
</div>
</template>
</TopBar>
<div
class="my-8 place-self-center"
:style="{
width: '742px',
}"
>
<div class="mb-8 flex items-center gap-1.5">
<div class="text-base text-gray-600">
{{ article.data?.category.category_name }}
</div>
<IconChevronRight class="h-3 w-3 text-gray-600" />
<div class="text-base text-gray-800">
{{ article.data?.sub_category.category_name }}
</div>
</div>
<div class="mb-4.5 flex items-center justify-between">
<div class="flex items-center gap-2">
<Avatar
:label="article.data?.author.full_name"
:image="article.data?.author.user_image"
/>
<div class="text-base text-gray-800">
{{ article.data?.author.full_name }}
</div>
<IconDot class="h-4 w-4 text-gray-600" />
<div class="text-xs text-gray-800">
{{ dateFormatted }}
</div>
</div>
<div class="flex items-center gap-2 text-gray-600">
<IconThumbsUp class="h-4 w-4" />
<div class="text-base">
{{ article.data?.helpful }}
</div>
<div class="text-base text-gray-300">|</div>
<IconThumbsDown class="h-4 w-4" />
<div class="text-base">
{{ article.data?.not_helpful }}
</div>
</div>
</div>
<div class="border-b pb-3 text-3xl font-semibold text-gray-900">
{{ article.data?.title }}
</div>
<!-- eslint-disable-next-line vue/no-v-html -->
<div
class="prose-sm my-4 max-w-none"
v-html="article.data?.content"

Check warning on line 73 in desk/src/pages/desk/knowledge-base/KnowledgeBaseArticle.vue

View workflow job for this annotation

GitHub Actions / ESLint - Reviewdog

[eslint] reported by reviewdog 🐶 'v-html' directive can lead to XSS attack. Raw Output: {"ruleId":"vue/no-v-html","severity":1,"message":"'v-html' directive can lead to XSS attack.","line":73,"column":9,"nodeType":"VAttribute","endLine":73,"endColumn":39}
></div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
import { createResource, debounce, Avatar, Button, Dropdown } from "frappe-ui";
import dayjs from "dayjs";
import { AGENT_PORTAL_KNOWLEDGE_BASE } from "@/router";
import { createToast } from "@/utils/toasts";
import TopBar from "@/components/TopBar.vue";
import IconChevronRight from "~icons/lucide/chevron-right";
import IconDot from "~icons/lucide/dot";
import IconMoreHorizontal from "~icons/lucide/more-horizontal";
import IconThumbsDown from "~icons/lucide/thumbs-down";
import IconThumbsUp from "~icons/lucide/thumbs-up";
import IconEdit from "~icons/lucide/edit-3";
import IconTrash from "~icons/lucide/trash-2";
const article = createResource({
url: "helpdesk.helpdesk.doctype.hd_article.api.get_article",
params: {
name: "de99e3d725",
},
auto: true,
});
const dateFormatted = computed(() =>
dayjs(article.data?.creation).format("MMMM D, YYYY")
);
const setValueRes = createResource({
url: "frappe.client.set_value",
onSuccess() {
article.reload();
},
onError(error) {
const msg = error.messages.join(", ");
createToast({
title: "Error updating article",
text: msg,
icon: "x",
iconClasses: "text-red-500",
});
},
});
const publish = debounce(() => {
setValueRes.submit({
doctype: "HD Article",
name: article.data.name,
fieldname: "status",
value: "Published",
});
}, 500);
const unpublish = debounce(() => {
setValueRes.submit({
doctype: "HD Article",
name: article.data.name,
fieldname: "status",
value: "Draft",
});
}, 500);
const bLabel = computed(() =>
article.data?.status === "Published" ? "Unpublish" : "Publish"
);
const bClick = computed(() =>
article.data?.status === "Published" ? unpublish : publish
);
const dOptions = [
{
label: "Edit",
icon: IconEdit,
onClick: () => console.log("Edit"),
},
{
label: "Delete",
icon: IconTrash,
onClick: () => console.log("Delete"),
},
];
</script>
5 changes: 3 additions & 2 deletions desk/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const AGENT_PORTAL_TICKET_LIST = "DeskTickets";
export const AGENT_PORTAL_TICKET_TYPE_LIST = "TicketTypes";
export const AGENT_PORTAL_TICKET_TYPE_NEW = "NewTicketType";
export const AGENT_PORTAL_TICKET_TYPE_SINGLE = "TicketType";
export const AGENT_PORTAL_KNOWLEDGE_BASE = "DeskKBHome";

export const KB_PUBLIC = "Knowledge Base";
export const KB_PUBLIC_ARTICLE = "PortalKBArticle";
Expand Down Expand Up @@ -168,9 +169,9 @@ const routes = [
},
{
path: "kb",
name: "DeskKBHome",
name: AGENT_PORTAL_KNOWLEDGE_BASE,
component: () =>
import("@/pages/desk/knowledge-base/KnowledgeBase.vue"),
import("@/pages/desk/knowledge-base/KnowledgeBaseArticle.vue"),
},
// {
// path: "kb",
Expand Down
18 changes: 18 additions & 0 deletions helpdesk/helpdesk/doctype/hd_article/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import frappe


@frappe.whitelist()
def get_article(name: str):
article = frappe.get_doc("HD Article", name).as_dict()
author = frappe.get_cached_doc("User", article["author"])
sub_category = frappe.get_cached_doc("HD Article Category", article["category"])
category = frappe.get_cached_doc(
"HD Article Category", sub_category.parent_category
)

return {
**article,
"author": author,
"category": category,
"sub_category": sub_category,
}
30 changes: 4 additions & 26 deletions helpdesk/helpdesk/doctype/hd_article/hd_article.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
"published_on",
"author",
"content_section",
"content_type",
"content",
"content_md",
"views",
"helpful",
"not_helpful",
"note"
"not_helpful"
],
"fields": [
{
Expand Down Expand Up @@ -63,30 +60,16 @@
"hidden": 1,
"label": "Not Helpful"
},
{
"allow_in_quick_entry": 1,
"default": "Rich Text",
"fieldname": "content_type",
"fieldtype": "Select",
"label": "Content Type",
"options": "Rich Text\nMarkdown"
},
{
"allow_in_quick_entry": 1,
"fieldname": "content_section",
"fieldtype": "Section Break",
"label": "Content"
},
{
"allow_in_quick_entry": 1,
"fieldname": "content_md",
"fieldtype": "Markdown Editor",
"label": "Content (Markdown)"
},
{
"allow_in_quick_entry": 1,
"fieldname": "content",
"fieldtype": "Text Editor",
"fieldtype": "Text",
"label": "Content"
},
{
Expand All @@ -107,11 +90,6 @@
"fieldname": "column_break_7",
"fieldtype": "Column Break"
},
{
"fieldname": "note",
"fieldtype": "Long Text",
"label": "Note"
},
{
"default": "-1",
"fieldname": "idx",
Expand All @@ -133,7 +111,7 @@
}
],
"links": [],
"modified": "2023-03-27 14:39:39.750824",
"modified": "2023-07-13 20:32:16.298366",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Article",
Expand Down Expand Up @@ -178,4 +156,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}

0 comments on commit e2ff0a0

Please sign in to comment.