@sqrzro/ui 4.0.0-alpha.72 → 4.0.0-alpha.73
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.
|
@@ -12,6 +12,9 @@ function Menu({ actions, align, classNameProps, classNames, data, isDisabled, la
|
|
|
12
12
|
const componentClassNames = useClassNames('menu', { props: classNameProps }, classNames);
|
|
13
13
|
const { controlProps, ref, targetProps } = usePopover();
|
|
14
14
|
const filteredActions = filterNull(actions);
|
|
15
|
-
return (_jsxs("div", { className: tw('relative', componentClassNames?.root), ref: ref, children: [_jsx(Button, { ...controlProps, classNameProps: classNameProps, isDisabled: isDisabled, children: label }), _jsx(Popover, { ...targetProps, align: align, classNameProps: classNameProps, vAlign: vAlign, children: _jsx("ul", { className: componentClassNames?.list, children: filteredActions.map((item, index) => (_jsx("li", { className: componentClassNames?.item, children: _jsx(Action, { ...item, data: data,
|
|
15
|
+
return (_jsxs("div", { className: tw('relative', componentClassNames?.root), ref: ref, children: [_jsx(Button, { ...controlProps, classNameProps: classNameProps, isDisabled: isDisabled, children: label }), _jsx(Popover, { ...targetProps, align: align, classNameProps: classNameProps, vAlign: vAlign, children: _jsx("ul", { className: componentClassNames?.list, children: filteredActions.map((item, index) => (_jsx("li", { className: componentClassNames?.item, children: _jsx(Action, { ...item, data: data, onSuccess: (...args) => {
|
|
16
|
+
item.onSuccess?.(...args);
|
|
17
|
+
controlProps.onClick();
|
|
18
|
+
}, render: (props) => (_jsx(MenuItem, { ...props, classNameProps: classNameProps })) }) }, index))) }) })] }));
|
|
16
19
|
}
|
|
17
20
|
export default Menu;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { UseSuccessArgs } from './useSuccess';
|
|
2
|
+
export interface ToastsArgs {
|
|
3
|
+
error?: string | false;
|
|
4
|
+
success?: string | false;
|
|
5
|
+
}
|
|
2
6
|
interface UseServerActionArgs<Response> extends UseSuccessArgs<Response> {
|
|
3
|
-
|
|
7
|
+
toasts?: ToastsArgs | false;
|
|
4
8
|
}
|
|
5
9
|
interface UseServerActionReturn {
|
|
6
10
|
handleClick: () => void;
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { useTransition } from 'react';
|
|
2
2
|
import useSuccess from './useSuccess';
|
|
3
|
+
import useToast from './useToast';
|
|
4
|
+
const DEFAULT_TOAST_MESSAGES = {
|
|
5
|
+
error: 'There was a problem submitting your request. Please try again later.',
|
|
6
|
+
success: 'Your request was submitted successfully.',
|
|
7
|
+
};
|
|
8
|
+
function getToastMessage(key, toasts) {
|
|
9
|
+
if (toasts === false || toasts?.[key] === false) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
return toasts?.[key] || DEFAULT_TOAST_MESSAGES[key];
|
|
13
|
+
}
|
|
3
14
|
function useServerAction(fn, args = {}) {
|
|
4
15
|
const { handleSuccess } = useSuccess(args);
|
|
16
|
+
const { toastSuccess } = useToast();
|
|
5
17
|
const [isLoading, startTransition] = useTransition();
|
|
6
18
|
function handleClick() {
|
|
7
19
|
startTransition(async () => {
|
|
@@ -10,6 +22,7 @@ function useServerAction(fn, args = {}) {
|
|
|
10
22
|
}
|
|
11
23
|
const response = await fn();
|
|
12
24
|
await handleSuccess(response);
|
|
25
|
+
toastSuccess(getToastMessage('success', args.toasts));
|
|
13
26
|
});
|
|
14
27
|
}
|
|
15
28
|
return { handleClick, isLoading };
|