fix route umkm

This commit is contained in:
arifal
2025-03-04 16:05:21 +07:00
parent 8fcf8859d6
commit 435a19346b
6 changed files with 175 additions and 160 deletions

View File

@@ -60,7 +60,7 @@ class UmkmController extends Controller
$modelInstance = Umkm::find($id); $modelInstance = Umkm::find($id);
// Pastikan model ditemukan // Pastikan model ditemukan
if (!$modelInstance) { if (!$modelInstance) {
return redirect()->route('umkm.index')->with('error', 'Umkm not found'); return redirect()->route('web-umkm.index')->with('error', 'Umkm not found');
} }
// Mengambil dan memetakan village_name dan district_name // Mengambil dan memetakan village_name dan district_name

View File

@@ -181,7 +181,7 @@ class UsersRoleMenuSeeder extends Seeder
], ],
[ [
"name" => "UMKM", "name" => "UMKM",
"url" => "umkm.index", "url" => "web-umkm.index",
"icon" => null, "icon" => null,
"parent_id" => $data->id, "parent_id" => $data->id,
"sort_order" => 4, "sort_order" => 4,

View File

@@ -14,7 +14,7 @@ npm ci --no-audit --no-fund
npm run build npm run build
echo "📦 Installing composer dependencies..." echo "📦 Installing composer dependencies..."
composer install --no-interaction --optimize-autoloader COMPOSER_ALLOW_SUPERUSER=1 composer install --no-interaction --optimize-autoloader
echo "🗄️ Running migrations..." echo "🗄️ Running migrations..."
php artisan migrate --force php artisan migrate --force

View File

@@ -16,10 +16,10 @@ document.addEventListener("DOMContentLoaded", function () {
Loading... Loading...
`; `;
const isEdit = saveButton.classList.contains("btn-edit"); const isEdit = saveButton.classList.contains("btn-edit");
const formData = new FormData(form) const formData = new FormData(form);
const toast = document.getElementById('toastEditUpdate'); const toast = document.getElementById("toastEditUpdate");
const toastBody = toast.querySelector('.toast-body'); const toastBody = toast.querySelector(".toast-body");
const toastHeader = toast.querySelector('.toast-header small'); const toastHeader = toast.querySelector(".toast-header small");
const data = {}; const data = {};
@@ -40,53 +40,88 @@ document.addEventListener("DOMContentLoaded", function () {
.querySelector('meta[name="api-token"]') .querySelector('meta[name="api-token"]')
.getAttribute("content")}`, .getAttribute("content")}`,
"Content-Type": "application/json", "Content-Type": "application/json",
} },
}) })
.then(response => response.json()) .then((response) => response.json())
.then(data => { .then((data) => {
console.log("Response data:", data); console.log("Response data:", data);
if (!data.errors) { if (!data.errors) {
// Remove existing icon (if any) before adding the new one // Remove existing icon (if any) before adding the new one
if (authLogo) { if (authLogo) {
// Hapus ikon yang sudah ada jika ada // Hapus ikon yang sudah ada jika ada
const existingIcon = authLogo.querySelector('.bx'); const existingIcon = authLogo.querySelector(".bx");
if (existingIcon) { if (existingIcon) {
authLogo.removeChild(existingIcon); authLogo.removeChild(existingIcon);
}
// Buat ikon baru
const icon = document.createElement("i");
icon.classList.add("bx", "bxs-check-square");
icon.style.fontSize = "25px";
icon.style.color = "green"; // Pastikan 'green' dalam bentuk string
// Tambahkan ikon ke dalam auth-logo
authLogo.appendChild(icon);
} }
// Buat ikon baru // Set success message for the toast
const icon = document.createElement('i'); toastBody.textContent = isEdit
icon.classList.add('bx', 'bxs-check-square'); ? "Data updated successfully!"
icon.style.fontSize = '25px'; : "Data created successfully!";
icon.style.color = 'green'; // Pastikan 'green' dalam bentuk string toast.classList.add("show"); // Show the toast
setTimeout(() => {
toast.classList.remove("show"); // Hide the toast after 3 seconds
}, 2000);
// Tambahkan ikon ke dalam auth-logo setTimeout(() => {
authLogo.appendChild(icon); window.location.href = "/data/web-umkm";
}, 1000);
} else {
if (authLogo) {
// Hapus ikon yang sudah ada jika ada
const existingIcon = authLogo.querySelector(".bx");
if (existingIcon) {
authLogo.removeChild(existingIcon);
}
// Buat ikon baru
const icon = document.createElement("i");
icon.classList.add("bx", "bxs-error-alt");
icon.style.fontSize = "25px";
icon.style.color = "red"; // Pastikan 'green' dalam bentuk string
// Tambahkan ikon ke dalam auth-logo
authLogo.appendChild(icon);
}
// Enable button and reset its text on error
modalButton.disabled = false;
modalButton.innerHTML = isEdit ? "Update" : "Create";
// Set error message for the toast
toastBody.textContent =
"Error: " + (data.message || "Something went wrong");
toast.classList.add("show"); // Show the toast
setTimeout(() => {
toast.classList.remove("show"); // Hide the toast after 3 seconds
}, 3000);
} }
})
// Set success message for the toast .catch((error) => {
toastBody.textContent = isEdit ? "Data updated successfully!" : "Data created successfully!"; console.error("Error:", error);
toast.classList.add('show'); // Show the toast
setTimeout(() => {
toast.classList.remove('show'); // Hide the toast after 3 seconds
}, 2000);
setTimeout(() => {
window.location.href = '/data/umkm';
}, 1000);
} else {
if (authLogo) { if (authLogo) {
// Hapus ikon yang sudah ada jika ada // Hapus ikon yang sudah ada jika ada
const existingIcon = authLogo.querySelector('.bx'); const existingIcon = authLogo.querySelector(".bx");
if (existingIcon) { if (existingIcon) {
authLogo.removeChild(existingIcon); authLogo.removeChild(existingIcon);
} }
// Buat ikon baru // Buat ikon baru
const icon = document.createElement('i'); const icon = document.createElement("i");
icon.classList.add('bx', 'bxs-error-alt'); icon.classList.add("bx", "bxs-error-alt");
icon.style.fontSize = '25px'; icon.style.fontSize = "25px";
icon.style.color = 'red'; // Pastikan 'green' dalam bentuk string icon.style.color = "red"; // Pastikan 'green' dalam bentuk string
// Tambahkan ikon ke dalam auth-logo // Tambahkan ikon ke dalam auth-logo
authLogo.appendChild(icon); authLogo.appendChild(icon);
@@ -96,47 +131,15 @@ document.addEventListener("DOMContentLoaded", function () {
modalButton.disabled = false; modalButton.disabled = false;
modalButton.innerHTML = isEdit ? "Update" : "Create"; modalButton.innerHTML = isEdit ? "Update" : "Create";
// Set error message for the toast // Set error message for the toast
toastBody.textContent = "Error: " + (data.message || "Something went wrong"); toastBody.textContent =
toast.classList.add('show'); // Show the toast "An error occurred while processing your request.";
toast.classList.add("show"); // Show the toast
setTimeout(() => { setTimeout(() => {
toast.classList.remove('show'); // Hide the toast after 3 seconds toast.classList.remove("show"); // Hide the toast after 3 seconds
}, 3000); }, 3000);
} });
})
.catch(error => {
console.error("Error:", error);
if (authLogo) {
// Hapus ikon yang sudah ada jika ada
const existingIcon = authLogo.querySelector('.bx');
if (existingIcon) {
authLogo.removeChild(existingIcon);
}
// Buat ikon baru
const icon = document.createElement('i');
icon.classList.add('bx', 'bxs-error-alt');
icon.style.fontSize = '25px';
icon.style.color = 'red'; // Pastikan 'green' dalam bentuk string
// Tambahkan ikon ke dalam auth-logo
authLogo.appendChild(icon);
}
// Enable button and reset its text on error
modalButton.disabled = false;
modalButton.innerHTML = isEdit ? "Update" : "Create";
// Set error message for the toast
toastBody.textContent = "An error occurred while processing your request.";
toast.classList.add('show'); // Show the toast
setTimeout(() => {
toast.classList.remove('show'); // Hide the toast after 3 seconds
}, 3000);
});
}); });
// Fungsi fetchOptions untuk autocomplete server-side // Fungsi fetchOptions untuk autocomplete server-side
@@ -145,7 +148,11 @@ document.addEventListener("DOMContentLoaded", function () {
if (inputValue.length < 2) return; if (inputValue.length < 2) return;
let districtValue = document.getElementById("district_name").value; // Ambil kecamatan terpilih let districtValue = document.getElementById("district_name").value; // Ambil kecamatan terpilih
let url = `${GlobalConfig.apiHost}/api/combobox/search-options?query=${encodeURIComponent(inputValue)}&field=${field}`; let url = `${
GlobalConfig.apiHost
}/api/combobox/search-options?query=${encodeURIComponent(
inputValue
)}&field=${field}`;
// Jika field desa, tambahkan kecamatan sebagai filter // Jika field desa, tambahkan kecamatan sebagai filter
if (field === "village_name") { if (field === "village_name") {
@@ -153,30 +160,30 @@ document.addEventListener("DOMContentLoaded", function () {
} }
fetch(url, { fetch(url, {
method: 'GET', method: "GET",
headers: { headers: {
Authorization: `Bearer ${document Authorization: `Bearer ${document
.querySelector('meta[name="api-token"]') .querySelector('meta[name="api-token"]')
.getAttribute("content")}`, .getAttribute("content")}`,
"Content-Type": "application/json", "Content-Type": "application/json",
} },
}) })
.then(response => response.json()) .then((response) => response.json())
.then(data => { .then((data) => {
let dataList = document.getElementById(field + "Options"); let dataList = document.getElementById(field + "Options");
dataList.innerHTML = ""; dataList.innerHTML = "";
data.forEach(item => { data.forEach((item) => {
let option = document.createElement("option"); let option = document.createElement("option");
option.value = item.name; option.value = item.name;
option.dataset.code = item.code; option.dataset.code = item.code;
dataList.appendChild(option); dataList.appendChild(option);
}); });
}) })
.catch(error => console.error("Error fetching options:", error)); .catch((error) => console.error("Error fetching options:", error));
}; };
document.querySelector('.btn-back').addEventListener('click', function() { document.querySelector(".btn-back").addEventListener("click", function () {
window.history.back(); window.history.back();
}); });
}); });

View File

@@ -18,58 +18,61 @@ console.log(dropzonePreviewNode);
url: `${GlobalConfig.apiHost}/api/umkm/import`, url: `${GlobalConfig.apiHost}/api/umkm/import`,
// url: "https://httpbin.org/post", // url: "https://httpbin.org/post",
method: "post", method: "post",
acceptedFiles: ".xls,.xlsx", // Use acceptedFiles for better validation acceptedFiles: ".xls,.xlsx", // Use acceptedFiles for better validation
previewTemplate: previewTemplate, previewTemplate: previewTemplate,
previewsContainer: "#dropzone-preview", previewsContainer: "#dropzone-preview",
autoProcessQueue: false, // Disable auto post autoProcessQueue: false, // Disable auto post
headers: { headers: {
Authorization: `Bearer ${document Authorization: `Bearer ${document
.querySelector('meta[name="api-token"]') .querySelector('meta[name="api-token"]')
.getAttribute("content")}` .getAttribute("content")}`,
}, },
init: function() { init: function () {
// Listen for the success event // Listen for the success event
this.on("success", function(file, response) { this.on("success", function (file, response) {
console.log("File successfully uploaded:", file); console.log("File successfully uploaded:", file);
console.log("API Response:", response); console.log("API Response:", response);
// Show success toast // Show success toast
showToast('bxs-check-square', 'green', response.message); showToast("bxs-check-square", "green", response.message);
document.getElementById("submit-upload").innerHTML = "Upload Files"; document.getElementById("submit-upload").innerHTML =
"Upload Files";
// Tunggu sebentar lalu reload halaman // Tunggu sebentar lalu reload halaman
setTimeout(() => { setTimeout(() => {
window.location.href = "/data/umkm"; window.location.href = "/data/web-umkm";
}, 2000); }, 2000);
}); });
// Listen for the error event // Listen for the error event
this.on("error", function(file, errorMessage) { this.on("error", function (file, errorMessage) {
console.error("Error uploading file:", file); console.error("Error uploading file:", file);
console.error("Error message:", errorMessage); console.error("Error message:", errorMessage);
// Handle the error response // Handle the error response
// Show error toast // Show error toast
showToast('bxs-error-alt', 'red', errorMessage.message); showToast("bxs-error-alt", "red", errorMessage.message);
document.getElementById("submit-upload").innerHTML = "Upload Files"; document.getElementById("submit-upload").innerHTML =
"Upload Files";
}); });
} },
}))); })));
// Add event listener to control the submission manually // Add event listener to control the submission manually
document.querySelector("#submit-upload").addEventListener("click", function() { document.querySelector("#submit-upload").addEventListener("click", function () {
console.log("Ini adalah value dropzone", dropzone.files[0]); console.log("Ini adalah value dropzone", dropzone.files[0]);
const formData = new FormData() const formData = new FormData();
console.log("Dropzonefiles",dropzone.files); console.log("Dropzonefiles", dropzone.files);
this.innerHTML = '<span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span>Loading...'; this.innerHTML =
'<span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span>Loading...';
// Pastikan ada file dalam queue sebelum memprosesnya // Pastikan ada file dalam queue sebelum memprosesnya
if (dropzone.files.length > 0) { if (dropzone.files.length > 0) {
formData.append('file', dropzone.files[0]) formData.append("file", dropzone.files[0]);
console.log("ini adalah form data on submit", ...formData); console.log("ini adalah form data on submit", ...formData);
dropzone.processQueue(); // Ini akan manual memicu upload dropzone.processQueue(); // Ini akan manual memicu upload
} else { } else {
// Show error toast when no file is selected // Show error toast when no file is selected
showToast('bxs-error-alt', 'red', "Please add a file first."); showToast("bxs-error-alt", "red", "Please add a file first.");
document.getElementById("submit-upload").innerHTML = "Upload Files"; document.getElementById("submit-upload").innerHTML = "Upload Files";
} }
}); });
@@ -82,62 +85,68 @@ dropzone.on("addedfile", function (file) {
console.log("Ukuran File:", (file.size / 1024).toFixed(2) + " KB"); console.log("Ukuran File:", (file.size / 1024).toFixed(2) + " KB");
}); });
dropzone.on("complete", function(file) { dropzone.on("complete", function (file) {
dropzone.removeFile(file); dropzone.removeFile(file);
}); });
// Add event listener to download file template // Add event listener to download file template
document.getElementById('downloadtempumkm').addEventListener('click', function() { document
var url = `${GlobalConfig.apiHost}/api/download-template-umkm`; .getElementById("downloadtempumkm")
fetch(url, { .addEventListener("click", function () {
method: 'GET', var url = `${GlobalConfig.apiHost}/api/download-template-umkm`;
headers: { fetch(url, {
Authorization: `Bearer ${document method: "GET",
.querySelector('meta[name="api-token"]') headers: {
.getAttribute("content")}` Authorization: `Bearer ${document
}, .querySelector('meta[name="api-token"]')
}) .getAttribute("content")}`,
.then(response => { },
if (response.ok) { })
return response.blob(); // Jika respons OK, konversi menjadi blob .then((response) => {
} else { if (response.ok) {
return response.json(); // Jika respons gagal, konversi menjadi JSON untuk menangani pesan error return response.blob(); // Jika respons OK, konversi menjadi blob
} } else {
}) return response.json(); // Jika respons gagal, konversi menjadi JSON untuk menangani pesan error
.then((blob) => { }
const url = window.URL.createObjectURL(blob); })
const a = document.createElement('a'); .then((blob) => {
a.style.display = 'none'; const url = window.URL.createObjectURL(blob);
a.href = url; const a = document.createElement("a");
a.download = 'template_umkm.xlsx'; a.style.display = "none";
document.body.appendChild(a); a.href = url;
a.click(); a.download = "template_umkm.xlsx";
window.URL.revokeObjectURL(url); document.body.appendChild(a);
}) a.click();
.catch((error) => { window.URL.revokeObjectURL(url);
console.error("Gagal mendownload file:", error); })
showToast('bxs-error-alt', 'red', "Template file is not already exist."); .catch((error) => {
}) console.error("Gagal mendownload file:", error);
}) showToast(
"bxs-error-alt",
"red",
"Template file is not already exist."
);
});
});
// Function to show toast // Function to show toast
function showToast(iconClass, iconColor, message) { function showToast(iconClass, iconColor, message) {
const toastElement = document.getElementById('toastUploadUmkm'); const toastElement = document.getElementById("toastUploadUmkm");
const toastBody = toastElement.querySelector('.toast-body'); const toastBody = toastElement.querySelector(".toast-body");
const toastHeader = toastElement.querySelector('.toast-header'); const toastHeader = toastElement.querySelector(".toast-header");
// Remove existing icon (if any) before adding the new one // Remove existing icon (if any) before adding the new one
const existingIcon = toastHeader.querySelector('.bx'); const existingIcon = toastHeader.querySelector(".bx");
if (existingIcon) { if (existingIcon) {
toastHeader.querySelector('.auth-logo').removeChild(existingIcon); // Remove the existing icon toastHeader.querySelector(".auth-logo").removeChild(existingIcon); // Remove the existing icon
} }
// Add the new icon to the toast header // Add the new icon to the toast header
const icon = document.createElement('i'); const icon = document.createElement("i");
icon.classList.add('bx', iconClass); icon.classList.add("bx", iconClass);
icon.style.fontSize = '25px'; icon.style.fontSize = "25px";
icon.style.color = iconColor; icon.style.color = iconColor;
toastHeader.querySelector('.auth-logo').appendChild(icon); toastHeader.querySelector(".auth-logo").appendChild(icon);
// Set the toast message // Set the toast message
toastBody.textContent = message; toastBody.textContent = message;
@@ -146,4 +155,3 @@ function showToast(iconClass, iconColor, message) {
const toast = new bootstrap.Toast(toastElement); // Inisialisasi Bootstrap Toast const toast = new bootstrap.Toast(toastElement); // Inisialisasi Bootstrap Toast
toast.show(); toast.show();
} }

View File

@@ -84,7 +84,7 @@ Route::group(['middleware' => 'auth'], function(){
Route::get('/advertisements/bulk-create', [AdvertisementController::class, 'bulkCreate'])->name('advertisements.bulk-create'); Route::get('/advertisements/bulk-create', [AdvertisementController::class, 'bulkCreate'])->name('advertisements.bulk-create');
// Resource route, kecuali create karena dibuat terpisah // Resource route, kecuali create karena dibuat terpisah
Route::resource('/umkm', UmkmController::class)->except(['create', 'show']); Route::resource('/web-umkm', UmkmController::class)->except(['create', 'show']);
// Rute khusus untuk create dan bulk-create // Rute khusus untuk create dan bulk-create
Route::get('/umkm/create', [UmkmController::class, 'create'])->name('umkm.create'); Route::get('/umkm/create', [UmkmController::class, 'create'])->name('umkm.create');