Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ux): response editor #1220

Merged
merged 8 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(ux): response editor
- Add a debounce of `500ms`
- Disable send button conditionally
  • Loading branch information
ssiyad committed May 22, 2023
commit c7a58d861555a3951c099a7d74a432afbbbac185
1 change: 1 addition & 0 deletions desk/src/pages/desk/ticket/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export async function init(id: number) {
},
replyViaAgent: {
method: "reply_via_agent",
debounce: 500,
onSuccess() {
clean();
},
Expand Down
31 changes: 21 additions & 10 deletions desk/src/pages/desk/ticket/editor/BottomSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,19 @@
label="Reply"
appearance="primary"
class="rounded-r-none bg-gray-900 text-white hover:bg-gray-800"
:disabled="isDisabled"
@click="newCommunication"
/>
<Dropdown
:options="dropdownOptions"
:button="{
icon: 'chevron-down',
appearance: 'primary',
class:
'rounded-l-none bg-gray-900 text-white hover:bg-gray-800',
}"
/>
<Dropdown :options="dropdownOptions">
<template #default="{ open }">
<Button
:icon="open ? 'chevron-up' : 'chevron-down'"
appearance="primary"
class="cursor-pointer rounded-l-none bg-gray-900 text-white hover:bg-gray-800"
:disabled="isDisabled"
/>
</template>
</Dropdown>
</div>
</div>
</div>
Expand All @@ -95,7 +97,7 @@
</template>

<script setup lang="ts">
import { ref } from "vue";
import { computed, ref } from "vue";
import {
createResource,
Button,
Expand All @@ -104,6 +106,7 @@ import {
TextEditorFixedMenu,
} from "frappe-ui";
import { useAuthStore } from "@/stores/auth";
import { isEmpty } from "@/utils/editor";
import { editor, ticket, clean } from "../data";
import { TextEditorMenuButtons as menuButtons } from "../../consts";
import CannedResponses from "./CannedResponses.vue";
Expand Down Expand Up @@ -133,16 +136,23 @@ const dropdownOptions = [

const insertRes = createResource({
url: "frappe.client.insert",
debounce: 500,
onSuccess() {
clean();
},
});

const isDisabled = computed(
() =>
isEmpty(editor.content) || ticket.replyViaAgent.loading || insertRes.loading
);

function removeAttachment(name: string) {
editor.attachments = editor.attachments.filter((x) => x.name != name);
}

function newCommunication() {
ticket.replyViaAgent.loading = true;
ticket.replyViaAgent.submit({
attachments: editor.attachments.map((x) => x.name),
cc: editor.cc.join(","),
Expand All @@ -152,6 +162,7 @@ function newCommunication() {
}

function newComment() {
insertRes.loading = true;
insertRes.submit({
doc: {
doctype: "HD Ticket Comment",
Expand Down
4 changes: 2 additions & 2 deletions desk/src/pages/desk/ticket/editor/ResponseEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<template #top>
<TopSection />
</template>
<template #editor="{ editor }">
<TextEditorContent :editor="editor" />
<template #editor="{ editor: e }">
<TextEditorContent :editor="e" />
</template>
<template #bottom>
<BottomSection />
Expand Down
9 changes: 4 additions & 5 deletions desk/src/utils/editor.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { isEmpty as isEmpty_ } from "lodash";

export function strip(content: string) {
const opening = new RegExp(/^<div class='content-block'><div>/);
const closing = new RegExp(/<\/div><\/div>$/);
const opening = new RegExp(/^<p>/);
const closing = new RegExp(/<\/p>$/);

return content.replace(opening, "").replace(closing, "");
}

/**
* Check if the content is empty. This is done by replacing all <div class="content-block">
* with empty strings.
* Check if the content is empty with empty strings
*/
export function isEmpty(content: string) {
return isEmpty_(strip(content).trim());
return isEmpty_(strip(content).trim());
}
Loading