proje-react-panel 1.1.3 → 1.1.4

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.
@@ -1,7 +1,6 @@
1
1
  import React, { useEffect } from 'react';
2
- import { initPanel } from '../initPanel';
3
- import { InitPanelOptions } from '../types/initPanelOptions';
4
2
  import { ErrorBoundary } from './ErrorBoundary';
3
+ import { ToastContainer } from 'react-toastify';
5
4
 
6
5
  type AppProps = {
7
6
  children: React.ReactNode;
@@ -13,5 +12,10 @@ export function Panel({ children }: AppProps) {
13
12
  initPanel(options);
14
13
  }, [init]);*/
15
14
 
16
- return <ErrorBoundary>{children}</ErrorBoundary>;
15
+ return (
16
+ <ErrorBoundary>
17
+ {children}
18
+ <ToastContainer />
19
+ </ErrorBoundary>
20
+ );
17
21
  }
@@ -5,6 +5,7 @@ import { FormField } from './FormField';
5
5
  import { useNavigate } from 'react-router';
6
6
  import { FormConfiguration } from '../../decorators/form/Form';
7
7
  import { AnyClass } from '../../types/AnyClass';
8
+ import { toast } from 'react-toastify';
8
9
 
9
10
  interface InnerFormProps<T extends AnyClass> {
10
11
  inputs: InputConfiguration[];
@@ -17,6 +18,7 @@ export function InnerForm<T extends AnyClass>({ inputs, formClass }: InnerFormPr
17
18
  const formRef = useRef<HTMLFormElement>(null);
18
19
  const navigate = useNavigate();
19
20
  const form = useFormContext<T>();
21
+ const loadingRef = useRef(false);
20
22
 
21
23
  return (
22
24
  <div className="form-wrapper">
@@ -24,6 +26,8 @@ export function InnerForm<T extends AnyClass>({ inputs, formClass }: InnerFormPr
24
26
  ref={formRef}
25
27
  onSubmit={form.handleSubmit(
26
28
  async (dataForm: T) => {
29
+ if (loadingRef.current) return;
30
+ loadingRef.current = true;
27
31
  try {
28
32
  const data =
29
33
  formClass.type === 'json'
@@ -37,17 +41,25 @@ export function InnerForm<T extends AnyClass>({ inputs, formClass }: InnerFormPr
37
41
  }
38
42
  return formData;
39
43
  })();
40
- await formClass.onSubmit(data);
44
+ const resut = await formClass.onSubmit(data);
45
+ form.reset(resut);
41
46
  setErrorMessage(null);
47
+ toast.success('Form submitted successfully');
42
48
  if (formClass.redirectBackOnSuccess) {
43
49
  navigate(-1);
44
50
  }
51
+ if (formClass.redirectSuccessUrl) {
52
+ navigate(formClass.redirectSuccessUrl);
53
+ }
45
54
  } catch (error: any) {
46
55
  const message =
47
56
  error?.response?.data?.message ||
48
57
  (error instanceof Error ? error.message : 'An error occurred');
58
+ toast.error('Something went wrong');
49
59
  setErrorMessage(message);
50
60
  console.error(error);
61
+ } finally {
62
+ loadingRef.current = false;
51
63
  }
52
64
  },
53
65
  (errors, event) => {
@@ -1,4 +1,4 @@
1
- import React, { useMemo, useCallback, useEffect, useState } from 'react';
1
+ import React, { useMemo, useCallback, useEffect, useState, useId } from 'react';
2
2
  import { useParams, useNavigate } from 'react-router';
3
3
  import { Datagrid } from './Datagrid';
4
4
  import { ErrorComponent } from '../ErrorComponent';
@@ -16,6 +16,7 @@ export function ListPage<T extends AnyClass>({
16
16
  model: AnyClassConstructor<T>;
17
17
  customHeader?: React.ReactNode;
18
18
  }) {
19
+ const id = useId();
19
20
  const listPageMeta = useMemo(() => getListPageMeta(model), [model]);
20
21
 
21
22
  const [loading, setLoading] = useState(true);
@@ -83,8 +84,8 @@ export function ListPage<T extends AnyClass>({
83
84
  fetchData(1, filters); // Reset to first page when filters change
84
85
  };
85
86
 
86
- if (loading) return <LoadingScreen />;
87
- if (error) return <ErrorComponent error={error} />;
87
+ if (loading) return <LoadingScreen id={id} />;
88
+ if (error) return <ErrorComponent id={id} error={error} />;
88
89
 
89
90
  return (
90
91
  <div className="list">
@@ -4,18 +4,22 @@ import { GetDetailsDataFN } from '../details/Details';
4
4
  import { InputConfiguration } from './Input';
5
5
 
6
6
  const DETAILS_METADATA_KEY = 'DetailsMetaData';
7
- export type OnSubmitFN<T> = (data: T | FormData) => Promise<T | FormData>;
7
+ export type OnSubmitFN<T> = (data: T | FormData) => Promise<T>;
8
8
 
9
9
  interface FormOptions<T extends AnyClass> {
10
10
  onSubmit: OnSubmitFN<T>;
11
11
  getDetailsData?: GetDetailsDataFN<T>;
12
+ /** @deprecated */
12
13
  redirectBackOnSuccess?: boolean;
13
14
  type?: 'json' | 'formData';
15
+ redirectSuccessUrl?: string;
14
16
  }
15
17
 
16
18
  export interface FormConfiguration<T extends AnyClass> extends FormOptions<T> {
19
+ /** @deprecated */
17
20
  redirectBackOnSuccess: boolean;
18
21
  type: 'json' | 'formData';
22
+ redirectSuccessUrl?: string;
19
23
  }
20
24
 
21
25
  export function Form<T extends AnyClass>(options?: FormOptions<T>): ClassDecorator {