@m4l/components 0.1.10 → 0.1.11

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.
@@ -14,8 +14,9 @@ import { R as RHFDateTime } from "../hook-form/RHFDateTime/index.js";
14
14
  import "@mui/x-date-pickers";
15
15
  import { R as RHFTextField } from "../hook-form/RHFTextField/index.js";
16
16
  import "../hook-form/RHFPeriod/index.js";
17
+ import "../ErrorLabel/index.js";
18
+ import "../Period/index.js";
17
19
  import { I as Icon } from "../Icon/index.js";
18
- import "../../index.js";
19
20
  import { L as LabelMemuItem, b as Actions, g as getCommonActionsDictionary } from "../CommonActions/components/Actions/index.js";
20
21
  import "@mui/material/Button";
21
22
  import { F as FilterButton } from "../mui_extended/Button/index.js";
@@ -0,0 +1,18 @@
1
+ import { styled } from "@mui/material";
2
+ import { jsx } from "react/jsx-runtime";
3
+ const Wrapper = styled("p")(({
4
+ theme
5
+ }) => ({
6
+ ...theme.typography.caption,
7
+ color: theme.palette.error.main,
8
+ margin: "8px 14px 0 14px"
9
+ }));
10
+ const ErrorLabel = (props) => {
11
+ const {
12
+ message
13
+ } = props;
14
+ return /* @__PURE__ */ jsx(Wrapper, {
15
+ children: message
16
+ });
17
+ };
18
+ export { ErrorLabel as E };
@@ -1,3 +1,6 @@
1
1
  import { Dictionary } from '@m4l/core';
2
2
  export declare function getPeriodComponetsDictionary(): string[];
3
3
  export declare const defaultPeriodDictionary: Dictionary;
4
+ export declare const LABEL_YEARS = "label_years";
5
+ export declare const LABEL_MONTHS = "label_months";
6
+ export declare const LABEL_DAYS = "label_days";
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { PeriodProps } from './types';
3
+ export declare const Period: (props: PeriodProps) => JSX.Element;
@@ -0,0 +1,230 @@
1
+ import { useModuleDictionary, useModuleSkeleton, useEnvironment } from "@m4l/core";
2
+ import { styled, Skeleton, Autocomplete, TextField } from "@mui/material";
3
+ import { useMemo } from "react";
4
+ import { I as Icon } from "../Icon/index.js";
5
+ import { jsxs, jsx } from "react/jsx-runtime";
6
+ import { g as getCommonActionsDictionary } from "../CommonActions/components/Actions/index.js";
7
+ import "@mui/material/Button";
8
+ import "../mui_extended/Button/index.js";
9
+ import "react-hook-form";
10
+ import "react-router-dom";
11
+ import "../../contexts/ModalContext/index.js";
12
+ import "@mui/lab";
13
+ const ContainerPeriod = styled("div")(({
14
+ theme,
15
+ error
16
+ }) => ({
17
+ display: "flex",
18
+ width: "100%",
19
+ height: "auto",
20
+ alignItems: "center",
21
+ gap: theme.spacing(1),
22
+ border: error ? `1px solid ${theme.palette.error.main}` : `1px solid ${theme.palette.divider}`,
23
+ padding: theme.spacing(0.5, 1),
24
+ borderRadius: "4px",
25
+ "& .MuiAutocomplete-root, & .MuiTextField-root": {
26
+ width: "100%"
27
+ },
28
+ "& .MuiAutocomplete-root .MuiTextField-root": {
29
+ width: "100%"
30
+ },
31
+ "& .MuiTextField-root .MuiInput-input": {
32
+ padding: "5px!important"
33
+ }
34
+ }));
35
+ const Gap = styled("div")(({
36
+ theme
37
+ }) => ({
38
+ width: "1px",
39
+ height: "20px",
40
+ backgroundColor: theme.palette.divider
41
+ }));
42
+ const SKTWrapper = styled("div")(({
43
+ theme
44
+ }) => ({
45
+ display: "flex",
46
+ width: "auto",
47
+ height: "37.5px",
48
+ alignItems: "center",
49
+ gap: theme.spacing(1),
50
+ border: `1px solid ${theme.palette.divider}`,
51
+ padding: theme.spacing(0.5, 1),
52
+ borderRadius: "4px"
53
+ }));
54
+ const FieldPeriod = styled("div")(({
55
+ theme
56
+ }) => ({
57
+ ...theme.typography.body2,
58
+ width: "100%",
59
+ display: "flex",
60
+ textOverflow: "elipsis",
61
+ overflow: "hidden",
62
+ padding: "5px",
63
+ textAlign: "left"
64
+ }));
65
+ const FieldValue = styled("div")(({
66
+ theme
67
+ }) => ({
68
+ ...theme.typography.body2,
69
+ width: "70px",
70
+ display: "flex",
71
+ textOverflow: "elipsis",
72
+ overflow: "hidden",
73
+ padding: "5px",
74
+ textAlign: "left"
75
+ }));
76
+ var ETimePeriods = /* @__PURE__ */ ((ETimePeriods2) => {
77
+ ETimePeriods2[ETimePeriods2["YEARS"] = 0] = "YEARS";
78
+ ETimePeriods2[ETimePeriods2["MONTHS"] = 1] = "MONTHS";
79
+ ETimePeriods2[ETimePeriods2["DAYS"] = 2] = "DAYS";
80
+ return ETimePeriods2;
81
+ })(ETimePeriods || {});
82
+ const getSelPeriodTime = (period) => {
83
+ if (!period)
84
+ return ETimePeriods.YEARS;
85
+ if (period.selPeriodTime)
86
+ return period.selPeriodTime;
87
+ if (period.years && period.years > 0)
88
+ return ETimePeriods.YEARS;
89
+ if (period.months && period.months > 0)
90
+ return ETimePeriods.MONTHS;
91
+ if (period.days && period.days > 0)
92
+ return ETimePeriods.DAYS;
93
+ return ETimePeriods.YEARS;
94
+ };
95
+ const getSingleValue = (period) => {
96
+ if (!period)
97
+ return "";
98
+ if (period.singleValue !== void 0)
99
+ return period.singleValue;
100
+ if (period.years && period.years > 0)
101
+ return period.years;
102
+ if (period.months && period.months > 0)
103
+ return period.months;
104
+ if (period.days && period.days > 0)
105
+ return period.days;
106
+ return "";
107
+ };
108
+ const Period = (props) => {
109
+ const {
110
+ value,
111
+ onChange,
112
+ error = false,
113
+ readOnly = false
114
+ } = props;
115
+ const {
116
+ getLabel
117
+ } = useModuleDictionary();
118
+ const isSkeleton = useModuleSkeleton();
119
+ const selPeriodTime = getSelPeriodTime(value);
120
+ const singleValue = getSingleValue(value);
121
+ const onTotalChange = (newPeriodTime, newValue) => {
122
+ const newPeriod = {
123
+ selPeriodTime: newPeriodTime,
124
+ singleValue: newValue
125
+ };
126
+ if (newValue !== "" && newValue > 0) {
127
+ newPeriod.years = 0;
128
+ newPeriod.months = 0;
129
+ newPeriod.days = 0;
130
+ if (newPeriodTime === ETimePeriods.YEARS)
131
+ newPeriod.years = newValue;
132
+ if (newPeriodTime === ETimePeriods.MONTHS)
133
+ newPeriod.months = newValue;
134
+ if (newPeriodTime === ETimePeriods.DAYS)
135
+ newPeriod.days = newValue;
136
+ }
137
+ onChange(newPeriod);
138
+ };
139
+ const onChangeTime = (newPeriodTime) => {
140
+ if (newPeriodTime) {
141
+ onTotalChange(newPeriodTime.id, singleValue);
142
+ }
143
+ };
144
+ const {
145
+ host_static_assets,
146
+ environment_assets
147
+ } = useEnvironment();
148
+ const options = useMemo(() => [{
149
+ id: 0,
150
+ label: getLabel("period.years")
151
+ }, {
152
+ id: 1,
153
+ label: getLabel("period.months")
154
+ }, {
155
+ id: 2,
156
+ label: getLabel("period.days")
157
+ }], [getLabel]);
158
+ if (isSkeleton) {
159
+ return /* @__PURE__ */ jsxs(SKTWrapper, {
160
+ children: [/* @__PURE__ */ jsx(Skeleton, {
161
+ variant: "rounded",
162
+ width: "100%"
163
+ }), /* @__PURE__ */ jsx(Gap, {}), /* @__PURE__ */ jsx(Skeleton, {
164
+ variant: "rounded",
165
+ width: "100%"
166
+ }), /* @__PURE__ */ jsx(Skeleton, {
167
+ variant: "circular",
168
+ width: 20,
169
+ sx: {
170
+ minWidth: "20px",
171
+ minHeight: "20px"
172
+ }
173
+ })]
174
+ });
175
+ }
176
+ if (readOnly) {
177
+ /* @__PURE__ */ jsxs(ContainerPeriod, {
178
+ error: false,
179
+ children: [/* @__PURE__ */ jsx(FieldPeriod, {
180
+ children: value.selPeriodTime
181
+ }), /* @__PURE__ */ jsx(Gap, {}), /* @__PURE__ */ jsx(FieldValue, {
182
+ children: value.singleValue
183
+ }), /* @__PURE__ */ jsx(Icon, {
184
+ src: `${host_static_assets}/${environment_assets}/frontend/components/period/assets/icons/clock.svg`
185
+ })]
186
+ });
187
+ }
188
+ return /* @__PURE__ */ jsxs(ContainerPeriod, {
189
+ error,
190
+ children: [/* @__PURE__ */ jsx(Autocomplete, {
191
+ options,
192
+ value: options[selPeriodTime],
193
+ disableClearable: true,
194
+ onChange: (_event, autcValue) => {
195
+ onChangeTime(autcValue);
196
+ },
197
+ renderInput: (params) => {
198
+ return /* @__PURE__ */ jsx(TextField, {
199
+ ...params,
200
+ fullWidth: true,
201
+ variant: "standard",
202
+ SelectProps: {
203
+ native: true
204
+ },
205
+ InputProps: {
206
+ disableUnderline: true,
207
+ ...params.InputProps
208
+ },
209
+ autoComplete: "off"
210
+ }, `tx_async_${params.id}`);
211
+ }
212
+ }), /* @__PURE__ */ jsx(Gap, {}), /* @__PURE__ */ jsx(TextField, {
213
+ type: "number",
214
+ variant: "standard",
215
+ value: singleValue,
216
+ InputProps: {
217
+ disableUnderline: true
218
+ },
219
+ onChange: (e) => {
220
+ onTotalChange(selPeriodTime, e.target.value === "" ? "" : parseInt(e.target.value));
221
+ }
222
+ }), /* @__PURE__ */ jsx(Icon, {
223
+ src: `${host_static_assets}/${environment_assets}/frontend/components/period/assets/icons/clock.svg`
224
+ })]
225
+ });
226
+ };
227
+ function getPeriodComponetsDictionary() {
228
+ return ["period"].concat(getCommonActionsDictionary());
229
+ }
230
+ export { Period as P, getPeriodComponetsDictionary as g };
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { WrapperProps } from './types';
3
+ export declare const ContainerPeriod: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & WrapperProps, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
4
+ export declare const Gap: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
5
+ export declare const SKTWrapper: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
6
+ export declare const FieldPeriod: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
7
+ export declare const FieldValue: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
@@ -0,0 +1,30 @@
1
+ export declare enum ETimePeriods {
2
+ YEARS = 0,
3
+ MONTHS = 1,
4
+ DAYS = 2
5
+ }
6
+ export declare type PeriodVariant = 'monoperiod' | 'multiperiod';
7
+ export declare type PeriodTime = {
8
+ id: number;
9
+ label: string;
10
+ };
11
+ export interface WrapperProps {
12
+ error: boolean;
13
+ }
14
+ export declare type PeriodType = {
15
+ selPeriodTime: ETimePeriods;
16
+ singleValue: number | '';
17
+ years?: number;
18
+ months?: number;
19
+ days?: number;
20
+ };
21
+ export interface PeriodProps {
22
+ value: PeriodType;
23
+ onChange: (newValue: PeriodType) => void;
24
+ error?: boolean;
25
+ readOnly?: boolean;
26
+ variant?: PeriodVariant;
27
+ }
28
+ export interface WrapperProps {
29
+ error: boolean;
30
+ }
@@ -70,7 +70,6 @@ const Value = styled("div", {
70
70
  height: valueHeight,
71
71
  marginTop: theme.spacing(1),
72
72
  [theme.breakpoints.up("sm")]: {
73
- marginLeft: theme.spacing(0),
74
73
  marginTop: "0px"
75
74
  },
76
75
  overflow: "hidden",
@@ -104,9 +104,8 @@ function columnNestedValueFormatter(props) {
104
104
  Component = React.Fragment
105
105
  } = props;
106
106
  return (obProps) => {
107
- console.log("columnNestedValueFormatter", obProps, fieldValue);
108
107
  return /* @__PURE__ */ jsx(Component, {
109
- children: getPropertyByString(obProps, fieldValue)
108
+ children: getPropertyByString(obProps, fieldValue) + ""
110
109
  });
111
110
  };
112
111
  }
@@ -1,16 +1,8 @@
1
- import { useModuleDictionary, useModuleSkeleton, useEnvironment } from "@m4l/core";
2
- import { styled, Skeleton, Autocomplete, TextField } from "@mui/material";
3
- import { useMemo } from "react";
1
+ import { styled } from "@mui/material";
4
2
  import { useFormContext, Controller } from "react-hook-form";
5
- import { I as Icon } from "../../Icon/index.js";
6
- import { ErrorLabel } from "../../../index.js";
7
- import { jsxs, jsx } from "react/jsx-runtime";
8
- import { g as getCommonActionsDictionary } from "../../CommonActions/components/Actions/index.js";
9
- import "@mui/material/Button";
10
- import "../../mui_extended/Button/index.js";
11
- import "react-router-dom";
12
- import "../../../contexts/ModalContext/index.js";
13
- import "@mui/lab";
3
+ import { E as ErrorLabel } from "../../ErrorLabel/index.js";
4
+ import { P as Period } from "../../Period/index.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
14
6
  const Wrapper = styled("div")(({
15
7
  theme
16
8
  }) => ({
@@ -21,123 +13,13 @@ const Wrapper = styled("div")(({
21
13
  alignItems: "flex-start",
22
14
  gap: theme.spacing(1)
23
15
  }));
24
- const ContainerPeriod = styled("div")(({
25
- theme,
26
- error
27
- }) => ({
28
- display: "flex",
29
- width: "100%",
30
- height: "auto",
31
- alignItems: "center",
32
- gap: theme.spacing(1),
33
- border: error ? `1px solid ${theme.palette.error.main}` : `1px solid ${theme.palette.divider}`,
34
- padding: theme.spacing(0.5, 1),
35
- borderRadius: "4px",
36
- "& .MuiAutocomplete-root, & .MuiTextField-root": {
37
- width: "100%"
38
- },
39
- "& .MuiAutocomplete-root .MuiTextField-root": {
40
- width: "100%"
41
- },
42
- "& .MuiTextField-root .MuiInput-input": {
43
- padding: "5px!important"
44
- }
45
- }));
46
- const SKTWrapper = styled("div")(({
47
- theme
48
- }) => ({
49
- display: "flex",
50
- width: "auto",
51
- height: "37.5px",
52
- alignItems: "center",
53
- gap: theme.spacing(1),
54
- border: `1px solid ${theme.palette.divider}`,
55
- padding: theme.spacing(0.5, 1),
56
- borderRadius: "4px"
57
- }));
58
- const Gap = styled("div")(({
59
- theme
60
- }) => ({
61
- width: "1px",
62
- height: "20px",
63
- backgroundColor: theme.palette.divider
64
- }));
65
- var ETimePeriods = /* @__PURE__ */ ((ETimePeriods2) => {
66
- ETimePeriods2[ETimePeriods2["YEARS"] = 0] = "YEARS";
67
- ETimePeriods2[ETimePeriods2["MONTHS"] = 1] = "MONTHS";
68
- ETimePeriods2[ETimePeriods2["DAYS"] = 2] = "DAYS";
69
- return ETimePeriods2;
70
- })(ETimePeriods || {});
71
- const getSelPeriodTime = (period) => {
72
- if (!period)
73
- return ETimePeriods.YEARS;
74
- if (period.selPeriodTime)
75
- return period.selPeriodTime;
76
- if (period.years && period.years > 0)
77
- return ETimePeriods.YEARS;
78
- if (period.months && period.months > 0)
79
- return ETimePeriods.MONTHS;
80
- if (period.days && period.days > 0)
81
- return ETimePeriods.DAYS;
82
- return ETimePeriods.YEARS;
83
- };
84
- const getSingleValue = (period) => {
85
- if (!period)
86
- return "";
87
- if (period.singleValue !== void 0)
88
- return period.singleValue;
89
- if (period.years && period.years > 0)
90
- return period.years;
91
- if (period.months && period.months > 0)
92
- return period.months;
93
- if (period.days && period.days > 0)
94
- return period.days;
95
- return "";
96
- };
97
16
  const RHFPeriod = (props) => {
98
17
  const {
99
- name,
100
- variant = "monoperiod"
18
+ name
101
19
  } = props;
102
- const {
103
- getLabel
104
- } = useModuleDictionary();
105
- const isSkeleton = useModuleSkeleton();
106
20
  const {
107
21
  control
108
22
  } = useFormContext();
109
- const {
110
- host_static_assets,
111
- environment_assets
112
- } = useEnvironment();
113
- const options = useMemo(() => [{
114
- id: 0,
115
- label: getLabel("period.years")
116
- }, {
117
- id: 1,
118
- label: getLabel("period.months")
119
- }, {
120
- id: 2,
121
- label: getLabel("period.days")
122
- }], [getLabel]);
123
- if (isSkeleton) {
124
- return /* @__PURE__ */ jsxs(SKTWrapper, {
125
- children: [/* @__PURE__ */ jsx(Skeleton, {
126
- variant: "rounded",
127
- width: "100%"
128
- }), /* @__PURE__ */ jsx(Gap, {}), /* @__PURE__ */ jsx(Skeleton, {
129
- variant: "rounded",
130
- width: "100%"
131
- }), /* @__PURE__ */ jsx(Skeleton, {
132
- variant: "circular",
133
- width: 20,
134
- sx: {
135
- minWidth: "20px",
136
- minHeight: "20px"
137
- }
138
- })]
139
- });
140
- }
141
23
  return /* @__PURE__ */ jsx(Controller, {
142
24
  name,
143
25
  control,
@@ -150,70 +32,11 @@ const RHFPeriod = (props) => {
150
32
  error
151
33
  }
152
34
  }) => {
153
- const selPeriodTime = getSelPeriodTime(value);
154
- const singleValue = getSingleValue(value);
155
- const onTotalChange = (newPeriodTime, newValue) => {
156
- const newPeriod = {
157
- selPeriodTime: newPeriodTime,
158
- singleValue: newValue,
159
- variant
160
- };
161
- if (newValue !== "" && newValue > 0) {
162
- newPeriod.years = 0;
163
- newPeriod.months = 0;
164
- newPeriod.days = 0;
165
- if (newPeriodTime === ETimePeriods.YEARS)
166
- newPeriod.years = newValue;
167
- if (newPeriodTime === ETimePeriods.MONTHS)
168
- newPeriod.months = newValue;
169
- if (newPeriodTime === ETimePeriods.DAYS)
170
- newPeriod.days = newValue;
171
- }
172
- onChange(newPeriod);
173
- };
174
- const onChangeTime = (newPeriodTime) => {
175
- if (newPeriodTime) {
176
- onTotalChange(newPeriodTime.id, singleValue);
177
- }
178
- };
179
35
  return /* @__PURE__ */ jsxs(Wrapper, {
180
- children: [/* @__PURE__ */ jsxs(ContainerPeriod, {
181
- error: !!error,
182
- children: [/* @__PURE__ */ jsx(Autocomplete, {
183
- options,
184
- value: options[selPeriodTime],
185
- disableClearable: true,
186
- onChange: (_event, autcValue) => {
187
- onChangeTime(autcValue);
188
- },
189
- renderInput: (params) => {
190
- return /* @__PURE__ */ jsx(TextField, {
191
- ...params,
192
- fullWidth: true,
193
- variant: "standard",
194
- SelectProps: {
195
- native: true
196
- },
197
- InputProps: {
198
- disableUnderline: true,
199
- ...params.InputProps
200
- },
201
- autoComplete: "off"
202
- }, `tx_async_${params.id}`);
203
- }
204
- }), /* @__PURE__ */ jsx(Gap, {}), /* @__PURE__ */ jsx(TextField, {
205
- type: "number",
206
- variant: "standard",
207
- value: singleValue,
208
- InputProps: {
209
- disableUnderline: true
210
- },
211
- onChange: (e) => {
212
- onTotalChange(selPeriodTime, e.target.value === "" ? "" : parseInt(e.target.value));
213
- }
214
- }), /* @__PURE__ */ jsx(Icon, {
215
- src: `${host_static_assets}/${environment_assets}/frontend/components/period/assets/icons/clock.svg`
216
- })]
36
+ children: [/* @__PURE__ */ jsx(Period, {
37
+ value,
38
+ onChange,
39
+ error: !!error
217
40
  }), error && /* @__PURE__ */ jsx(ErrorLabel, {
218
41
  message: error.message || ""
219
42
  })]
@@ -221,7 +44,4 @@ const RHFPeriod = (props) => {
221
44
  }
222
45
  });
223
46
  };
224
- function getPeriodComponetsDictionary() {
225
- return ["period"].concat(getCommonActionsDictionary());
226
- }
227
- export { RHFPeriod as R, getPeriodComponetsDictionary as g };
47
+ export { RHFPeriod as R };
@@ -1,6 +1,2 @@
1
1
  /// <reference types="react" />
2
- import { WrapperProps } from './types';
3
2
  export declare const Wrapper: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
4
- export declare const ContainerPeriod: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & WrapperProps, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
5
- export declare const SKTWrapper: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
6
- export declare const Gap: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
@@ -1,28 +1,4 @@
1
- export declare type PeriodProps = {
2
- name: string;
3
- variant?: 'single';
4
- };
5
- export declare enum ETimePeriods {
6
- YEARS = 0,
7
- MONTHS = 1,
8
- DAYS = 2
9
- }
10
- export declare type PeriodVariant = 'monoperiod' | 'multiperiod';
11
- export declare type PeriodTime = {
12
- id: number;
13
- label: string;
14
- };
15
- export declare type PeriodType = {
16
- variant: PeriodVariant;
17
- selPeriodTime: ETimePeriods;
18
- singleValue: number | '';
19
- years?: number;
20
- months?: number;
21
- days?: number;
22
- };
23
- export interface WrapperProps {
24
- error: boolean;
25
- }
1
+ import { PeriodVariant } from '../../../components/Period/types';
26
2
  export declare type RHFPeriodProps = {
27
3
  name: string;
28
4
  variant?: PeriodVariant;
@@ -9,6 +9,5 @@ export { RHFSelect } from './RHFSelect';
9
9
  export { RHFTextField } from './RHFTextField';
10
10
  export { RHFRadioGroup } from './RHFRadioGroup';
11
11
  export { RHFPeriod } from './RHFPeriod';
12
- export type { PeriodType } from './RHFPeriod/types';
13
- export { getPeriodComponetsDictionary } from './RHFPeriod/dictionary';
12
+ export { getPeriodComponetsDictionary } from '../Period/dictionary';
14
13
  export * from './RHFUpload';
@@ -28,6 +28,8 @@ export * from '../components/NoItemSelected/dictionary';
28
28
  export * from '../components/ObjectLogs';
29
29
  export * from '../components/ObjectLogs/dictionary';
30
30
  export * from '../components/PaperForm';
31
+ export * from '../components/Period';
32
+ export type { PeriodType } from '../components/Period/types';
31
33
  export * from '../components/Page';
32
34
  export * from '../components/PropertyValue';
33
35
  export * from '../components/Resizeable';
@@ -0,0 +1,42 @@
1
+ import { useNetwork, useFlags } from "@m4l/core";
2
+ import { useState, useEffect } from "react";
3
+ const useFormAddEdit = (props) => {
4
+ const { initialValues, objectId, endPoint, formatDataEnpoint } = props;
5
+ const [formValues, setFormValues] = useState(initialValues);
6
+ const [statusLoad, setStatusLoad] = useState(
7
+ objectId === void 0 ? "new" : "edit"
8
+ );
9
+ const { networkOperation } = useNetwork();
10
+ const { addFlag } = useFlags();
11
+ useEffect(() => {
12
+ let mounted = true;
13
+ if (statusLoad === "edit") {
14
+ networkOperation({
15
+ method: "GET",
16
+ endPoint: `${endPoint}/${objectId}`
17
+ }).then(
18
+ (response) => {
19
+ if (mounted) {
20
+ if (formatDataEnpoint) {
21
+ setFormValues(formatDataEnpoint(response));
22
+ } else {
23
+ setFormValues(response);
24
+ }
25
+ setStatusLoad("reload_values_provider");
26
+ }
27
+ },
28
+ () => {
29
+ setStatusLoad("error");
30
+ }
31
+ );
32
+ } else if (statusLoad === "new" || statusLoad === "reload_values_provider") {
33
+ addFlag("form_loaded");
34
+ setStatusLoad("ready");
35
+ }
36
+ return () => {
37
+ mounted = false;
38
+ };
39
+ }, [statusLoad]);
40
+ return { formValues, statusLoad };
41
+ };
42
+ export { useFormAddEdit as u };
package/index.js CHANGED
@@ -1,19 +1,21 @@
1
1
  export { I as IconButton, a as IconButtonAnimate } from "./components/mui_extended/IconButton/index.js";
2
2
  import "framer-motion";
3
- import { styled } from "@mui/material";
4
- import { jsx } from "react/jsx-runtime";
3
+ import "@mui/material";
4
+ import "react/jsx-runtime";
5
5
  export { L as LoadingScreen } from "./components/animate/LoadingScreen/index.js";
6
- import { useState, useEffect } from "react";
6
+ import "react";
7
7
  import "react-hook-form";
8
8
  export { F as FormProvider } from "./components/hook-form/FormProvider/index.js";
9
- import { useNetwork, useFlags } from "@m4l/core";
9
+ import "@m4l/core";
10
10
  export { R as RHFAutocomplete } from "./components/hook-form/RHFAutocomplete/index.js";
11
11
  export { R as RHFAutocompleteAsync } from "./components/hook-form/RHFAutocompleteAsync/index.js";
12
12
  export { R as RHFCheckbox } from "./components/hook-form/RHFCheckbox/index.js";
13
13
  export { R as RHFDateTime } from "./components/hook-form/RHFDateTime/index.js";
14
14
  import "@mui/x-date-pickers";
15
15
  export { R as RHFTextField } from "./components/hook-form/RHFTextField/index.js";
16
- export { R as RHFPeriod, g as getPeriodComponetsDictionary } from "./components/hook-form/RHFPeriod/index.js";
16
+ export { R as RHFPeriod } from "./components/hook-form/RHFPeriod/index.js";
17
+ export { E as ErrorLabel } from "./components/ErrorLabel/index.js";
18
+ export { P as Period, g as getPeriodComponetsDictionary } from "./components/Period/index.js";
17
19
  export { I as Icon } from "./components/Icon/index.js";
18
20
  import "@mui/material/styles";
19
21
  export { b as Actions, M as MenuActions, d as defaultCommonActionsDictionary, g as getCommonActionsDictionary } from "./components/CommonActions/components/Actions/index.js";
@@ -74,10 +76,10 @@ export { A as ActionFormCancel } from "./components/CommonActions/components/Act
74
76
  export { A as ActionFormIntro } from "./components/CommonActions/components/ActionFormIntro/index.js";
75
77
  export { L as Loadable } from "./components/Loadable/index.js";
76
78
  export { S as ScrollToTop } from "./components/ScrollToTop/index.js";
79
+ export { u as useFormAddEdit } from "./hooks/useFormAddEdit/index.js";
77
80
  export { u as useModal } from "./hooks/useModal/index.js";
78
81
  export { L as Logo } from "./assets/Logo/index.js";
79
82
  import "./node_modules.js";
80
- import "./index.js";
81
83
  import "./utils/index.js";
82
84
  import "./react-data-grid.js";
83
85
  import "clsx";
@@ -88,57 +90,3 @@ import "simplebar-react";
88
90
  import "yup";
89
91
  import "./react-resizable.js";
90
92
  import "react-helmet-async";
91
- const Wrapper = styled("p")(({
92
- theme
93
- }) => ({
94
- ...theme.typography.caption,
95
- color: theme.palette.error.main
96
- }));
97
- const ErrorLabel = (props) => {
98
- const {
99
- message
100
- } = props;
101
- return /* @__PURE__ */ jsx(Wrapper, {
102
- children: message
103
- });
104
- };
105
- const useFormAddEdit = (props) => {
106
- const { initialValues, objectId, endPoint, formatDataEnpoint } = props;
107
- const [formValues, setFormValues] = useState(initialValues);
108
- const [statusLoad, setStatusLoad] = useState(
109
- objectId === void 0 ? "new" : "edit"
110
- );
111
- const { networkOperation } = useNetwork();
112
- const { addFlag } = useFlags();
113
- useEffect(() => {
114
- let mounted = true;
115
- if (statusLoad === "edit") {
116
- networkOperation({
117
- method: "GET",
118
- endPoint: `${endPoint}/${objectId}`
119
- }).then(
120
- (response) => {
121
- if (mounted) {
122
- if (formatDataEnpoint) {
123
- setFormValues(formatDataEnpoint(response));
124
- } else {
125
- setFormValues(response);
126
- }
127
- setStatusLoad("reload_values_provider");
128
- }
129
- },
130
- () => {
131
- setStatusLoad("error");
132
- }
133
- );
134
- } else if (statusLoad === "new" || statusLoad === "reload_values_provider") {
135
- addFlag("form_loaded");
136
- setStatusLoad("ready");
137
- }
138
- return () => {
139
- mounted = false;
140
- };
141
- }, [statusLoad]);
142
- return { formValues, statusLoad };
143
- };
144
- export { ErrorLabel, useFormAddEdit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/components",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "license": "UNLICENSED",
5
5
  "dependencies": {
6
6
  "@m4l/core": "*",