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: add confimation dialog and use it to handle discard ticket #2039

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 0 additions & 53 deletions desk/package.json

This file was deleted.

39 changes: 39 additions & 0 deletions desk/src/components/ConfirmationDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<div class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50" v-if="visible">
<div class="bg-white rounded shadow-lg p-6 w-96 max-w-full">
<p class="text-lg mb-4">{{ message }}</p>
<div class="flex justify-end space-x-2">
<button
class="inline-flex items-center justify-center gap-2 transition-colors focus:outline-none text-white bg-gray-900 hover:bg-gray-800 active:bg-gray-700 focus-visible:ring focus-visible:ring-gray-400 h-7 text-base px-2 rounded"
@click="cancel"
>
No
</button>
<button
class="inline-flex items-center justify-center gap-2 transition-colors focus:outline-none text-white bg-gray-900 hover:bg-gray-800 active:bg-gray-700 focus-visible:ring focus-visible:ring-gray-400 h-7 text-base px-2 rounded"
@click="confirm"
>
Yes
</button>
</div>
</div>
</div>
</template>

<script>
export default {
props: {
visible: { type: Boolean, required: true },
message: { type: String, default: "Are you sure?" },
},
methods: {
confirm() {
this.$emit("confirm");
},
cancel() {
this.$emit("cancel");
},
},
};
</script>

46 changes: 39 additions & 7 deletions desk/src/components/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@
label="Discard"
theme="gray"
variant="subtle"
@click="
() => {
editor.commands.clearContent(true);
$emit('clear');
}
"
@click="showConfirmation = true"
/>
<slot name="bottom-right" />
</div>
</div>
</div>
</template>
</FTextEditor>

<!-- Include the ConfirmationDialog component -->
<ConfirmationDialog
:visible="showConfirmation"
message="Are you sure you want to discard your changes?"
@confirm="handleConfirm"
@cancel="handleCancel"
/>
</div>
</template>
<script setup lang="ts">
Expand All @@ -59,6 +62,8 @@ import { TextEditor as FTextEditor, TextEditorFixedMenu } from "frappe-ui";
import { useAuthStore } from "@/stores/auth";
import { UserAvatar } from "@/components";
import { PreserveVideoControls } from "@/tiptap-extensions";
import ConfirmationDialog from "@/components/ConfirmationDialog.vue"; // Import the ConfirmationDialog component
import { useRouter } from "vue-router"; // Import the Vue Router

interface P {
modelValue: string;
Expand All @@ -74,11 +79,16 @@ const props = withDefaults(defineProps<P>(), {
autofocus: false,
});

defineEmits<E>();
const emit = defineEmits<{
(event: "clear"): void;
(event: "update:modelValue", value: string): void;
}>();

const e = ref(null);
const editor = computed(() => e.value.editor);
const authStore = useAuthStore();
const router = useRouter(); // Create a router instance
const showConfirmation = ref(false);
const fixedMenu = [
"Paragraph",
["Heading 2", "Heading 3", "Heading 4", "Heading 5"],
Expand All @@ -91,6 +101,28 @@ const fixedMenu = [
"Code",
];

// Handle confirmation actions
function handleConfirm() {
showConfirmation.value = false;
if (editor.value) {
editor.value.commands.clearContent(true);
}
emit("clear");

// Check if the user is in the Customer Portal
if (window.location.pathname.includes("/my-tickets")) {
// Route to the TicketsCustomer page
router.push({ name: "TicketsCustomer" });
} else {
// Otherwise, route to the TicketsAgent page
router.push({ name: "TicketsAgent" });
}
}

function handleCancel() {
showConfirmation.value = false;
}

defineExpose({
editor,
});
Expand Down
Loading