next-recomponents 1.5.99 → 1.6.2
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 +35 -5
- package/dist/index.d.ts +35 -5
- package/dist/index.js +202 -202
- package/dist/index.mjs +202 -202
- package/package.json +1 -1
- package/src/table/h.tsx +3 -2
- package/src/table/td.tsx +5 -4
- package/src/use-resources/index.ts +209 -209
- package/src/use-resources/types.ts +11 -7
package/dist/index.d.mts
CHANGED
|
@@ -80,18 +80,48 @@ interface Props$2 extends DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaE
|
|
|
80
80
|
}
|
|
81
81
|
declare function TextArea({ label, className, maxLength, onChange, children, ...props }: Props$2): react_jsx_runtime.JSX.Element;
|
|
82
82
|
|
|
83
|
-
interface ItemsRecord {
|
|
84
|
-
typeof:
|
|
83
|
+
interface ItemsRecord<T = any> {
|
|
84
|
+
typeof: T;
|
|
85
85
|
id?: number | string | string[] | undefined;
|
|
86
86
|
defaultParams?: Record<string, any>;
|
|
87
87
|
}
|
|
88
|
-
interface Props$1 {
|
|
88
|
+
interface Props$1<T extends Record<string, ItemsRecord>> {
|
|
89
89
|
baseURI: string;
|
|
90
|
-
endpoints:
|
|
90
|
+
endpoints: T;
|
|
91
91
|
onError?: (error: any) => void;
|
|
92
92
|
}
|
|
93
|
+
interface ShowOptions {
|
|
94
|
+
limit?: number;
|
|
95
|
+
merge?: boolean;
|
|
96
|
+
page?: number;
|
|
97
|
+
[key: string | number]: string | number | undefined | null | boolean;
|
|
98
|
+
}
|
|
99
|
+
type EnhancedEndpoints<T extends Record<string, ItemsRecord>> = {
|
|
100
|
+
[K in keyof T]: {
|
|
101
|
+
typeof: T[K]["typeof"];
|
|
102
|
+
state: "success" | "loading" | "error";
|
|
103
|
+
show: (props: ShowOptions) => Promise<Array<T[K]["typeof"]>>;
|
|
104
|
+
create: (data: Partial<T[K]["typeof"]> | Partial<T[K]["typeof"]>[]) => Promise<T[K]["typeof"]>;
|
|
105
|
+
update: (id: number | string, data: Partial<T[K]["typeof"]> | Partial<T[K]["typeof"]>[]) => Promise<T[K]["typeof"]>;
|
|
106
|
+
remove: (id: number | string) => Promise<T[K]["typeof"]>;
|
|
107
|
+
find: (id: number | string, props?: Record<string, string>) => Promise<T[K]["typeof"]>;
|
|
108
|
+
getAllPages: (limit: number) => Promise<Array<T[K]["typeof"]>>;
|
|
109
|
+
data: Array<T[K]["typeof"]>;
|
|
110
|
+
selectedItem: T[K]["typeof"];
|
|
111
|
+
params: Record<string, any>;
|
|
112
|
+
currentPage: number;
|
|
113
|
+
totalItems: number;
|
|
114
|
+
totalPages: number;
|
|
115
|
+
errorMessage: string | undefined;
|
|
116
|
+
autoLoad?: boolean;
|
|
117
|
+
defaultParams?: Record<string, any>;
|
|
118
|
+
id?: number | string;
|
|
119
|
+
loaded: boolean;
|
|
120
|
+
setLoaded: () => void;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
93
123
|
|
|
94
|
-
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1):
|
|
124
|
+
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1<T>): EnhancedEndpoints<T>;
|
|
95
125
|
|
|
96
126
|
interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
97
127
|
label?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -80,18 +80,48 @@ interface Props$2 extends DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaE
|
|
|
80
80
|
}
|
|
81
81
|
declare function TextArea({ label, className, maxLength, onChange, children, ...props }: Props$2): react_jsx_runtime.JSX.Element;
|
|
82
82
|
|
|
83
|
-
interface ItemsRecord {
|
|
84
|
-
typeof:
|
|
83
|
+
interface ItemsRecord<T = any> {
|
|
84
|
+
typeof: T;
|
|
85
85
|
id?: number | string | string[] | undefined;
|
|
86
86
|
defaultParams?: Record<string, any>;
|
|
87
87
|
}
|
|
88
|
-
interface Props$1 {
|
|
88
|
+
interface Props$1<T extends Record<string, ItemsRecord>> {
|
|
89
89
|
baseURI: string;
|
|
90
|
-
endpoints:
|
|
90
|
+
endpoints: T;
|
|
91
91
|
onError?: (error: any) => void;
|
|
92
92
|
}
|
|
93
|
+
interface ShowOptions {
|
|
94
|
+
limit?: number;
|
|
95
|
+
merge?: boolean;
|
|
96
|
+
page?: number;
|
|
97
|
+
[key: string | number]: string | number | undefined | null | boolean;
|
|
98
|
+
}
|
|
99
|
+
type EnhancedEndpoints<T extends Record<string, ItemsRecord>> = {
|
|
100
|
+
[K in keyof T]: {
|
|
101
|
+
typeof: T[K]["typeof"];
|
|
102
|
+
state: "success" | "loading" | "error";
|
|
103
|
+
show: (props: ShowOptions) => Promise<Array<T[K]["typeof"]>>;
|
|
104
|
+
create: (data: Partial<T[K]["typeof"]> | Partial<T[K]["typeof"]>[]) => Promise<T[K]["typeof"]>;
|
|
105
|
+
update: (id: number | string, data: Partial<T[K]["typeof"]> | Partial<T[K]["typeof"]>[]) => Promise<T[K]["typeof"]>;
|
|
106
|
+
remove: (id: number | string) => Promise<T[K]["typeof"]>;
|
|
107
|
+
find: (id: number | string, props?: Record<string, string>) => Promise<T[K]["typeof"]>;
|
|
108
|
+
getAllPages: (limit: number) => Promise<Array<T[K]["typeof"]>>;
|
|
109
|
+
data: Array<T[K]["typeof"]>;
|
|
110
|
+
selectedItem: T[K]["typeof"];
|
|
111
|
+
params: Record<string, any>;
|
|
112
|
+
currentPage: number;
|
|
113
|
+
totalItems: number;
|
|
114
|
+
totalPages: number;
|
|
115
|
+
errorMessage: string | undefined;
|
|
116
|
+
autoLoad?: boolean;
|
|
117
|
+
defaultParams?: Record<string, any>;
|
|
118
|
+
id?: number | string;
|
|
119
|
+
loaded: boolean;
|
|
120
|
+
setLoaded: () => void;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
93
123
|
|
|
94
|
-
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1):
|
|
124
|
+
declare function useResources<T extends Record<string, ItemsRecord>>({ baseURI, endpoints, onError, }: Props$1<T>): EnhancedEndpoints<T>;
|
|
95
125
|
|
|
96
126
|
interface CustomSelectProps extends React$1.DetailedHTMLProps<React$1.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
97
127
|
label?: string;
|
package/dist/index.js
CHANGED
|
@@ -11146,25 +11146,25 @@ function TD(_a) {
|
|
|
11146
11146
|
"mapedData",
|
|
11147
11147
|
"setMapedData"
|
|
11148
11148
|
]);
|
|
11149
|
-
var _a2, _b2;
|
|
11149
|
+
var _a2, _b2, _c;
|
|
11150
11150
|
const [isHidded, setIsHidded] = (0, import_react23.useState)(false);
|
|
11151
|
-
const newProps = symbols && import_react23.default.isValidElement(symbols[item == null ? void 0 : item.name]) && ((
|
|
11151
|
+
const newProps = symbols && import_react23.default.isValidElement(symbols[item == null ? void 0 : item.name]) && ((_c = Object.keys((_a2 = symbols[item == null ? void 0 : item.name]) == null ? void 0 : _a2.props)) == null ? void 0 : _c.reduce(
|
|
11152
11152
|
(acc, i) => {
|
|
11153
11153
|
try {
|
|
11154
11154
|
const newAcc = __spreadValues({}, acc);
|
|
11155
11155
|
const hasEvent = `${i}`.startsWith("on");
|
|
11156
11156
|
if (hasEvent) {
|
|
11157
|
-
newAcc[i] = (e) => {
|
|
11157
|
+
newAcc[i] = (e) => __async(null, null, function* () {
|
|
11158
11158
|
var _a3, _b3;
|
|
11159
11159
|
e.item = item;
|
|
11160
|
-
(_b3 = (_a3 = symbols[item == null ? void 0 : item.name].props)[i]) == null ? void 0 : _b3.call(_a3, e);
|
|
11161
|
-
};
|
|
11160
|
+
yield (_b3 = (_a3 = symbols[item == null ? void 0 : item.name].props)[i]) == null ? void 0 : _b3.call(_a3, e);
|
|
11161
|
+
});
|
|
11162
11162
|
}
|
|
11163
11163
|
return newAcc;
|
|
11164
11164
|
} catch (error) {
|
|
11165
11165
|
}
|
|
11166
11166
|
},
|
|
11167
|
-
{
|
|
11167
|
+
__spreadValues({}, (_b2 = symbols[item == null ? void 0 : item.name]) == null ? void 0 : _b2.props)
|
|
11168
11168
|
));
|
|
11169
11169
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
11170
11170
|
"td",
|
|
@@ -11179,7 +11179,8 @@ function TD(_a) {
|
|
|
11179
11179
|
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: symbols && symbols[item == null ? void 0 : item.name] && "flex justify-between", children: [
|
|
11180
11180
|
symbols && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: import_react23.default.Children.map(symbols[item == null ? void 0 : item.name], (child) => {
|
|
11181
11181
|
if (import_react23.default.isValidElement(child)) {
|
|
11182
|
-
|
|
11182
|
+
const { type, props: props2 } = child;
|
|
11183
|
+
return import_react23.default.createElement(type, __spreadValues({}, newProps));
|
|
11183
11184
|
}
|
|
11184
11185
|
return child;
|
|
11185
11186
|
}) }),
|
|
@@ -32087,6 +32088,7 @@ function HTable(_a) {
|
|
|
32087
32088
|
return null;
|
|
32088
32089
|
}
|
|
32089
32090
|
}
|
|
32091
|
+
const dataKey = ((_b2 = md == null ? void 0 : md.id) == null ? void 0 : _b2.content) || trKey;
|
|
32090
32092
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
32091
32093
|
"tr",
|
|
32092
32094
|
{
|
|
@@ -32094,6 +32096,7 @@ function HTable(_a) {
|
|
|
32094
32096
|
var _a3;
|
|
32095
32097
|
(_a3 = modalRef.current) == null ? void 0 : _a3.showModal();
|
|
32096
32098
|
},
|
|
32099
|
+
"data-key": dataKey,
|
|
32097
32100
|
onClick: (e) => setSelected(trKey),
|
|
32098
32101
|
className: [
|
|
32099
32102
|
"hover:bg-green-100 ",
|
|
@@ -32118,7 +32121,7 @@ function HTable(_a) {
|
|
|
32118
32121
|
);
|
|
32119
32122
|
})
|
|
32120
32123
|
},
|
|
32121
|
-
|
|
32124
|
+
dataKey
|
|
32122
32125
|
);
|
|
32123
32126
|
}) }),
|
|
32124
32127
|
totals && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tfoot", { className: "bg-gray-800 text-white", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tr", { children: head.map((h, fkey) => {
|
|
@@ -32297,178 +32300,67 @@ function useResources({
|
|
|
32297
32300
|
[key]: {
|
|
32298
32301
|
loaded: false,
|
|
32299
32302
|
id: (_a = endpoints[key]) == null ? void 0 : _a.id,
|
|
32300
|
-
defaultParams: (_b = endpoints[key]) == null ? void 0 : _b.defaultParams
|
|
32303
|
+
defaultParams: (_b = endpoints[key]) == null ? void 0 : _b.defaultParams,
|
|
32304
|
+
data: [],
|
|
32305
|
+
selectedItem: {}
|
|
32301
32306
|
}
|
|
32302
32307
|
});
|
|
32303
32308
|
return newAcc;
|
|
32304
32309
|
}, {})
|
|
32305
32310
|
);
|
|
32306
|
-
const results = Object.keys(endpoints).reduce(
|
|
32307
|
-
|
|
32308
|
-
|
|
32309
|
-
|
|
32310
|
-
|
|
32311
|
-
|
|
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);
|
|
32377
|
-
} else {
|
|
32378
|
-
newInfo[key].data = [d];
|
|
32379
|
-
}
|
|
32380
|
-
}
|
|
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;
|
|
32311
|
+
const results = Object.keys(endpoints).reduce(
|
|
32312
|
+
(acc, key) => {
|
|
32313
|
+
var _c, _d, _e, _f, _g, _h, _i;
|
|
32314
|
+
const endpoint = endpoints[key];
|
|
32315
|
+
const showFunc = (_a, autoLoad = false) => __async(null, null, function* () {
|
|
32316
|
+
var _b = _a, { limit = 10, page = 1, merge = true } = _b, query = __objRest(_b, ["limit", "page", "merge"]);
|
|
32401
32317
|
const options = {
|
|
32402
|
-
method: "
|
|
32318
|
+
method: "GET",
|
|
32403
32319
|
url: `${baseURI}/${key}`,
|
|
32404
|
-
|
|
32320
|
+
params: __spreadValues({ limit, page }, query),
|
|
32405
32321
|
headers: { Authorization: token }
|
|
32406
32322
|
};
|
|
32407
32323
|
const newInfo = __spreadValues({}, info);
|
|
32408
|
-
newInfo[key] = newInfo[key] || {};
|
|
32409
32324
|
newInfo[key].state = "loading";
|
|
32410
32325
|
newInfo[key].errorMessage = "";
|
|
32326
|
+
newInfo[key].params = query;
|
|
32327
|
+
newInfo[key].loaded = true;
|
|
32411
32328
|
setInfo(newInfo);
|
|
32412
32329
|
try {
|
|
32413
32330
|
const consulta = yield import_axios.default.request(options);
|
|
32414
32331
|
const d = consulta.data;
|
|
32415
32332
|
newInfo[key].state = "success";
|
|
32416
32333
|
newInfo[key].errorMessage = "";
|
|
32417
|
-
|
|
32418
|
-
|
|
32419
|
-
|
|
32420
|
-
|
|
32421
|
-
);
|
|
32422
|
-
if (index >= 0) {
|
|
32423
|
-
newInfo[key].data[index] = d;
|
|
32424
|
-
} else {
|
|
32425
|
-
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32426
|
-
newInfo[key].data.unshift(d);
|
|
32427
|
-
} else {
|
|
32428
|
-
newInfo[key].data = [d];
|
|
32429
|
-
}
|
|
32430
|
-
}
|
|
32431
|
-
}
|
|
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);
|
|
32442
|
-
} else {
|
|
32443
|
-
newInfo[key].data = [d];
|
|
32444
|
-
}
|
|
32445
|
-
}
|
|
32446
|
-
}
|
|
32334
|
+
newInfo[key].data = merge ? page == 1 ? d.data : [...d.data, ...newInfo[key].data || []] : d.data;
|
|
32335
|
+
newInfo[key].totalItems = d.totalItems;
|
|
32336
|
+
newInfo[key].totalPages = d.totalPages;
|
|
32337
|
+
newInfo[key].currentPage = d.currentPage;
|
|
32447
32338
|
setInfo(__spreadValues({}, newInfo));
|
|
32448
|
-
return d;
|
|
32339
|
+
return d.data;
|
|
32449
32340
|
} catch (error) {
|
|
32450
32341
|
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32451
32342
|
newInfo[key].state = "error";
|
|
32452
|
-
newInfo[key].errorMessage =
|
|
32343
|
+
newInfo[key].errorMessage = item == null ? void 0 : item.meaning;
|
|
32453
32344
|
if (error.status == 403) {
|
|
32454
32345
|
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32455
32346
|
}
|
|
32456
32347
|
setInfo(__spreadValues({}, newInfo));
|
|
32457
32348
|
return error;
|
|
32458
32349
|
}
|
|
32459
|
-
})
|
|
32460
|
-
|
|
32461
|
-
var _a, _b, _c2;
|
|
32350
|
+
});
|
|
32351
|
+
const findFunc = (id3, query) => __async(null, null, function* () {
|
|
32352
|
+
var _a, _b, _c2, _d2;
|
|
32462
32353
|
const options = {
|
|
32463
|
-
method: "
|
|
32354
|
+
method: "GET",
|
|
32464
32355
|
url: `${baseURI}/${key}/${id3}`,
|
|
32465
|
-
|
|
32356
|
+
params: __spreadValues({}, query),
|
|
32466
32357
|
headers: { Authorization: token }
|
|
32467
32358
|
};
|
|
32468
32359
|
const newInfo = __spreadValues({}, info);
|
|
32469
|
-
newInfo[key] = newInfo[key] || {};
|
|
32470
32360
|
newInfo[key].state = "loading";
|
|
32471
32361
|
newInfo[key].errorMessage = "";
|
|
32362
|
+
newInfo[key].params = query;
|
|
32363
|
+
newInfo[key].loaded = true;
|
|
32472
32364
|
setInfo(newInfo);
|
|
32473
32365
|
try {
|
|
32474
32366
|
const consulta = yield import_axios.default.request(options);
|
|
@@ -32476,13 +32368,12 @@ function useResources({
|
|
|
32476
32368
|
newInfo[key].state = "success";
|
|
32477
32369
|
newInfo[key].errorMessage = "";
|
|
32478
32370
|
newInfo[key].selectedItem = d;
|
|
32479
|
-
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32480
|
-
|
|
32481
|
-
);
|
|
32371
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex((d2) => (d2 == null ? void 0 : d2.id) == id3);
|
|
32372
|
+
console.log("index", index, (_c2 = newInfo[key]) == null ? void 0 : _c2.data);
|
|
32482
32373
|
if (index >= 0) {
|
|
32483
32374
|
newInfo[key].data[index] = d;
|
|
32484
32375
|
} else {
|
|
32485
|
-
if ((
|
|
32376
|
+
if ((_d2 = newInfo[key]) == null ? void 0 : _d2.data) {
|
|
32486
32377
|
newInfo[key].data.unshift(d);
|
|
32487
32378
|
} else {
|
|
32488
32379
|
newInfo[key].data = [d];
|
|
@@ -32500,62 +32391,171 @@ function useResources({
|
|
|
32500
32391
|
setInfo(__spreadValues({}, newInfo));
|
|
32501
32392
|
return error;
|
|
32502
32393
|
}
|
|
32503
|
-
})
|
|
32504
|
-
|
|
32505
|
-
|
|
32506
|
-
|
|
32507
|
-
|
|
32508
|
-
|
|
32509
|
-
|
|
32510
|
-
|
|
32511
|
-
|
|
32512
|
-
|
|
32513
|
-
|
|
32514
|
-
|
|
32515
|
-
|
|
32516
|
-
|
|
32517
|
-
|
|
32518
|
-
const d = consulta.data;
|
|
32519
|
-
newInfo[key].state = "success";
|
|
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].state = "loading";
|
|
32520
32409
|
newInfo[key].errorMessage = "";
|
|
32521
|
-
newInfo
|
|
32522
|
-
|
|
32523
|
-
|
|
32524
|
-
|
|
32525
|
-
|
|
32526
|
-
newInfo[key].
|
|
32410
|
+
setInfo(newInfo);
|
|
32411
|
+
try {
|
|
32412
|
+
const consulta = yield import_axios.default.request(options);
|
|
32413
|
+
const d = consulta.data;
|
|
32414
|
+
newInfo[key].state = "success";
|
|
32415
|
+
newInfo[key].errorMessage = "";
|
|
32416
|
+
if (Array.isArray(data)) {
|
|
32417
|
+
for (let datum of data) {
|
|
32418
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32419
|
+
(d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
|
|
32420
|
+
);
|
|
32421
|
+
if (index >= 0) {
|
|
32422
|
+
newInfo[key].data[index] = d;
|
|
32423
|
+
} else {
|
|
32424
|
+
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32425
|
+
newInfo[key].data.unshift(d);
|
|
32426
|
+
} else {
|
|
32427
|
+
newInfo[key].data = [d];
|
|
32428
|
+
}
|
|
32429
|
+
}
|
|
32430
|
+
}
|
|
32431
|
+
newInfo[key].data = newInfo[key].data.flat();
|
|
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) == (data == null ? void 0 : data.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);
|
|
32442
|
+
} else {
|
|
32443
|
+
newInfo[key].data = [d];
|
|
32444
|
+
}
|
|
32445
|
+
}
|
|
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;
|
|
32527
32458
|
}
|
|
32528
|
-
|
|
32529
|
-
|
|
32530
|
-
|
|
32531
|
-
const
|
|
32532
|
-
|
|
32533
|
-
|
|
32534
|
-
|
|
32535
|
-
|
|
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].state = "loading";
|
|
32470
|
+
newInfo[key].errorMessage = "";
|
|
32471
|
+
setInfo(newInfo);
|
|
32472
|
+
try {
|
|
32473
|
+
const consulta = yield import_axios.default.request(options);
|
|
32474
|
+
const d = consulta.data;
|
|
32475
|
+
newInfo[key].state = "success";
|
|
32476
|
+
newInfo[key].errorMessage = "";
|
|
32477
|
+
newInfo[key].selectedItem = d;
|
|
32478
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32479
|
+
(d2) => (d2 == null ? void 0 : d2.id) == id3
|
|
32480
|
+
);
|
|
32481
|
+
if (index >= 0) {
|
|
32482
|
+
newInfo[key].data[index] = d;
|
|
32483
|
+
} else {
|
|
32484
|
+
if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
|
|
32485
|
+
newInfo[key].data.unshift(d);
|
|
32486
|
+
} else {
|
|
32487
|
+
newInfo[key].data = [d];
|
|
32488
|
+
}
|
|
32489
|
+
}
|
|
32490
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32491
|
+
return d;
|
|
32492
|
+
} catch (error) {
|
|
32493
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32494
|
+
newInfo[key].state = "error";
|
|
32495
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32496
|
+
if (error.status == 403) {
|
|
32497
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32498
|
+
}
|
|
32499
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32500
|
+
return error;
|
|
32536
32501
|
}
|
|
32537
|
-
|
|
32538
|
-
|
|
32539
|
-
|
|
32540
|
-
|
|
32541
|
-
|
|
32542
|
-
|
|
32543
|
-
|
|
32544
|
-
|
|
32545
|
-
|
|
32546
|
-
|
|
32547
|
-
|
|
32548
|
-
|
|
32549
|
-
|
|
32550
|
-
|
|
32551
|
-
|
|
32552
|
-
|
|
32553
|
-
|
|
32554
|
-
|
|
32555
|
-
|
|
32556
|
-
|
|
32557
|
-
|
|
32558
|
-
|
|
32502
|
+
}),
|
|
32503
|
+
remove: (id3) => __async(null, null, function* () {
|
|
32504
|
+
var _a, _b;
|
|
32505
|
+
const options = {
|
|
32506
|
+
method: "DELETE",
|
|
32507
|
+
url: `${baseURI}/${key}/${id3}`,
|
|
32508
|
+
headers: { Authorization: token }
|
|
32509
|
+
};
|
|
32510
|
+
const newInfo = __spreadValues({}, info);
|
|
32511
|
+
newInfo[key].state = "loading";
|
|
32512
|
+
newInfo[key].errorMessage = "";
|
|
32513
|
+
setInfo(newInfo);
|
|
32514
|
+
try {
|
|
32515
|
+
const consulta = yield import_axios.default.request(options);
|
|
32516
|
+
const d = consulta.data;
|
|
32517
|
+
newInfo[key].state = "success";
|
|
32518
|
+
newInfo[key].errorMessage = "";
|
|
32519
|
+
newInfo[key].selectedItem = d;
|
|
32520
|
+
const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
|
|
32521
|
+
(d2) => (d2 == null ? void 0 : d2.id) == id3
|
|
32522
|
+
);
|
|
32523
|
+
if (index >= 0) {
|
|
32524
|
+
newInfo[key].data.splice(index, 1);
|
|
32525
|
+
}
|
|
32526
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32527
|
+
return d.data;
|
|
32528
|
+
} catch (error) {
|
|
32529
|
+
const item = http_codes_default.find((s) => s.code == error.status);
|
|
32530
|
+
newInfo[key].state = "error";
|
|
32531
|
+
newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
|
|
32532
|
+
if (error.status == 403) {
|
|
32533
|
+
onError == null ? void 0 : onError(__spreadValues({ error }, { errorMessage: item == null ? void 0 : item.meaning }));
|
|
32534
|
+
}
|
|
32535
|
+
setInfo(__spreadValues({}, newInfo));
|
|
32536
|
+
return error;
|
|
32537
|
+
}
|
|
32538
|
+
}),
|
|
32539
|
+
totalPages: (_c = info[key]) == null ? void 0 : _c.totalPages,
|
|
32540
|
+
currentPage: (_d = info[key]) == null ? void 0 : _d.currentPage,
|
|
32541
|
+
state: ((_e = info[key]) == null ? void 0 : _e.state) || "success",
|
|
32542
|
+
errorMessage: (_f = info[key]) == null ? void 0 : _f.errorMessage,
|
|
32543
|
+
params: (_g = info[key]) == null ? void 0 : _g.params,
|
|
32544
|
+
setLoaded: () => {
|
|
32545
|
+
const newInfo = __spreadValues({}, info);
|
|
32546
|
+
newInfo[key].loaded = true;
|
|
32547
|
+
setInfo(newInfo);
|
|
32548
|
+
},
|
|
32549
|
+
getAllPages: (limit = 10) => __async(null, null, function* () {
|
|
32550
|
+
console.log("Not aviable");
|
|
32551
|
+
}),
|
|
32552
|
+
data: ((_h = info[key]) == null ? void 0 : _h.data) || [],
|
|
32553
|
+
selectedItem: ((_i = info[key]) == null ? void 0 : _i.selectedItem) || {}
|
|
32554
|
+
});
|
|
32555
|
+
return acc;
|
|
32556
|
+
},
|
|
32557
|
+
{}
|
|
32558
|
+
);
|
|
32559
32559
|
function doSome() {
|
|
32560
32560
|
return __async(this, null, function* () {
|
|
32561
32561
|
var _a, _b, _c, _d, _e;
|