@applica-software-guru/react-admin 1.5.329 → 1.5.330

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
@@ -108,5 +108,5 @@
108
108
  "type": "module",
109
109
  "types": "dist/index.d.ts",
110
110
  "typings": "dist/index.d.ts",
111
- "version": "1.5.329"
111
+ "version": "1.5.330"
112
112
  }
@@ -7,10 +7,19 @@ import { Button } from './Button';
7
7
  import { Confirm, DeleteWithConfirmButtonProps as RaDeleteWithConfirmButtonProps } from 'ra-ui-materialui';
8
8
  import { Box, SxProps, Typography, useTheme } from '@mui/material';
9
9
  import { DeleteFilled } from '@ant-design/icons';
10
+ import { useCallback } from 'react';
10
11
 
11
12
  type DeleteWithConfirmButtonProps<RecordType extends RaRecord = RaRecord> =
12
13
  RaDeleteWithConfirmButtonProps<RecordType> & {
13
14
  dialogSx?: SxProps;
15
+ /**
16
+ * @deprecated confirmTitle prop is deprecated, please use confirmContent instead.
17
+ */
18
+ confirmTitle?: React.ReactNode;
19
+ /**
20
+ * onConfirm {callback} is used to handle a custom delete action when user confirms the deletion.
21
+ */
22
+ onConfirm?: () => void;
14
23
  };
15
24
 
16
25
  function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
@@ -30,6 +39,7 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
30
39
  onClick,
31
40
  redirect = 'list',
32
41
  translateOptions = {},
42
+ onConfirm,
33
43
  ...rest
34
44
  } = props;
35
45
  const translate = useTranslate();
@@ -46,6 +56,17 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
46
56
  resource
47
57
  });
48
58
 
59
+ const handleOnConfirm = useCallback(
60
+ (event: any) => {
61
+ if (onConfirm) {
62
+ onConfirm();
63
+ } else {
64
+ handleDelete(event);
65
+ }
66
+ },
67
+ [handleDelete, onConfirm]
68
+ );
69
+
49
70
  return (
50
71
  <>
51
72
  <Button
@@ -122,9 +143,9 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
122
143
  )
123
144
  }
124
145
  content={
125
- confirmContent || (
126
- <Typography maxWidth="300px" variant="h4" align="center">
127
- {translate('ra.message.delete_content', {
146
+ <Typography maxWidth="300px" variant="h4" align="center">
147
+ {confirmContent ||
148
+ translate('ra.message.delete_content', {
128
149
  _: 'ra.message.delete_content',
129
150
  name: translate(`resources.${resource}.forcedCaseName`, {
130
151
  smart_count: 1,
@@ -138,8 +159,7 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
138
159
  }),
139
160
  id: record?.id
140
161
  })}
141
- </Typography>
142
- )
162
+ </Typography>
143
163
  }
144
164
  confirmColor={confirmColor}
145
165
  translateOptions={{
@@ -156,7 +176,7 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
156
176
  id: record?.id,
157
177
  ...translateOptions
158
178
  }}
159
- onConfirm={handleDelete}
179
+ onConfirm={handleOnConfirm}
160
180
  onClose={handleDialogClose}
161
181
  />
162
182
  </>
@@ -19,10 +19,11 @@ import {
19
19
  import { styled, useTheme } from '@mui/material/styles';
20
20
  import { FormDataConsumer, RaRecord, useTranslate, useTranslateLabel } from 'ra-core';
21
21
  import * as React from 'react';
22
- import { Children, ReactElement, ReactNode, useCallback, useMemo, useRef, useState } from 'react';
23
- import { Confirm, useArrayInput } from 'react-admin';
22
+ import { Children, ReactElement, ReactNode, useCallback, useMemo, useRef } from 'react';
23
+ import { useArrayInput } from 'react-admin';
24
24
  import { UseFieldArrayReturn, useFormContext } from 'react-hook-form';
25
25
  import { Tooltip } from '@/components/@extended';
26
+ import { DeleteWithConfirmButton } from '@/components/ra-buttons';
26
27
 
27
28
  /**
28
29
  * How to use TableFormIterator:
@@ -57,7 +58,6 @@ function RawTableFormIterator(props: TableFormIteratorProps): ReactElement | nul
57
58
  inset,
58
59
  sx
59
60
  } = props;
60
- const [confirmIsOpen, setConfirmIsOpen] = useState<boolean>(false);
61
61
  const { fields, remove, replace, append } = useArrayInput(props);
62
62
  const { resetField } = useFormContext();
63
63
  const theme = useTheme();
@@ -129,7 +129,6 @@ function RawTableFormIterator(props: TableFormIteratorProps): ReactElement | nul
129
129
 
130
130
  const handleArrayClear = useCallback(() => {
131
131
  replace([]);
132
- setConfirmIsOpen(false);
133
132
  }, [replace]);
134
133
 
135
134
  const context = useMemo(
@@ -217,9 +216,10 @@ function RawTableFormIterator(props: TableFormIteratorProps): ReactElement | nul
217
216
  {!disableRemove && showClearAllButton ? (
218
217
  <TableCell key="actions" sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
219
218
  <ActionsMenu horizontal>
220
- <Typography color="error" onClick={() => setConfirmIsOpen(true)}>
221
- {translate('ra.action.delete')}
222
- </Typography>
219
+ <DeleteWithConfirmButton
220
+ onConfirm={handleArrayClear}
221
+ confirmContent={translate('ra.message.clear_array_input')}
222
+ />
223
223
  </ActionsMenu>
224
224
  </TableCell>
225
225
  ) : (
@@ -264,16 +264,6 @@ function RawTableFormIterator(props: TableFormIteratorProps): ReactElement | nul
264
264
  </TableBody>
265
265
  </Table>
266
266
  </TableContainer>
267
-
268
- {fields.length > 0 && (
269
- <Confirm
270
- isOpen={confirmIsOpen}
271
- title={translate('ra.action.clear_array_input')}
272
- content={translate('ra.message.clear_array_input')}
273
- onConfirm={handleArrayClear}
274
- onClose={() => setConfirmIsOpen(false)}
275
- />
276
- )}
277
267
  </div>
278
268
  </TableFormIteratorContext.Provider>
279
269
  ) : null;
@@ -1,25 +1,24 @@
1
1
  import { EditButton } from './EditButton';
2
2
  import { ActionsMenu } from '@/components/ActionsMenu';
3
+ import { DeleteWithConfirmButton } from '@/components/ra-buttons';
3
4
  import { useTableFormIterator } from '@/components/ra-forms/TableForm/TableFormIteratorContext';
4
5
  import {
5
6
  TableFormIteratorItemContext,
6
7
  TableFormIteratorItemContextValue
7
8
  } from '@/components/ra-forms/TableForm/TableFormIteratorItemContext';
8
- import { Button, Stack, TableCell } from '@mui/material';
9
+ import { Stack, TableCell } from '@mui/material';
9
10
  import { RaRecord } from 'ra-core';
10
11
  import { Children, ReactElement, ReactNode, cloneElement, isValidElement, useMemo } from 'react';
11
12
  import * as React from 'react';
12
- import { Confirm, useTranslate } from 'react-admin';
13
+ import { useTranslate } from 'react-admin';
13
14
 
14
15
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
16
  const TableFormIteratorItem = React.forwardRef((props: TableFormIteratorItemProps, _: any) => {
16
17
  const { children, disabled, disableRemove = false, index, member, resource, record } = props;
17
18
  const translate = useTranslate();
18
- const [confirmIsOpen, setConfirmIsOpen] = React.useState<boolean>(false);
19
19
  const { total, remove } = useTableFormIterator();
20
20
 
21
21
  const handleRowDelete = React.useCallback(() => {
22
- setConfirmIsOpen(false);
23
22
  remove(index);
24
23
  }, [index, remove]);
25
24
 
@@ -75,9 +74,10 @@ const TableFormIteratorItem = React.forwardRef((props: TableFormIteratorItemProp
75
74
  <TableCell>
76
75
  <Stack direction="row" spacing={1} justifyContent="center" alignItems="center">
77
76
  <ActionsMenu horizontal>
78
- <Button onClick={() => setConfirmIsOpen(true)} color="error" sx={{ justifyContent: 'flex-start' }}>
79
- {translate('ra.action.delete')}
80
- </Button>
77
+ <DeleteWithConfirmButton
78
+ onConfirm={handleRowDelete}
79
+ confirmContent={translate('ra.message.remove_item')}
80
+ />
81
81
  {renderEditButton}
82
82
  </ActionsMenu>
83
83
  </Stack>
@@ -90,17 +90,6 @@ const TableFormIteratorItem = React.forwardRef((props: TableFormIteratorItemProp
90
90
  </Stack>
91
91
  </TableCell>
92
92
  ) : null}
93
-
94
- {/** @ts-ignore */}
95
- {children.length > 0 && (
96
- <Confirm
97
- isOpen={confirmIsOpen}
98
- title={translate('ra.action.remove_item')}
99
- content={translate('ra.message.remove_item')}
100
- onConfirm={handleRowDelete}
101
- onClose={() => setConfirmIsOpen(false)}
102
- />
103
- )}
104
93
  </TableFormIteratorItemContext.Provider>
105
94
  );
106
95
  });