felicity-lims/frontend/vite/src/modules/samples.ts

117 lines
3.1 KiB
TypeScript
Raw Normal View History

2021-11-09 14:48:44 +08:00
import Swal from 'sweetalert2';
2021-11-12 05:30:10 +08:00
import { toRefs, computed, reactive } from 'vue';
2021-11-09 14:48:44 +08:00
import { useMutation } from '@urql/vue';
import {
REINSTATE_SAMPLES,
RECEIVE_SAMPLES,
CANCEL_SAMPLES,
2021-11-12 05:30:10 +08:00
} from '../graphql/analyses.mutations';
2021-11-09 14:48:44 +08:00
import store from '../store';
2021-11-12 05:30:10 +08:00
export default function useSampleComposable(){
2021-11-09 14:48:44 +08:00
const state = reactive({
2021-11-12 05:30:10 +08:00
samples: computed(() => store.getters.getSamples ),
2021-11-09 14:48:44 +08:00
})
// CANCEL_SAMPLES
2021-11-12 05:30:10 +08:00
const { executeMutation: _canceller } = useMutation(CANCEL_SAMPLES);
const cancelSamples = async (samples: string[]) => {
2021-11-09 14:48:44 +08:00
try {
Swal.fire({
title: 'Are you sure?',
text: "You want to cancel these samples",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, cancel now!',
cancelButtonText: 'No, do not cancel!',
}).then((result) => {
if (result.isConfirmed) {
2021-11-12 05:30:10 +08:00
_canceller({ samples }).then(_ => {});
2021-11-09 14:48:44 +08:00
Swal.fire(
'Its Happening!',
'Your samples have been cancelled.',
'success'
).then(_ => location.reload())
}
})
} catch (error) {
2021-11-12 05:30:10 +08:00
console.log(error)
2021-11-09 14:48:44 +08:00
}
}
// REINSTATE_SAMPLES
2021-11-12 05:30:10 +08:00
const { executeMutation: _reinstater } = useMutation(REINSTATE_SAMPLES);
const reInstateSamples = async (samples: string[]) => {
2021-11-09 14:48:44 +08:00
try {
Swal.fire({
title: 'Are you sure?',
text: "You want to reinstate samples",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, reinstate now!',
cancelButtonText: 'No, do not reinstate!',
}).then((result) => {
if (result.isConfirmed) {
2021-11-12 05:30:10 +08:00
_reinstater({ samples }).then(_ => {});
2021-11-09 14:48:44 +08:00
Swal.fire(
'Its Happening!',
'Your samples have been reinstated.',
'success'
).then(_ => location.reload())
}
})
} catch (error) {
2021-11-12 05:30:10 +08:00
console.log(error)
2021-11-09 14:48:44 +08:00
}
}
// RECEIVE_SAMPLES
2021-11-12 05:30:10 +08:00
const { executeMutation: _receiver } = useMutation(RECEIVE_SAMPLES);
const receiveSamples = async (samples: string[]) => {
2021-11-09 14:48:44 +08:00
try {
Swal.fire({
title: 'Are you sure?',
text: "You want to receive samples",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, receice now!',
cancelButtonText: 'No, do not receive!',
}).then((result) => {
if (result.isConfirmed) {
2021-11-12 05:30:10 +08:00
_receiver({ samples }).then(_ => {});
2021-11-09 14:48:44 +08:00
Swal.fire(
'Its Happening!',
2021-11-12 05:30:10 +08:00
'Your samples have been received.',
2021-11-09 14:48:44 +08:00
'success'
).then(_ => location.reload())
}
})
} catch (error) {
console.log(error)
}
}
return {
...toRefs(state),
2021-11-12 05:30:10 +08:00
cancelSamples,
reInstateSamples,
receiveSamples,
2021-11-09 14:48:44 +08:00
}
}