@bluemarble/bm-components 1.5.0 → 1.7.0
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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +250 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +259 -220
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -4096,13 +4096,13 @@ var ApiHelper = class _ApiHelper {
|
|
|
4096
4096
|
};
|
|
4097
4097
|
|
|
4098
4098
|
// src/hooks/useFormHelper.ts
|
|
4099
|
-
import { useContext as useContext3, useEffect as useEffect4, useRef as useRef3 } from "react";
|
|
4099
|
+
import { useCallback as useCallback3, useContext as useContext3, useEffect as useEffect4, useRef as useRef3 } from "react";
|
|
4100
4100
|
|
|
4101
4101
|
// src/hooks/useAlert.ts
|
|
4102
4102
|
import { useContext as useContext2 } from "react";
|
|
4103
4103
|
|
|
4104
4104
|
// src/contexts/AlertContext.tsx
|
|
4105
|
-
import React25 from "react";
|
|
4105
|
+
import React25, { useCallback } from "react";
|
|
4106
4106
|
import { createContext, useState as useState3 } from "react";
|
|
4107
4107
|
|
|
4108
4108
|
// src/components/Toast/index.tsx
|
|
@@ -4146,14 +4146,17 @@ var AlertProvider = ({ children }) => {
|
|
|
4146
4146
|
const [severity, setSeverity] = useState3("info");
|
|
4147
4147
|
const [message, setMessage] = useState3("");
|
|
4148
4148
|
const [isVisible, setIsVisible] = useState3(false);
|
|
4149
|
-
const createAlert = (
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4149
|
+
const createAlert = useCallback(
|
|
4150
|
+
(newMessage, severity2) => {
|
|
4151
|
+
setMessage(newMessage);
|
|
4152
|
+
setSeverity(severity2);
|
|
4153
|
+
setIsVisible(true);
|
|
4154
|
+
},
|
|
4155
|
+
[]
|
|
4156
|
+
);
|
|
4157
|
+
const onCloseToast = useCallback(() => {
|
|
4155
4158
|
setIsVisible(false);
|
|
4156
|
-
}
|
|
4159
|
+
}, []);
|
|
4157
4160
|
return /* @__PURE__ */ React25.createElement(AlertContext.Provider, { value: { createAlert } }, children, /* @__PURE__ */ React25.createElement(
|
|
4158
4161
|
Toast,
|
|
4159
4162
|
{
|
|
@@ -4171,16 +4174,16 @@ var useAlert = () => {
|
|
|
4171
4174
|
};
|
|
4172
4175
|
|
|
4173
4176
|
// src/hooks/useLoading.ts
|
|
4174
|
-
import { useState as useState4 } from "react";
|
|
4177
|
+
import { useCallback as useCallback2, useState as useState4 } from "react";
|
|
4175
4178
|
function useLoading() {
|
|
4176
4179
|
const [state, setState] = useState4([]);
|
|
4177
|
-
const isLoading = (prop) => state.includes(prop);
|
|
4178
|
-
const setLoading = (prop, remove) => {
|
|
4180
|
+
const isLoading = useCallback2((prop) => state.includes(prop), [state]);
|
|
4181
|
+
const setLoading = useCallback2((prop, remove) => {
|
|
4179
4182
|
if (remove)
|
|
4180
4183
|
setState((prevState) => prevState.filter((state2) => state2 !== prop));
|
|
4181
4184
|
else
|
|
4182
4185
|
setState((prevState) => [...prevState, prop]);
|
|
4183
|
-
};
|
|
4186
|
+
}, []);
|
|
4184
4187
|
return { isLoading, setLoading };
|
|
4185
4188
|
}
|
|
4186
4189
|
|
|
@@ -4200,59 +4203,68 @@ function useFormHelper() {
|
|
|
4200
4203
|
const { createAlert } = alertProps;
|
|
4201
4204
|
const { setLoading } = loadingProps;
|
|
4202
4205
|
const sourceRef = useRef3(new AbortController());
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4206
|
+
const onSubmitWrapper = useCallback3(
|
|
4207
|
+
(fn, { name }) => {
|
|
4208
|
+
return (fields, methods) => __async(this, null, function* () {
|
|
4209
|
+
const LOADING_NAME = name;
|
|
4210
|
+
setLoading(LOADING_NAME);
|
|
4211
|
+
try {
|
|
4212
|
+
yield fn(fields, methods);
|
|
4213
|
+
} catch (error) {
|
|
4214
|
+
errorHandler(error, methods.setErrors);
|
|
4215
|
+
} finally {
|
|
4216
|
+
setLoading(LOADING_NAME, true);
|
|
4217
|
+
}
|
|
4218
|
+
});
|
|
4219
|
+
},
|
|
4220
|
+
[setLoading]
|
|
4221
|
+
);
|
|
4222
|
+
const onRequestWrapper = useCallback3(
|
|
4223
|
+
(fn, { name }) => {
|
|
4224
|
+
return (...params) => __async(this, null, function* () {
|
|
4225
|
+
const LOADING_NAME = name;
|
|
4226
|
+
setLoading(LOADING_NAME);
|
|
4227
|
+
api.interceptors.request.use(
|
|
4228
|
+
(config) => {
|
|
4229
|
+
if (!config.signal && sourceRef.current && config.method === "get") {
|
|
4230
|
+
config.signal = sourceRef.current.signal;
|
|
4231
|
+
}
|
|
4232
|
+
return config;
|
|
4233
|
+
},
|
|
4234
|
+
(error) => {
|
|
4235
|
+
return Promise.reject(error);
|
|
4224
4236
|
}
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
return
|
|
4237
|
+
);
|
|
4238
|
+
try {
|
|
4239
|
+
const response = yield fn(...params);
|
|
4240
|
+
return response;
|
|
4241
|
+
} catch (error) {
|
|
4242
|
+
errorHandler(error);
|
|
4243
|
+
} finally {
|
|
4244
|
+
setLoading(LOADING_NAME, true);
|
|
4245
|
+
}
|
|
4246
|
+
});
|
|
4247
|
+
},
|
|
4248
|
+
[setLoading, api]
|
|
4249
|
+
);
|
|
4250
|
+
const errorHandler = useCallback3(
|
|
4251
|
+
(error, callback) => {
|
|
4252
|
+
if ((error == null ? void 0 : error.message) === "cancel.navigation")
|
|
4253
|
+
return;
|
|
4254
|
+
if (callback) {
|
|
4255
|
+
if (error.response.data.code === "invalid.body") {
|
|
4256
|
+
const errors = error.response.data.details.issues;
|
|
4257
|
+
const currentErrors = errors.reduce((acc, item) => {
|
|
4258
|
+
acc[item.path.join(".")] = item.message;
|
|
4259
|
+
return acc;
|
|
4260
|
+
}, {});
|
|
4261
|
+
callback(currentErrors);
|
|
4229
4262
|
}
|
|
4230
|
-
);
|
|
4231
|
-
try {
|
|
4232
|
-
const response = yield fn(...params);
|
|
4233
|
-
return response;
|
|
4234
|
-
} catch (error) {
|
|
4235
|
-
errorHandler(error);
|
|
4236
|
-
} finally {
|
|
4237
|
-
setLoading(LOADING_NAME, true);
|
|
4238
|
-
}
|
|
4239
|
-
});
|
|
4240
|
-
}
|
|
4241
|
-
function errorHandler(error, callback) {
|
|
4242
|
-
if ((error == null ? void 0 : error.message) === "cancel.navigation")
|
|
4243
|
-
return;
|
|
4244
|
-
if (callback) {
|
|
4245
|
-
if (error.response.data.code === "invalid.body") {
|
|
4246
|
-
const errors = error.response.data.details.issues;
|
|
4247
|
-
const currentErrors = errors.reduce((acc, item) => {
|
|
4248
|
-
acc[item.path.join(".")] = item.message;
|
|
4249
|
-
return acc;
|
|
4250
|
-
}, {});
|
|
4251
|
-
callback(currentErrors);
|
|
4252
4263
|
}
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4264
|
+
createAlert(formatErrorMessage(error), "error");
|
|
4265
|
+
},
|
|
4266
|
+
[formatErrorMessage, createAlert]
|
|
4267
|
+
);
|
|
4256
4268
|
useEffect4(() => {
|
|
4257
4269
|
return () => {
|
|
4258
4270
|
sourceRef.current.abort();
|
|
@@ -4580,11 +4592,11 @@ var AuthHelper = class {
|
|
|
4580
4592
|
};
|
|
4581
4593
|
|
|
4582
4594
|
// src/hooks/useGrid.ts
|
|
4583
|
-
import { useMemo as useMemo3, useState as useState6 } from "react";
|
|
4595
|
+
import { useCallback as useCallback5, useMemo as useMemo3, useState as useState6 } from "react";
|
|
4584
4596
|
|
|
4585
4597
|
// src/hooks/useFilter.ts
|
|
4586
4598
|
import moment2 from "moment";
|
|
4587
|
-
import { useState as useState5 } from "react";
|
|
4599
|
+
import { useCallback as useCallback4, useState as useState5 } from "react";
|
|
4588
4600
|
|
|
4589
4601
|
// src/components/utils/getObjectValue.ts
|
|
4590
4602
|
function getObjectValue(obj) {
|
|
@@ -4600,7 +4612,7 @@ function getObjectValue(obj) {
|
|
|
4600
4612
|
// src/hooks/useFilter.ts
|
|
4601
4613
|
function useFilter() {
|
|
4602
4614
|
const [selectedFilters, setSelectedFilters] = useState5([]);
|
|
4603
|
-
const filterBy = (newFilter) => {
|
|
4615
|
+
const filterBy = useCallback4((newFilter) => {
|
|
4604
4616
|
const propToCompare = (newFilter == null ? void 0 : newFilter.id) ? "id" : "prop";
|
|
4605
4617
|
function removeRepeatedFilters(filter) {
|
|
4606
4618
|
return filter[propToCompare] !== newFilter[propToCompare];
|
|
@@ -4609,13 +4621,16 @@ function useFilter() {
|
|
|
4609
4621
|
...filters.filter(removeRepeatedFilters),
|
|
4610
4622
|
newFilter
|
|
4611
4623
|
]);
|
|
4612
|
-
};
|
|
4613
|
-
const removeFilter = (
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4624
|
+
}, []);
|
|
4625
|
+
const removeFilter = useCallback4(
|
|
4626
|
+
(prop, isId) => {
|
|
4627
|
+
const propToCompare = isId ? "id" : "prop";
|
|
4628
|
+
setSelectedFilters(
|
|
4629
|
+
selectedFilters.filter((filter) => filter[propToCompare] !== prop)
|
|
4630
|
+
);
|
|
4631
|
+
},
|
|
4632
|
+
[selectedFilters]
|
|
4633
|
+
);
|
|
4619
4634
|
function clearAllFilters() {
|
|
4620
4635
|
setSelectedFilters([]);
|
|
4621
4636
|
}
|
|
@@ -4686,68 +4701,82 @@ function useGrid({
|
|
|
4686
4701
|
);
|
|
4687
4702
|
const [currentPage, setCurrentPage] = useState6(defaultCurrentPage || 0);
|
|
4688
4703
|
const [rowsPerPage, setRowsPerPage] = useState6(rowsPerPageOptions[0]);
|
|
4689
|
-
const
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4704
|
+
const [updatedTimes, setUpdatedTimes] = useState6(0);
|
|
4705
|
+
const toggleSortedDirection = useCallback5(
|
|
4706
|
+
(direction) => {
|
|
4707
|
+
if (direction === "asc")
|
|
4708
|
+
return "desc";
|
|
4709
|
+
return "asc";
|
|
4710
|
+
},
|
|
4711
|
+
[]
|
|
4712
|
+
);
|
|
4713
|
+
const setSort = useCallback5((prop, direction) => {
|
|
4695
4714
|
setSortedBy((prev) => [...prev, { prop, direction }]);
|
|
4696
|
-
}
|
|
4697
|
-
const onSortBy = (
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
if (currentSorted
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4715
|
+
}, []);
|
|
4716
|
+
const onSortBy = useCallback5(
|
|
4717
|
+
(prop) => {
|
|
4718
|
+
if (!prop)
|
|
4719
|
+
return;
|
|
4720
|
+
const currentSorted = sortedBy.find((p) => p.prop === prop);
|
|
4721
|
+
if (currentSorted) {
|
|
4722
|
+
if (currentSorted.direction === "asc") {
|
|
4723
|
+
setSortedBy((prev) => prev.filter((p) => p.prop !== prop));
|
|
4724
|
+
} else {
|
|
4725
|
+
setSortedBy((prev) => {
|
|
4726
|
+
const newArr = prev.map((p) => {
|
|
4727
|
+
if (p.prop !== prop)
|
|
4728
|
+
return p;
|
|
4729
|
+
return {
|
|
4730
|
+
prop: p.prop,
|
|
4731
|
+
direction: toggleSortedDirection(p.direction)
|
|
4732
|
+
};
|
|
4733
|
+
});
|
|
4734
|
+
return [...newArr].slice(0);
|
|
4713
4735
|
});
|
|
4714
|
-
|
|
4715
|
-
|
|
4736
|
+
}
|
|
4737
|
+
} else {
|
|
4738
|
+
setSortedBy((prev) => [...prev, { prop, direction: "desc" }]);
|
|
4716
4739
|
}
|
|
4717
|
-
}
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4740
|
+
},
|
|
4741
|
+
[toggleSortedDirection, sortedBy]
|
|
4742
|
+
);
|
|
4743
|
+
const set = useCallback5((data) => {
|
|
4744
|
+
setUpdatedTimes((prev) => prev + 1);
|
|
4722
4745
|
setDefaultData(data);
|
|
4723
|
-
};
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4746
|
+
}, []);
|
|
4747
|
+
const sortData = useCallback5(
|
|
4748
|
+
(data) => {
|
|
4749
|
+
if (sortedBy.length > 0) {
|
|
4750
|
+
const symbolDir = {
|
|
4751
|
+
asc: "",
|
|
4752
|
+
desc: "-"
|
|
4753
|
+
};
|
|
4754
|
+
const formattedKeys = sortedBy.map(
|
|
4755
|
+
({ prop, direction }) => `${symbolDir[direction]}${prop}`
|
|
4756
|
+
);
|
|
4757
|
+
return data.sort(sortBy(...formattedKeys));
|
|
4758
|
+
} else
|
|
4759
|
+
return data;
|
|
4760
|
+
},
|
|
4761
|
+
[sortedBy]
|
|
4762
|
+
);
|
|
4763
|
+
const onPageChange = useCallback5((pageNumber) => {
|
|
4738
4764
|
if (pageNumber < 0)
|
|
4739
4765
|
return;
|
|
4740
4766
|
if (pageNumber > totalNumberOfPages)
|
|
4741
4767
|
return;
|
|
4742
4768
|
setCurrentPage(pageNumber);
|
|
4743
|
-
};
|
|
4744
|
-
const onChangeRowsPerPage = (
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4769
|
+
}, []);
|
|
4770
|
+
const onChangeRowsPerPage = useCallback5(
|
|
4771
|
+
(rows) => {
|
|
4772
|
+
let totalNumberOfPages2 = Math.round(filteredData.length / rows) - 1;
|
|
4773
|
+
totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
|
|
4774
|
+
if (currentPage > totalNumberOfPages2)
|
|
4775
|
+
setCurrentPage(totalNumberOfPages2);
|
|
4776
|
+
setRowsPerPage(rows);
|
|
4777
|
+
},
|
|
4778
|
+
[currentPage]
|
|
4779
|
+
);
|
|
4751
4780
|
const filteredData = useMemo3(() => {
|
|
4752
4781
|
let newData = defaultData.slice(0);
|
|
4753
4782
|
if (search && search.value !== "") {
|
|
@@ -4762,10 +4791,11 @@ function useGrid({
|
|
|
4762
4791
|
const startPage = currentPage * rowsPerPage;
|
|
4763
4792
|
const endPage = startPage + rowsPerPage;
|
|
4764
4793
|
return sortedData.slice(startPage, endPage);
|
|
4765
|
-
}, [
|
|
4794
|
+
}, [filteredData, currentPage, rowsPerPage, sortData]);
|
|
4766
4795
|
const totalNumberOfPages = Math.ceil(filteredData.length / rowsPerPage) - 1;
|
|
4767
4796
|
return {
|
|
4768
4797
|
data: displayData,
|
|
4798
|
+
updatedTimes,
|
|
4769
4799
|
set,
|
|
4770
4800
|
onSortBy,
|
|
4771
4801
|
sortedBy,
|
|
@@ -4816,7 +4846,7 @@ function createSearch(options) {
|
|
|
4816
4846
|
}
|
|
4817
4847
|
|
|
4818
4848
|
// src/hooks/useAsyncGrid.ts
|
|
4819
|
-
import { useCallback, useEffect as useEffect5, useState as useState7 } from "react";
|
|
4849
|
+
import { useCallback as useCallback6, useEffect as useEffect5, useState as useState7 } from "react";
|
|
4820
4850
|
function useAsyncGrid({
|
|
4821
4851
|
columns,
|
|
4822
4852
|
filters = [],
|
|
@@ -4838,49 +4868,52 @@ function useAsyncGrid({
|
|
|
4838
4868
|
const [currentPage, setCurrentPage] = useState7(defaultCurrentPage || 0);
|
|
4839
4869
|
const [rowsPerPage, setRowsPerPage] = useState7(rowsPerPageOptions[0]);
|
|
4840
4870
|
const totalNumberOfPages = Math.ceil(totalNumberOfItems / rowsPerPage) - 1;
|
|
4841
|
-
const toggleSortedDirection = (
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4871
|
+
const toggleSortedDirection = useCallback6(
|
|
4872
|
+
(direction) => {
|
|
4873
|
+
if (direction === "asc")
|
|
4874
|
+
return "desc";
|
|
4875
|
+
return "asc";
|
|
4876
|
+
},
|
|
4877
|
+
[]
|
|
4878
|
+
);
|
|
4879
|
+
const setSort = useCallback6((prop, direction) => {
|
|
4847
4880
|
setSortedBy((prev) => [...prev, { prop, direction }]);
|
|
4848
|
-
}
|
|
4849
|
-
const onSortBy = (
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
if (currentSorted
|
|
4856
|
-
|
|
4881
|
+
}, []);
|
|
4882
|
+
const onSortBy = useCallback6(
|
|
4883
|
+
(prop) => __async(this, null, function* () {
|
|
4884
|
+
if (!prop)
|
|
4885
|
+
return;
|
|
4886
|
+
let finalArr = [];
|
|
4887
|
+
const currentSorted = sortedBy.find((p) => p.prop === prop);
|
|
4888
|
+
if (currentSorted) {
|
|
4889
|
+
if (currentSorted.direction === "asc") {
|
|
4890
|
+
finalArr = sortedBy.filter((p) => p.prop !== prop);
|
|
4891
|
+
} else {
|
|
4892
|
+
finalArr = sortedBy.map((p) => {
|
|
4893
|
+
if (p.prop !== prop)
|
|
4894
|
+
return p;
|
|
4895
|
+
return {
|
|
4896
|
+
prop: p.prop,
|
|
4897
|
+
direction: toggleSortedDirection(p.direction)
|
|
4898
|
+
};
|
|
4899
|
+
});
|
|
4900
|
+
}
|
|
4857
4901
|
} else {
|
|
4858
|
-
finalArr = sortedBy
|
|
4859
|
-
if (p.prop !== prop)
|
|
4860
|
-
return p;
|
|
4861
|
-
return {
|
|
4862
|
-
prop: p.prop,
|
|
4863
|
-
direction: toggleSortedDirection(p.direction)
|
|
4864
|
-
};
|
|
4865
|
-
});
|
|
4902
|
+
finalArr = [...sortedBy, { prop, direction: "desc" }];
|
|
4866
4903
|
}
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
});
|
|
4875
|
-
});
|
|
4876
|
-
const set = useCallback(
|
|
4877
|
-
(data) => {
|
|
4878
|
-
setDefaultData(data);
|
|
4879
|
-
},
|
|
4880
|
-
[setDefaultData]
|
|
4904
|
+
yield updateGridContent({
|
|
4905
|
+
page: currentPage,
|
|
4906
|
+
sortedBy: finalArr,
|
|
4907
|
+
rowsPerPage
|
|
4908
|
+
});
|
|
4909
|
+
}),
|
|
4910
|
+
[sortedBy, toggleSortedDirection, rowsPerPage, currentPage]
|
|
4881
4911
|
);
|
|
4882
|
-
|
|
4883
|
-
|
|
4912
|
+
const set = useCallback6((data) => {
|
|
4913
|
+
setDefaultData(data);
|
|
4914
|
+
}, []);
|
|
4915
|
+
const baseRequest = useCallback6(
|
|
4916
|
+
(_0) => __async(this, [_0], function* ({
|
|
4884
4917
|
page,
|
|
4885
4918
|
search: search2,
|
|
4886
4919
|
filters: filters2,
|
|
@@ -4903,12 +4936,13 @@ function useAsyncGrid({
|
|
|
4903
4936
|
const { data } = yield axiosInstance.get(pathWithParams);
|
|
4904
4937
|
setTotalNumberOfItems(data.totalNumberOfItems);
|
|
4905
4938
|
return data.rows;
|
|
4906
|
-
} catch (
|
|
4939
|
+
} catch (_) {
|
|
4907
4940
|
return [];
|
|
4908
4941
|
}
|
|
4909
|
-
})
|
|
4910
|
-
|
|
4911
|
-
|
|
4942
|
+
}),
|
|
4943
|
+
[axiosInstance, url]
|
|
4944
|
+
);
|
|
4945
|
+
const updateGridContent = useCallback6(
|
|
4912
4946
|
(_0) => __async(this, [_0], function* ({
|
|
4913
4947
|
page,
|
|
4914
4948
|
sortedBy: sortedBy2,
|
|
@@ -4928,40 +4962,44 @@ function useAsyncGrid({
|
|
|
4928
4962
|
setRowsPerPage(rowsPerPage2);
|
|
4929
4963
|
set(result);
|
|
4930
4964
|
setCurrentPage(page);
|
|
4931
|
-
} catch (error) {
|
|
4932
|
-
throw error;
|
|
4933
4965
|
} finally {
|
|
4934
4966
|
setIsLoading(false);
|
|
4935
4967
|
}
|
|
4936
4968
|
}),
|
|
4937
|
-
[set,
|
|
4969
|
+
[set, search, filters, onRequest, baseRequest]
|
|
4938
4970
|
);
|
|
4939
|
-
const onPageChange = (
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4971
|
+
const onPageChange = useCallback6(
|
|
4972
|
+
(pageNumber) => {
|
|
4973
|
+
if (pageNumber < 0)
|
|
4974
|
+
return;
|
|
4975
|
+
if (pageNumber > totalNumberOfPages)
|
|
4976
|
+
return;
|
|
4977
|
+
updateGridContent({ page: pageNumber, sortedBy, rowsPerPage });
|
|
4978
|
+
},
|
|
4979
|
+
[updateGridContent, totalNumberOfPages, sortedBy, rowsPerPage]
|
|
4980
|
+
);
|
|
4981
|
+
const onChangeRowsPerPage = useCallback6(
|
|
4982
|
+
(rows) => {
|
|
4983
|
+
let totalNumberOfPages2 = Math.round(totalNumberOfItems / rows) - 1;
|
|
4984
|
+
totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
|
|
4985
|
+
if (currentPage > totalNumberOfPages2)
|
|
4986
|
+
updateGridContent({
|
|
4987
|
+
page: totalNumberOfPages2,
|
|
4988
|
+
sortedBy,
|
|
4989
|
+
rowsPerPage: rows
|
|
4990
|
+
});
|
|
4950
4991
|
updateGridContent({
|
|
4951
|
-
page:
|
|
4992
|
+
page: currentPage,
|
|
4952
4993
|
sortedBy,
|
|
4953
4994
|
rowsPerPage: rows
|
|
4954
4995
|
});
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
rowsPerPage: rows
|
|
4959
|
-
});
|
|
4960
|
-
};
|
|
4996
|
+
},
|
|
4997
|
+
[updateGridContent, totalNumberOfItems, sortedBy, currentPage]
|
|
4998
|
+
);
|
|
4961
4999
|
const displayData = defaultData;
|
|
4962
5000
|
useEffect5(() => {
|
|
4963
5001
|
updateGridContent({ page: 0, sortedBy: [], rowsPerPage });
|
|
4964
|
-
}, []);
|
|
5002
|
+
}, [updateGridContent, rowsPerPage]);
|
|
4965
5003
|
return {
|
|
4966
5004
|
data: displayData,
|
|
4967
5005
|
set,
|
|
@@ -4993,7 +5031,7 @@ function useEvent(event, handler, passive = false) {
|
|
|
4993
5031
|
}
|
|
4994
5032
|
|
|
4995
5033
|
// src/contexts/AuthContext.tsx
|
|
4996
|
-
import
|
|
5034
|
+
import React27, { useCallback as useCallback7 } from "react";
|
|
4997
5035
|
import {
|
|
4998
5036
|
createContext as createContext3,
|
|
4999
5037
|
useEffect as useEffect7,
|
|
@@ -5012,31 +5050,32 @@ function CreateAuthProvider({
|
|
|
5012
5050
|
const [user, setUser] = useState8();
|
|
5013
5051
|
const [status, setStatus] = useState8("unauthenticated");
|
|
5014
5052
|
const { createAlert } = useAlert();
|
|
5015
|
-
const signIn = (
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5053
|
+
const signIn = useCallback7(
|
|
5054
|
+
(_0) => __async(this, [_0], function* ({ email, password }) {
|
|
5055
|
+
setStatus("loading");
|
|
5056
|
+
try {
|
|
5057
|
+
const response = yield api.post("/auth/login", {
|
|
5058
|
+
email,
|
|
5059
|
+
password
|
|
5060
|
+
});
|
|
5061
|
+
const { token } = response.data;
|
|
5062
|
+
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
|
5063
|
+
const { data } = yield api.get("/auth/me");
|
|
5064
|
+
setUser(data);
|
|
5065
|
+
setStatus("autenticated");
|
|
5066
|
+
return true;
|
|
5067
|
+
} catch (error) {
|
|
5068
|
+
createAlert(error.response.data.error, "error");
|
|
5069
|
+
setStatus("unauthenticated");
|
|
5070
|
+
throw error;
|
|
5071
|
+
}
|
|
5072
|
+
}),
|
|
5073
|
+
[createAlert, api]
|
|
5074
|
+
);
|
|
5075
|
+
const ClientSignOut = useCallback7(() => __async(this, null, function* () {
|
|
5076
|
+
yield api.get("/auth/logout");
|
|
5077
|
+
setUser(void 0);
|
|
5078
|
+
}), [api]);
|
|
5040
5079
|
useEffect7(() => {
|
|
5041
5080
|
const token = parseCookies2()[sessionTokenName];
|
|
5042
5081
|
if (token) {
|
|
@@ -5049,7 +5088,7 @@ function CreateAuthProvider({
|
|
|
5049
5088
|
});
|
|
5050
5089
|
}
|
|
5051
5090
|
}, [api, sessionTokenName]);
|
|
5052
|
-
return /* @__PURE__ */
|
|
5091
|
+
return /* @__PURE__ */ React27.createElement(
|
|
5053
5092
|
Provider,
|
|
5054
5093
|
{
|
|
5055
5094
|
value: {
|