next-recomponents 2.0.39 → 2.0.40

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
@@ -3882,98 +3882,97 @@ function Input({
3882
3882
  className,
3883
3883
  regex,
3884
3884
  invalidMessage = "Valor no v\xE1lido",
3885
+ icon = null,
3885
3886
  ...props
3886
3887
  }) {
3887
3888
  const value = `${(props == null ? void 0 : props.value) || ""}`;
3888
3889
  const isValid = !regex ? true : regex.test(value);
3889
3890
  const isPassword = props.type === "password";
3890
3891
  const [showPassword, setShowPassword] = (0, import_react4.useState)(false);
3891
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "w-full", children: [
3892
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "flex flex-col gap-1", children: [
3893
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "font-bold", children: [
3892
+ const svg = icon;
3893
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "w-full relative", children: [
3894
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "relative flex items-center border rounded bg-white pr-1 mb-5", children: [
3895
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3896
+ "input",
3897
+ {
3898
+ ...props,
3899
+ type: isPassword && showPassword ? "text" : props.type,
3900
+ className: [
3901
+ "flex p-2 w-full bg-transparent pt-4",
3902
+ isPassword && "pr-10",
3903
+ value !== "" && !isValid && "bg-red-200 text-black",
3904
+ value !== "" && isValid && "bg-green-200 text-black",
3905
+ className
3906
+ ].filter(Boolean).join(" ")
3907
+ }
3908
+ ),
3909
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "absolute -top-2.5 left-2 text-xs font-bold bg-white px-1", children: [
3894
3910
  label,
3895
- " ",
3896
- (props == null ? void 0 : props.required) && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-red-500", children: "*" })
3911
+ (props == null ? void 0 : props.required) && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-red-500 ml-1", children: "*" })
3897
3912
  ] }),
3898
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "relative", children: [
3899
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3900
- "input",
3901
- {
3902
- ...props,
3903
- type: isPassword && showPassword ? "text" : props.type,
3904
- className: [
3905
- "p-2 w-full rounded border shadow",
3906
- isPassword && "pr-10",
3907
- value !== "" && !isValid && "bg-red-200 text-black",
3908
- value !== "" && isValid && "bg-green-200 text-black",
3909
- className
3910
- ].filter(Boolean).join(" ")
3911
- }
3912
- ),
3913
- isPassword && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3914
- "button",
3915
- {
3916
- type: "button",
3917
- onClick: () => setShowPassword((prev) => !prev),
3918
- className: "absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-800 focus:outline-none",
3919
- "aria-label": showPassword ? "Ocultar contrase\xF1a" : "Mostrar contrase\xF1a",
3920
- children: showPassword ? (
3921
- // Ojo cerrado (ocultar)
3922
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3923
- "svg",
3924
- {
3925
- xmlns: "http://www.w3.org/2000/svg",
3926
- className: "h-5 w-5",
3927
- fill: "none",
3928
- viewBox: "0 0 24 24",
3929
- stroke: "currentColor",
3930
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3913
+ isPassword ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3914
+ "button",
3915
+ {
3916
+ type: "button",
3917
+ onClick: () => setShowPassword((prev) => !prev),
3918
+ className: "absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-800 focus:outline-none",
3919
+ "aria-label": showPassword ? "Ocultar contrase\xF1a" : "Mostrar contrase\xF1a",
3920
+ children: showPassword ? (
3921
+ // Ojo cerrado (ocultar)
3922
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3923
+ "svg",
3924
+ {
3925
+ xmlns: "http://www.w3.org/2000/svg",
3926
+ className: "h-5 w-5",
3927
+ fill: "none",
3928
+ viewBox: "0 0 24 24",
3929
+ stroke: "currentColor",
3930
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3931
+ "path",
3932
+ {
3933
+ strokeLinecap: "round",
3934
+ strokeLinejoin: "round",
3935
+ strokeWidth: 2,
3936
+ d: "M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"
3937
+ }
3938
+ )
3939
+ }
3940
+ )
3941
+ ) : (
3942
+ // Ojo abierto (mostrar)
3943
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
3944
+ "svg",
3945
+ {
3946
+ xmlns: "http://www.w3.org/2000/svg",
3947
+ className: "h-5 w-5",
3948
+ fill: "none",
3949
+ viewBox: "0 0 24 24",
3950
+ stroke: "currentColor",
3951
+ children: [
3952
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3953
+ "path",
3954
+ {
3955
+ strokeLinecap: "round",
3956
+ strokeLinejoin: "round",
3957
+ strokeWidth: 2,
3958
+ d: "M15 12a3 3 0 11-6 0 3 3 0 016 0z"
3959
+ }
3960
+ ),
3961
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3931
3962
  "path",
3932
3963
  {
3933
3964
  strokeLinecap: "round",
3934
3965
  strokeLinejoin: "round",
3935
3966
  strokeWidth: 2,
3936
- d: "M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"
3967
+ d: "M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
3937
3968
  }
3938
3969
  )
3939
- }
3940
- )
3941
- ) : (
3942
- // Ojo abierto (mostrar)
3943
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
3944
- "svg",
3945
- {
3946
- xmlns: "http://www.w3.org/2000/svg",
3947
- className: "h-5 w-5",
3948
- fill: "none",
3949
- viewBox: "0 0 24 24",
3950
- stroke: "currentColor",
3951
- children: [
3952
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3953
- "path",
3954
- {
3955
- strokeLinecap: "round",
3956
- strokeLinejoin: "round",
3957
- strokeWidth: 2,
3958
- d: "M15 12a3 3 0 11-6 0 3 3 0 016 0z"
3959
- }
3960
- ),
3961
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3962
- "path",
3963
- {
3964
- strokeLinecap: "round",
3965
- strokeLinejoin: "round",
3966
- strokeWidth: 2,
3967
- d: "M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
3968
- }
3969
- )
3970
- ]
3971
- }
3972
- )
3970
+ ]
3971
+ }
3973
3972
  )
3974
- }
3975
- )
3976
- ] })
3973
+ )
3974
+ }
3975
+ ) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("i", { className: "absulute right-[12px] text-[#3a7bd5] ", children: svg })
3977
3976
  ] }),
3978
3977
  !isValid && value !== "" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "text-red-800 invalid", children: invalidMessage })
3979
3978
  ] });
@@ -36178,35 +36177,32 @@ function TextArea({
36178
36177
  ...props
36179
36178
  }) {
36180
36179
  const [value, setValue] = (0, import_react6.useState)((props == null ? void 0 : props.value) || "");
36181
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "w-full", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: "flex flex-col gap-1", children: [
36182
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "font-bold ", children: [
36180
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "w-full relative mb-5", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "relative flex items-center border rounded bg-white ", children: [
36181
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
36182
+ "textarea",
36183
+ {
36184
+ ...props,
36185
+ className: ["p-1 w-full transparent", className].join(" "),
36186
+ value,
36187
+ onChange: (e) => {
36188
+ if (maxLength) {
36189
+ e.target.value = e.target.value.slice(0, maxLength);
36190
+ }
36191
+ setValue(e.target.value);
36192
+ onChange == null ? void 0 : onChange(e);
36193
+ }
36194
+ }
36195
+ ),
36196
+ " ",
36197
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: "absolute -top-2.5 left-2 text-xs font-bold bg-white px-1", children: [
36183
36198
  label,
36184
36199
  " ",
36185
36200
  (props == null ? void 0 : props.required) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-red-500", children: "*" })
36186
36201
  ] }),
36187
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
36188
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
36189
- "textarea",
36190
- {
36191
- ...props,
36192
- className: ["p-1 w-full rounded border shadow", className].join(
36193
- " "
36194
- ),
36195
- value,
36196
- onChange: (e) => {
36197
- if (maxLength) {
36198
- e.target.value = e.target.value.slice(0, maxLength);
36199
- }
36200
- setValue(e.target.value);
36201
- onChange == null ? void 0 : onChange(e);
36202
- }
36203
- }
36204
- ),
36205
- maxLength && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: " text-xs text-gray text-right", children: [
36206
- value.length,
36207
- " / ",
36208
- maxLength
36209
- ] })
36202
+ maxLength && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: " text-xs text-gray text-right", children: [
36203
+ value.length,
36204
+ " / ",
36205
+ maxLength
36210
36206
  ] })
36211
36207
  ] }) });
36212
36208
  }
@@ -36303,27 +36299,6 @@ var httpStatusCodes = [
36303
36299
  var http_codes_default = httpStatusCodes;
36304
36300
 
36305
36301
  // src/use-resources/index.ts
36306
- function getErrorMeaning(error) {
36307
- var _a;
36308
- return (_a = http_codes_default.find((s) => s.code === (error == null ? void 0 : error.status))) == null ? void 0 : _a.meaning;
36309
- }
36310
- function mergeDataArray(existing, incoming, matchId) {
36311
- const idx = existing.findIndex((d) => (d == null ? void 0 : d.id) == matchId);
36312
- if (idx >= 0) {
36313
- return existing.map((d, i) => i === idx ? incoming : d);
36314
- }
36315
- return [incoming, ...existing];
36316
- }
36317
- function cloneKey(state, key) {
36318
- var _a;
36319
- return {
36320
- ...state,
36321
- [key]: {
36322
- ...state[key],
36323
- data: ((_a = state[key]) == null ? void 0 : _a.data) ? [...state[key].data] : []
36324
- }
36325
- };
36326
- }
36327
36302
  function useResources({
36328
36303
  baseURI,
36329
36304
  endpoints,
@@ -36331,304 +36306,391 @@ function useResources({
36331
36306
  }) {
36332
36307
  const token = useToken();
36333
36308
  const [info, setInfo] = (0, import_react8.useState)(
36334
- () => Object.keys(endpoints).reduce((acc, key) => {
36309
+ Object.keys(endpoints).reduce((acc, key) => {
36335
36310
  var _a, _b;
36336
- acc[key] = {
36337
- loaded: false,
36338
- id: (_a = endpoints[key]) == null ? void 0 : _a.id,
36339
- defaultParams: (_b = endpoints[key]) == null ? void 0 : _b.defaultParams,
36340
- data: [],
36341
- selectedItem: {},
36342
- state: "success",
36343
- errorMessage: ""
36344
- };
36345
- return acc;
36346
- }, {})
36347
- );
36348
- const infoRef = (0, import_react8.useRef)(info);
36349
- (0, import_react8.useEffect)(() => {
36350
- infoRef.current = info;
36351
- }, [info]);
36352
- const setKeyLoading = (0, import_react8.useCallback)((key) => {
36353
- setInfo((prev) => ({
36354
- ...cloneKey(prev, key),
36355
- [key]: {
36356
- ...cloneKey(prev, key)[key],
36357
- state: "loading",
36358
- errorMessage: ""
36359
- }
36360
- }));
36361
- }, []);
36362
- const setKeyError = (0, import_react8.useCallback)(
36363
- (key, error) => {
36364
- const meaning = getErrorMeaning(error);
36365
- if ((error == null ? void 0 : error.status) === 403) onError == null ? void 0 : onError({ error, errorMessage: meaning });
36366
- setInfo((prev) => ({
36367
- ...cloneKey(prev, key),
36311
+ const newAcc = {
36312
+ ...acc,
36368
36313
  [key]: {
36369
- ...cloneKey(prev, key)[key],
36370
- state: "error",
36371
- errorMessage: meaning || (error == null ? void 0 : error.message)
36314
+ loaded: false,
36315
+ id: (_a = endpoints[key]) == null ? void 0 : _a.id,
36316
+ defaultParams: (_b = endpoints[key]) == null ? void 0 : _b.defaultParams,
36317
+ data: [],
36318
+ selectedItem: {}
36372
36319
  }
36373
- }));
36374
- },
36375
- [onError]
36320
+ };
36321
+ return newAcc;
36322
+ }, {})
36376
36323
  );
36377
- const show = (0, import_react8.useCallback)(
36378
- async (key, { limit = 10, page = 1, merge = true, ...query }) => {
36379
- setInfo((prev) => ({
36380
- ...cloneKey(prev, key),
36381
- [key]: {
36382
- ...cloneKey(prev, key)[key],
36383
- state: "loading",
36384
- errorMessage: "",
36385
- params: query,
36386
- loaded: true
36387
- }
36388
- }));
36389
- try {
36390
- const { data: res } = await import_axios.default.get(`${baseURI}/${key}`, {
36324
+ const results = Object.keys(endpoints).reduce(
36325
+ (acc, key) => {
36326
+ var _a, _b, _c, _d, _e, _f, _g;
36327
+ const endpoint = endpoints[key];
36328
+ const showFunc = async ({ limit = 10, page = 1, merge = true, ...query }, autoLoad = false) => {
36329
+ const options = {
36330
+ method: "GET",
36331
+ url: `${baseURI}/${key}`,
36391
36332
  params: { limit, page, ...query },
36392
36333
  headers: { Authorization: token }
36393
- });
36394
- setInfo((prev) => {
36395
- var _a, _b;
36396
- const prevData = (_b = (_a = prev[key]) == null ? void 0 : _a.data) != null ? _b : [];
36397
- const merged = merge ? page === 1 ? res.data : [...prevData, ...res.data] : res.data;
36398
- return {
36399
- ...prev,
36400
- [key]: {
36401
- ...prev[key],
36402
- state: "success",
36403
- errorMessage: "",
36404
- data: merged,
36405
- totalItems: res.totalItems,
36406
- totalPages: res.totalPages,
36407
- currentPage: res.currentPage
36334
+ };
36335
+ const newInfo = { ...info };
36336
+ newInfo[key].state = "loading";
36337
+ newInfo[key].errorMessage = "";
36338
+ newInfo[key].params = query;
36339
+ newInfo[key].loaded = true;
36340
+ setInfo(newInfo);
36341
+ try {
36342
+ const consulta = await import_axios.default.request(options);
36343
+ const d = consulta.data;
36344
+ newInfo[key].state = "success";
36345
+ newInfo[key].errorMessage = "";
36346
+ newInfo[key].data = merge ? page == 1 ? d.data : [...d.data, ...newInfo[key].data || []] : d.data;
36347
+ newInfo[key].totalItems = d.totalItems;
36348
+ newInfo[key].totalPages = d.totalPages;
36349
+ newInfo[key].currentPage = d.currentPage;
36350
+ setInfo({ ...newInfo });
36351
+ return d.data;
36352
+ } catch (error) {
36353
+ const item = http_codes_default.find((s) => s.code == error.status);
36354
+ newInfo[key].state = "error";
36355
+ newInfo[key].errorMessage = item == null ? void 0 : item.meaning;
36356
+ if (error.status == 403) {
36357
+ onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36358
+ }
36359
+ setInfo({ ...newInfo });
36360
+ return error;
36361
+ }
36362
+ };
36363
+ const findFunc = async (id, query) => {
36364
+ var _a2, _b2, _c2;
36365
+ const options = {
36366
+ method: "GET",
36367
+ url: `${baseURI}/${key}/${id}`,
36368
+ params: { ...query },
36369
+ headers: { Authorization: token }
36370
+ };
36371
+ const newInfo = { ...info };
36372
+ newInfo[key].state = "loading";
36373
+ newInfo[key].errorMessage = "";
36374
+ newInfo[key].params = query;
36375
+ newInfo[key].loaded = true;
36376
+ setInfo(newInfo);
36377
+ try {
36378
+ const consulta = await import_axios.default.request(options);
36379
+ const d = consulta.data;
36380
+ newInfo[key].state = "success";
36381
+ newInfo[key].errorMessage = "";
36382
+ newInfo[key].selectedItem = d;
36383
+ const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex((d2) => (d2 == null ? void 0 : d2.id) == id);
36384
+ if (index >= 0) {
36385
+ newInfo[key].data[index] = d;
36386
+ } else {
36387
+ if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36388
+ newInfo[key].data.unshift(d);
36389
+ } else {
36390
+ newInfo[key].data = [d];
36408
36391
  }
36409
- };
36410
- });
36411
- return res.data;
36412
- } catch (error) {
36413
- setKeyError(key, error);
36414
- return error;
36415
- }
36416
- },
36417
- [baseURI, token, setKeyError]
36418
- );
36419
- const find = (0, import_react8.useCallback)(
36420
- async (key, id, query) => {
36421
- setInfo((prev) => ({
36422
- ...cloneKey(prev, key),
36423
- [key]: {
36424
- ...cloneKey(prev, key)[key],
36425
- state: "loading",
36426
- errorMessage: "",
36427
- params: query,
36428
- loaded: true
36392
+ }
36393
+ setInfo({ ...newInfo });
36394
+ return d;
36395
+ } catch (error) {
36396
+ const item = http_codes_default.find((s) => s.code == error.status);
36397
+ newInfo[key].state = "error";
36398
+ newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36399
+ if (error.status == 403) {
36400
+ onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36401
+ }
36402
+ setInfo({ ...newInfo });
36403
+ return error;
36429
36404
  }
36430
- }));
36431
- try {
36432
- const { data: d } = await import_axios.default.get(`${baseURI}/${key}/${id}`, {
36433
- params: query,
36405
+ };
36406
+ const bodyCreateFunc = async (data) => {
36407
+ var _a2, _b2, _c2, _d2, _e2, _f2;
36408
+ const options = {
36409
+ method: "POST",
36410
+ url: `${baseURI}/${key}`,
36411
+ data: Array.isArray(data) ? [...data] : { ...data },
36434
36412
  headers: { Authorization: token }
36435
- });
36436
- setInfo((prev) => {
36437
- var _a, _b;
36438
- return {
36439
- ...prev,
36440
- [key]: {
36441
- ...prev[key],
36442
- state: "success",
36443
- errorMessage: "",
36444
- selectedItem: d,
36445
- data: mergeDataArray((_b = (_a = prev[key]) == null ? void 0 : _a.data) != null ? _b : [], d, id)
36413
+ };
36414
+ const newInfo = { ...info };
36415
+ newInfo[key].state = "loading";
36416
+ newInfo[key].errorMessage = "";
36417
+ setInfo(newInfo);
36418
+ try {
36419
+ const consulta = await import_axios.default.request(options);
36420
+ const d = consulta.data;
36421
+ newInfo[key].state = "success";
36422
+ newInfo[key].errorMessage = "";
36423
+ if (Array.isArray(data)) {
36424
+ for (let datum of data) {
36425
+ const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36426
+ (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
36427
+ );
36428
+ if (index >= 0) {
36429
+ newInfo[key].data[index] = d;
36430
+ } else {
36431
+ if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36432
+ newInfo[key].data.unshift(d);
36433
+ } else {
36434
+ newInfo[key].data = [d];
36435
+ }
36436
+ }
36446
36437
  }
36447
- };
36448
- });
36449
- return d;
36450
- } catch (error) {
36451
- setKeyError(key, error);
36452
- return error;
36453
- }
36454
- },
36455
- [baseURI, token, setKeyError]
36456
- );
36457
- const buildFormData = (data) => {
36458
- const fd = new FormData();
36459
- if (Array.isArray(data)) {
36460
- data.forEach((item, i) => {
36461
- Object.entries(item).forEach(
36462
- ([k, v]) => fd.append(`${k}[${i}]`, v)
36463
- );
36464
- });
36465
- } else {
36466
- Object.entries(data).forEach(([k, v]) => fd.append(k, v));
36467
- }
36468
- return fd;
36469
- };
36470
- const hasFiles = (data) => Array.isArray(data) ? data.some((item) => Object.values(item).some((v) => v instanceof File)) : Object.values(data).some((v) => v instanceof File);
36471
- const create = (0, import_react8.useCallback)(
36472
- async (key, data) => {
36473
- setKeyLoading(key);
36474
- const isForm = hasFiles(data);
36475
- const payload = isForm ? buildFormData(data) : Array.isArray(data) ? [...data] : { ...data };
36476
- const headers = { Authorization: token };
36477
- if (isForm) headers["Content-Type"] = "multipart/form-data";
36478
- try {
36479
- const { data: d } = await import_axios.default.post(`${baseURI}/${key}`, payload, {
36480
- headers
36481
- });
36482
- setInfo((prev) => {
36483
- var _a, _b;
36484
- const prevData = (_b = (_a = prev[key]) == null ? void 0 : _a.data) != null ? _b : [];
36485
- const incoming = Array.isArray(d) ? d : [d];
36486
- const updatedData = incoming.reduce(
36487
- (acc, item) => mergeDataArray(acc, item, item == null ? void 0 : item.id),
36488
- [...prevData]
36489
- );
36490
- return {
36491
- ...prev,
36492
- [key]: {
36493
- ...prev[key],
36494
- state: "success",
36495
- errorMessage: "",
36496
- selectedItem: Array.isArray(data) ? prev[key].selectedItem : d,
36497
- data: updatedData
36438
+ newInfo[key].data = newInfo[key].data.flat();
36439
+ } else {
36440
+ newInfo[key].selectedItem = d;
36441
+ const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
36442
+ (d2) => (d2 == null ? void 0 : d2.id) == (data == null ? void 0 : data.id)
36443
+ );
36444
+ if (index >= 0) {
36445
+ newInfo[key].data[index] = d;
36446
+ } else {
36447
+ if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
36448
+ newInfo[key].data.unshift(d);
36449
+ } else {
36450
+ newInfo[key].data = [d];
36451
+ }
36452
+ }
36453
+ }
36454
+ setInfo({ ...newInfo });
36455
+ return d;
36456
+ } catch (error) {
36457
+ const item = http_codes_default.find((s) => s.code == error.status);
36458
+ newInfo[key].state = "error";
36459
+ newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36460
+ if (error.status == 403) {
36461
+ onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36462
+ }
36463
+ setInfo({ ...newInfo });
36464
+ return error;
36465
+ }
36466
+ };
36467
+ const formCreateFunc = async (data) => {
36468
+ var _a2, _b2, _c2, _d2, _e2, _f2;
36469
+ const newInfo = { ...info };
36470
+ newInfo[key].state = "loading";
36471
+ newInfo[key].errorMessage = "";
36472
+ setInfo(newInfo);
36473
+ try {
36474
+ const formData = new FormData();
36475
+ if (Array.isArray(data)) {
36476
+ data.forEach((item, i) => {
36477
+ for (const [k, v] of Object.entries(item)) {
36478
+ formData.append(`${k}[${i}]`, v);
36479
+ }
36480
+ });
36481
+ } else {
36482
+ for (const [k, v] of Object.entries(data)) {
36483
+ formData.append(k, v);
36484
+ }
36485
+ }
36486
+ const options = {
36487
+ method: "POST",
36488
+ url: `${baseURI}/${key}`,
36489
+ data: formData,
36490
+ headers: {
36491
+ Authorization: token,
36492
+ "Content-Type": "multipart/form-data"
36498
36493
  }
36499
36494
  };
36500
- });
36501
- return d;
36502
- } catch (error) {
36503
- setKeyError(key, error);
36504
- return error;
36505
- }
36506
- },
36507
- [baseURI, token, setKeyLoading, setKeyError]
36508
- );
36509
- const update = (0, import_react8.useCallback)(
36510
- async (key, id, data) => {
36511
- setKeyLoading(key);
36512
- try {
36513
- const { data: d } = await import_axios.default.patch(
36514
- `${baseURI}/${key}/${id}`,
36515
- Array.isArray(data) ? [...data] : { ...data },
36516
- { headers: { Authorization: token } }
36517
- );
36518
- setInfo((prev) => {
36519
- var _a, _b, _c, _d;
36520
- return {
36521
- ...prev,
36522
- [key]: {
36523
- ...prev[key],
36524
- state: "success",
36525
- errorMessage: "",
36526
- selectedItem: { ...prev[key].selectedItem, ...d },
36527
- data: mergeDataArray(
36528
- (_b = (_a = prev[key]) == null ? void 0 : _a.data) != null ? _b : [],
36529
- { ...(_d = (_c = prev[key]) == null ? void 0 : _c.data) == null ? void 0 : _d.find((i) => (i == null ? void 0 : i.id) == id), ...d },
36530
- id
36531
- )
36495
+ const consulta = await import_axios.default.request(options);
36496
+ const d = consulta.data;
36497
+ newInfo[key].state = "success";
36498
+ newInfo[key].errorMessage = "";
36499
+ if (Array.isArray(data)) {
36500
+ for (let datum of data) {
36501
+ const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36502
+ (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
36503
+ );
36504
+ if (index >= 0) {
36505
+ newInfo[key].data[index] = d;
36506
+ } else {
36507
+ if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36508
+ newInfo[key].data.unshift(d);
36509
+ } else {
36510
+ newInfo[key].data = [d];
36511
+ }
36512
+ }
36513
+ }
36514
+ newInfo[key].data = newInfo[key].data.flat();
36515
+ } else {
36516
+ newInfo[key].selectedItem = d;
36517
+ const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
36518
+ (d2) => (d2 == null ? void 0 : d2.id) == (data == null ? void 0 : data.id)
36519
+ );
36520
+ if (index >= 0) {
36521
+ newInfo[key].data[index] = d;
36522
+ } else {
36523
+ if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
36524
+ newInfo[key].data.unshift(d);
36525
+ } else {
36526
+ newInfo[key].data = [d];
36527
+ }
36532
36528
  }
36529
+ }
36530
+ setInfo({ ...newInfo });
36531
+ return d;
36532
+ } catch (error) {
36533
+ const item = http_codes_default.find((s) => s.code == error.status);
36534
+ newInfo[key].state = "error";
36535
+ newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36536
+ if (error.status == 403) {
36537
+ onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36538
+ }
36539
+ setInfo({ ...newInfo });
36540
+ return error;
36541
+ }
36542
+ };
36543
+ acc[key] = {
36544
+ ...endpoint,
36545
+ loaded: false,
36546
+ show: showFunc,
36547
+ find: findFunc,
36548
+ create: async (data) => {
36549
+ const hasFile = Array.isArray(data) ? data.some(
36550
+ (item) => Object.values(item).some((value) => value instanceof File)
36551
+ ) : Object.values(data).some((value) => value instanceof File);
36552
+ if (hasFile) {
36553
+ return await formCreateFunc(data);
36554
+ }
36555
+ return await bodyCreateFunc(data);
36556
+ },
36557
+ update: async (id, data) => {
36558
+ var _a2, _b2, _c2;
36559
+ const options = {
36560
+ method: "PATCH",
36561
+ url: `${baseURI}/${key}/${id}`,
36562
+ data: Array.isArray(data) ? [...data] : { ...data },
36563
+ headers: { Authorization: token }
36533
36564
  };
36534
- });
36535
- return d;
36536
- } catch (error) {
36537
- setKeyError(key, error);
36538
- return error;
36539
- }
36540
- },
36541
- [baseURI, token, setKeyLoading, setKeyError]
36542
- );
36543
- const remove = (0, import_react8.useCallback)(
36544
- async (key, id) => {
36545
- setKeyLoading(key);
36546
- try {
36547
- const { data: d } = await import_axios.default.delete(`${baseURI}/${key}/${id}`, {
36548
- headers: { Authorization: token }
36549
- });
36550
- setInfo((prev) => {
36551
- var _a, _b;
36552
- return {
36553
- ...prev,
36554
- [key]: {
36555
- ...prev[key],
36556
- state: "success",
36557
- errorMessage: "",
36558
- selectedItem: d,
36559
- data: ((_b = (_a = prev[key]) == null ? void 0 : _a.data) != null ? _b : []).filter((item) => (item == null ? void 0 : item.id) != id)
36565
+ const newInfo = { ...info };
36566
+ newInfo[key].state = "loading";
36567
+ newInfo[key].errorMessage = "";
36568
+ setInfo(newInfo);
36569
+ try {
36570
+ const consulta = await import_axios.default.request(options);
36571
+ const d = consulta.data;
36572
+ newInfo[key].state = "success";
36573
+ newInfo[key].errorMessage = "";
36574
+ newInfo[key].selectedItem = { ...newInfo[key].selectedItem, ...d };
36575
+ const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36576
+ (d2) => (d2 == null ? void 0 : d2.id) == id
36577
+ );
36578
+ if (index >= 0) {
36579
+ newInfo[key].data[index] = { ...newInfo[key].data[index], ...d };
36580
+ } else {
36581
+ if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36582
+ newInfo[key].data.unshift(d);
36583
+ } else {
36584
+ newInfo[key].data = [d];
36585
+ }
36560
36586
  }
36587
+ setInfo({ ...newInfo });
36588
+ return d;
36589
+ } catch (error) {
36590
+ const item = http_codes_default.find((s) => s.code == error.status);
36591
+ newInfo[key].state = "error";
36592
+ newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36593
+ if (error.status == 403) {
36594
+ onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36595
+ }
36596
+ setInfo({ ...newInfo });
36597
+ return error;
36598
+ }
36599
+ },
36600
+ remove: async (id) => {
36601
+ var _a2, _b2;
36602
+ const options = {
36603
+ method: "DELETE",
36604
+ url: `${baseURI}/${key}/${id}`,
36605
+ headers: { Authorization: token }
36561
36606
  };
36562
- });
36563
- return d;
36564
- } catch (error) {
36565
- setKeyError(key, error);
36566
- return error;
36567
- }
36568
- },
36569
- [baseURI, token, setKeyLoading, setKeyError]
36570
- );
36571
- const getAllPages = (0, import_react8.useCallback)(
36572
- async (key, limit = 100) => {
36573
- var _a, _b;
36574
- const allData = [];
36575
- let page = 1;
36576
- let totalPages = 1;
36577
- do {
36578
- const pageData = await show(key, { limit, page, merge: false });
36579
- if (Array.isArray(pageData)) allData.push(...pageData);
36580
- totalPages = (_b = (_a = infoRef.current[key]) == null ? void 0 : _a.totalPages) != null ? _b : page;
36581
- page++;
36582
- } while (page <= totalPages);
36583
- setInfo((prev) => ({
36584
- ...prev,
36585
- [key]: { ...prev[key], data: allData }
36586
- }));
36587
- return allData;
36607
+ const newInfo = { ...info };
36608
+ newInfo[key].state = "loading";
36609
+ newInfo[key].errorMessage = "";
36610
+ setInfo(newInfo);
36611
+ try {
36612
+ const consulta = await import_axios.default.request(options);
36613
+ const d = consulta.data;
36614
+ newInfo[key].state = "success";
36615
+ newInfo[key].errorMessage = "";
36616
+ newInfo[key].selectedItem = d;
36617
+ const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36618
+ (d2) => (d2 == null ? void 0 : d2.id) == id
36619
+ );
36620
+ if (index >= 0) {
36621
+ newInfo[key].data.splice(index, 1);
36622
+ }
36623
+ setInfo({ ...newInfo });
36624
+ return d.data;
36625
+ } catch (error) {
36626
+ const item = http_codes_default.find((s) => s.code == error.status);
36627
+ newInfo[key].state = "error";
36628
+ newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36629
+ if (error.status == 403) {
36630
+ onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36631
+ }
36632
+ setInfo({ ...newInfo });
36633
+ return error;
36634
+ }
36635
+ },
36636
+ totalPages: (_a = info[key]) == null ? void 0 : _a.totalPages,
36637
+ currentPage: (_b = info[key]) == null ? void 0 : _b.currentPage,
36638
+ state: ((_c = info[key]) == null ? void 0 : _c.state) || "success",
36639
+ errorMessage: (_d = info[key]) == null ? void 0 : _d.errorMessage,
36640
+ params: (_e = info[key]) == null ? void 0 : _e.params,
36641
+ setLoaded: () => {
36642
+ const newInfo = { ...info };
36643
+ newInfo[key].loaded = true;
36644
+ setInfo(newInfo);
36645
+ },
36646
+ getAllPages: async (limit = 100) => {
36647
+ const allData = [];
36648
+ let currentPage = 1;
36649
+ let totalPages = 1;
36650
+ while (currentPage <= totalPages) {
36651
+ const response = await results[key].show({
36652
+ limit,
36653
+ page: currentPage
36654
+ });
36655
+ const currentInfo = info[key];
36656
+ if (Array.isArray(response)) {
36657
+ allData.push(...response);
36658
+ }
36659
+ currentPage = currentInfo.currentPage || currentPage + 1;
36660
+ totalPages = currentInfo.totalPages || currentPage;
36661
+ }
36662
+ const newInfo = { ...info };
36663
+ newInfo[key].data = allData;
36664
+ newInfo[key].currentPage = currentPage;
36665
+ newInfo[key].totalPages = totalPages;
36666
+ setInfo(newInfo);
36667
+ return allData;
36668
+ },
36669
+ data: ((_f = info[key]) == null ? void 0 : _f.data) || [],
36670
+ selectedItem: ((_g = info[key]) == null ? void 0 : _g.selectedItem) || {}
36671
+ };
36672
+ return acc;
36588
36673
  },
36589
- [show]
36674
+ {}
36590
36675
  );
36676
+ async function doSome() {
36677
+ var _a, _b, _c, _d, _e;
36678
+ const key = Object.keys(info).find((k) => {
36679
+ return info[k].loaded === false;
36680
+ });
36681
+ if (key) {
36682
+ if ((_a = info[key]) == null ? void 0 : _a.id) {
36683
+ await results[key].find((_b = info[key]) == null ? void 0 : _b.id, (_c = info[key]) == null ? void 0 : _c.defaultParams);
36684
+ } else if ((_d = info[key]) == null ? void 0 : _d.defaultParams) {
36685
+ await results[key].show((_e = info[key]) == null ? void 0 : _e.defaultParams);
36686
+ } else {
36687
+ results[key].setLoaded();
36688
+ }
36689
+ }
36690
+ }
36591
36691
  (0, import_react8.useEffect)(() => {
36592
- var _a, _b;
36593
- const key = Object.keys(info).find((k) => info[k].loaded === false);
36594
- if (!key) return;
36595
- if ((_a = info[key]) == null ? void 0 : _a.id) {
36596
- find(key, info[key].id, info[key].defaultParams);
36597
- } else if ((_b = info[key]) == null ? void 0 : _b.defaultParams) {
36598
- show(key, info[key].defaultParams);
36599
- } else {
36600
- setInfo((prev) => ({
36601
- ...prev,
36602
- [key]: { ...prev[key], loaded: true }
36603
- }));
36604
- }
36605
- }, [
36606
- Object.keys(info).map((k) => info[k].loaded).join(",")
36607
- ]);
36608
- const results = Object.keys(endpoints).reduce((acc, key) => {
36609
- var _a, _b, _c, _d;
36610
- const s = info[key];
36611
- acc[key] = {
36612
- ...endpoints[key],
36613
- data: (_a = s == null ? void 0 : s.data) != null ? _a : [],
36614
- selectedItem: (_b = s == null ? void 0 : s.selectedItem) != null ? _b : {},
36615
- state: (_c = s == null ? void 0 : s.state) != null ? _c : "success",
36616
- errorMessage: s == null ? void 0 : s.errorMessage,
36617
- params: s == null ? void 0 : s.params,
36618
- totalPages: s == null ? void 0 : s.totalPages,
36619
- currentPage: s == null ? void 0 : s.currentPage,
36620
- totalItems: s == null ? void 0 : s.totalItems,
36621
- loaded: (_d = s == null ? void 0 : s.loaded) != null ? _d : false,
36622
- show: (opts) => show(key, opts),
36623
- find: (id, query) => find(key, id, query),
36624
- create: (data) => create(key, data),
36625
- update: (id, data) => update(key, id, data),
36626
- remove: (id) => remove(key, id),
36627
- getAllPages: (limit) => getAllPages(key, limit),
36628
- setLoaded: () => setInfo((prev) => ({ ...prev, [key]: { ...prev[key], loaded: true } }))
36629
- };
36630
- return acc;
36631
- }, {});
36692
+ doSome();
36693
+ }, [JSON.stringify(Object.values(info).map((v) => v.loaded))]);
36632
36694
  return results;
36633
36695
  }
36634
36696
 
@@ -36752,23 +36814,15 @@ function Select({
36752
36814
  }
36753
36815
  }
36754
36816
  }, [isOpen]);
36755
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { ref: containerRef, className: "w-full", children: [
36756
- label && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("label", { className: "font-bold mb-1 block", children: [
36757
- label,
36758
- " ",
36759
- (props == null ? void 0 : props.required) && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "text-red-500", children: "*" })
36760
- ] }),
36761
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "relative", children: [
36817
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { ref: containerRef, className: "w-full relative mb-5", children: [
36818
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "relative flex items-center border rounded bg-white", children: [
36762
36819
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
36763
36820
  "input",
36764
36821
  {
36765
36822
  autoComplete: "off",
36766
36823
  ref: inputRef,
36767
36824
  ...props,
36768
- className: [
36769
- "p-2 w-full rounded border shadow",
36770
- props == null ? void 0 : props.className
36771
- ].join(" "),
36825
+ className: ["p-2 w-full transparent", props == null ? void 0 : props.className].join(" "),
36772
36826
  value: inputValue,
36773
36827
  onBlur: (e) => {
36774
36828
  setTimeout(() => {
@@ -36798,6 +36852,11 @@ function Select({
36798
36852
  onKeyDown: handleKeyDown
36799
36853
  }
36800
36854
  ),
36855
+ label && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("label", { className: "absolute -top-2.5 left-2 text-xs font-bold bg-white px-1", children: [
36856
+ label,
36857
+ " ",
36858
+ (props == null ? void 0 : props.required) && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "text-red-500", children: "*" })
36859
+ ] }),
36801
36860
  !isOpen && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "absolute top-0 right-0 flex flex-col justify-center items-center px-2 py-2 font-bold", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SelectIcon, {}) }),
36802
36861
  isOpen && inputValue != "" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
36803
36862
  "button",
@@ -36821,7 +36880,7 @@ function Select({
36821
36880
  "div",
36822
36881
  {
36823
36882
  style: { zIndex: 9999999999 },
36824
- className: `absolute w-full border rounded shadow bg-white z-10 max-h-100 overflow-y-auto ${openUpwards ? "bottom-full mb-1" : "mt-1"}`,
36883
+ className: `absolute w-full border rounded shadow bg-white z-10 max-h-100 top-10 overflow-y-auto ${openUpwards ? "bottom-full mb-1" : "mt-1"}`,
36825
36884
  children: filtered.map((opt, index) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
36826
36885
  "div",
36827
36886
  {
@@ -37028,13 +37087,6 @@ function PopupOverlay({
37028
37087
  {
37029
37088
  className: "fixed inset-0 flex items-center justify-center z-[1000] ",
37030
37089
  style: { background: "rgba(15,23,42,0.45)", backdropFilter: "blur(2px)" },
37031
- onClick: (e) => {
37032
- var _a;
37033
- if (e.target === e.currentTarget) {
37034
- onClose(false);
37035
- (_a = popup.onCancel) == null ? void 0 : _a.call(popup);
37036
- }
37037
- },
37038
37090
  children: [
37039
37091
  /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("style", { children: `
37040
37092
  @keyframes fadeInScale {