changes
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -93,8 +93,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, nextTick } from "vue";
|
||||
import axios from "axios";
|
||||
import { useNuxtApp } from "nuxt/app";
|
||||
import { apiUrl, putApiUrl } from "~/components/marketing/email/Email.utils";
|
||||
|
||||
@@ -167,7 +165,7 @@ const handleSave = async () => {
|
||||
const isUpdate = isEditMode.value && props.id;
|
||||
|
||||
try {
|
||||
dataEmailList.value = await axios.get(apiUrlPost).then((res) => res.data.rows);
|
||||
dataEmailList.value = await $fetch(apiUrlPost).then((res) => res.data.rows);
|
||||
let response;
|
||||
|
||||
if (dataEmailList.value.some((item) => item.name === data.value.name.trim() && item.id !== props.id)) {
|
||||
@@ -176,19 +174,18 @@ const handleSave = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const body = {
|
||||
name: data.value.name.trim(),
|
||||
email: data.value.email,
|
||||
};
|
||||
|
||||
if (isUpdate) {
|
||||
response = await axios.put(`${apiUrlPut}${props.id}`, {
|
||||
name: data.value.name.trim(),
|
||||
email: data.value.email,
|
||||
});
|
||||
response = await $fetch(`${apiUrlPut}${props.id}`, { method: "PUT", body });
|
||||
} else {
|
||||
response = await axios.post(apiUrlPost, {
|
||||
name: data.value.name.trim(),
|
||||
email: data.value.email,
|
||||
});
|
||||
response = await $fetch(apiUrlPost, { method: "POST", body });
|
||||
}
|
||||
|
||||
if (response.status === 200 || response.status === 201 || response.status === 204) {
|
||||
if (response) {
|
||||
$snackbar(isUpdate ? `"${data.value.name}" cập nhật thành công!` : `"${data.value.name}" tạo thành công!`);
|
||||
|
||||
loading.value = false;
|
||||
@@ -198,13 +195,8 @@ const handleSave = async () => {
|
||||
throw new Error(`Failed to ${isUpdate ? "update" : "create"} the Gmail list`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error ${isUpdate ? "cập nhật" : "tạo"} danh sách:`, error);
|
||||
|
||||
const errorMessage = axios.isAxiosError(error)
|
||||
? error.response?.data?.message || `Lỗi khi ${isUpdate ? "cập nhật" : "tạo"} danh sách`
|
||||
: "Đã xảy ra lỗi";
|
||||
|
||||
$snackbar(errorMessage);
|
||||
console.error(`Lỗi khi ${isUpdate ? "cập nhật" : "tạo"} danh sách`, error);
|
||||
$snackbar(`Lỗi khi ${isUpdate ? "cập nhật" : "tạo"} danh sách`);
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
@@ -214,11 +206,14 @@ const handleCreateNew = async () => {
|
||||
const emailListUrl = `${apiUrl}/Email_List/`;
|
||||
|
||||
try {
|
||||
const response = await axios.post(emailListUrl, {
|
||||
name: data.value.name.trim(),
|
||||
email: data.value.email,
|
||||
const response = await $fetch(emailListUrl, {
|
||||
method: "POST",
|
||||
body: {
|
||||
name: data.value.name.trim(),
|
||||
email: data.value.email,
|
||||
},
|
||||
});
|
||||
if (response.status === 200 || response.status === 201) {
|
||||
if (response) {
|
||||
$snackbar("Tạo danh sách email mới thành công!");
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user