From 4228ba5129d1f929a43c606497c883321d78fbaf Mon Sep 17 00:00:00 2001 From: Alexandro Uc Santos Date: Thu, 14 Dec 2023 21:59:45 -0600 Subject: [PATCH] add: delete load --- package-lock.json | 10 +++ package.json | 1 + src/components/CardLoad.vue | 49 ++++++++++++++- src/components/FormLoadModal.vue | 69 ++++++++++++-------- src/components/ProposalsModal.vue | 101 +++++++++++++++++------------- src/helpers/status.js | 4 +- src/stores/loads.js | 23 +++++-- 7 files changed, 179 insertions(+), 78 deletions(-) diff --git a/package-lock.json b/package-lock.json index 299f90b..80c4578 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "axios": "^1.6.2", "pinia": "^2.1.7", "sass": "^1.69.5", + "sweetalert2": "^11.10.1", "vue": "^3.3.4", "vue-multiselect": "^3.0.0-beta.3", "vue-router": "^4.2.5", @@ -996,6 +997,15 @@ "kdbush": "^4.0.2" } }, + "node_modules/sweetalert2": { + "version": "11.10.1", + "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.10.1.tgz", + "integrity": "sha512-qu145oBuFfjYr5yZW9OSdG6YmRxDf8CnkgT/sXMfrXGe+asFy2imC2vlaLQ/L/naZ/JZna1MPAY56G4qYM0VUQ==", + "funding": { + "type": "individual", + "url": "https://github.com/sponsors/limonte" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", diff --git a/package.json b/package.json index 0d4ad48..c447c33 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "axios": "^1.6.2", "pinia": "^2.1.7", "sass": "^1.69.5", + "sweetalert2": "^11.10.1", "vue": "^3.3.4", "vue-multiselect": "^3.0.0-beta.3", "vue-router": "^4.2.5", diff --git a/src/components/CardLoad.vue b/src/components/CardLoad.vue index a4b75fb..4bfec35 100644 --- a/src/components/CardLoad.vue +++ b/src/components/CardLoad.vue @@ -3,6 +3,7 @@ import { getStatusPublished } from '../helpers/status'; import { getStatusLoad } from '../helpers/status'; import { useLoadsStore } from '../stores/loads'; + import Swal from 'sweetalert2' const loadsStore = useLoadsStore(); @@ -11,13 +12,55 @@ type: Object, required: true, } - }) + }); + + const openAttachmentsModal = () => { loadsStore.currentLoad = props.load; loadsStore.openAttachmentsModal = true; } + const handleDeleteLoad = async() => { + Swal.fire({ + title: 'Eliminar carga!', + text: '¿Estás seguro de eliminar esta carga?', + icon: 'warning', + showCancelButton: true, + cancelButtonColor: "#d33", + confirmButtonText: 'Eliminar', + cancelButtonText: 'Cancelar', + }).then(async(result) => { + if(result.isConfirmed) { + Swal.fire({ + title: 'Por favor espere!', + html: 'Eliminando carga...',// add html attribute if you want or remove + allowOutsideClick: false, + didOpen: () => { + Swal.showLoading() + }, + }); + const resp = await loadsStore.deleteLoad(props.load._id); + if(resp != null) { + loadsStore.loads = loadsStore.loads.filter(load => load._id !== props.load._id); + Swal.fire({ + title: "Carga eliminada!", + text: "Tu carga ha sido eliminada exitosamente.", + icon: "success" + }); + } else { + Swal.fire({ + title: "No eliminado!", + text: "Tu carga no se pudo eliminar, intente más tarde.", + icon: "error" + }); + } + } + + }); + + } + const openEditModal = () => { loadsStore.currentLoad = props.load loadsStore.openModalEdit = true; @@ -74,7 +117,7 @@
@@ -455,6 +467,11 @@ justify-content: center; } + .btns-footer { + display: flex; + gap: 1rem; + } + .radius-sm{ border-radius: 5px; } diff --git a/src/components/ProposalsModal.vue b/src/components/ProposalsModal.vue index bca4cdd..ad11900 100644 --- a/src/components/ProposalsModal.vue +++ b/src/components/ProposalsModal.vue @@ -4,6 +4,8 @@ import Spiner from './ui/Spiner.vue'; import { getDateMonthDay } from '../helpers/date_formats'; import VehicleInfo from './VehicleInfo.vue'; + import Swal from 'sweetalert2' + const loadsStore = useLoadsStore(); const isLoading = ref(false); @@ -32,13 +34,23 @@ }; } - const handleCancelProposal = (proposal) => { - const index = loadsStore.proposalsOfLoads.findIndex((p) => p._id === proposal._id); - // console.log(loadsStore.proposalsOfLoads[index]) - loadsStore.proposalsOfLoads[index] = { - ...proposal, - is_accepted: false - }; + const handleCancelProposal = async(proposal) => { + const {isConfirmed} = await Swal.fire({ + title: 'Cancelar oferta!', + text: '¿Estás seguro de cancelar esta oferta?', + icon: 'question', + showCancelButton: true, + confirmButtonText: 'Si', + cancelButtonText: 'No' + }) + if( isConfirmed ) { + const index = loadsStore.proposalsOfLoads.findIndex((p) => p._id === proposal._id); + // console.log(loadsStore.proposalsOfLoads[index]) + loadsStore.proposalsOfLoads[index] = { + ...proposal, + is_accepted: false + }; + } } @@ -59,44 +71,49 @@