This commit is contained in:
Viet An
2026-06-10 20:10:55 +07:00
parent 8ba1a0b5cf
commit 7325230280
5 changed files with 45 additions and 194 deletions

View File

@@ -183,9 +183,6 @@
</template>
<script setup lang="ts">
import { ref, watch, onMounted } from "vue";
import axios from "axios";
import { useNuxtApp } from "nuxt/app";
import { apiUrl, putApiUrl } from "~/components/marketing/email/Email.utils";
const props = defineProps({
@@ -223,10 +220,10 @@ const fetchJobs = async () => {
}
isLoading.value = true;
try {
const response = await axios.get(`${apiUrl}/Email_Job/`, {
const response = await $fetch(`${apiUrl}/Email_Job/`, {
params: { template_id: props.templateId },
});
jobs.value = response.data.rows || [];
jobs.value = response.rows || [];
} catch (error) {
console.error("Error fetching email jobs:", error);
$snackbar(`Error fetching jobs`);
@@ -260,14 +257,17 @@ const closeForm = () => {
const saveJob = async () => {
isSaving.value = true;
try {
let response;
const data = { ...jobForm.value };
if (isEditing.value) {
response = await axios.put(`${putApiUrl}/Email_Job/${data.id}`, data);
} else {
response = await axios.post(`${apiUrl}/Email_Job/`, data);
}
if (response.status === 200 || response.status === 201) {
const response = isEditing.value
? await $fetch(`${putApiUrl}/Email_Job/${data.id}`, {
method: "PUT",
body: data,
})
: await $fetch(`${apiUrl}/Email_Job/`, {
method: "POST",
body: data,
});
if (response) {
$snackbar(`Job saved successfully`);
await fetchJobs();
closeForm();
@@ -283,7 +283,10 @@ const saveJob = async () => {
const toggleJobStatus = async (job: any) => {
const updatedJob = { ...job, active: !job.active };
try {
await axios.put(`${putApiUrl}/Email_Job/${job.id}`, updatedJob);
await $fetch(`${putApiUrl}/Email_Job/${job.id}`, {
method: "PUT",
body: updatedJob,
});
$snackbar(`Job status updated`);
await fetchJobs();
} catch (error) {
@@ -300,7 +303,9 @@ const confirmDelete = (job: any) => {
const deleteJob = async (jobId: number) => {
try {
await axios.delete(`${putApiUrl}/Email_Job/${jobId}`);
await $fetch(`${putApiUrl}/Email_Job/${jobId}`, {
method: "DELETE",
});
$snackbar(`Job deleted successfully`);
await fetchJobs();
} catch (error) {