add: acepted, delete proposals & delete load
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useLoadsStore } from '../stores/loads';
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
import Spiner from './ui/Spiner.vue';
|
||||
import { getDateMonthDay } from '../helpers/date_formats';
|
||||
import VehicleInfo from './VehicleInfo.vue';
|
||||
@@ -8,7 +9,9 @@
|
||||
|
||||
|
||||
const loadsStore = useLoadsStore();
|
||||
const authStore = useAuthStore();
|
||||
const isLoading = ref(false);
|
||||
const isLoadingActions = ref(false);
|
||||
|
||||
onMounted(() => {
|
||||
getProposalsData()
|
||||
@@ -25,31 +28,117 @@
|
||||
loadsStore.currentLoad = false;
|
||||
}
|
||||
|
||||
const handleAceptedProposal = (proposal) => {
|
||||
const index = loadsStore.proposalsOfLoads.findIndex((p) => p._id === proposal._id);
|
||||
console.log(loadsStore.proposalsOfLoads[index])
|
||||
loadsStore.proposalsOfLoads[index] = {
|
||||
...proposal,
|
||||
is_accepted: true
|
||||
};
|
||||
const handleAceptedProposal = async(proposal) => {
|
||||
|
||||
const load_id = proposal.load._id;
|
||||
|
||||
let loadData = {
|
||||
status : "Completed",
|
||||
contract_start_date: new Date(),
|
||||
carrier: proposal.carrier._id,
|
||||
vehicle: proposal.vehicle._id,
|
||||
}
|
||||
|
||||
isLoadingActions.value = true;
|
||||
let load = await loadsStore.updateLoad(load_id, loadData);
|
||||
|
||||
if(load != null) {
|
||||
const index = loadsStore.loads.findIndex((load) => load._id === load_id);
|
||||
loadsStore.loads[index] = load;
|
||||
const proposal_id = proposal._id;
|
||||
|
||||
let formData = {
|
||||
accepted_by : authStore.user,
|
||||
accepted_date : new Date(),
|
||||
is_accepted : true,
|
||||
}
|
||||
const resp = await loadsStore.updateProposal(proposal_id, formData);
|
||||
if(resp){
|
||||
const index = loadsStore.proposalsOfLoads.findIndex((p) => p._id === proposal_id);
|
||||
loadsStore.proposalsOfLoads[index] = {
|
||||
...proposal,
|
||||
...formData
|
||||
};
|
||||
Swal.fire({
|
||||
title: "Oferta aceptada!",
|
||||
text: "La oferta fue aceptada exitosamente.",
|
||||
icon: "success"
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: "Error!",
|
||||
text: "No se pudo actualizar oferta, intente más tarde.",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: "Error!",
|
||||
text: "No se pudo aceptar oferta, intente más tarde.",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
isLoadingActions.value = false;
|
||||
|
||||
}
|
||||
|
||||
const handleCancelProposal = async(proposal) => {
|
||||
const proposal_id = proposal._id;
|
||||
const load_id = proposal.load._id;
|
||||
const {isConfirmed} = await Swal.fire({
|
||||
title: 'Cancelar oferta!',
|
||||
text: '¿Estás seguro de cancelar esta oferta?',
|
||||
icon: 'question',
|
||||
icon: 'warning',
|
||||
cancelButtonColor: "#d33",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Si',
|
||||
confirmButtonText: 'Si, cancelar',
|
||||
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
|
||||
};
|
||||
let loadData = {
|
||||
status : "Published",
|
||||
contract_start_date: null,
|
||||
carrier: null,
|
||||
vehicle: null,
|
||||
}
|
||||
|
||||
isLoadingActions.value = true;
|
||||
let load = await loadsStore.updateLoad(load_id, loadData);
|
||||
if(load) {
|
||||
const index = loadsStore.loads.findIndex((load) => load._id === load_id);
|
||||
loadsStore.loads[index] = load;
|
||||
let formData = {
|
||||
accepted_by : null,
|
||||
accepted_date : null,
|
||||
is_accepted : false,
|
||||
}
|
||||
const resp = await loadsStore.updateProposal(proposal_id, formData);
|
||||
if(resp) {
|
||||
const index = loadsStore.proposalsOfLoads.findIndex((p) => p._id === proposal._id);
|
||||
loadsStore.proposalsOfLoads[index] = {
|
||||
...proposal,
|
||||
...formData
|
||||
};
|
||||
Swal.fire({
|
||||
title: "Oferta cancelada!",
|
||||
text: "La oferta fue retirada exitosamente.",
|
||||
icon: "success"
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: "Error!",
|
||||
text: "No se pudo retirar oferta, intente más tarde",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: "Error!",
|
||||
text: "Algo salio mal, intente más tarde",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
isLoadingActions.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +178,8 @@
|
||||
{{ proposal.comment }}
|
||||
</div>
|
||||
<VehicleInfo v-if="proposal.vehicle" :vehicle="proposal.vehicle"/>
|
||||
<div class="d-flex justify-content-end gap-3">
|
||||
<Spiner v-if="isLoadingActions"/>
|
||||
<div class="d-flex justify-content-end gap-3" v-else>
|
||||
<div v-if="proposal.is_accepted" class="indicator-check">
|
||||
<i class="fa-solid fa-check"></i>
|
||||
Aceptado
|
||||
|
||||
Reference in New Issue
Block a user