Add service platform foundation
This commit is contained in:
@@ -316,6 +316,7 @@ const state = {
|
||||
latestStats: null,
|
||||
allStats: null,
|
||||
analytics: null,
|
||||
serviceCenters: [],
|
||||
receiptFile: null,
|
||||
serviceWorkerRegistration: null,
|
||||
period: {
|
||||
@@ -798,6 +799,36 @@ function openCarProfile() {
|
||||
document.querySelector("#carProfileSection").scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
}
|
||||
|
||||
async function loadServiceCenters() {
|
||||
state.serviceCenters = await api("/service-centers/my");
|
||||
renderServiceCenters();
|
||||
}
|
||||
|
||||
function renderServiceCenters() {
|
||||
const root = document.querySelector("#serviceCentersList");
|
||||
if (!root) return;
|
||||
if (!state.serviceCenters.length) {
|
||||
root.innerHTML = `<div class="empty">СТО пока не создано</div>`;
|
||||
return;
|
||||
}
|
||||
root.innerHTML = state.serviceCenters
|
||||
.map(
|
||||
(center) => `
|
||||
<div class="stack-item">
|
||||
<strong>${center.display_name || center.name}</strong>
|
||||
<small>${[center.city, center.address].filter(Boolean).join(", ") || "Адрес не указан"}</small>
|
||||
<small>Статус: ${center.verification_status}</small>
|
||||
</div>
|
||||
`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
|
||||
function renderPlaceholderList(selector, message) {
|
||||
const root = document.querySelector(selector);
|
||||
if (root) root.innerHTML = `<div class="empty">${message}</div>`;
|
||||
}
|
||||
|
||||
function renderStats(stats) {
|
||||
const root = document.querySelector("#stats");
|
||||
if (!stats) {
|
||||
@@ -1398,6 +1429,49 @@ document.querySelector("#openNotificationsBtn").addEventListener("click", () =>
|
||||
document.querySelector("#notificationsSection").scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
});
|
||||
|
||||
document.querySelector("#openConfirmationsBtn").addEventListener("click", () => {
|
||||
document.querySelector("#confirmationsSection").classList.remove("hidden");
|
||||
renderPlaceholderList("#confirmationRequests", "Новых запросов нет");
|
||||
document.querySelector("#confirmationsSection").scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
});
|
||||
|
||||
document.querySelector("#openConnectedServicesBtn").addEventListener("click", () => {
|
||||
document.querySelector("#connectedServicesSection").classList.remove("hidden");
|
||||
renderPlaceholderList("#connectedServices", "Подключенных автосервисов пока нет");
|
||||
document.querySelector("#connectedServicesSection").scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
});
|
||||
|
||||
document.querySelector("#openServicePanelBtn").addEventListener("click", async (event) => {
|
||||
await runAction(event.currentTarget, "Загружаю СТО...", async () => {
|
||||
document.querySelector("#servicePanelSection").classList.remove("hidden");
|
||||
await loadServiceCenters();
|
||||
document.querySelector("#servicePanelSection").scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector("#serviceCenterForm").addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
await runAction(form.querySelector('button[type="submit"]'), "Создаю СТО...", async () => {
|
||||
const data = formData(form);
|
||||
await api("/service-centers", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
display_name: data.display_name,
|
||||
legal_name: data.legal_name || null,
|
||||
country: data.country || null,
|
||||
city: data.city || null,
|
||||
address: data.address || null,
|
||||
phone: data.phone || null,
|
||||
business_registration_number: data.business_registration_number || null,
|
||||
}),
|
||||
});
|
||||
form.reset();
|
||||
await loadServiceCenters();
|
||||
toast("СТО создано");
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector("#enableNotificationsBtn").addEventListener("click", enableNotifications);
|
||||
|
||||
document.querySelector("#openScanBtn").addEventListener("click", () => {
|
||||
|
||||
Reference in New Issue
Block a user