next-recomponents 1.5.96 → 1.5.98
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.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +272 -237
- package/dist/index.mjs +291 -258
- package/package.json +1 -1
- package/src/button/index.tsx +1 -6
- package/src/use-resources/index.ts +285 -252
- package/src/use-resources/types.ts +2 -0
package/dist/index.d.mts
CHANGED
|
@@ -82,6 +82,8 @@ declare function TextArea({ label, className, maxLength, onChange, children, ...
|
|
|
82
82
|
|
|
83
83
|
interface ItemsRecord {
|
|
84
84
|
typeof: Object;
|
|
85
|
+
id?: number;
|
|
86
|
+
defaultParams?: Record<string, any>;
|
|
85
87
|
}
|
|
86
88
|
interface Props$1 {
|
|
87
89
|
baseURI: string;
|
|
@@ -89,7 +91,7 @@ interface Props$1 {
|
|
|
89
91
|
onError?: (error: any) => void;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1):
|
|
94
|
+
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1): any;
|
|
93
95
|
|
|
94
96
|
interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
95
97
|
label?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -82,6 +82,8 @@ declare function TextArea({ label, className, maxLength, onChange, children, ...
|
|
|
82
82
|
|
|
83
83
|
interface ItemsRecord {
|
|
84
84
|
typeof: Object;
|
|
85
|
+
id?: number;
|
|
86
|
+
defaultParams?: Record<string, any>;
|
|
85
87
|
}
|
|
86
88
|
interface Props$1 {
|
|
87
89
|
baseURI: string;
|
|
@@ -89,7 +91,7 @@ interface Props$1 {
|
|
|
89
91
|
onError?: (error: any) => void;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1):
|
|
94
|
+
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1): any;
|
|
93
95
|
|
|
94
96
|
interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
95
97
|
label?: string;
|
package/dist/index.js
CHANGED
|
@@ -32290,77 +32290,134 @@ function useResources({
|
|
|
32290
32290
|
onError
|
|
32291
32291
|
}) {
|
|
32292
32292
|
const token = useToken();
|
|
32293
|
-
const [info, setInfo] = (0, import_react28.useState)(
|
|
32294
|
-
|
|
32295
|
-
|
|
32296
|
-
|
|
32297
|
-
|
|
32298
|
-
|
|
32299
|
-
|
|
32300
|
-
|
|
32301
|
-
|
|
32302
|
-
|
|
32303
|
-
|
|
32304
|
-
|
|
32305
|
-
|
|
32306
|
-
|
|
32307
|
-
|
|
32308
|
-
|
|
32309
|
-
|
|
32310
|
-
|
|
32311
|
-
|
|
32312
|
-
|
|
32313
|
-
|
|
32314
|
-
|
|
32315
|
-
|
|
32316
|
-
|
|
32317
|
-
|
|
32318
|
-
|
|
32319
|
-
|
|
32293
|
+
const [info, setInfo] = (0, import_react28.useState)(
|
|
32294
|
+
Object.keys(endpoints).reduce((acc, key) => {
|
|
32295
|
+
var _a, _b;
|
|
32296
|
+
const newAcc = __spreadProps(__spreadValues({}, acc), {
|
|
32297
|
+
[key]: {
|
|
32298
|
+
loaded: false,
|
|
32299
|
+
id: (_a = endpoints[key]) == null ? void 0 : _a.id,
|
|
32300
|
+
defaultParams: (_b = endpoints[key]) == null ? void 0 : _b.defaultParams
|
|
32301
|
+
}
|
|
32302
|
+
});
|
|
32303
|
+
return newAcc;
|
|
32304
|
+
}, {})
|
|
32305
|
+
);
|
|
32306
|
+
const results = Object.keys(endpoints).reduce((acc, key) => {
|
|
32307
|
+
var _c, _d, _e, _f, _g, _h, _i;
|
|
32308
|
+
const endpoint = endpoints[key];
|
|
32309
|
+
const showFunc = (_a, autoLoad = false) => __async(null, null, function* () {
|
|
32310
|
+
var _b = _a, { limit = 10, page = 1, merge = true } = _b, query = __objRest(_b, ["limit", "page", "merge"]);
|
|
32311
|
+
const options = {
|
|
32312
|
+
method: "GET",
|
|
32313
|
+
url: `${baseURI}/${key}`,
|
|
32314
|
+
params: __spreadValues({ limit, page }, query),
|
|
32315
|
+
headers: { Authorization: token }
|
|
32316
|
+
};
|
|
32317
|
+
const newInfo = __spreadValues({}, info);
|
|
32318
|
+
newInfo[key] = newInfo[key] || {};
|
|
32319
|
+
newInfo[key].state = "loading";
|
|
32320
|
+
newInfo[key].errorMessage = "";
|
|
32321
|
+
newInfo[key].params = query;
|
|
32322
|
+
newInfo[key].loaded = true;
|
|
32323
|
+
setInfo(newInfo);
|
|
32324
|
+
try {
|
|
32325
|
+
const consulta = yield import_axios.default.request(options);
|
|
32326
|
+
const d = consulta.data;
|
|
32327
|
+
newInfo[key].state = "success";
|
|
32328
|
+
newInfo[key].errorMessage = "";
|
|
32329
|
+
newInfo[key].data = merge ? page == 1 ? d.data : [...d.data, ...newInfo[key].data || []] : d.data;
|
|
32330
|
+
newInfo[key].totalItems = d.totalItems;
|
|
32331
|
+
newInfo[key].totalPages = d.totalPages;
|
|
32332
|
+
newInfo[key].currentPage = d.currentPage;
|
|
32333
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32334
|
+
return d.data;
|
|
32335
|
+
} catch (error) {
|
|
32336
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32337
|
+
newInfo[key].state = "error";
|
|
32338
|
+
newInfo[key].errorMessage = item == null ? void 0 : item.meaning;
|
|
32339
|
+
if (error.status == 403) {
|
|
32340
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32341
|
+
}
|
|
32342
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32343
|
+
return error;
|
|
32344
|
+
}
|
|
32345
|
+
});
|
|
32346
|
+
const findFunc = (id3, query, autoLoad = false) => __async(null, null, function* () {
|
|
32347
|
+
var _a, _b, _c2;
|
|
32348
|
+
const options = {
|
|
32349
|
+
method: "GET",
|
|
32350
|
+
url: `${baseURI}/${key}/${id3}`,
|
|
32351
|
+
params: __spreadValues({}, query),
|
|
32352
|
+
headers: { Authorization: token }
|
|
32353
|
+
};
|
|
32354
|
+
const newInfo = __spreadValues({}, info);
|
|
32355
|
+
newInfo[key] = newInfo[key] || {};
|
|
32356
|
+
newInfo[key].state = "loading";
|
|
32357
|
+
newInfo[key].errorMessage = "";
|
|
32358
|
+
newInfo[key].params = query;
|
|
32359
|
+
newInfo[key].loaded = true;
|
|
32360
|
+
setInfo(newInfo);
|
|
32361
|
+
try {
|
|
32362
|
+
const consulta = yield import_axios.default.request(options);
|
|
32363
|
+
const d = consulta.data;
|
|
32364
|
+
newInfo[key].state = "success";
|
|
32365
|
+
newInfo[key].errorMessage = "";
|
|
32366
|
+
if (autoLoad) {
|
|
32367
|
+
} else {
|
|
32368
|
+
newInfo[key].selectedItem = d;
|
|
32369
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32370
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32371
|
+
);
|
|
32372
|
+
if (index >= 0) {
|
|
32373
|
+
newInfo[key].data[index] = d;
|
|
32374
|
+
} else {
|
|
32375
|
+
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32376
|
+
newInfo[key].data.unshift(d);
|
|
32320
32377
|
} else {
|
|
32321
|
-
newInfo[key].data =
|
|
32322
|
-
newInfo[key].totalItems = d.totalItems;
|
|
32323
|
-
newInfo[key].totalPages = d.totalPages;
|
|
32324
|
-
newInfo[key].currentPage = d.currentPage;
|
|
32378
|
+
newInfo[key].data = [d];
|
|
32325
32379
|
}
|
|
32326
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32327
|
-
return d.data;
|
|
32328
|
-
} catch (error) {
|
|
32329
|
-
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32330
|
-
newInfo[key].state = "error";
|
|
32331
|
-
newInfo[key].errorMessage = item == null ? void 0 : item.meaning;
|
|
32332
|
-
if (error.status == 403) {
|
|
32333
|
-
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32334
|
-
}
|
|
32335
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32336
|
-
return error;
|
|
32337
32380
|
}
|
|
32338
|
-
}
|
|
32339
|
-
|
|
32340
|
-
|
|
32341
|
-
|
|
32342
|
-
|
|
32343
|
-
|
|
32344
|
-
|
|
32345
|
-
|
|
32346
|
-
};
|
|
32347
|
-
|
|
32348
|
-
|
|
32349
|
-
|
|
32381
|
+
}
|
|
32382
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32383
|
+
return d;
|
|
32384
|
+
} catch (error) {
|
|
32385
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32386
|
+
newInfo[key].state = "error";
|
|
32387
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32388
|
+
if (error.status == 403) {
|
|
32389
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32390
|
+
}
|
|
32391
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32392
|
+
return error;
|
|
32393
|
+
}
|
|
32394
|
+
});
|
|
32395
|
+
acc[key] = __spreadProps(__spreadValues({}, endpoint), {
|
|
32396
|
+
loaded: false,
|
|
32397
|
+
show: showFunc,
|
|
32398
|
+
find: findFunc,
|
|
32399
|
+
create: (data) => __async(null, null, function* () {
|
|
32400
|
+
var _a, _b, _c2, _d2, _e2, _f2;
|
|
32401
|
+
const options = {
|
|
32402
|
+
method: "POST",
|
|
32403
|
+
url: `${baseURI}/${key}`,
|
|
32404
|
+
data: Array.isArray(data) ? [...data] : __spreadValues({}, data),
|
|
32405
|
+
headers: { Authorization: token }
|
|
32406
|
+
};
|
|
32407
|
+
const newInfo = __spreadValues({}, info);
|
|
32408
|
+
newInfo[key] = newInfo[key] || {};
|
|
32409
|
+
newInfo[key].state = "loading";
|
|
32410
|
+
newInfo[key].errorMessage = "";
|
|
32411
|
+
setInfo(newInfo);
|
|
32412
|
+
try {
|
|
32413
|
+
const consulta = yield import_axios.default.request(options);
|
|
32414
|
+
const d = consulta.data;
|
|
32415
|
+
newInfo[key].state = "success";
|
|
32350
32416
|
newInfo[key].errorMessage = "";
|
|
32351
|
-
|
|
32352
|
-
|
|
32353
|
-
setInfo(newInfo);
|
|
32354
|
-
try {
|
|
32355
|
-
const consulta = yield import_axios.default.request(options);
|
|
32356
|
-
const d = consulta.data;
|
|
32357
|
-
newInfo[key].state = "success";
|
|
32358
|
-
newInfo[key].errorMessage = "";
|
|
32359
|
-
if (autoLoad) {
|
|
32360
|
-
} else {
|
|
32361
|
-
newInfo[key].selectedItem = d;
|
|
32417
|
+
if (Array.isArray(data)) {
|
|
32418
|
+
for (let datum of data) {
|
|
32362
32419
|
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32363
|
-
(d2) => (d2 == null ? void 0 : d2.id) == (
|
|
32420
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
|
|
32364
32421
|
);
|
|
32365
32422
|
if (index >= 0) {
|
|
32366
32423
|
newInfo[key].data[index] = d;
|
|
@@ -32372,181 +32429,159 @@ function useResources({
|
|
|
32372
32429
|
}
|
|
32373
32430
|
}
|
|
32374
32431
|
}
|
|
32375
|
-
|
|
32376
|
-
|
|
32377
|
-
|
|
32378
|
-
|
|
32379
|
-
|
|
32380
|
-
|
|
32381
|
-
|
|
32382
|
-
|
|
32383
|
-
|
|
32384
|
-
|
|
32385
|
-
return error;
|
|
32386
|
-
}
|
|
32387
|
-
});
|
|
32388
|
-
acc[key] = __spreadProps(__spreadValues({}, endpoint), {
|
|
32389
|
-
loaded: !((_c = acc[key]) == null ? void 0 : _c.loaded) ? ((_d = acc[key]) == null ? void 0 : _d.id) ? findFunc(acc[key].id, (_e = acc[key]) == null ? void 0 : _e.defaultParams) : ((_f = acc[key]) == null ? void 0 : _f.defaultParams) ? showFunc(acc[key].defaultParams) : true : true,
|
|
32390
|
-
show: showFunc,
|
|
32391
|
-
find: findFunc,
|
|
32392
|
-
create: (data) => __async(null, null, function* () {
|
|
32393
|
-
var _a, _b, _c2, _d2, _e2, _f2;
|
|
32394
|
-
const options = {
|
|
32395
|
-
method: "POST",
|
|
32396
|
-
url: `${baseURI}/${key}`,
|
|
32397
|
-
data: Array.isArray(data) ? [...data] : __spreadValues({}, data),
|
|
32398
|
-
headers: { Authorization: token }
|
|
32399
|
-
};
|
|
32400
|
-
const newInfo = __spreadValues({}, info);
|
|
32401
|
-
newInfo[key] = newInfo[key] || {};
|
|
32402
|
-
newInfo[key].state = "loading";
|
|
32403
|
-
newInfo[key].errorMessage = "";
|
|
32404
|
-
setInfo(newInfo);
|
|
32405
|
-
try {
|
|
32406
|
-
const consulta = yield import_axios.default.request(options);
|
|
32407
|
-
const d = consulta.data;
|
|
32408
|
-
newInfo[key].state = "success";
|
|
32409
|
-
newInfo[key].errorMessage = "";
|
|
32410
|
-
if (Array.isArray(data)) {
|
|
32411
|
-
for (let datum of data) {
|
|
32412
|
-
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32413
|
-
(d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
|
|
32414
|
-
);
|
|
32415
|
-
if (index >= 0) {
|
|
32416
|
-
newInfo[key].data[index] = d;
|
|
32417
|
-
} else {
|
|
32418
|
-
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32419
|
-
newInfo[key].data.unshift(d);
|
|
32420
|
-
} else {
|
|
32421
|
-
newInfo[key].data = [d];
|
|
32422
|
-
}
|
|
32423
|
-
}
|
|
32424
|
-
}
|
|
32425
|
-
} else {
|
|
32426
|
-
newInfo[key].selectedItem = d;
|
|
32427
|
-
const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
|
|
32428
|
-
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32429
|
-
);
|
|
32430
|
-
if (index >= 0) {
|
|
32431
|
-
newInfo[key].data[index] = d;
|
|
32432
|
-
} else {
|
|
32433
|
-
if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
|
|
32434
|
-
newInfo[key].data.unshift(d);
|
|
32435
|
-
} else {
|
|
32436
|
-
newInfo[key].data = [d];
|
|
32437
|
-
}
|
|
32438
|
-
}
|
|
32439
|
-
}
|
|
32440
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32441
|
-
return d;
|
|
32442
|
-
} catch (error) {
|
|
32443
|
-
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32444
|
-
newInfo[key].state = "error";
|
|
32445
|
-
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32446
|
-
if (error.status == 403) {
|
|
32447
|
-
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32448
|
-
}
|
|
32449
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32450
|
-
return error;
|
|
32451
|
-
}
|
|
32452
|
-
}),
|
|
32453
|
-
update: (id3, data) => __async(null, null, function* () {
|
|
32454
|
-
var _a, _b, _c2;
|
|
32455
|
-
const options = {
|
|
32456
|
-
method: "PATCH",
|
|
32457
|
-
url: `${baseURI}/${key}/${id3}`,
|
|
32458
|
-
data: Array.isArray(data) ? [...data] : __spreadValues({}, data),
|
|
32459
|
-
headers: { Authorization: token }
|
|
32460
|
-
};
|
|
32461
|
-
const newInfo = __spreadValues({}, info);
|
|
32462
|
-
newInfo[key] = newInfo[key] || {};
|
|
32463
|
-
newInfo[key].state = "loading";
|
|
32464
|
-
newInfo[key].errorMessage = "";
|
|
32465
|
-
setInfo(newInfo);
|
|
32466
|
-
try {
|
|
32467
|
-
const consulta = yield import_axios.default.request(options);
|
|
32468
|
-
const d = consulta.data;
|
|
32469
|
-
newInfo[key].state = "success";
|
|
32470
|
-
newInfo[key].errorMessage = "";
|
|
32471
|
-
newInfo[key].selectedItem = d;
|
|
32472
|
-
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32473
|
-
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32474
|
-
);
|
|
32475
|
-
if (index >= 0) {
|
|
32476
|
-
newInfo[key].data[index] = d;
|
|
32432
|
+
} else {
|
|
32433
|
+
newInfo[key].selectedItem = d;
|
|
32434
|
+
const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
|
|
32435
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32436
|
+
);
|
|
32437
|
+
if (index >= 0) {
|
|
32438
|
+
newInfo[key].data[index] = d;
|
|
32439
|
+
} else {
|
|
32440
|
+
if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
|
|
32441
|
+
newInfo[key].data.unshift(d);
|
|
32477
32442
|
} else {
|
|
32478
|
-
|
|
32479
|
-
newInfo[key].data.unshift(d);
|
|
32480
|
-
} else {
|
|
32481
|
-
newInfo[key].data = [d];
|
|
32482
|
-
}
|
|
32483
|
-
}
|
|
32484
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32485
|
-
return d;
|
|
32486
|
-
} catch (error) {
|
|
32487
|
-
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32488
|
-
newInfo[key].state = "error";
|
|
32489
|
-
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32490
|
-
if (error.status == 403) {
|
|
32491
|
-
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32443
|
+
newInfo[key].data = [d];
|
|
32492
32444
|
}
|
|
32493
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32494
|
-
return error;
|
|
32495
32445
|
}
|
|
32496
|
-
}
|
|
32497
|
-
|
|
32498
|
-
|
|
32499
|
-
|
|
32500
|
-
|
|
32501
|
-
|
|
32502
|
-
|
|
32503
|
-
|
|
32504
|
-
|
|
32505
|
-
|
|
32506
|
-
|
|
32507
|
-
|
|
32508
|
-
|
|
32509
|
-
|
|
32510
|
-
|
|
32511
|
-
|
|
32512
|
-
|
|
32513
|
-
|
|
32514
|
-
|
|
32515
|
-
|
|
32516
|
-
|
|
32517
|
-
|
|
32518
|
-
|
|
32519
|
-
|
|
32520
|
-
|
|
32521
|
-
|
|
32522
|
-
|
|
32523
|
-
|
|
32524
|
-
|
|
32525
|
-
|
|
32526
|
-
|
|
32527
|
-
|
|
32528
|
-
|
|
32529
|
-
|
|
32530
|
-
|
|
32531
|
-
|
|
32446
|
+
}
|
|
32447
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32448
|
+
return d;
|
|
32449
|
+
} catch (error) {
|
|
32450
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32451
|
+
newInfo[key].state = "error";
|
|
32452
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32453
|
+
if (error.status == 403) {
|
|
32454
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32455
|
+
}
|
|
32456
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32457
|
+
return error;
|
|
32458
|
+
}
|
|
32459
|
+
}),
|
|
32460
|
+
update: (id3, data) => __async(null, null, function* () {
|
|
32461
|
+
var _a, _b, _c2;
|
|
32462
|
+
const options = {
|
|
32463
|
+
method: "PATCH",
|
|
32464
|
+
url: `${baseURI}/${key}/${id3}`,
|
|
32465
|
+
data: Array.isArray(data) ? [...data] : __spreadValues({}, data),
|
|
32466
|
+
headers: { Authorization: token }
|
|
32467
|
+
};
|
|
32468
|
+
const newInfo = __spreadValues({}, info);
|
|
32469
|
+
newInfo[key] = newInfo[key] || {};
|
|
32470
|
+
newInfo[key].state = "loading";
|
|
32471
|
+
newInfo[key].errorMessage = "";
|
|
32472
|
+
setInfo(newInfo);
|
|
32473
|
+
try {
|
|
32474
|
+
const consulta = yield import_axios.default.request(options);
|
|
32475
|
+
const d = consulta.data;
|
|
32476
|
+
newInfo[key].state = "success";
|
|
32477
|
+
newInfo[key].errorMessage = "";
|
|
32478
|
+
newInfo[key].selectedItem = d;
|
|
32479
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32480
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32481
|
+
);
|
|
32482
|
+
if (index >= 0) {
|
|
32483
|
+
newInfo[key].data[index] = d;
|
|
32484
|
+
} else {
|
|
32485
|
+
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32486
|
+
newInfo[key].data.unshift(d);
|
|
32487
|
+
} else {
|
|
32488
|
+
newInfo[key].data = [d];
|
|
32532
32489
|
}
|
|
32533
|
-
}
|
|
32534
|
-
|
|
32535
|
-
|
|
32536
|
-
|
|
32537
|
-
|
|
32538
|
-
|
|
32539
|
-
|
|
32540
|
-
|
|
32541
|
-
|
|
32542
|
-
|
|
32543
|
-
|
|
32544
|
-
|
|
32545
|
-
|
|
32546
|
-
},
|
|
32547
|
-
|
|
32548
|
-
|
|
32549
|
-
|
|
32490
|
+
}
|
|
32491
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32492
|
+
return d;
|
|
32493
|
+
} catch (error) {
|
|
32494
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32495
|
+
newInfo[key].state = "error";
|
|
32496
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32497
|
+
if (error.status == 403) {
|
|
32498
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32499
|
+
}
|
|
32500
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32501
|
+
return error;
|
|
32502
|
+
}
|
|
32503
|
+
}),
|
|
32504
|
+
remove: (id3) => __async(null, null, function* () {
|
|
32505
|
+
var _a, _b;
|
|
32506
|
+
const options = {
|
|
32507
|
+
method: "DELETE",
|
|
32508
|
+
url: `${baseURI}/${key}/${id3}`,
|
|
32509
|
+
headers: { Authorization: token }
|
|
32510
|
+
};
|
|
32511
|
+
const newInfo = __spreadValues({}, info);
|
|
32512
|
+
newInfo[key] = newInfo[key] || {};
|
|
32513
|
+
newInfo[key].state = "loading";
|
|
32514
|
+
newInfo[key].errorMessage = "";
|
|
32515
|
+
setInfo(newInfo);
|
|
32516
|
+
try {
|
|
32517
|
+
const consulta = yield import_axios.default.request(options);
|
|
32518
|
+
const d = consulta.data;
|
|
32519
|
+
newInfo[key].state = "success";
|
|
32520
|
+
newInfo[key].errorMessage = "";
|
|
32521
|
+
newInfo[key].selectedItem = d;
|
|
32522
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32523
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32524
|
+
);
|
|
32525
|
+
if (index >= 0) {
|
|
32526
|
+
newInfo[key].data.splice(index, 1);
|
|
32527
|
+
}
|
|
32528
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32529
|
+
return d.data;
|
|
32530
|
+
} catch (error) {
|
|
32531
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32532
|
+
newInfo[key].state = "error";
|
|
32533
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32534
|
+
if (error.status == 403) {
|
|
32535
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32536
|
+
}
|
|
32537
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32538
|
+
return error;
|
|
32539
|
+
}
|
|
32540
|
+
}),
|
|
32541
|
+
totalPages: (_c = info[key]) == null ? void 0 : _c.totalPages,
|
|
32542
|
+
currentPage: (_d = info[key]) == null ? void 0 : _d.currentPage,
|
|
32543
|
+
state: ((_e = info[key]) == null ? void 0 : _e.state) || "success",
|
|
32544
|
+
errorMessage: (_f = info[key]) == null ? void 0 : _f.errorMessage,
|
|
32545
|
+
params: (_g = info[key]) == null ? void 0 : _g.params,
|
|
32546
|
+
setLoaded: () => {
|
|
32547
|
+
const newInfo = __spreadValues({}, info);
|
|
32548
|
+
newInfo[key].loaded = true;
|
|
32549
|
+
setInfo(newInfo);
|
|
32550
|
+
},
|
|
32551
|
+
getAllPages: (limit = 10) => __async(null, null, function* () {
|
|
32552
|
+
console.log("Not aviable");
|
|
32553
|
+
}),
|
|
32554
|
+
data: ((_h = info[key]) == null ? void 0 : _h.data) || [],
|
|
32555
|
+
selectedItem: ((_i = info[key]) == null ? void 0 : _i.selectedItem) || {}
|
|
32556
|
+
});
|
|
32557
|
+
return acc;
|
|
32558
|
+
}, {});
|
|
32559
|
+
function doSome() {
|
|
32560
|
+
return __async(this, null, function* () {
|
|
32561
|
+
var _a, _b, _c, _d, _e;
|
|
32562
|
+
const key = Object.keys(info).find((k) => {
|
|
32563
|
+
return info[k].loaded === false;
|
|
32564
|
+
});
|
|
32565
|
+
if (key) {
|
|
32566
|
+
if ((_a = info[key]) == null ? void 0 : _a.id) {
|
|
32567
|
+
yield results[key].find((_b = info[key]) == null ? void 0 : _b.id, (_c = info[key]) == null ? void 0 : _c.defaultParams);
|
|
32568
|
+
} else if ((_d = info[key]) == null ? void 0 : _d.defaultParams) {
|
|
32569
|
+
yield results[key].show((_e = info[key]) == null ? void 0 : _e.defaultParams);
|
|
32570
|
+
} else {
|
|
32571
|
+
results[key].setLoaded();
|
|
32572
|
+
}
|
|
32573
|
+
}
|
|
32574
|
+
});
|
|
32575
|
+
}
|
|
32576
|
+
(0, import_react28.useEffect)(() => {
|
|
32577
|
+
doSome();
|
|
32578
|
+
}, [
|
|
32579
|
+
//si algun key de info no ha sido leido
|
|
32580
|
+
Object.keys(info).map((key) => {
|
|
32581
|
+
return info[key].loaded;
|
|
32582
|
+
})
|
|
32583
|
+
]);
|
|
32584
|
+
return results;
|
|
32550
32585
|
}
|
|
32551
32586
|
|
|
32552
32587
|
// src/select/index.tsx
|