tw-react-components 0.0.180 → 0.0.182

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.
Files changed (2) hide show
  1. package/index.esm.js +30 -1
  2. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -1773,12 +1773,20 @@ const Dialog = Object.assign($Dialog, {
1773
1773
  });
1774
1774
 
1775
1775
  const ConfirmDialog = ({ open, title, children, yesLabel, noLabel, onConfirm, onClose, dataTestId = 'confirm-dialog', }) => {
1776
+ const { toast } = useToast();
1776
1777
  const [loading, setLoading] = useState(false);
1777
1778
  const handleConfirm = () => __awaiter(void 0, void 0, void 0, function* () {
1778
1779
  setLoading(true);
1779
1780
  try {
1780
1781
  yield onConfirm();
1781
1782
  }
1783
+ catch (error) {
1784
+ toast({
1785
+ variant: 'destructive',
1786
+ title: 'Error',
1787
+ description: error instanceof Error ? error.message : 'Something went wrong',
1788
+ });
1789
+ }
1782
1790
  finally {
1783
1791
  setLoading(false);
1784
1792
  }
@@ -1847,7 +1855,20 @@ const Sheet = Object.assign(DialogPrimitive.Root, {
1847
1855
 
1848
1856
  const FormDialog = ({ className, formClassName, open, title, form, children, submitLabel = 'Submit', cancelLabel = 'Cancel', extraAction, as: As = Sheet, onSubmit, onInvalid, onClose, dataTestId = 'form-dialog', }) => {
1849
1857
  const id = useId();
1850
- return (jsx(As, { open: open, onOpenChange: (value) => !value && onClose(), children: jsxs(As.Content, { className: className, dataTestId: `${dataTestId}-content`, children: [jsx(As.Header, { dataTestId: `${dataTestId}-header`, children: jsx(As.Title, { dataTestId: `${dataTestId}-title`, children: title }) }), jsx(FormProvider, Object.assign({}, form, { children: jsx("form", { id: `form-${id}`, className: cn('flex h-full w-full flex-col gap-2 overflow-auto', formClassName), onSubmit: form.handleSubmit(onSubmit, onInvalid), "data-testid": `${dataTestId}-form`, children: children }) })), jsxs(As.Footer, { className: "w-full sm:justify-between", dataTestId: `${dataTestId}-footer`, children: [extraAction, jsxs(As.Footer, { className: "ml-auto", dataTestId: `${dataTestId}-actions`, children: [jsx(As.Close, { asChild: true, children: jsx(Button, { color: "red", dataTestId: `${dataTestId}-cancel-button`, disabled: form.formState.isSubmitting, children: cancelLabel }) }), jsx(Button, { color: "green", type: "submit", form: `form-${id}`, loading: form.formState.isSubmitting, dataTestId: `${dataTestId}-submit-button`, children: submitLabel })] })] })] }) }));
1858
+ const { toast } = useToast();
1859
+ const handleSubmit = (data, event) => __awaiter(void 0, void 0, void 0, function* () {
1860
+ try {
1861
+ yield onSubmit(data, event);
1862
+ }
1863
+ catch (error) {
1864
+ toast({
1865
+ variant: 'destructive',
1866
+ title: 'Error',
1867
+ description: error instanceof Error ? error.message : 'Something went wrong',
1868
+ });
1869
+ }
1870
+ });
1871
+ return (jsx(As, { open: open, onOpenChange: (value) => !value && onClose(), children: jsxs(As.Content, { className: className, dataTestId: `${dataTestId}-content`, children: [jsx(As.Header, { dataTestId: `${dataTestId}-header`, children: jsx(As.Title, { dataTestId: `${dataTestId}-title`, children: title }) }), jsx(FormProvider, Object.assign({}, form, { children: jsx("form", { id: `form-${id}`, className: cn('flex h-full w-full flex-col gap-2 overflow-auto', formClassName), onSubmit: form.handleSubmit(handleSubmit, onInvalid), "data-testid": `${dataTestId}-form`, children: children }) })), jsxs(As.Footer, { className: "w-full sm:justify-between", dataTestId: `${dataTestId}-footer`, children: [extraAction, jsxs(As.Footer, { className: "ml-auto", dataTestId: `${dataTestId}-actions`, children: [jsx(As.Close, { asChild: true, children: jsx(Button, { color: "red", dataTestId: `${dataTestId}-cancel-button`, disabled: form.formState.isSubmitting, children: cancelLabel }) }), jsx(Button, { color: "green", type: "submit", form: `form-${id}`, loading: form.formState.isSubmitting, dataTestId: `${dataTestId}-submit-button`, children: submitLabel })] })] })] }) }));
1851
1872
  };
1852
1873
 
1853
1874
  function ListSorter({ className, items, dataTestId = 'list-sorter', idResolver, renderer, onChange, }) {
@@ -1877,6 +1898,7 @@ function SortableItem({ item, index, dataTestId, renderer, }) {
1877
1898
  }
1878
1899
 
1879
1900
  function ListSorterDialog({ className, open, title, items, idResolver, renderer, cancelLabel, submitLabel, onSubmit, onClose, dataTestId = 'list-sorter-dialog', }) {
1901
+ const { toast } = useToast();
1880
1902
  const [sortedItems, setSortedItems] = useState(structuredClone(items));
1881
1903
  const [loading, setLoading] = useState(false);
1882
1904
  useEffect(() => {
@@ -1889,6 +1911,13 @@ function ListSorterDialog({ className, open, title, items, idResolver, renderer,
1889
1911
  try {
1890
1912
  yield onSubmit(sortedItems);
1891
1913
  }
1914
+ catch (error) {
1915
+ toast({
1916
+ variant: 'destructive',
1917
+ title: 'Error',
1918
+ description: error instanceof Error ? error.message : 'Something went wrong',
1919
+ });
1920
+ }
1892
1921
  finally {
1893
1922
  setLoading(false);
1894
1923
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tw-react-components",
3
3
  "description": "A set of React components build with TailwindCSS to make a nice dashboard.",
4
- "version": "0.0.180",
4
+ "version": "0.0.182",
5
5
  "license": "MIT",
6
6
  "homepage": "https://bacali95.github.io/tw-react-components",
7
7
  "type": "module",