@bluemarble/bm-components 2.4.0 → 2.4.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.js CHANGED
@@ -3155,7 +3155,7 @@ import React10, { useState as useState2 } from "react";
3155
3155
  // src/components/Grid/EditableTableCell/DefaultInput.tsx
3156
3156
  import React8 from "react";
3157
3157
  import { TextField as TextField2 } from "@mui/material";
3158
- import moment from "moment";
3158
+ import dayjs from "dayjs";
3159
3159
  var DefaultInput = (allProps) => {
3160
3160
  const {
3161
3161
  TextFieldProps: TextFieldProps3,
@@ -3174,9 +3174,9 @@ var DefaultInput = (allProps) => {
3174
3174
  if (formatInputDefautvalue) return formatInputDefautvalue(value);
3175
3175
  switch (type) {
3176
3176
  case "date":
3177
- return moment(value).format("YYYY-MM-DD");
3177
+ return dayjs(value).format("YYYY-MM-DD");
3178
3178
  case "datetime-local":
3179
- return moment(value).format("YYYY-MM-DDTHH:mm:ss");
3179
+ return dayjs(value).format("YYYY-MM-DDTHH:mm:ss");
3180
3180
  default:
3181
3181
  return String(value);
3182
3182
  }
@@ -3246,9 +3246,7 @@ var InputMask = (allProps) => {
3246
3246
  handleCancelEditing,
3247
3247
  setIsEditing
3248
3248
  } = allProps;
3249
- const { ref, unmaskedValue, setValue } = useIMask(
3250
- mask
3251
- );
3249
+ const { ref, unmaskedValue, setValue } = useIMask(mask);
3252
3250
  const handleSave = (event) => {
3253
3251
  setIsEditing(false);
3254
3252
  setValue(String(event.target?.value));
@@ -3484,8 +3482,8 @@ import {
3484
3482
  } from "@mui/material";
3485
3483
  import { useField } from "formik";
3486
3484
  var CustomInputLabel = InputLabel;
3487
- function Select({ withFormik = true, ...rest }) {
3488
- if (withFormik) return /* @__PURE__ */ React13.createElement(FormikSelect, { ...rest });
3485
+ function Select({ withFormik = true, helperText, ...rest }) {
3486
+ if (withFormik) return /* @__PURE__ */ React13.createElement(FormikSelect, { helperText, ...rest });
3489
3487
  else return /* @__PURE__ */ React13.createElement(BaseSelect, { ...rest });
3490
3488
  }
3491
3489
  function BaseSelect({
@@ -3703,7 +3701,9 @@ function FormikAutocomplete({
3703
3701
  import React15 from "react";
3704
3702
  import {
3705
3703
  Checkbox as MuiCheckbox,
3706
- FormControlLabel
3704
+ FormControl as FormControl2,
3705
+ FormControlLabel,
3706
+ FormHelperText as FormHelperText2
3707
3707
  } from "@mui/material";
3708
3708
  import { useField as useField3 } from "formik";
3709
3709
  var Checkbox = ({
@@ -3716,47 +3716,49 @@ var Checkbox = ({
3716
3716
  };
3717
3717
  var BaseCheckbox = ({
3718
3718
  label,
3719
+ helperText,
3719
3720
  FormControlLabelProps: FormControlLabelProps3,
3720
3721
  ...props
3721
3722
  }) => {
3722
- return /* @__PURE__ */ React15.createElement(
3723
+ return /* @__PURE__ */ React15.createElement(FormControl2, null, /* @__PURE__ */ React15.createElement(
3723
3724
  FormControlLabel,
3724
3725
  {
3725
3726
  label,
3726
3727
  control: /* @__PURE__ */ React15.createElement(MuiCheckbox, { ...props }),
3727
3728
  ...FormControlLabelProps3
3728
3729
  }
3729
- );
3730
+ ), helperText && /* @__PURE__ */ React15.createElement(FormHelperText2, null, helperText));
3730
3731
  };
3731
3732
  var FormikCheckbox = ({
3732
3733
  label,
3733
3734
  name,
3735
+ helperText,
3734
3736
  FormControlLabelProps: FormControlLabelProps3,
3735
3737
  ...props
3736
3738
  }) => {
3737
- const [{ value, ...field }, , { setValue }] = useField3({
3738
- name
3739
- });
3739
+ const [{ value, ...field }, { error }, { setValue }] = useField3({ name });
3740
3740
  const onChange = (_, value2) => {
3741
3741
  setValue(value2);
3742
3742
  };
3743
- return /* @__PURE__ */ React15.createElement(
3743
+ return /* @__PURE__ */ React15.createElement(FormControl2, { error: Boolean(error) }, /* @__PURE__ */ React15.createElement(
3744
3744
  FormControlLabel,
3745
3745
  {
3746
3746
  label,
3747
- control: /* @__PURE__ */ React15.createElement(MuiCheckbox, { ...props, defaultChecked: Boolean(value) }),
3747
+ control: /* @__PURE__ */ React15.createElement(MuiCheckbox, { ...props, checked: Boolean(value) }),
3748
3748
  ...field,
3749
3749
  onChange,
3750
3750
  ...FormControlLabelProps3
3751
3751
  }
3752
- );
3752
+ ), (error || helperText) && /* @__PURE__ */ React15.createElement(FormHelperText2, null, error ?? helperText));
3753
3753
  };
3754
3754
 
3755
3755
  // src/components/Switch/index.tsx
3756
3756
  import React16 from "react";
3757
3757
  import {
3758
3758
  Switch as MuiSwitch,
3759
- FormControlLabel as FormControlLabel2
3759
+ FormControl as FormControl3,
3760
+ FormControlLabel as FormControlLabel2,
3761
+ FormHelperText as FormHelperText3
3760
3762
  } from "@mui/material";
3761
3763
  import { useField as useField4 } from "formik";
3762
3764
  var Switch = ({ withFormik = true, name, ...props }) => {
@@ -3765,52 +3767,53 @@ var Switch = ({ withFormik = true, name, ...props }) => {
3765
3767
  };
3766
3768
  var BaseSwitch = ({
3767
3769
  label,
3770
+ helperText,
3768
3771
  FormControlLabelProps: FormControlLabelProps3,
3769
3772
  ...props
3770
3773
  }) => {
3771
- return /* @__PURE__ */ React16.createElement(
3774
+ return /* @__PURE__ */ React16.createElement(FormControl3, null, /* @__PURE__ */ React16.createElement(
3772
3775
  FormControlLabel2,
3773
3776
  {
3774
3777
  label,
3775
3778
  control: /* @__PURE__ */ React16.createElement(MuiSwitch, { ...props }),
3776
3779
  ...FormControlLabelProps3
3777
3780
  }
3778
- );
3781
+ ), helperText && /* @__PURE__ */ React16.createElement(FormHelperText3, null, helperText));
3779
3782
  };
3780
3783
  var FormikSwitch = ({
3781
3784
  label,
3782
3785
  name,
3786
+ helperText,
3783
3787
  FormControlLabelProps: FormControlLabelProps3,
3784
3788
  ...props
3785
3789
  }) => {
3786
- const [{ value, onChange: unused, ...field }, , { setValue }] = useField4({
3787
- name
3788
- });
3790
+ const [{ value, onChange: unused, ...field }, { error }, { setValue }] = useField4({ name });
3789
3791
  const onChange = (_, value2) => {
3790
3792
  setValue(value2);
3791
3793
  };
3792
- return /* @__PURE__ */ React16.createElement(
3794
+ return /* @__PURE__ */ React16.createElement(FormControl3, { error: Boolean(error) }, /* @__PURE__ */ React16.createElement(
3793
3795
  FormControlLabel2,
3794
3796
  {
3795
3797
  label,
3796
3798
  onChange,
3797
- control: /* @__PURE__ */ React16.createElement(MuiSwitch, { defaultChecked: value, ...props }),
3799
+ control: /* @__PURE__ */ React16.createElement(MuiSwitch, { checked: value, ...props }),
3798
3800
  ...field,
3799
3801
  ...FormControlLabelProps3
3800
3802
  }
3801
- );
3803
+ ), (error || helperText) && /* @__PURE__ */ React16.createElement(FormHelperText3, null, error ?? helperText));
3802
3804
  };
3803
3805
 
3804
3806
  // src/components/Radio/index.tsx
3805
3807
  import React17 from "react";
3806
3808
  import {
3807
- FormControl as FormControl2,
3809
+ FormControl as FormControl4,
3808
3810
  FormControlLabel as FormControlLabel3,
3811
+ FormHelperText as FormHelperText4,
3809
3812
  FormLabel,
3810
3813
  Radio as MuiRadio,
3811
3814
  RadioGroup
3812
3815
  } from "@mui/material";
3813
- import { Field as Field3 } from "formik";
3816
+ import { useField as useField5 } from "formik";
3814
3817
  var Radio = ({
3815
3818
  name,
3816
3819
  withFormik = true,
@@ -3822,9 +3825,10 @@ var Radio = ({
3822
3825
  var BaseRadio = ({
3823
3826
  label,
3824
3827
  options,
3828
+ helperText,
3825
3829
  ...rest
3826
3830
  }) => {
3827
- return /* @__PURE__ */ React17.createElement(FormControl2, null, label && /* @__PURE__ */ React17.createElement(FormLabel, null, label), /* @__PURE__ */ React17.createElement(RadioGroup, { ...rest }, options.map((option) => /* @__PURE__ */ React17.createElement(
3831
+ return /* @__PURE__ */ React17.createElement(FormControl4, null, label && /* @__PURE__ */ React17.createElement(FormLabel, null, label), /* @__PURE__ */ React17.createElement(RadioGroup, { ...rest }, options.map((option) => /* @__PURE__ */ React17.createElement(
3828
3832
  FormControlLabel3,
3829
3833
  {
3830
3834
  key: String(option.value),
@@ -3832,22 +3836,21 @@ var BaseRadio = ({
3832
3836
  label: option.label,
3833
3837
  control: /* @__PURE__ */ React17.createElement(MuiRadio, null)
3834
3838
  }
3835
- ))));
3839
+ ))), helperText && /* @__PURE__ */ React17.createElement(FormHelperText4, null, helperText));
3836
3840
  };
3837
3841
  var FormikRadio = ({
3838
3842
  label,
3839
3843
  name,
3840
3844
  options,
3845
+ helperText,
3841
3846
  ...rest
3842
3847
  }) => {
3843
- const onChange = (setFieldValue, value) => {
3844
- setFieldValue(name, value);
3845
- };
3846
- return /* @__PURE__ */ React17.createElement(Field3, null, ({ field: { value }, form: { setFieldValue } }) => /* @__PURE__ */ React17.createElement(FormControl2, null, label && /* @__PURE__ */ React17.createElement(FormLabel, null, label), /* @__PURE__ */ React17.createElement(
3848
+ const [{ value }, meta, { setValue }] = useField5(name);
3849
+ return /* @__PURE__ */ React17.createElement(FormControl4, { error: Boolean(meta.error) }, label && /* @__PURE__ */ React17.createElement(FormLabel, null, label), /* @__PURE__ */ React17.createElement(
3847
3850
  RadioGroup,
3848
3851
  {
3849
- defaultValue: value,
3850
- onChange: (_, value2) => onChange(setFieldValue, value2),
3852
+ value: value ?? "",
3853
+ onChange: (_, val) => setValue(val),
3851
3854
  ...rest
3852
3855
  },
3853
3856
  options.map((option) => /* @__PURE__ */ React17.createElement(
@@ -3859,7 +3862,7 @@ var FormikRadio = ({
3859
3862
  control: /* @__PURE__ */ React17.createElement(MuiRadio, null)
3860
3863
  }
3861
3864
  ))
3862
- )));
3865
+ ), /* @__PURE__ */ React17.createElement(FormHelperText4, null, helperText || meta.error));
3863
3866
  };
3864
3867
 
3865
3868
  // src/components/LargeButton/index.tsx
@@ -4153,6 +4156,11 @@ import {
4153
4156
  Modal as MuiModal
4154
4157
  } from "@mui/material";
4155
4158
  var Modal = ({ open, onClose, BoxProps: BoxProps3, ...rest }) => {
4159
+ if (process.env.NODE_ENV !== "production") {
4160
+ console.warn(
4161
+ "[Modal] is deprecated. Use `BaseDialog` instead. `Modal` will be removed in a future release."
4162
+ );
4163
+ }
4156
4164
  return /* @__PURE__ */ React23.createElement(MuiModal, { open, onClose, ...rest }, /* @__PURE__ */ React23.createElement(
4157
4165
  Box5,
4158
4166
  {
@@ -4547,6 +4555,7 @@ var _ApiHelper = class _ApiHelper {
4547
4555
  return async (req, res) => {
4548
4556
  const methods = factory(req, res);
4549
4557
  const handler = methods[req.method];
4558
+ if (!handler) throw new HttpError(405, "M\xE9todo inv\xE1lido");
4550
4559
  const methodWithMiddlewares = this.middlewares.reduce((acc, fn) => {
4551
4560
  return fn(acc, options);
4552
4561
  }, handler);
@@ -4582,191 +4591,8 @@ var _ApiHelper = class _ApiHelper {
4582
4591
  _ApiHelper.parserErrorWrapper = _ApiHelper.parse;
4583
4592
  var ApiHelper = _ApiHelper;
4584
4593
 
4585
- // src/hooks/useFormHelper.ts
4586
- import { useCallback as useCallback4, useContext as useContext4, useEffect as useEffect4, useRef as useRef4 } from "react";
4587
-
4588
- // src/hooks/useAlert.ts
4589
- import { useContext as useContext3 } from "react";
4590
-
4591
- // src/contexts/AlertContext.tsx
4592
- import React31, { useCallback as useCallback2 } from "react";
4593
- import { createContext as createContext3, useState as useState6 } from "react";
4594
-
4595
- // src/components/Toast/index.tsx
4596
- import React30 from "react";
4597
- import { Alert, IconButton as IconButton5, Snackbar } from "@mui/material";
4598
- import { MdClose as MdClose3 } from "react-icons/md";
4599
- var Toast = ({ open, onClose, severity, message }) => {
4600
- return /* @__PURE__ */ React30.createElement(React30.Fragment, null, /* @__PURE__ */ React30.createElement(
4601
- Snackbar,
4602
- {
4603
- open,
4604
- autoHideDuration: 6e3,
4605
- onClose,
4606
- anchorOrigin: { vertical: "top", horizontal: "right" },
4607
- sx: { zIndex: 99999999 }
4608
- },
4609
- /* @__PURE__ */ React30.createElement(
4610
- Alert,
4611
- {
4612
- severity,
4613
- elevation: 2,
4614
- action: /* @__PURE__ */ React30.createElement(
4615
- IconButton5,
4616
- {
4617
- "aria-label": "close",
4618
- color: "inherit",
4619
- size: "small",
4620
- onClick: onClose
4621
- },
4622
- /* @__PURE__ */ React30.createElement(MdClose3, { fontSize: "inherit" })
4623
- )
4624
- },
4625
- message
4626
- )
4627
- ));
4628
- };
4629
-
4630
- // src/contexts/AlertContext.tsx
4631
- var AlertContext = createContext3({});
4632
- var AlertProvider = ({ children }) => {
4633
- const [severity, setSeverity] = useState6("info");
4634
- const [message, setMessage] = useState6("");
4635
- const [isVisible, setIsVisible] = useState6(false);
4636
- const createAlert = useCallback2(
4637
- (newMessage, severity2) => {
4638
- setMessage(newMessage);
4639
- setSeverity(severity2);
4640
- setIsVisible(true);
4641
- },
4642
- []
4643
- );
4644
- const onCloseToast = useCallback2(() => {
4645
- setIsVisible(false);
4646
- }, []);
4647
- return /* @__PURE__ */ React31.createElement(AlertContext.Provider, { value: { createAlert } }, children, /* @__PURE__ */ React31.createElement(
4648
- Toast,
4649
- {
4650
- open: isVisible,
4651
- onClose: onCloseToast,
4652
- severity,
4653
- message
4654
- }
4655
- ));
4656
- };
4657
-
4658
- // src/hooks/useAlert.ts
4659
- var useAlert = () => {
4660
- return useContext3(AlertContext);
4661
- };
4662
-
4663
- // src/hooks/useLoading.ts
4664
- import { useCallback as useCallback3, useState as useState7 } from "react";
4665
- function useLoading() {
4666
- const [state, setState] = useState7([]);
4667
- const isLoading = useCallback3((prop) => state.includes(prop), [state]);
4668
- const setLoading = useCallback3((prop, remove) => {
4669
- if (remove)
4670
- setState((prevState) => prevState.filter((state2) => state2 !== prop));
4671
- else setState((prevState) => [...prevState, prop]);
4672
- }, []);
4673
- return { isLoading, setLoading };
4674
- }
4675
-
4676
- // src/contexts/FormHelperProvider.tsx
4677
- import React32 from "react";
4678
- import { createContext as createContext4 } from "react";
4679
- var FormHelperContext = createContext4({});
4680
- var FormHelperProvider = ({ formatErrorMessage, api, children }) => {
4681
- return /* @__PURE__ */ React32.createElement(FormHelperContext.Provider, { value: { formatErrorMessage, api } }, children);
4682
- };
4683
-
4684
- // src/hooks/useFormHelper.ts
4685
- function useFormHelper() {
4686
- const alertProps = useAlert();
4687
- const loadingProps = useLoading();
4688
- const { api, formatErrorMessage } = useContext4(FormHelperContext);
4689
- const { createAlert } = alertProps;
4690
- const { setLoading } = loadingProps;
4691
- const sourceRef = useRef4(new AbortController());
4692
- const onSubmitWrapper = useCallback4(
4693
- (fn, { name }) => {
4694
- return async (fields, methods) => {
4695
- const LOADING_NAME = name;
4696
- setLoading(LOADING_NAME);
4697
- try {
4698
- await fn(fields, methods);
4699
- } catch (error) {
4700
- errorHandler(error, methods.setErrors);
4701
- } finally {
4702
- setLoading(LOADING_NAME, true);
4703
- }
4704
- };
4705
- },
4706
- [setLoading]
4707
- );
4708
- const onRequestWrapper = useCallback4(
4709
- (fn, { name }) => {
4710
- return async (...params) => {
4711
- const LOADING_NAME = name;
4712
- setLoading(LOADING_NAME);
4713
- api.interceptors.request.use(
4714
- (config) => {
4715
- if (!config.signal && sourceRef.current && config.method === "get") {
4716
- config.signal = sourceRef.current.signal;
4717
- }
4718
- return config;
4719
- },
4720
- (error) => {
4721
- return Promise.reject(error);
4722
- }
4723
- );
4724
- try {
4725
- const response = await fn(...params);
4726
- return response;
4727
- } catch (error) {
4728
- errorHandler(error);
4729
- } finally {
4730
- setLoading(LOADING_NAME, true);
4731
- }
4732
- };
4733
- },
4734
- [setLoading, api]
4735
- );
4736
- const errorHandler = useCallback4(
4737
- (error, callback) => {
4738
- if (error?.message === "cancel.navigation") return;
4739
- if (callback) {
4740
- if (error.response.data.code === "invalid.body") {
4741
- const errors = error.response.data.details.issues;
4742
- const currentErrors = errors.reduce((acc, item) => {
4743
- acc[item.path.join(".")] = item.message;
4744
- return acc;
4745
- }, {});
4746
- callback(currentErrors);
4747
- }
4748
- }
4749
- createAlert(formatErrorMessage(error), "error");
4750
- },
4751
- [formatErrorMessage, createAlert]
4752
- );
4753
- useEffect4(() => {
4754
- return () => {
4755
- sourceRef.current.abort();
4756
- sourceRef.current = new AbortController();
4757
- };
4758
- }, []);
4759
- return {
4760
- ...alertProps,
4761
- ...loadingProps,
4762
- onSubmitWrapper,
4763
- onRequestWrapper
4764
- };
4765
- }
4766
-
4767
4594
  // src/helpers/authHelper.ts
4768
4595
  import { serialize as serialize2 } from "cookie";
4769
- import { v4 as uuid } from "uuid";
4770
4596
  import jwt from "jsonwebtoken";
4771
4597
 
4772
4598
  // packages/nookies/index.ts
@@ -4878,6 +4704,7 @@ var nookies = {
4878
4704
  };
4879
4705
 
4880
4706
  // src/helpers/authHelper.ts
4707
+ import { randomUUID } from "crypto";
4881
4708
  function decodeSessionToken({
4882
4709
  req,
4883
4710
  res,
@@ -4920,7 +4747,7 @@ var AuthHelper = class {
4920
4747
  expiresIn: this.tokenExpTimeInSeconds || 60 * 15
4921
4748
  // 15 minutos
4922
4749
  });
4923
- const uniqueToken = uuid();
4750
+ const uniqueToken = randomUUID();
4924
4751
  await this.onCreateRefreshToken(userId, uniqueToken);
4925
4752
  return {
4926
4753
  token,
@@ -4952,7 +4779,7 @@ var AuthHelper = class {
4952
4779
  if (!req.url) return res.status(400).json({ error: "url not sent" });
4953
4780
  if (req.url.endsWith("/login")) {
4954
4781
  const loginResult = await this.onLogin(req.body);
4955
- if (loginResult.status === "sucess") {
4782
+ if (loginResult.status === "success") {
4956
4783
  const { refreshToken, token } = await this.generateJwtAndRefreshToken(
4957
4784
  loginResult.userId,
4958
4785
  {}
@@ -5139,11 +4966,10 @@ var AuthHelper = class {
5139
4966
  };
5140
4967
 
5141
4968
  // src/hooks/useGrid.ts
5142
- import { useCallback as useCallback6, useEffect as useEffect5, useMemo as useMemo3, useState as useState9 } from "react";
4969
+ import { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo3, useState as useState7 } from "react";
5143
4970
 
5144
4971
  // src/hooks/useFilter.ts
5145
- import moment2 from "moment";
5146
- import { useCallback as useCallback5, useState as useState8 } from "react";
4972
+ import { useCallback as useCallback2, useState as useState6 } from "react";
5147
4973
 
5148
4974
  // src/components/utils/getObjectValue.ts
5149
4975
  function getObjectValue(obj) {
@@ -5158,11 +4984,11 @@ function getObjectValue(obj) {
5158
4984
 
5159
4985
  // src/hooks/useFilter.ts
5160
4986
  function useFilter(props = { defaultFilters: [] }) {
5161
- const [selectedFilters, setSelectedFilters] = useState8(() => {
4987
+ const [selectedFilters, setSelectedFilters] = useState6(() => {
5162
4988
  const { defaultFilters } = props;
5163
4989
  return defaultFilters || [];
5164
4990
  });
5165
- const filterBy = useCallback5((newFilter) => {
4991
+ const filterBy = useCallback2((newFilter) => {
5166
4992
  const propToCompare = newFilter?.id ? "id" : "prop";
5167
4993
  function removeRepeatedFilters(filter) {
5168
4994
  return filter[propToCompare] !== newFilter[propToCompare];
@@ -5172,7 +4998,7 @@ function useFilter(props = { defaultFilters: [] }) {
5172
4998
  newFilter
5173
4999
  ]);
5174
5000
  }, []);
5175
- const removeFilter = useCallback5(
5001
+ const removeFilter = useCallback2(
5176
5002
  (prop, isId) => {
5177
5003
  const propToCompare = isId ? "id" : "prop";
5178
5004
  setSelectedFilters(
@@ -5213,13 +5039,13 @@ function compareFilter(item, filter) {
5213
5039
  case "valueNotIn":
5214
5040
  return !itemValue.includes(filter.value);
5215
5041
  case "gte":
5216
- return isDate(itemValue) ? moment2(String(itemValue)).isSameOrAfter(filter.value) : itemValue >= filter.value;
5042
+ return isDate(itemValue) ? new Date(String(itemValue)) >= filter.value : itemValue >= filter.value;
5217
5043
  case "gt":
5218
- return isDate(itemValue) ? moment2(String(itemValue)).isAfter(filter.value) : itemValue > filter.value;
5044
+ return isDate(itemValue) ? new Date(String(itemValue)) > filter.value : itemValue > filter.value;
5219
5045
  case "lte":
5220
- return isDate(itemValue) ? moment2(String(itemValue)).isSameOrBefore(filter.value) : itemValue <= filter.value;
5046
+ return isDate(itemValue) ? new Date(String(itemValue)) <= filter.value : itemValue <= filter.value;
5221
5047
  case "lt":
5222
- return isDate(itemValue) ? moment2(String(itemValue)).isBefore(filter.value) : itemValue < filter.value;
5048
+ return isDate(itemValue) ? new Date(String(itemValue)) < filter.value : itemValue < filter.value;
5223
5049
  }
5224
5050
  }
5225
5051
  function createFilter(filters) {
@@ -5264,29 +5090,29 @@ function useGrid({
5264
5090
  defaultCurrentPage,
5265
5091
  defaultSortedBy
5266
5092
  }) {
5267
- const [defaultData, setDefaultData] = useState9(externalDefaultData || []);
5268
- const [sortedBy, setSortedBy] = useState9(
5093
+ const [defaultData, setDefaultData] = useState7(externalDefaultData || []);
5094
+ const [sortedBy, setSortedBy] = useState7(
5269
5095
  defaultSortedBy || []
5270
5096
  );
5271
- const [currentPage, setCurrentPage] = useState9(defaultCurrentPage || 0);
5272
- const [rowsPerPage, setRowsPerPage] = useState9(rowsPerPageOptions[0]);
5273
- const toggleSortedDirection = useCallback6(
5097
+ const [currentPage, setCurrentPage] = useState7(defaultCurrentPage || 0);
5098
+ const [rowsPerPage, setRowsPerPage] = useState7(rowsPerPageOptions[0]);
5099
+ const toggleSortedDirection = useCallback3(
5274
5100
  (direction) => {
5275
5101
  if (direction === "asc") return "desc";
5276
5102
  return "asc";
5277
5103
  },
5278
5104
  []
5279
5105
  );
5280
- const clearSort = useCallback6(() => {
5106
+ const clearSort = useCallback3(() => {
5281
5107
  setSortedBy([]);
5282
5108
  }, []);
5283
- const appendSort = useCallback6((prop, direction) => {
5109
+ const appendSort = useCallback3((prop, direction) => {
5284
5110
  setSortedBy((prev) => [...prev, { prop, direction }]);
5285
5111
  }, []);
5286
- const setSort = useCallback6((prop, direction) => {
5112
+ const setSort = useCallback3((prop, direction) => {
5287
5113
  setSortedBy([{ prop, direction }]);
5288
5114
  }, []);
5289
- const onSortBy = useCallback6(
5115
+ const onSortBy = useCallback3(
5290
5116
  (prop) => {
5291
5117
  if (!prop) return;
5292
5118
  const currentSorted = sortedBy.find((p) => p.prop === prop);
@@ -5311,10 +5137,10 @@ function useGrid({
5311
5137
  },
5312
5138
  [toggleSortedDirection, sortedBy]
5313
5139
  );
5314
- const set = useCallback6((data) => {
5140
+ const set = useCallback3((data) => {
5315
5141
  setDefaultData(data);
5316
5142
  }, []);
5317
- const sortData = useCallback6(
5143
+ const sortData = useCallback3(
5318
5144
  (data) => {
5319
5145
  if (sortedBy.length > 0) {
5320
5146
  const symbolDir = {
@@ -5334,7 +5160,7 @@ function useGrid({
5334
5160
  if (pageNumber > totalNumberOfPages) return;
5335
5161
  setCurrentPage(pageNumber);
5336
5162
  };
5337
- const onChangeRowsPerPage = useCallback6(
5163
+ const onChangeRowsPerPage = useCallback3(
5338
5164
  (rows) => {
5339
5165
  let totalNumberOfPages2 = Math.round(filteredData.length / rows) - 1;
5340
5166
  totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
@@ -5365,7 +5191,7 @@ function useGrid({
5365
5191
  return filteredData.slice(startPage, endPage);
5366
5192
  }, [currentPage, rowsPerPage, filteredData]);
5367
5193
  const totalNumberOfPages = Math.ceil(filteredData.length / rowsPerPage) - 1;
5368
- useEffect5(() => {
5194
+ useEffect4(() => {
5369
5195
  if (externalDefaultData) setDefaultData(externalDefaultData);
5370
5196
  }, [externalDefaultData]);
5371
5197
  return {
@@ -5440,7 +5266,7 @@ function createSearch(options) {
5440
5266
  }
5441
5267
 
5442
5268
  // src/hooks/useAsyncGrid.ts
5443
- import { useCallback as useCallback7, useEffect as useEffect6, useState as useState10 } from "react";
5269
+ import { useCallback as useCallback4, useEffect as useEffect5, useState as useState8 } from "react";
5444
5270
  function useAsyncGrid({
5445
5271
  columns,
5446
5272
  filters = [],
@@ -5453,26 +5279,26 @@ function useAsyncGrid({
5453
5279
  defaultCurrentPage,
5454
5280
  defaultSortedBy
5455
5281
  }) {
5456
- const [defaultData, setDefaultData] = useState10(externalDefaultData || []);
5457
- const [sortedBy, setSortedBy] = useState10(
5282
+ const [defaultData, setDefaultData] = useState8(externalDefaultData || []);
5283
+ const [sortedBy, setSortedBy] = useState8(
5458
5284
  defaultSortedBy || []
5459
5285
  );
5460
- const [totalNumberOfItems, setTotalNumberOfItems] = useState10(0);
5461
- const [isLoading, setIsLoading] = useState10(false);
5462
- const [currentPage, setCurrentPage] = useState10(defaultCurrentPage || 0);
5463
- const [rowsPerPage, setRowsPerPage] = useState10(rowsPerPageOptions[0]);
5286
+ const [totalNumberOfItems, setTotalNumberOfItems] = useState8(0);
5287
+ const [isLoading, setIsLoading] = useState8(false);
5288
+ const [currentPage, setCurrentPage] = useState8(defaultCurrentPage || 0);
5289
+ const [rowsPerPage, setRowsPerPage] = useState8(rowsPerPageOptions[0]);
5464
5290
  const totalNumberOfPages = Math.ceil(totalNumberOfItems / rowsPerPage) - 1;
5465
- const toggleSortedDirection = useCallback7(
5291
+ const toggleSortedDirection = useCallback4(
5466
5292
  (direction) => {
5467
5293
  if (direction === "asc") return "desc";
5468
5294
  return "asc";
5469
5295
  },
5470
5296
  []
5471
5297
  );
5472
- const setSort = useCallback7((prop, direction) => {
5298
+ const setSort = useCallback4((prop, direction) => {
5473
5299
  setSortedBy((prev) => [...prev, { prop, direction }]);
5474
5300
  }, []);
5475
- const onSortBy = useCallback7(
5301
+ const onSortBy = useCallback4(
5476
5302
  async (prop) => {
5477
5303
  if (!prop) return;
5478
5304
  let finalArr = [];
@@ -5500,10 +5326,10 @@ function useAsyncGrid({
5500
5326
  },
5501
5327
  [sortedBy, toggleSortedDirection, rowsPerPage, currentPage]
5502
5328
  );
5503
- const set = useCallback7((data) => {
5329
+ const set = useCallback4((data) => {
5504
5330
  setDefaultData(data);
5505
5331
  }, []);
5506
- const baseRequest = useCallback7(
5332
+ const baseRequest = useCallback4(
5507
5333
  async ({
5508
5334
  page,
5509
5335
  search: search2,
@@ -5532,7 +5358,7 @@ function useAsyncGrid({
5532
5358
  },
5533
5359
  [axiosInstance, url]
5534
5360
  );
5535
- const updateGridContent = useCallback7(
5361
+ const updateGridContent = useCallback4(
5536
5362
  async ({
5537
5363
  page,
5538
5364
  sortedBy: sortedBy2,
@@ -5558,7 +5384,7 @@ function useAsyncGrid({
5558
5384
  },
5559
5385
  [set, search, filters, onRequest, baseRequest]
5560
5386
  );
5561
- const onPageChange = useCallback7(
5387
+ const onPageChange = useCallback4(
5562
5388
  (pageNumber) => {
5563
5389
  if (pageNumber < 0) return;
5564
5390
  if (pageNumber > totalNumberOfPages) return;
@@ -5566,7 +5392,7 @@ function useAsyncGrid({
5566
5392
  },
5567
5393
  [updateGridContent, totalNumberOfPages, sortedBy, rowsPerPage]
5568
5394
  );
5569
- const onChangeRowsPerPage = useCallback7(
5395
+ const onChangeRowsPerPage = useCallback4(
5570
5396
  (rows) => {
5571
5397
  let totalNumberOfPages2 = Math.round(totalNumberOfItems / rows) - 1;
5572
5398
  totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
@@ -5585,7 +5411,7 @@ function useAsyncGrid({
5585
5411
  [updateGridContent, totalNumberOfItems, sortedBy, currentPage]
5586
5412
  );
5587
5413
  const displayData = defaultData;
5588
- useEffect6(() => {
5414
+ useEffect5(() => {
5589
5415
  updateGridContent({ page: 0, sortedBy: [], rowsPerPage });
5590
5416
  }, [updateGridContent, rowsPerPage]);
5591
5417
  return {
@@ -5608,9 +5434,9 @@ function useAsyncGrid({
5608
5434
  }
5609
5435
 
5610
5436
  // src/hooks/useEvent.ts
5611
- import { useEffect as useEffect7 } from "react";
5437
+ import { useEffect as useEffect6 } from "react";
5612
5438
  function useEvent(event, handler, passive = false) {
5613
- useEffect7(() => {
5439
+ useEffect6(() => {
5614
5440
  window.addEventListener(event, handler, passive);
5615
5441
  return function cleanup() {
5616
5442
  window.removeEventListener(event, handler);
@@ -5618,6 +5444,188 @@ function useEvent(event, handler, passive = false) {
5618
5444
  });
5619
5445
  }
5620
5446
 
5447
+ // src/hooks/useLoading.ts
5448
+ import { useCallback as useCallback5, useState as useState9 } from "react";
5449
+ function useLoading() {
5450
+ const [state, setState] = useState9([]);
5451
+ const isLoading = useCallback5((prop) => state.includes(prop), [state]);
5452
+ const setLoading = useCallback5((prop, remove) => {
5453
+ if (remove)
5454
+ setState((prevState) => prevState.filter((state2) => state2 !== prop));
5455
+ else setState((prevState) => [...prevState, prop]);
5456
+ }, []);
5457
+ return { isLoading, setLoading };
5458
+ }
5459
+
5460
+ // src/hooks/useAlert.ts
5461
+ import { useContext as useContext3 } from "react";
5462
+
5463
+ // src/contexts/AlertContext.tsx
5464
+ import React31, { useCallback as useCallback6 } from "react";
5465
+ import { createContext as createContext3, useState as useState10 } from "react";
5466
+
5467
+ // src/components/Toast/index.tsx
5468
+ import React30 from "react";
5469
+ import { Alert, IconButton as IconButton5, Snackbar } from "@mui/material";
5470
+ import { MdClose as MdClose3 } from "react-icons/md";
5471
+ var Toast = ({ open, onClose, severity, message }) => {
5472
+ return /* @__PURE__ */ React30.createElement(React30.Fragment, null, /* @__PURE__ */ React30.createElement(
5473
+ Snackbar,
5474
+ {
5475
+ open,
5476
+ autoHideDuration: 6e3,
5477
+ onClose,
5478
+ anchorOrigin: { vertical: "top", horizontal: "right" },
5479
+ sx: { zIndex: 99999999 }
5480
+ },
5481
+ /* @__PURE__ */ React30.createElement(
5482
+ Alert,
5483
+ {
5484
+ severity,
5485
+ elevation: 2,
5486
+ action: /* @__PURE__ */ React30.createElement(
5487
+ IconButton5,
5488
+ {
5489
+ "aria-label": "close",
5490
+ color: "inherit",
5491
+ size: "small",
5492
+ onClick: onClose
5493
+ },
5494
+ /* @__PURE__ */ React30.createElement(MdClose3, { fontSize: "inherit" })
5495
+ )
5496
+ },
5497
+ message
5498
+ )
5499
+ ));
5500
+ };
5501
+
5502
+ // src/contexts/AlertContext.tsx
5503
+ var AlertContext = createContext3({});
5504
+ var AlertProvider = ({ children }) => {
5505
+ const [severity, setSeverity] = useState10("info");
5506
+ const [message, setMessage] = useState10("");
5507
+ const [isVisible, setIsVisible] = useState10(false);
5508
+ const createAlert = useCallback6(
5509
+ (newMessage, severity2) => {
5510
+ setMessage(newMessage);
5511
+ setSeverity(severity2);
5512
+ setIsVisible(true);
5513
+ },
5514
+ []
5515
+ );
5516
+ const onCloseToast = useCallback6(() => {
5517
+ setIsVisible(false);
5518
+ }, []);
5519
+ return /* @__PURE__ */ React31.createElement(AlertContext.Provider, { value: { createAlert } }, children, /* @__PURE__ */ React31.createElement(
5520
+ Toast,
5521
+ {
5522
+ open: isVisible,
5523
+ onClose: onCloseToast,
5524
+ severity,
5525
+ message
5526
+ }
5527
+ ));
5528
+ };
5529
+
5530
+ // src/hooks/useAlert.ts
5531
+ var useAlert = () => {
5532
+ return useContext3(AlertContext);
5533
+ };
5534
+
5535
+ // src/hooks/useFormHelper.ts
5536
+ import { useCallback as useCallback7, useContext as useContext4, useEffect as useEffect7, useRef as useRef4 } from "react";
5537
+
5538
+ // src/contexts/FormHelperProvider.tsx
5539
+ import React32 from "react";
5540
+ import { createContext as createContext4 } from "react";
5541
+ var FormHelperContext = createContext4({});
5542
+ var FormHelperProvider = ({ formatErrorMessage, api, children }) => {
5543
+ return /* @__PURE__ */ React32.createElement(FormHelperContext.Provider, { value: { formatErrorMessage, api } }, children);
5544
+ };
5545
+
5546
+ // src/hooks/useFormHelper.ts
5547
+ function useFormHelper() {
5548
+ const alertProps = useAlert();
5549
+ const loadingProps = useLoading();
5550
+ const { api, formatErrorMessage } = useContext4(FormHelperContext);
5551
+ const { createAlert } = alertProps;
5552
+ const { setLoading } = loadingProps;
5553
+ const sourceRef = useRef4(new AbortController());
5554
+ const onSubmitWrapper = useCallback7(
5555
+ (fn, { name }) => {
5556
+ return async (fields, methods) => {
5557
+ const LOADING_NAME = name;
5558
+ setLoading(LOADING_NAME);
5559
+ try {
5560
+ await fn(fields, methods);
5561
+ } catch (error) {
5562
+ errorHandler(error, methods.setErrors);
5563
+ } finally {
5564
+ setLoading(LOADING_NAME, true);
5565
+ }
5566
+ };
5567
+ },
5568
+ [setLoading]
5569
+ );
5570
+ const onRequestWrapper = useCallback7(
5571
+ (fn, { name }) => {
5572
+ return async (...params) => {
5573
+ const LOADING_NAME = name;
5574
+ setLoading(LOADING_NAME);
5575
+ api.interceptors.request.use(
5576
+ (config) => {
5577
+ if (!config.signal && sourceRef.current && config.method === "get") {
5578
+ config.signal = sourceRef.current.signal;
5579
+ }
5580
+ return config;
5581
+ },
5582
+ (error) => {
5583
+ return Promise.reject(error);
5584
+ }
5585
+ );
5586
+ try {
5587
+ const response = await fn(...params);
5588
+ return response;
5589
+ } catch (error) {
5590
+ errorHandler(error);
5591
+ } finally {
5592
+ setLoading(LOADING_NAME, true);
5593
+ }
5594
+ };
5595
+ },
5596
+ [setLoading, api]
5597
+ );
5598
+ const errorHandler = useCallback7(
5599
+ (error, callback) => {
5600
+ if (error?.message === "cancel.navigation") return;
5601
+ if (callback) {
5602
+ if (error.response.data.code === "invalid.body") {
5603
+ const errors = error.response.data.details.issues;
5604
+ const currentErrors = errors.reduce((acc, item) => {
5605
+ acc[item.path.join(".")] = item.message;
5606
+ return acc;
5607
+ }, {});
5608
+ callback(currentErrors);
5609
+ }
5610
+ }
5611
+ createAlert(formatErrorMessage(error), "error");
5612
+ },
5613
+ [formatErrorMessage, createAlert]
5614
+ );
5615
+ useEffect7(() => {
5616
+ return () => {
5617
+ sourceRef.current.abort();
5618
+ sourceRef.current = new AbortController();
5619
+ };
5620
+ }, []);
5621
+ return {
5622
+ ...alertProps,
5623
+ ...loadingProps,
5624
+ onSubmitWrapper,
5625
+ onRequestWrapper
5626
+ };
5627
+ }
5628
+
5621
5629
  // src/contexts/AuthContext.tsx
5622
5630
  import React33, { useCallback as useCallback8 } from "react";
5623
5631
  import {