@applica-software-guru/react-admin 1.4.201 → 1.4.202

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applica-software-guru/react-admin",
3
- "version": "1.4.201",
3
+ "version": "1.4.202",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -2,6 +2,7 @@ import {
2
2
  Button,
3
3
  CreateButtonClasses,
4
4
  CreateContextProvider,
5
+ CreateControllerProps,
5
6
  CreateControllerResult,
6
7
  RedirectionSideEffect,
7
8
  SaveButton,
@@ -9,16 +10,17 @@ import {
9
10
  useNotify,
10
11
  useRedirect,
11
12
  useResourceContext,
12
- useTranslate
13
+ useTranslate,
14
+ UseCreateMutateParams
13
15
  } from 'react-admin';
14
16
  import { Dialog, Fab, useMediaQuery, useTheme } from '@mui/material';
15
17
  import React, { useCallback, useState } from 'react';
16
18
  import { SxProps, Theme, styled } from '@mui/material/styles';
17
- import { PlusCircleOutlined } from '@ant-design/icons';
18
19
  import { Toolbar } from '../ra-forms';
19
20
  import clsx from 'clsx';
20
21
  import { useAppConfig } from '../../hooks';
21
22
  import { useQueryClient } from 'react-query';
23
+ import ContentAdd from '@mui/icons-material/Add';
22
24
 
23
25
  const updateColl = (old: any, data: any) => {
24
26
  const id = data.id;
@@ -38,13 +40,22 @@ const setManyQueryData = (coll: any, data: any) => (coll && coll.length > 0 ? up
38
40
  const setListQueryData = (res: any, data: any) =>
39
41
  res && res.data ? { ...res, data: updateColl(res.data, data), total: res.total + 1 } : res;
40
42
 
41
- export type CreateInDialogContentProps = {
43
+ export type CreateInDialogContentProps = CreateControllerProps & {
42
44
  onClose: () => void;
43
45
  record?: any;
44
46
  redirect: RedirectionSideEffect | boolean | undefined;
45
47
  children: React.ReactElement;
48
+ /**
49
+ * @deprecated Use mutationOptions.onSubmit instead
50
+ */
46
51
  onSubmit?: (record: any, close: () => void) => void;
52
+ /**
53
+ * @deprecated Use mutationOptions.onSuccess instead
54
+ */
47
55
  onSuccess?: (data: any) => void;
56
+ /**
57
+ * @deprecated Use mutationOptions.onError instead
58
+ */
48
59
  onError?: (error: any) => void;
49
60
  };
50
61
 
@@ -55,14 +66,15 @@ const CreateInDialogContent = ({
55
66
  redirect: _redirect = false,
56
67
  onSubmit,
57
68
  onSuccess,
58
- onError
69
+ onError,
70
+ ...props
59
71
  }: CreateInDialogContentProps) => {
60
72
  const queryClient = useQueryClient();
61
73
  const resource = useResourceContext();
62
74
  const redirect = useRedirect();
63
75
  const notify = useNotify();
64
76
  const handleSuccess = useCallback(
65
- (data: any) => {
77
+ (data: any, variables: UseCreateMutateParams<any>, context: unknown) => {
66
78
  const now = Date.now();
67
79
  const updatedAt = now;
68
80
 
@@ -83,11 +95,17 @@ const CreateInDialogContent = ({
83
95
  if (onSuccess) {
84
96
  onSuccess(data);
85
97
  }
98
+ // WARN: This is a temporary solution to handle onSuccess from mutationOptions
99
+ if (props?.mutationOptions?.onSuccess) {
100
+ props.mutationOptions.onSuccess(data, variables, context);
101
+ }
86
102
  },
87
103
  [onClose, onSuccess, queryClient, resource, notify, redirect, _redirect]
88
104
  );
89
105
  const { save, ...createProps } = useCreateController({
106
+ ...props,
90
107
  mutationOptions: {
108
+ ...props?.mutationOptions,
91
109
  onSuccess: handleSuccess,
92
110
  onError: onError
93
111
  }
@@ -144,7 +162,7 @@ const StyledFab = styled(Fab, { overridesResolver: (_props, styles) => styles.ro
144
162
  }
145
163
  }));
146
164
 
147
- export type CreateInDialogButtonProps = {
165
+ export type CreateInDialogButtonProps = CreateControllerProps & {
148
166
  fullWidth?: boolean;
149
167
  maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | false;
150
168
  label?: string;
@@ -159,8 +177,18 @@ export type CreateInDialogButtonProps = {
159
177
  * If set to false, the button will always render as a regular button, regardless of the screen size.
160
178
  */
161
179
  fab: boolean;
180
+ /**
181
+ * @deprecated Use mutationOptions.onSubmit instead
182
+ */
162
183
  onSubmit?: (record: any, close: () => void) => void;
184
+ /**
185
+ * @deprecated Use mutationOptions.onSuccess instead
186
+ */
163
187
  onSuccess?: (data: any) => void;
188
+ /**
189
+ *
190
+ * @deprecated Use mutationOptions.onError instead
191
+ */
164
192
  onError?: (error: any) => void;
165
193
  };
166
194
 
@@ -204,11 +232,11 @@ export function CreateInDialogButton({
204
232
  aria-label={label && translate(label)}
205
233
  onClick={handleOpen}
206
234
  >
207
- <PlusCircleOutlined />
235
+ <ContentAdd />
208
236
  </StyledFab>
209
237
  ) : (
210
238
  <Button {...props} sx={sx} label={label} onClick={handleOpen} style={style}>
211
- <PlusCircleOutlined />
239
+ <ContentAdd />
212
240
  </Button>
213
241
  )}
214
242
  <Dialog
@@ -37,8 +37,7 @@ const StyledRoot = styled(StyledDiv, { slot: 'root' })(({ theme, bulkActionButto
37
37
  },
38
38
  [theme.breakpoints.down('md')]: {
39
39
  marginTop: 0,
40
- display: 'none',
41
- visibility: 'hidden'
40
+ display: 'contents'
42
41
  }
43
42
  }
44
43
  },