@opencitylabs/formio-custom-components 0.6.3 → 0.6.4

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/dist/index.js CHANGED
@@ -5374,6 +5374,12 @@ var bt = {
5374
5374
  });
5375
5375
  }
5376
5376
  }, pe = (e) => {
5377
+ let n = t?.dataValue?.id, r = n ? "PATCH" : "POST", i = n ? `meetings/${n}` : "meetings";
5378
+ return window.FormioHelper.authenticatedRequest(r, i, e).catch((t) => {
5379
+ if ((t?.response?.status === 404 || t?.status === 404) && r === "PATCH") return window.FormioHelper.authenticatedRequest("POST", "meetings", e);
5380
+ throw t;
5381
+ });
5382
+ }, L = (e) => {
5377
5383
  let r = JSON.parse(e), i = {
5378
5384
  status: 6,
5379
5385
  calendar: r.calendar_id,
@@ -5393,7 +5399,7 @@ var bt = {
5393
5399
  calendar_group_office_id: t?.data?.user_group?.id,
5394
5400
  calendar_group_place_id: t?.data?.place?.id
5395
5401
  };
5396
- window.FormioHelper.authenticatedRequest(t?.dataValue?.id ? "PATCH" : "POST", t?.dataValue?.id ? `meetings/${t.dataValue.id}` : "meetings", i).then((e) => {
5402
+ pe(i).then((e) => {
5397
5403
  v({
5398
5404
  day: C(r.date).format("dddd, DD MMMM YYYY"),
5399
5405
  startDate: r.start_time,
@@ -5422,7 +5428,7 @@ var bt = {
5422
5428
  showConfirmButton: !1
5423
5429
  });
5424
5430
  });
5425
- }, L = (e) => {
5431
+ }, me = (e) => {
5426
5432
  let t = /* @__PURE__ */ new Set(), n = [];
5427
5433
  return e.forEach((e) => {
5428
5434
  let r = C(e.date), i = r.format("YYYY-MM");
@@ -5431,10 +5437,10 @@ var bt = {
5431
5437
  label: r.format("MMMM YYYY").replace(/^\w/, (e) => e.toUpperCase())
5432
5438
  }));
5433
5439
  }), n;
5434
- }, me = async () => {
5440
+ }, he = async () => {
5435
5441
  let e = t?.root?.data?.place?.merge_availabilities ? t?.root?.data?.place?.merged_availabilities_link : null, r = p().format("YYYY-MM-DD"), i = p().add(1, "month").format("YYYY-MM-DD"), a = t?.root?.data?.place?.calendars[0]?.id || null, s = e ? ue(e, r, i) : de(r, i, a), c = Ct("AVAILABILITY", s), l = St("AVAILABILITY", c);
5436
5442
  if (l) {
5437
- d(l), ie(L(l));
5443
+ d(l), ie(me(l));
5438
5444
  return;
5439
5445
  } else n({});
5440
5446
  g(!0);
@@ -5448,7 +5454,7 @@ var bt = {
5448
5454
  });
5449
5455
  return;
5450
5456
  }
5451
- xt("AVAILABILITY", c, e), d(e), ie(L(e));
5457
+ xt("AVAILABILITY", c, e), d(e), ie(me(e));
5452
5458
  } catch (e) {
5453
5459
  g(!1), console.error("Errore nel caricamento disponibilità:", e);
5454
5460
  }
@@ -5483,12 +5489,12 @@ var bt = {
5483
5489
  }));
5484
5490
  }
5485
5491
  }, [A]);
5486
- let he = () => window.innerWidth > 768 ? "timeGridWeek" : "timeGridDay";
5492
+ let ge = () => window.innerWidth > 768 ? "timeGridWeek" : "timeGridDay";
5487
5493
  s(() => {
5488
5494
  let e = () => {
5489
5495
  let e = N.current;
5490
5496
  if (!e) return;
5491
- let t = he();
5497
+ let t = ge();
5492
5498
  t !== e.getView().type && e.setOption("view", t);
5493
5499
  };
5494
5500
  return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
@@ -5500,7 +5506,7 @@ var bt = {
5500
5506
  endDate: C(e.to_time).format("HH:mm")
5501
5507
  }));
5502
5508
  }, [E]);
5503
- let ge = () => {
5509
+ let _e = () => {
5504
5510
  let e = Dt();
5505
5511
  N.current = w(ce.current, [oe], {
5506
5512
  events: [],
@@ -5509,7 +5515,7 @@ var bt = {
5509
5515
  firstDay: 1,
5510
5516
  date: e.date,
5511
5517
  slotEventOverlap: !1,
5512
- view: he(),
5518
+ view: ge(),
5513
5519
  height: "400px",
5514
5520
  views: {
5515
5521
  timeGridWeek: {
@@ -5560,7 +5566,7 @@ var bt = {
5560
5566
  calendar_group_office_id: t?.data?.user_group?.id,
5561
5567
  calendar_group_place_id: t?.data?.place?.id
5562
5568
  };
5563
- window.FormioHelper.authenticatedRequest(t?.dataValue?.id ? "PATCH" : "POST", t?.dataValue?.id ? `meetings/${t.dataValue.id}` : "meetings", u).then((e) => {
5569
+ pe(u).then((e) => {
5564
5570
  let r;
5565
5571
  !e || e === "" ? r = {
5566
5572
  ...u,
@@ -5589,7 +5595,7 @@ var bt = {
5589
5595
  });
5590
5596
  });
5591
5597
  },
5592
- viewDidMount: _e,
5598
+ viewDidMount: z,
5593
5599
  eventDidMount: (e) => {
5594
5600
  let { event: t, el: n } = e, r = t.extendedProps;
5595
5601
  n.setAttribute("data-event-id", t.id + "-" + r.date + "-" + r.start_time);
@@ -5598,10 +5604,10 @@ var bt = {
5598
5604
  g(e);
5599
5605
  }
5600
5606
  });
5601
- }, _e = (e) => {
5602
- t?.root?.data?.place && N.current.setOption("eventSources", [{ events: z }]);
5607
+ }, z = (e) => {
5608
+ t?.root?.data?.place && N.current.setOption("eventSources", [{ events: B }]);
5603
5609
  };
5604
- async function z(e) {
5610
+ async function B(e) {
5605
5611
  try {
5606
5612
  N.current.setOption("events", []);
5607
5613
  let n = p(e.start).format("YYYY-MM-DD"), r = new Date(e.end);
@@ -5626,7 +5632,7 @@ var bt = {
5626
5632
  extendedProps: { ...e }
5627
5633
  })), f = le(u);
5628
5634
  return N.current.setOption("slotMinTime", f.earliestStartTime), N.current.setOption("slotMaxTime", f.latestEndTime), P(u), yt(N.current, d), setTimeout(() => {
5629
- B(d);
5635
+ V(d);
5630
5636
  }, 500), d;
5631
5637
  } catch (e) {
5632
5638
  throw console.error("Errore nel caricamento disponibilità:", e), e;
@@ -5642,16 +5648,16 @@ var bt = {
5642
5648
  return;
5643
5649
  }
5644
5650
  let r = t?.dataValue ?? t?.getValue();
5645
- r && r?.draft_expiration && C().isAfter(r.draft_expiration) && (n({}), Ot()), t?.data?.service_data?.view_type === "calendar" || e.view === "calendar" ? N?.current || ge() : t?.data?.service_data?.view_type === "select" || e.view === "select" ? me() : alert(o.t("Il componente non è configurato per la visualizzazione a calendario"));
5651
+ r && r?.draft_expiration && C().isAfter(r.draft_expiration) && (n({}), Ot()), t?.data?.service_data?.view_type === "calendar" || e.view === "calendar" ? N?.current || _e() : t?.data?.service_data?.view_type === "select" || e.view === "select" ? he() : alert(o.t("Il componente non è configurato per la visualizzazione a calendario"));
5646
5652
  } catch (e) {
5647
5653
  console.error("Errore durante l'inizializzazione del calendario:", e);
5648
5654
  }
5649
5655
  }
5650
5656
  return r = setTimeout(a, 500), () => {
5651
- i = !0, r && clearTimeout(r), N.current &&= (ce.current?.destroy?.(), null);
5657
+ i = !0, r && clearTimeout(r), N.current &&= (N.current.destroy(), null);
5652
5658
  };
5653
5659
  }, [t?.root?.data?.place]);
5654
- function B(e) {
5660
+ function V(e) {
5655
5661
  let n = t?.dataValue;
5656
5662
  if (!n?.from_time) return;
5657
5663
  let r = C(n.from_time).format("DD-MM-YYYY HH:mm"), i = C(n.to_time).format("DD-MM-YYYY HH:mm"), a = e.find((e) => C(e.start).format("DD-MM-YYYY HH:mm") === r && C(e.end).format("DD-MM-YYYY HH:mm") === i);
@@ -5667,7 +5673,7 @@ var bt = {
5667
5673
  }));
5668
5674
  }
5669
5675
  return s(() => {
5670
- document.querySelector(".formio-read-only") && ne === !1 ? _(!0) : (t?.data?.service_data?.view_type === "select" ? me() : t?.data?.service_data?.view_type === "calendar" && ge(), _(!1));
5676
+ document.querySelector(".formio-read-only") && ne === !1 ? _(!0) : (t?.data?.service_data?.view_type === "select" ? he() : t?.data?.service_data?.view_type === "calendar" && _e(), _(!1));
5671
5677
  }, []), s(() => {
5672
5678
  ne && setTimeout(() => {
5673
5679
  let e = t?.dataValue ?? t?.getValue();
@@ -5727,7 +5733,7 @@ var bt = {
5727
5733
  /* @__PURE__ */ a(x, {
5728
5734
  label: "Orario",
5729
5735
  id: "selectSlot",
5730
- onChange: pe,
5736
+ onChange: L,
5731
5737
  disabled: E.length === 0,
5732
5738
  children: [/* @__PURE__ */ i("option", {
5733
5739
  value: "",