@boobooking/dashboard-ui-components 0.16.2 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -332,15 +332,44 @@ exportOrders() {
332
332
  ```
333
333
 
334
334
  - Запрос — `GET` с cookie сессии (`credentials: 'same-origin'`).
335
- - Promise отклоняется: при ответе не `2xx` (код в тексте ошибки), при
336
- перенаправлении — обычно на страницу входа после истёкшей сессии — и при
337
- сетевой ошибке.
335
+ - Promise отклоняется:
336
+ - при перенаправлении — обычно на страницу входа после истёкшей сессии:
337
+ у ошибки `redirectUrl` — адрес, куда в итоге привёл сервер, `status` —
338
+ `null`;
339
+ - при ответе не `2xx`: `status` — код ответа, `redirectUrl` — `null`;
340
+ - при сетевой ошибке — ошибкой `fetch`, без этих полей.
338
341
  - Имя файла — из `Content-Disposition` (`filename*=UTF-8''…`, затем
339
342
  `filename`), без него — последний сегмент пути адреса, без пути —
340
343
  `download`.
341
344
  - Таймаута нет; уход со страницы скачивание не прерывает. Файл до
342
345
  сохранения целиком в памяти вкладки.
343
346
 
347
+ Ссылка при истёкшей сессии привела бы браузер на страницу входа. Чтобы
348
+ страница вела себя так же, она сама переходит по `redirectUrl`: пакет
349
+ не импортирует ни Inertia, ни роутер. В приложении на Inertia:
350
+
351
+ ```js
352
+ import { router } from '@inertiajs/vue3'
353
+
354
+ exportOrders() {
355
+ this.exportFailure = "";
356
+ this.exportLoading = true;
357
+
358
+ downloadFile(this.exportUrl)
359
+ .catch((error) => {
360
+ if (error.redirectUrl) {
361
+ router.visit(error.redirectUrl);
362
+ return;
363
+ }
364
+
365
+ this.exportFailure = "Попробуйте ещё раз";
366
+ })
367
+ .finally(() => {
368
+ this.exportLoading = false;
369
+ });
370
+ }
371
+ ```
372
+
344
373
  ### ConfirmationModal
345
374
 
346
375
  Модалка подтверждения действия: заголовок, текст, кнопка действия и кнопка
package/dist/index.js CHANGED
@@ -269,8 +269,14 @@ function xe(e) {
269
269
  }
270
270
  async function Se(e) {
271
271
  let t = await fetch(e, { credentials: "same-origin" });
272
- if (t.redirected) throw Error(`downloadFile: сервер перенаправил запрос ${e}`);
273
- if (!t.ok) throw Error(`downloadFile: ответ ${t.status} на ${e}`);
272
+ if (t.redirected) throw Object.assign(/* @__PURE__ */ Error(`downloadFile: сервер перенаправил запрос ${e}`), {
273
+ redirectUrl: t.url,
274
+ status: null
275
+ });
276
+ if (!t.ok) throw Object.assign(/* @__PURE__ */ Error(`downloadFile: ответ ${t.status} на ${e}`), {
277
+ redirectUrl: null,
278
+ status: t.status
279
+ });
274
280
  let n = be(t.headers.get("Content-Disposition")) ?? xe(e) ?? "download", r = URL.createObjectURL(await t.blob()), i = document.createElement("a");
275
281
  i.href = r, i.download = n, i.style.display = "none", document.body.appendChild(i), i.click(), i.remove(), setTimeout(() => URL.revokeObjectURL(r), ye);
276
282
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boobooking/dashboard-ui-components",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "description": "Компоненты дашборда на Vue 3",
5
5
  "keywords": [
6
6
  "vue",