next-recomponents 2.0.35 → 2.0.38

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
@@ -3668,19 +3668,8 @@ function Container({
3668
3668
  expandedFooter = false,
3669
3669
  expandedMenu = false
3670
3670
  }) {
3671
- const [isSidebarOpen, setIsSidebarOpen] = (0, import_react2.useState)(expandedMenu);
3671
+ const [isSidebarOpen, setIsSidebarOpen] = (0, import_react2.useState)(false);
3672
3672
  const [isFooterOpen, setIsFooterOpen] = (0, import_react2.useState)(expandedFooter);
3673
- const handleClick = (state) => {
3674
- window.localStorage.setItem("isSidebarOpen", JSON.stringify(state));
3675
- };
3676
- (0, import_react2.useEffect)(() => {
3677
- if (typeof window !== "undefined") {
3678
- const storedSidebarState = window.localStorage.getItem("isSidebarOpen");
3679
- if (storedSidebarState && window.innerWidth >= 768) {
3680
- setIsSidebarOpen(JSON.parse(storedSidebarState));
3681
- }
3682
- }
3683
- }, []);
3684
3673
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-col h-screen", children: [
3685
3674
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "", children: [
3686
3675
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "bg-blue-600 text-white p-4 flex justify-between items-center shadow-md", children: [
@@ -3689,7 +3678,6 @@ function Container({
3689
3678
  {
3690
3679
  onClick: () => {
3691
3680
  setIsSidebarOpen(!isSidebarOpen);
3692
- handleClick(!isSidebarOpen);
3693
3681
  },
3694
3682
  className: "bg-blue-600 text-white px-2 py-1 rounded-r",
3695
3683
  children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MenuIcon, {})
@@ -3728,6 +3716,10 @@ function Container({
3728
3716
  className: `bg-blue-500 text-white overflow-y-auto fixed md:static top-0 left-0 h-full z-50 md:z-auto transition-all duration-300 ease-in-out
3729
3717
  ${isSidebarOpen ? "w-full md:w-[250px]" : "w-0 md:w-[60px]"}
3730
3718
  `,
3719
+ onMouseEnter: (e) => {
3720
+ setIsSidebarOpen(true);
3721
+ },
3722
+ onMouseLeave: (e) => setIsSidebarOpen(false),
3731
3723
  children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "p-4 ", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("ul", { className: "space-y-3", children: [
3732
3724
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
3733
3725
  "li",
@@ -3735,7 +3727,6 @@ function Container({
3735
3727
  className: "p-2 md:hidden flex items-center justify-between font-bold",
3736
3728
  onClick: (e) => {
3737
3729
  setIsSidebarOpen(false);
3738
- handleClick(false);
3739
3730
  },
3740
3731
  children: [
3741
3732
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MenuIcon, {}),
@@ -3771,7 +3762,6 @@ function Container({
3771
3762
  className: "fixed inset-0 bg-black bg-opacity-40 z-40",
3772
3763
  onClick: () => {
3773
3764
  setIsSidebarOpen(false);
3774
- handleClick(false);
3775
3765
  }
3776
3766
  }
3777
3767
  ),
@@ -36417,140 +36407,152 @@ function useResources({
36417
36407
  return error;
36418
36408
  }
36419
36409
  };
36410
+ const mergeDataArray = (existingData, newItem, matchId) => {
36411
+ if (!existingData) return [newItem];
36412
+ const index = existingData.findIndex((d) => (d == null ? void 0 : d.id) == matchId);
36413
+ if (index >= 0) {
36414
+ return existingData.map(
36415
+ (d, i) => i === index ? newItem : d
36416
+ );
36417
+ }
36418
+ return [newItem, ...existingData];
36419
+ };
36420
36420
  const bodyCreateFunc = async (data) => {
36421
- var _a2, _b2, _c2, _d2, _e2, _f2;
36421
+ var _a2, _b2, _c2, _d2, _e2;
36422
36422
  const options = {
36423
36423
  method: "POST",
36424
36424
  url: `${baseURI}/${key}`,
36425
36425
  data: Array.isArray(data) ? [...data] : { ...data },
36426
36426
  headers: { Authorization: token }
36427
36427
  };
36428
- const newInfo = { ...info };
36429
- newInfo[key].state = "loading";
36430
- newInfo[key].errorMessage = "";
36428
+ const newInfo = {
36429
+ ...info,
36430
+ [key]: {
36431
+ ...info[key],
36432
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36433
+ state: "loading",
36434
+ errorMessage: ""
36435
+ }
36436
+ };
36431
36437
  setInfo(newInfo);
36432
36438
  try {
36433
36439
  const consulta = await import_axios.default.request(options);
36434
36440
  const d = consulta.data;
36435
- newInfo[key].state = "success";
36436
- newInfo[key].errorMessage = "";
36441
+ let updatedData;
36437
36442
  if (Array.isArray(data)) {
36438
- for (let datum of data) {
36439
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36440
- (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
36441
- );
36442
- if (index >= 0) {
36443
- newInfo[key].data[index] = d;
36444
- } else {
36445
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36446
- newInfo[key].data.unshift(d);
36447
- } else {
36448
- newInfo[key].data = [d];
36449
- }
36450
- }
36443
+ updatedData = [...(_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) != null ? _d2 : []];
36444
+ for (const datum of data) {
36445
+ updatedData = mergeDataArray(updatedData, d, datum == null ? void 0 : datum.id);
36451
36446
  }
36452
- newInfo[key].data = newInfo[key].data.flat();
36447
+ updatedData = updatedData.flat();
36453
36448
  } else {
36454
- newInfo[key].selectedItem = d;
36455
- const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
36456
- (d2) => (d2 == null ? void 0 : d2.id) == (data == null ? void 0 : data.id)
36449
+ updatedData = mergeDataArray(
36450
+ (_e2 = newInfo[key]) == null ? void 0 : _e2.data,
36451
+ d,
36452
+ data == null ? void 0 : data.id
36457
36453
  );
36458
- if (index >= 0) {
36459
- newInfo[key].data[index] = d;
36460
- } else {
36461
- if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
36462
- newInfo[key].data.unshift(d);
36463
- } else {
36464
- newInfo[key].data = [d];
36465
- }
36466
- }
36467
36454
  }
36468
- setInfo({ ...newInfo });
36455
+ setInfo({
36456
+ ...newInfo,
36457
+ [key]: {
36458
+ ...newInfo[key],
36459
+ state: "success",
36460
+ errorMessage: "",
36461
+ selectedItem: Array.isArray(data) ? newInfo[key].selectedItem : d,
36462
+ data: updatedData
36463
+ }
36464
+ });
36469
36465
  return d;
36470
36466
  } catch (error) {
36471
36467
  const item = http_codes_default.find((s) => s.code == error.status);
36472
- newInfo[key].state = "error";
36473
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36474
36468
  if (error.status == 403) {
36475
- onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36469
+ onError == null ? void 0 : onError({ error, errorMessage: item == null ? void 0 : item.meaning });
36476
36470
  }
36477
- setInfo({ ...newInfo });
36471
+ setInfo({
36472
+ ...newInfo,
36473
+ [key]: {
36474
+ ...newInfo[key],
36475
+ state: "error",
36476
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36477
+ }
36478
+ });
36478
36479
  return error;
36479
36480
  }
36480
36481
  };
36481
36482
  const formCreateFunc = async (data) => {
36482
- var _a2, _b2, _c2, _d2, _e2, _f2;
36483
- const newInfo = { ...info };
36484
- newInfo[key].state = "loading";
36485
- newInfo[key].errorMessage = "";
36486
- setInfo(newInfo);
36487
- try {
36488
- const formData = new FormData();
36489
- if (Array.isArray(data)) {
36490
- data.forEach((item, i) => {
36491
- for (const [k, v] of Object.entries(item)) {
36492
- formData.append(`${k}[${i}]`, v);
36493
- }
36494
- });
36495
- } else {
36496
- for (const [k, v] of Object.entries(data)) {
36497
- formData.append(k, v);
36483
+ var _a2, _b2, _c2, _d2, _e2;
36484
+ const formData = new FormData();
36485
+ if (Array.isArray(data)) {
36486
+ data.forEach((item, i) => {
36487
+ for (const [k, v] of Object.entries(item)) {
36488
+ formData.append(`${k}[${i}]`, v);
36498
36489
  }
36490
+ });
36491
+ } else {
36492
+ for (const [k, v] of Object.entries(data)) {
36493
+ formData.append(k, v);
36499
36494
  }
36500
- const options = {
36501
- method: "POST",
36502
- url: `${baseURI}/${key}`,
36503
- data: formData,
36504
- headers: {
36505
- Authorization: token,
36506
- "Content-Type": "multipart/form-data"
36507
- }
36508
- };
36495
+ }
36496
+ const options = {
36497
+ method: "POST",
36498
+ url: `${baseURI}/${key}`,
36499
+ data: formData,
36500
+ headers: {
36501
+ Authorization: token,
36502
+ "Content-Type": "multipart/form-data"
36503
+ }
36504
+ };
36505
+ const newInfo = {
36506
+ ...info,
36507
+ [key]: {
36508
+ ...info[key],
36509
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36510
+ state: "loading",
36511
+ errorMessage: ""
36512
+ }
36513
+ };
36514
+ setInfo(newInfo);
36515
+ try {
36509
36516
  const consulta = await import_axios.default.request(options);
36510
36517
  const d = consulta.data;
36511
- newInfo[key].state = "success";
36512
- newInfo[key].errorMessage = "";
36518
+ let updatedData;
36513
36519
  if (Array.isArray(data)) {
36514
- for (let datum of data) {
36515
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36516
- (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
36517
- );
36518
- if (index >= 0) {
36519
- newInfo[key].data[index] = d;
36520
- } else {
36521
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36522
- newInfo[key].data.unshift(d);
36523
- } else {
36524
- newInfo[key].data = [d];
36525
- }
36526
- }
36520
+ updatedData = [...(_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) != null ? _d2 : []];
36521
+ for (const datum of data) {
36522
+ updatedData = mergeDataArray(updatedData, d, datum == null ? void 0 : datum.id);
36527
36523
  }
36528
- newInfo[key].data = newInfo[key].data.flat();
36524
+ updatedData = updatedData.flat();
36529
36525
  } else {
36530
- newInfo[key].selectedItem = d;
36531
- const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
36532
- (d2) => (d2 == null ? void 0 : d2.id) == (data == null ? void 0 : data.id)
36526
+ updatedData = mergeDataArray(
36527
+ (_e2 = newInfo[key]) == null ? void 0 : _e2.data,
36528
+ d,
36529
+ data == null ? void 0 : data.id
36533
36530
  );
36534
- if (index >= 0) {
36535
- newInfo[key].data[index] = d;
36536
- } else {
36537
- if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
36538
- newInfo[key].data.unshift(d);
36539
- } else {
36540
- newInfo[key].data = [d];
36541
- }
36542
- }
36543
36531
  }
36544
- setInfo({ ...newInfo });
36532
+ setInfo({
36533
+ ...newInfo,
36534
+ [key]: {
36535
+ ...newInfo[key],
36536
+ state: "success",
36537
+ errorMessage: "",
36538
+ selectedItem: Array.isArray(data) ? newInfo[key].selectedItem : d,
36539
+ data: updatedData
36540
+ }
36541
+ });
36545
36542
  return d;
36546
36543
  } catch (error) {
36547
36544
  const item = http_codes_default.find((s) => s.code == error.status);
36548
- newInfo[key].state = "error";
36549
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36550
36545
  if (error.status == 403) {
36551
- onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36546
+ onError == null ? void 0 : onError({ error, errorMessage: item == null ? void 0 : item.meaning });
36552
36547
  }
36553
- setInfo({ ...newInfo });
36548
+ setInfo({
36549
+ ...newInfo,
36550
+ [key]: {
36551
+ ...newInfo[key],
36552
+ state: "error",
36553
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36554
+ }
36555
+ });
36554
36556
  return error;
36555
36557
  }
36556
36558
  };
@@ -36569,81 +36571,107 @@ function useResources({
36569
36571
  return await bodyCreateFunc(data);
36570
36572
  },
36571
36573
  update: async (id, data) => {
36572
- var _a2, _b2, _c2;
36574
+ var _a2, _b2, _c2, _d2, _e2;
36573
36575
  const options = {
36574
36576
  method: "PATCH",
36575
36577
  url: `${baseURI}/${key}/${id}`,
36576
36578
  data: Array.isArray(data) ? [...data] : { ...data },
36577
36579
  headers: { Authorization: token }
36578
36580
  };
36579
- const newInfo = { ...info };
36580
- newInfo[key].state = "loading";
36581
- newInfo[key].errorMessage = "";
36581
+ const newInfo = {
36582
+ ...info,
36583
+ [key]: {
36584
+ ...info[key],
36585
+ // ✅ copia superficial del key
36586
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36587
+ // ✅ copia del array
36588
+ state: "loading",
36589
+ errorMessage: ""
36590
+ }
36591
+ };
36582
36592
  setInfo(newInfo);
36583
36593
  try {
36584
36594
  const consulta = await import_axios.default.request(options);
36585
36595
  const d = consulta.data;
36586
- newInfo[key].state = "success";
36587
- newInfo[key].errorMessage = "";
36588
- newInfo[key].selectedItem = { ...newInfo[key].selectedItem, ...d };
36589
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36590
- (d2) => (d2 == null ? void 0 : d2.id) == id
36596
+ const index = (_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) == null ? void 0 : _d2.findIndex(
36597
+ (item) => (item == null ? void 0 : item.id) == id
36591
36598
  );
36592
- if (index >= 0) {
36593
- newInfo[key].data[index] = { ...newInfo[key].data[index], ...d };
36594
- } else {
36595
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36596
- newInfo[key].data.unshift(d);
36597
- } else {
36598
- newInfo[key].data = [d];
36599
+ const updatedData = index >= 0 ? newInfo[key].data.map(
36600
+ (item, i) => i === index ? { ...item, ...d } : item
36601
+ ) : ((_e2 = newInfo[key]) == null ? void 0 : _e2.data) ? [d, ...newInfo[key].data] : [d];
36602
+ const updatedInfo = {
36603
+ ...newInfo,
36604
+ [key]: {
36605
+ ...newInfo[key],
36606
+ state: "success",
36607
+ errorMessage: "",
36608
+ selectedItem: { ...newInfo[key].selectedItem, ...d },
36609
+ data: updatedData
36599
36610
  }
36600
- }
36601
- setInfo({ ...newInfo });
36611
+ };
36612
+ setInfo(updatedInfo);
36602
36613
  return d;
36603
36614
  } catch (error) {
36604
36615
  const item = http_codes_default.find((s) => s.code == error.status);
36605
- newInfo[key].state = "error";
36606
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36616
+ setInfo({
36617
+ ...newInfo,
36618
+ [key]: {
36619
+ ...newInfo[key],
36620
+ state: "error",
36621
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36622
+ }
36623
+ });
36607
36624
  if (error.status == 403) {
36608
36625
  onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36609
36626
  }
36610
- setInfo({ ...newInfo });
36611
36627
  return error;
36612
36628
  }
36613
36629
  },
36614
36630
  remove: async (id) => {
36615
- var _a2, _b2;
36631
+ var _a2, _b2, _c2, _d2, _e2;
36616
36632
  const options = {
36617
36633
  method: "DELETE",
36618
36634
  url: `${baseURI}/${key}/${id}`,
36619
36635
  headers: { Authorization: token }
36620
36636
  };
36621
- const newInfo = { ...info };
36622
- newInfo[key].state = "loading";
36623
- newInfo[key].errorMessage = "";
36637
+ const newInfo = {
36638
+ ...info,
36639
+ [key]: {
36640
+ ...info[key],
36641
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36642
+ state: "loading",
36643
+ errorMessage: ""
36644
+ }
36645
+ };
36624
36646
  setInfo(newInfo);
36625
36647
  try {
36626
36648
  const consulta = await import_axios.default.request(options);
36627
36649
  const d = consulta.data;
36628
- newInfo[key].state = "success";
36629
- newInfo[key].errorMessage = "";
36630
- newInfo[key].selectedItem = d;
36631
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36632
- (d2) => (d2 == null ? void 0 : d2.id) == id
36633
- );
36634
- if (index >= 0) {
36635
- newInfo[key].data.splice(index, 1);
36636
- }
36637
- setInfo({ ...newInfo });
36650
+ setInfo({
36651
+ ...newInfo,
36652
+ [key]: {
36653
+ ...newInfo[key],
36654
+ state: "success",
36655
+ errorMessage: "",
36656
+ selectedItem: d,
36657
+ data: (_e2 = (_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) == null ? void 0 : _d2.filter((item) => (item == null ? void 0 : item.id) != id)) != null ? _e2 : []
36658
+ // ✅ filter en lugar de splice
36659
+ }
36660
+ });
36638
36661
  return d.data;
36639
36662
  } catch (error) {
36640
36663
  const item = http_codes_default.find((s) => s.code == error.status);
36641
- newInfo[key].state = "error";
36642
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36643
36664
  if (error.status == 403) {
36644
- onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36665
+ onError == null ? void 0 : onError({ error, errorMessage: item == null ? void 0 : item.meaning });
36645
36666
  }
36646
- setInfo({ ...newInfo });
36667
+ setInfo({
36668
+ ...newInfo,
36669
+ [key]: {
36670
+ ...newInfo[key],
36671
+ state: "error",
36672
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36673
+ }
36674
+ });
36647
36675
  return error;
36648
36676
  }
36649
36677
  },