1+ <template >
2+ <div class =" relative" >
3+ <button :class =" getOptionsButtonClass()" v-on:click =" toggleOptionsMenu()" >
4+ <svg aria-label =" Show options" viewBox =" 0 0 13 16" version =" 1.1" width =" 13" height =" 16" role =" img" >
5+ <path fill-rule =" evenodd" d =" M1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3zm5 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3zM13 7.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z" ></path >
6+ </svg >
7+ </button >
8+ <div class =" absolute bg-white border rounded right-0 shadow text-sm whitespace-no-wrap" v-if =" isMenuOpened" >
9+ <button class =" hover:bg-red-300 py-2 px-3" v-on:click =" confirmDeleteJob()" >Delete Job</button >
10+ </div >
11+ </div >
12+ </template >
13+
14+ <script >
15+ import Swal from ' sweetalert2' ;
16+
17+ export default {
18+ props: {
19+ job: {
20+ type: Object ,
21+ required: true ,
22+ },
23+ },
24+
25+ data () {
26+ return {
27+ isMenuOpened: false ,
28+ };
29+ },
30+
31+ methods: {
32+ getOptionsButtonClass () {
33+ const classes = ' p-2 hover:bg-gray-200 rounded-full' ;
34+
35+ return classes + ` ${ this .isMenuOpened ? ' bg-gray-200' : ' ' } ` ;
36+ },
37+
38+ toggleOptionsMenu () {
39+ this .isMenuOpened = ! this .isMenuOpened ;
40+ },
41+
42+ async deleteJob () {
43+ await this .$store .dispatch (' deleteJobs' , {
44+ id: this .job .id ,
45+ });
46+
47+ await this .$store .dispatch (' collectJobs' );
48+ },
49+
50+ async confirmDeleteJob () {
51+ this .toggleOptionsMenu ();
52+
53+ const response = await Swal .fire ({
54+ type: ' warning' ,
55+ title: ' Job Deletion' ,
56+ text: ' Do you want to delete job permanently?' ,
57+ showCancelButton: true ,
58+ confirmButtonText: ' Delete' ,
59+ confirmButtonColor: ' #f56565' ,
60+ });
61+
62+ if (response .value ) {
63+ this .deleteJob ();
64+
65+ await Swal .fire ({
66+ type: ' success' ,
67+ title: ' Job Deleted!' ,
68+ });
69+
70+ const jobsListUrl = this .$store .getters .getUrl (' /jobs' );
71+ const currentUrl = window .location .href ;
72+ if (currentUrl !== jobsListUrl) {
73+ window .location .href = jobsListUrl;
74+ }
75+ }
76+ },
77+ },
78+ }
79+ </script >
0 commit comments