next-recomponents 1.5.3 → 1.5.5
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 +1 -30
- package/dist/index.d.ts +1 -30
- package/dist/index.js +201 -206
- package/dist/index.mjs +202 -207
- package/package.json +1 -1
- package/src/table/h.tsx +1 -1
- package/src/table/td.tsx +1 -2
- package/src/use-resources/index.ts +468 -205
- package/src/use-resources/types.ts +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -85,40 +85,11 @@ interface ItemsRecord {
|
|
|
85
85
|
}
|
|
86
86
|
interface Props$1 {
|
|
87
87
|
baseURI: string;
|
|
88
|
-
authURI?: string;
|
|
89
88
|
endpoints: Record<string, Partial<ItemsRecord>>;
|
|
90
89
|
onError?: (error: any) => void;
|
|
91
90
|
}
|
|
92
|
-
interface ShowOptions {
|
|
93
|
-
limit?: number;
|
|
94
|
-
merge?: boolean;
|
|
95
|
-
page?: number;
|
|
96
|
-
[key: string | number]: string | number | undefined | null | boolean;
|
|
97
|
-
}
|
|
98
|
-
type EnhancedEndpoints<T extends Record<string, ItemsRecord>> = {
|
|
99
|
-
[K in keyof T]: {
|
|
100
|
-
typeof: T[K]["typeof"];
|
|
101
|
-
state: "success" | "loading" | "error";
|
|
102
|
-
show: (props: ShowOptions) => Promise<Array<T[K]["typeof"]>>;
|
|
103
|
-
create: (data: Partial<T[K]["typeof"]> | Partial<T[K]["typeof"]>[]) => Promise<T[K]["typeof"]>;
|
|
104
|
-
update: (id: number | string, data: Partial<T[K]["typeof"]> | Partial<T[K]["typeof"]>[]) => Promise<T[K]["typeof"]>;
|
|
105
|
-
remove: (id: number | string) => Promise<T[K]["typeof"]>;
|
|
106
|
-
find: (id: number | string, props?: Record<string, string>) => Promise<T[K]["typeof"]>;
|
|
107
|
-
getAllPages: (limit: number) => Promise<Array<T[K]["typeof"]>>;
|
|
108
|
-
data: T[K]["typeof"][];
|
|
109
|
-
selectedItem: T[K]["typeof"];
|
|
110
|
-
params: Record<string, any>;
|
|
111
|
-
currentPage: number;
|
|
112
|
-
totalItems: number;
|
|
113
|
-
totalPages: number;
|
|
114
|
-
errorMessage: string;
|
|
115
|
-
autoLoad?: Boolean;
|
|
116
|
-
defaultParams?: Record<string, any>;
|
|
117
|
-
id?: number | string;
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
91
|
|
|
121
|
-
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI,
|
|
92
|
+
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1): any;
|
|
122
93
|
|
|
123
94
|
interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
124
95
|
label?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -85,40 +85,11 @@ interface ItemsRecord {
|
|
|
85
85
|
}
|
|
86
86
|
interface Props$1 {
|
|
87
87
|
baseURI: string;
|
|
88
|
-
authURI?: string;
|
|
89
88
|
endpoints: Record<string, Partial<ItemsRecord>>;
|
|
90
89
|
onError?: (error: any) => void;
|
|
91
90
|
}
|
|
92
|
-
interface ShowOptions {
|
|
93
|
-
limit?: number;
|
|
94
|
-
merge?: boolean;
|
|
95
|
-
page?: number;
|
|
96
|
-
[key: string | number]: string | number | undefined | null | boolean;
|
|
97
|
-
}
|
|
98
|
-
type EnhancedEndpoints<T extends Record<string, ItemsRecord>> = {
|
|
99
|
-
[K in keyof T]: {
|
|
100
|
-
typeof: T[K]["typeof"];
|
|
101
|
-
state: "success" | "loading" | "error";
|
|
102
|
-
show: (props: ShowOptions) => Promise<Array<T[K]["typeof"]>>;
|
|
103
|
-
create: (data: Partial<T[K]["typeof"]> | Partial<T[K]["typeof"]>[]) => Promise<T[K]["typeof"]>;
|
|
104
|
-
update: (id: number | string, data: Partial<T[K]["typeof"]> | Partial<T[K]["typeof"]>[]) => Promise<T[K]["typeof"]>;
|
|
105
|
-
remove: (id: number | string) => Promise<T[K]["typeof"]>;
|
|
106
|
-
find: (id: number | string, props?: Record<string, string>) => Promise<T[K]["typeof"]>;
|
|
107
|
-
getAllPages: (limit: number) => Promise<Array<T[K]["typeof"]>>;
|
|
108
|
-
data: T[K]["typeof"][];
|
|
109
|
-
selectedItem: T[K]["typeof"];
|
|
110
|
-
params: Record<string, any>;
|
|
111
|
-
currentPage: number;
|
|
112
|
-
totalItems: number;
|
|
113
|
-
totalPages: number;
|
|
114
|
-
errorMessage: string;
|
|
115
|
-
autoLoad?: Boolean;
|
|
116
|
-
defaultParams?: Record<string, any>;
|
|
117
|
-
id?: number | string;
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
91
|
|
|
121
|
-
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI,
|
|
92
|
+
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1): any;
|
|
122
93
|
|
|
123
94
|
interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
124
95
|
label?: string;
|
package/dist/index.js
CHANGED
|
@@ -11186,11 +11186,10 @@ function TD(_a) {
|
|
|
11186
11186
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: (item == null ? void 0 : item.handler) ? import_react23.default.Children.map(item.handler, (handler) => {
|
|
11187
11187
|
if (import_react23.default.isValidElement(handler)) {
|
|
11188
11188
|
const { type, props: props2 } = handler;
|
|
11189
|
-
|
|
11190
|
-
return import_react23.default.createElement(type, __spreadProps(__spreadValues({}, otherProps), {
|
|
11189
|
+
return import_react23.default.createElement(type, __spreadProps(__spreadValues({}, props2), {
|
|
11191
11190
|
value: mapedData[index][item.name].content,
|
|
11192
11191
|
onChange: (e) => {
|
|
11193
|
-
var
|
|
11192
|
+
var _a3, _b3;
|
|
11194
11193
|
const nmd = [...mapedData];
|
|
11195
11194
|
nmd[index][item.name].content = e.target.value;
|
|
11196
11195
|
e.item = Object.assign(
|
|
@@ -11207,7 +11206,7 @@ function TD(_a) {
|
|
|
11207
11206
|
setMapedData == null ? void 0 : setMapedData(nmd2);
|
|
11208
11207
|
};
|
|
11209
11208
|
setMapedData == null ? void 0 : setMapedData(nmd);
|
|
11210
|
-
(_b3 = (
|
|
11209
|
+
(_b3 = (_a3 = handler == null ? void 0 : handler.props) == null ? void 0 : _a3.onChange) == null ? void 0 : _b3.call(_a3, e);
|
|
11211
11210
|
}
|
|
11212
11211
|
}));
|
|
11213
11212
|
}
|
|
@@ -31987,7 +31986,7 @@ function HTable(_a) {
|
|
|
31987
31986
|
const isObject2 = typeOf == "object";
|
|
31988
31987
|
const isDate = typeOf == "string" && d[key].toString().includes("T");
|
|
31989
31988
|
const cellTypeOf = isDate ? "date" : isObject2 ? "object" : typeOf;
|
|
31990
|
-
const content = cellTypeOf == "date" ? d[key].split("T").join(" ").split(".")[0] : cellTypeOf == "object" ? import_react25.default.isValidElement(d[key]) ? ((_b2 = d[key]) == null ? void 0 : _b2.props).
|
|
31989
|
+
const content = cellTypeOf == "date" ? d[key].split("T").join(" ").split(".")[0] : cellTypeOf == "object" ? import_react25.default.isValidElement(d[key]) ? ((_b2 = d[key]) == null ? void 0 : _b2.props).value : JSON.stringify(d[key]) : d[key];
|
|
31991
31990
|
const handler = import_react25.default.isValidElement(d[key]) ? d[key] : null;
|
|
31992
31991
|
obj[key] = {
|
|
31993
31992
|
index: trkey,
|
|
@@ -32287,31 +32286,66 @@ var http_codes_default = httpStatusCodes;
|
|
|
32287
32286
|
// src/use-resources/index.ts
|
|
32288
32287
|
function useResources({
|
|
32289
32288
|
baseURI,
|
|
32290
|
-
authURI = "/auth/login",
|
|
32291
32289
|
endpoints,
|
|
32292
32290
|
onError
|
|
32293
32291
|
}) {
|
|
32294
32292
|
const token = useToken();
|
|
32295
32293
|
const [info, setInfo] = (0, import_react28.useState)({});
|
|
32296
|
-
const result = (
|
|
32294
|
+
const result = Object.keys(endpoints).reduce((acc, key) => {
|
|
32297
32295
|
var _c, _d, _e, _f, _g, _h, _i;
|
|
32298
|
-
const
|
|
32299
|
-
|
|
32300
|
-
|
|
32301
|
-
|
|
32302
|
-
|
|
32303
|
-
|
|
32304
|
-
|
|
32305
|
-
|
|
32306
|
-
|
|
32307
|
-
|
|
32308
|
-
|
|
32309
|
-
|
|
32310
|
-
|
|
32296
|
+
const endpoint = endpoints[key];
|
|
32297
|
+
const showFunc = (_a) => __async(null, null, function* () {
|
|
32298
|
+
var _b = _a, {
|
|
32299
|
+
limit = 10,
|
|
32300
|
+
page = 1,
|
|
32301
|
+
merge = true
|
|
32302
|
+
} = _b, query = __objRest(_b, [
|
|
32303
|
+
"limit",
|
|
32304
|
+
"page",
|
|
32305
|
+
"merge"
|
|
32306
|
+
]);
|
|
32307
|
+
const options = {
|
|
32308
|
+
method: "GET",
|
|
32309
|
+
url: `${baseURI}/${key}`,
|
|
32310
|
+
params: __spreadValues({ limit, page }, query),
|
|
32311
|
+
headers: { Authorization: token }
|
|
32312
|
+
};
|
|
32313
|
+
const newInfo = __spreadValues({}, info);
|
|
32314
|
+
newInfo[key] = newInfo[key] || {};
|
|
32315
|
+
newInfo[key].state = "loading";
|
|
32316
|
+
newInfo[key].errorMessage = "";
|
|
32317
|
+
newInfo[key].params = query;
|
|
32318
|
+
setInfo(newInfo);
|
|
32319
|
+
try {
|
|
32320
|
+
const consulta = yield import_axios.default.request(options);
|
|
32321
|
+
const d = consulta.data;
|
|
32322
|
+
newInfo[key].state = "success";
|
|
32323
|
+
newInfo[key].errorMessage = "";
|
|
32324
|
+
newInfo[key].data = merge ? page == 1 ? d.data : [...d.data, ...newInfo[key].data || []] : d.data;
|
|
32325
|
+
newInfo[key].totalItems = d.totalItems;
|
|
32326
|
+
newInfo[key].totalPages = d.totalPages;
|
|
32327
|
+
newInfo[key].currentPage = d.currentPage;
|
|
32328
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32329
|
+
return d.data;
|
|
32330
|
+
} catch (error) {
|
|
32331
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32332
|
+
newInfo[key].state = "error";
|
|
32333
|
+
newInfo[key].errorMessage = item == null ? void 0 : item.meaning;
|
|
32334
|
+
if (error.status == 403) {
|
|
32335
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32336
|
+
}
|
|
32337
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32338
|
+
return error;
|
|
32339
|
+
}
|
|
32340
|
+
});
|
|
32341
|
+
acc[key] = __spreadProps(__spreadValues({}, endpoint), {
|
|
32342
|
+
show: showFunc,
|
|
32343
|
+
find: (id3, query) => __async(null, null, function* () {
|
|
32344
|
+
var _a, _b, _c2;
|
|
32311
32345
|
const options = {
|
|
32312
32346
|
method: "GET",
|
|
32313
|
-
url: `${baseURI}/${key}`,
|
|
32314
|
-
params: __spreadValues({
|
|
32347
|
+
url: `${baseURI}/${key}/${id3}`,
|
|
32348
|
+
params: __spreadValues({}, query),
|
|
32315
32349
|
headers: { Authorization: token }
|
|
32316
32350
|
};
|
|
32317
32351
|
const newInfo = __spreadValues({}, info);
|
|
@@ -32325,226 +32359,187 @@ function useResources({
|
|
|
32325
32359
|
const d = consulta.data;
|
|
32326
32360
|
newInfo[key].state = "success";
|
|
32327
32361
|
newInfo[key].errorMessage = "";
|
|
32328
|
-
newInfo[key].
|
|
32329
|
-
newInfo[key].
|
|
32330
|
-
|
|
32331
|
-
|
|
32362
|
+
newInfo[key].selectedItem = d;
|
|
32363
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32364
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32365
|
+
);
|
|
32366
|
+
if (index >= 0) {
|
|
32367
|
+
newInfo[key].data[index] = d;
|
|
32368
|
+
} else {
|
|
32369
|
+
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32370
|
+
newInfo[key].data.unshift(d);
|
|
32371
|
+
} else {
|
|
32372
|
+
newInfo[key].data = [d];
|
|
32373
|
+
}
|
|
32374
|
+
}
|
|
32332
32375
|
setInfo(__spreadValues({}, newInfo));
|
|
32333
|
-
return d
|
|
32376
|
+
return d;
|
|
32334
32377
|
} catch (error) {
|
|
32335
32378
|
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32336
32379
|
newInfo[key].state = "error";
|
|
32337
|
-
newInfo[key].errorMessage = item == null ? void 0 : item.meaning;
|
|
32380
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32338
32381
|
if (error.status == 403) {
|
|
32339
32382
|
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32340
32383
|
}
|
|
32341
32384
|
setInfo(__spreadValues({}, newInfo));
|
|
32342
32385
|
return error;
|
|
32343
32386
|
}
|
|
32344
|
-
})
|
|
32345
|
-
|
|
32346
|
-
|
|
32347
|
-
|
|
32348
|
-
|
|
32349
|
-
|
|
32350
|
-
|
|
32351
|
-
|
|
32352
|
-
|
|
32353
|
-
|
|
32354
|
-
|
|
32355
|
-
|
|
32356
|
-
|
|
32357
|
-
|
|
32358
|
-
|
|
32359
|
-
|
|
32360
|
-
|
|
32361
|
-
|
|
32362
|
-
const consulta = yield import_axios.default.request(options);
|
|
32363
|
-
const d = consulta.data;
|
|
32364
|
-
newInfo[key].state = "success";
|
|
32365
|
-
newInfo[key].errorMessage = "";
|
|
32366
|
-
newInfo[key].selectedItem = d;
|
|
32367
|
-
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32368
|
-
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32369
|
-
);
|
|
32370
|
-
if (index >= 0) {
|
|
32371
|
-
newInfo[key].data[index] = d;
|
|
32372
|
-
} else {
|
|
32373
|
-
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32374
|
-
newInfo[key].data.unshift(d);
|
|
32375
|
-
} else {
|
|
32376
|
-
newInfo[key].data = [d];
|
|
32377
|
-
}
|
|
32378
|
-
}
|
|
32379
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32380
|
-
return d;
|
|
32381
|
-
} catch (error) {
|
|
32382
|
-
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32383
|
-
newInfo[key].state = "error";
|
|
32384
|
-
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32385
|
-
if (error.status == 403) {
|
|
32386
|
-
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32387
|
-
}
|
|
32388
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32389
|
-
return error;
|
|
32390
|
-
}
|
|
32391
|
-
}),
|
|
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";
|
|
32387
|
+
}),
|
|
32388
|
+
create: (data) => __async(null, null, function* () {
|
|
32389
|
+
var _a, _b, _c2, _d2, _e2, _f2;
|
|
32390
|
+
const options = {
|
|
32391
|
+
method: "POST",
|
|
32392
|
+
url: `${baseURI}/${key}`,
|
|
32393
|
+
data: Array.isArray(data) ? [...data] : __spreadValues({}, data),
|
|
32394
|
+
headers: { Authorization: token }
|
|
32395
|
+
};
|
|
32396
|
+
const newInfo = __spreadValues({}, info);
|
|
32397
|
+
newInfo[key] = newInfo[key] || {};
|
|
32398
|
+
newInfo[key].state = "loading";
|
|
32399
|
+
newInfo[key].errorMessage = "";
|
|
32400
|
+
setInfo(newInfo);
|
|
32401
|
+
try {
|
|
32402
|
+
const consulta = yield import_axios.default.request(options);
|
|
32403
|
+
const d = consulta.data;
|
|
32404
|
+
newInfo[key].state = "success";
|
|
32403
32405
|
newInfo[key].errorMessage = "";
|
|
32404
|
-
|
|
32405
|
-
|
|
32406
|
-
|
|
32407
|
-
|
|
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)
|
|
32406
|
+
if (Array.isArray(data)) {
|
|
32407
|
+
for (let datum of data) {
|
|
32408
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32409
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
|
|
32429
32410
|
);
|
|
32430
32411
|
if (index >= 0) {
|
|
32431
32412
|
newInfo[key].data[index] = d;
|
|
32432
32413
|
} else {
|
|
32433
|
-
if ((
|
|
32414
|
+
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32434
32415
|
newInfo[key].data.unshift(d);
|
|
32435
32416
|
} else {
|
|
32436
32417
|
newInfo[key].data = [d];
|
|
32437
32418
|
}
|
|
32438
32419
|
}
|
|
32439
32420
|
}
|
|
32440
|
-
|
|
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 = "";
|
|
32421
|
+
} else {
|
|
32471
32422
|
newInfo[key].selectedItem = d;
|
|
32472
|
-
const index = (
|
|
32423
|
+
const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
|
|
32473
32424
|
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32474
32425
|
);
|
|
32475
32426
|
if (index >= 0) {
|
|
32476
32427
|
newInfo[key].data[index] = d;
|
|
32477
32428
|
} else {
|
|
32478
|
-
if ((
|
|
32429
|
+
if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
|
|
32479
32430
|
newInfo[key].data.unshift(d);
|
|
32480
32431
|
} else {
|
|
32481
32432
|
newInfo[key].data = [d];
|
|
32482
32433
|
}
|
|
32483
32434
|
}
|
|
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 }));
|
|
32492
|
-
}
|
|
32493
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32494
|
-
return error;
|
|
32495
32435
|
}
|
|
32496
|
-
|
|
32497
|
-
|
|
32498
|
-
|
|
32499
|
-
const
|
|
32500
|
-
|
|
32501
|
-
|
|
32502
|
-
|
|
32503
|
-
|
|
32504
|
-
|
|
32505
|
-
|
|
32506
|
-
|
|
32436
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32437
|
+
return d;
|
|
32438
|
+
} catch (error) {
|
|
32439
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32440
|
+
newInfo[key].state = "error";
|
|
32441
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32442
|
+
if (error.status == 403) {
|
|
32443
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32444
|
+
}
|
|
32445
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32446
|
+
return error;
|
|
32447
|
+
}
|
|
32448
|
+
}),
|
|
32449
|
+
update: (id3, data) => __async(null, null, function* () {
|
|
32450
|
+
var _a, _b, _c2;
|
|
32451
|
+
const options = {
|
|
32452
|
+
method: "PATCH",
|
|
32453
|
+
url: `${baseURI}/${key}/${id3}`,
|
|
32454
|
+
data: Array.isArray(data) ? [...data] : __spreadValues({}, data),
|
|
32455
|
+
headers: { Authorization: token }
|
|
32456
|
+
};
|
|
32457
|
+
const newInfo = __spreadValues({}, info);
|
|
32458
|
+
newInfo[key] = newInfo[key] || {};
|
|
32459
|
+
newInfo[key].state = "loading";
|
|
32460
|
+
newInfo[key].errorMessage = "";
|
|
32461
|
+
setInfo(newInfo);
|
|
32462
|
+
try {
|
|
32463
|
+
const consulta = yield import_axios.default.request(options);
|
|
32464
|
+
const d = consulta.data;
|
|
32465
|
+
newInfo[key].state = "success";
|
|
32507
32466
|
newInfo[key].errorMessage = "";
|
|
32508
|
-
|
|
32509
|
-
|
|
32510
|
-
|
|
32511
|
-
|
|
32512
|
-
|
|
32513
|
-
newInfo[key].
|
|
32514
|
-
|
|
32515
|
-
|
|
32516
|
-
|
|
32517
|
-
|
|
32518
|
-
|
|
32519
|
-
newInfo[key].data.splice(index, 1);
|
|
32520
|
-
}
|
|
32521
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32522
|
-
return d.data;
|
|
32523
|
-
} catch (error) {
|
|
32524
|
-
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32525
|
-
newInfo[key].state = "error";
|
|
32526
|
-
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32527
|
-
if (error.status == 403) {
|
|
32528
|
-
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32467
|
+
newInfo[key].selectedItem = d;
|
|
32468
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32469
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32470
|
+
);
|
|
32471
|
+
if (index >= 0) {
|
|
32472
|
+
newInfo[key].data[index] = d;
|
|
32473
|
+
} else {
|
|
32474
|
+
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32475
|
+
newInfo[key].data.unshift(d);
|
|
32476
|
+
} else {
|
|
32477
|
+
newInfo[key].data = [d];
|
|
32529
32478
|
}
|
|
32530
|
-
setInfo(__spreadValues({}, newInfo));
|
|
32531
|
-
return error;
|
|
32532
32479
|
}
|
|
32533
|
-
|
|
32534
|
-
|
|
32535
|
-
|
|
32536
|
-
|
|
32537
|
-
|
|
32538
|
-
|
|
32539
|
-
|
|
32540
|
-
|
|
32541
|
-
|
|
32542
|
-
|
|
32543
|
-
|
|
32544
|
-
|
|
32545
|
-
|
|
32546
|
-
|
|
32547
|
-
|
|
32480
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32481
|
+
return d;
|
|
32482
|
+
} catch (error) {
|
|
32483
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32484
|
+
newInfo[key].state = "error";
|
|
32485
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32486
|
+
if (error.status == 403) {
|
|
32487
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32488
|
+
}
|
|
32489
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32490
|
+
return error;
|
|
32491
|
+
}
|
|
32492
|
+
}),
|
|
32493
|
+
remove: (id3) => __async(null, null, function* () {
|
|
32494
|
+
var _a, _b;
|
|
32495
|
+
const options = {
|
|
32496
|
+
method: "DELETE",
|
|
32497
|
+
url: `${baseURI}/${key}/${id3}`,
|
|
32498
|
+
headers: { Authorization: token }
|
|
32499
|
+
};
|
|
32500
|
+
const newInfo = __spreadValues({}, info);
|
|
32501
|
+
newInfo[key] = newInfo[key] || {};
|
|
32502
|
+
newInfo[key].state = "loading";
|
|
32503
|
+
newInfo[key].errorMessage = "";
|
|
32504
|
+
setInfo(newInfo);
|
|
32505
|
+
try {
|
|
32506
|
+
const consulta = yield import_axios.default.request(options);
|
|
32507
|
+
const d = consulta.data;
|
|
32508
|
+
newInfo[key].state = "success";
|
|
32509
|
+
newInfo[key].errorMessage = "";
|
|
32510
|
+
newInfo[key].selectedItem = d;
|
|
32511
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32512
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
|
|
32513
|
+
);
|
|
32514
|
+
if (index >= 0) {
|
|
32515
|
+
newInfo[key].data.splice(index, 1);
|
|
32516
|
+
}
|
|
32517
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32518
|
+
return d.data;
|
|
32519
|
+
} catch (error) {
|
|
32520
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32521
|
+
newInfo[key].state = "error";
|
|
32522
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32523
|
+
if (error.status == 403) {
|
|
32524
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32525
|
+
}
|
|
32526
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32527
|
+
return error;
|
|
32528
|
+
}
|
|
32529
|
+
}),
|
|
32530
|
+
totalPages: (_c = info[key]) == null ? void 0 : _c.totalPages,
|
|
32531
|
+
currentPage: (_d = info[key]) == null ? void 0 : _d.currentPage,
|
|
32532
|
+
state: ((_e = info[key]) == null ? void 0 : _e.state) || "success",
|
|
32533
|
+
errorMessage: (_f = info[key]) == null ? void 0 : _f.errorMessage,
|
|
32534
|
+
params: (_g = info[key]) == null ? void 0 : _g.params,
|
|
32535
|
+
getAllPages: (limit = 10) => __async(null, null, function* () {
|
|
32536
|
+
console.log("Not aviable");
|
|
32537
|
+
}),
|
|
32538
|
+
data: ((_h = info[key]) == null ? void 0 : _h.data) || [],
|
|
32539
|
+
selectedItem: ((_i = info[key]) == null ? void 0 : _i.selectedItem) || {}
|
|
32540
|
+
});
|
|
32541
|
+
return acc;
|
|
32542
|
+
}, {});
|
|
32548
32543
|
(0, import_react28.useEffect)(() => {
|
|
32549
32544
|
var _a, _b;
|
|
32550
32545
|
for (let item in result) {
|