@portnet/ui 0.1.13 → 0.1.15

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.
@@ -104,7 +104,8 @@ const PuiSpecificReferentielField = _ref2 => {
104
104
  getReturnedValue,
105
105
  getRenderedValue,
106
106
  onChange,
107
- onError
107
+ onError,
108
+ fetchDataFunction
108
109
  } = _ref2;
109
110
  const {
110
111
  token,
@@ -122,7 +123,7 @@ const PuiSpecificReferentielField = _ref2 => {
122
123
  payload: pageNumber
123
124
  });
124
125
  };
125
- const submitHandler = async values => {
126
+ const defaultSubmitHandler = async values => {
126
127
  try {
127
128
  dataFetchingDispatch({
128
129
  type: "GET_DATA"
@@ -152,6 +153,38 @@ const PuiSpecificReferentielField = _ref2 => {
152
153
  onError(error);
153
154
  }
154
155
  };
156
+ const submitHandler = async (values, formikBag) => {
157
+ // Check if dataFetchingDispatch is not null and a custom submit handler function is provided
158
+ if (dataFetchingDispatch && fetchDataFunction) {
159
+ try {
160
+ dataFetchingDispatch({
161
+ type: "GET_DATA"
162
+ });
163
+ const data = await fetchDataFunction(searchKey, specifications, dataFetchingState.pageNumber, dataFetchingState.pageSize, values);
164
+ if (data.success) {
165
+ dataFetchingDispatch({
166
+ type: "SUCCESSED",
167
+ payload: {
168
+ data: data.results,
169
+ totalElements: data.totalElements
170
+ }
171
+ });
172
+ } else {
173
+ throw new Error(data.message);
174
+ }
175
+ } catch (error) {
176
+ dataFetchingDispatch({
177
+ type: "FAILED",
178
+ payload: error.message
179
+ });
180
+ if (onError) {
181
+ onError(error);
182
+ }
183
+ }
184
+ } else {
185
+ return defaultSubmitHandler(values, formikBag);
186
+ }
187
+ };
155
188
  React.useEffect(() => {
156
189
  if (isMounted) {
157
190
  var _formRef$current;
@@ -307,7 +340,8 @@ PuiSpecificReferentielField.propTypes = {
307
340
  getRenderedValue: _propTypes.default.func.isRequired,
308
341
  getReturnedValue: _propTypes.default.func,
309
342
  onChange: _propTypes.default.func,
310
- onError: _propTypes.default.func
343
+ onError: _propTypes.default.func,
344
+ fetchDataFunction: _propTypes.default.func
311
345
  };
312
346
  PuiSpecificReferentielField.defaultProps = {
313
347
  disabled: false,
@@ -320,6 +354,7 @@ PuiSpecificReferentielField.defaultProps = {
320
354
  tableProps: {},
321
355
  getReturnedValue: row => row,
322
356
  onError: () => {},
323
- onChange: () => {}
357
+ onChange: () => {},
358
+ fetchDataFunction: null
324
359
  };
325
360
  var _default = exports.default = PuiSpecificReferentielField;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portnet/ui",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Portnet UI",
5
5
  "keywords": [
6
6
  "react",