proje-react-panel 1.0.14 → 1.0.16

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 (168) hide show
  1. package/.cursor/rules.md +122 -0
  2. package/.cursor/settings.json +57 -0
  3. package/.eslintrc.js +5 -0
  4. package/.eslintrc.json +26 -0
  5. package/.prettierrc +10 -0
  6. package/.vscode/launch.json +27 -0
  7. package/.vscode/settings.json +8 -0
  8. package/PTD.md +234 -0
  9. package/README.md +62 -28
  10. package/dist/api/CrudApi.d.ts +12 -0
  11. package/dist/components/Panel.d.ts +2 -2
  12. package/dist/components/components/Checkbox.d.ts +6 -0
  13. package/dist/components/components/Counter.d.ts +9 -0
  14. package/dist/components/components/FormField.d.ts +13 -0
  15. package/dist/components/components/ImageUploader.d.ts +15 -0
  16. package/dist/components/components/InnerForm.d.ts +12 -0
  17. package/dist/components/components/LoadingScreen.d.ts +2 -0
  18. package/dist/components/components/index.d.ts +8 -0
  19. package/dist/components/components/list/Datagrid.d.ts +13 -0
  20. package/dist/components/components/list/EmptyList.d.ts +2 -0
  21. package/dist/components/components/list/FilterPopup.d.ts +11 -0
  22. package/dist/components/components/list/ListPage.d.ts +22 -0
  23. package/dist/components/components/list/Pagination.d.ts +11 -0
  24. package/dist/components/components/list/index.d.ts +0 -0
  25. package/dist/components/layout/Layout.d.ts +2 -1
  26. package/dist/components/layout/SideBar.d.ts +4 -3
  27. package/dist/components/layout/index.d.ts +2 -0
  28. package/dist/components/list/Datagrid.d.ts +12 -0
  29. package/dist/components/list/EmptyList.d.ts +2 -0
  30. package/dist/components/list/FilterPopup.d.ts +10 -0
  31. package/dist/components/list/Pagination.d.ts +11 -0
  32. package/dist/components/list/index.d.ts +0 -0
  33. package/dist/{src/screens → components/pages}/ControllerDetails.d.ts +1 -1
  34. package/dist/components/pages/FormPage.d.ts +12 -0
  35. package/dist/components/pages/ListPage.d.ts +18 -0
  36. package/dist/components/pages/Login.d.ts +13 -0
  37. package/dist/decorators/form/Form.d.ts +6 -0
  38. package/dist/decorators/form/FormOptions.d.ts +7 -0
  39. package/dist/decorators/form/Input.d.ts +17 -0
  40. package/dist/decorators/form/getFormFields.d.ts +3 -0
  41. package/dist/decorators/list/Cell.d.ts +21 -0
  42. package/dist/decorators/list/GetCellFields.d.ts +2 -0
  43. package/dist/decorators/list/ImageCell.d.ts +6 -0
  44. package/dist/decorators/list/List.d.ts +28 -0
  45. package/dist/decorators/list/ListData.d.ts +6 -0
  46. package/dist/decorators/list/getListFields.d.ts +2 -0
  47. package/dist/index.cjs.js +1 -1
  48. package/dist/index.d.ts +20 -10
  49. package/dist/index.esm.js +1 -1
  50. package/dist/initPanel.d.ts +2 -2
  51. package/dist/store/store.d.ts +1 -5
  52. package/dist/types/AnyClass.d.ts +1 -0
  53. package/dist/types/ScreenCreatorData.d.ts +5 -3
  54. package/dist/types/initPanelOptions.d.ts +0 -6
  55. package/dist/utils/format.d.ts +1 -0
  56. package/dist/utils/getFields.d.ts +2 -1
  57. package/package.json +13 -6
  58. package/src/api/CrudApi.ts +30 -11
  59. package/src/assets/icons/svg/create.svg +9 -0
  60. package/src/assets/icons/svg/filter.svg +3 -0
  61. package/src/assets/icons/svg/pencil.svg +8 -0
  62. package/src/assets/icons/svg/search.svg +8 -0
  63. package/src/assets/icons/svg/trash.svg +8 -0
  64. package/src/components/Panel.tsx +11 -11
  65. package/src/components/components/Checkbox.tsx +9 -0
  66. package/src/components/components/Counter.tsx +51 -0
  67. package/src/components/components/FormField.tsx +94 -0
  68. package/src/components/components/ImageUploader.tsx +301 -0
  69. package/src/components/components/InnerForm.tsx +74 -0
  70. package/src/components/components/LoadingScreen.tsx +12 -0
  71. package/src/components/components/index.ts +8 -0
  72. package/src/components/components/list/Datagrid.tsx +121 -0
  73. package/src/components/components/list/EmptyList.tsx +26 -0
  74. package/src/components/components/list/FilterPopup.tsx +202 -0
  75. package/src/components/components/list/ListPage.tsx +178 -0
  76. package/src/components/components/list/Pagination.tsx +110 -0
  77. package/src/components/components/list/index.ts +1 -0
  78. package/src/components/layout/Layout.tsx +8 -1
  79. package/src/components/layout/SideBar.tsx +103 -31
  80. package/src/components/layout/index.ts +2 -0
  81. package/src/components/pages/ControllerDetails.tsx +37 -0
  82. package/src/components/pages/FormPage.tsx +34 -0
  83. package/src/components/pages/Login.tsx +79 -0
  84. package/src/decorators/form/Form.ts +18 -0
  85. package/src/decorators/form/FormOptions.ts +8 -0
  86. package/src/decorators/form/Input.ts +53 -0
  87. package/src/decorators/form/getFormFields.ts +13 -0
  88. package/src/decorators/list/Cell.ts +32 -0
  89. package/src/decorators/list/GetCellFields.ts +13 -0
  90. package/src/decorators/list/ImageCell.ts +13 -0
  91. package/src/decorators/list/List.ts +31 -0
  92. package/src/decorators/list/ListData.ts +7 -0
  93. package/src/decorators/list/getListFields.ts +10 -0
  94. package/src/index.ts +28 -10
  95. package/src/initPanel.ts +4 -12
  96. package/src/store/store.ts +23 -28
  97. package/src/styles/counter.scss +42 -0
  98. package/src/styles/filter-popup.scss +134 -0
  99. package/src/styles/image-uploader.scss +94 -0
  100. package/src/styles/index.scss +26 -7
  101. package/src/styles/layout.scss +1 -6
  102. package/src/styles/list.scss +175 -7
  103. package/src/styles/loading-screen.scss +42 -0
  104. package/src/styles/pagination.scss +66 -0
  105. package/src/styles/sidebar.scss +64 -0
  106. package/src/styles/utils/scrollbar.scss +19 -0
  107. package/src/types/AnyClass.ts +1 -0
  108. package/src/types/ScreenCreatorData.ts +5 -3
  109. package/src/types/initPanelOptions.ts +1 -7
  110. package/src/types/svg.d.ts +5 -0
  111. package/src/utils/format.ts +7 -0
  112. package/src/utils/getFields.ts +11 -9
  113. package/dist/api/crudApi.d.ts +0 -17
  114. package/dist/components/Form.d.ts +0 -6
  115. package/dist/components/FormField.d.ts +0 -13
  116. package/dist/components/list/List.d.ts +0 -10
  117. package/dist/components/screens/ControllerCreate.d.ts +0 -5
  118. package/dist/components/screens/ControllerDetails.d.ts +0 -5
  119. package/dist/components/screens/ControllerEdit.d.ts +0 -5
  120. package/dist/components/screens/ControllerList.d.ts +0 -5
  121. package/dist/components/screens/Login.d.ts +0 -2
  122. package/dist/decorators/Cell.d.ts +0 -9
  123. package/dist/decorators/Input.d.ts +0 -13
  124. package/dist/hooks/useScreens.d.ts +0 -2
  125. package/dist/initPanelOptions.d.ts +0 -8
  126. package/dist/screens/ControllerCreate.d.ts +0 -5
  127. package/dist/screens/ControllerDetails.d.ts +0 -5
  128. package/dist/screens/ControllerEdit.d.ts +0 -5
  129. package/dist/screens/ControllerList.d.ts +0 -5
  130. package/dist/screens/Form.d.ts +0 -6
  131. package/dist/src/api/crudApi.d.ts +0 -6
  132. package/dist/src/components/Panel.d.ts +0 -9
  133. package/dist/src/components/layout/Layout.d.ts +0 -11
  134. package/dist/src/components/layout/SideBar.d.ts +0 -10
  135. package/dist/src/components/list/List.d.ts +0 -10
  136. package/dist/src/decorators/Cell.d.ts +0 -10
  137. package/dist/src/decorators/Crud.d.ts +0 -6
  138. package/dist/src/index.d.ts +0 -8
  139. package/dist/src/screens/ControllerCreate.d.ts +0 -5
  140. package/dist/src/screens/ControllerEdit.d.ts +0 -5
  141. package/dist/src/screens/ControllerList.d.ts +0 -5
  142. package/dist/src/screens/Form.d.ts +0 -6
  143. package/dist/src/store/store.d.ts +0 -19
  144. package/dist/src/types/Screen.d.ts +0 -4
  145. package/dist/src/types/ScreenCreatorData.d.ts +0 -8
  146. package/dist/src/utils/createScreens.d.ts +0 -1
  147. package/dist/src/utils/getFields.d.ts +0 -2
  148. package/dist/src/utils/getScreens.d.ts +0 -2
  149. package/dist/utils/crudScreens.d.ts +0 -2
  150. package/dist/utils/getScreens.d.ts +0 -2
  151. package/src/api/AuthApi.ts +0 -14
  152. package/src/components/Form.tsx +0 -70
  153. package/src/components/FormField.tsx +0 -60
  154. package/src/components/list/List.tsx +0 -81
  155. package/src/components/screens/ControllerCreate.tsx +0 -7
  156. package/src/components/screens/ControllerDetails.tsx +0 -40
  157. package/src/components/screens/ControllerEdit.tsx +0 -35
  158. package/src/components/screens/ControllerList.tsx +0 -45
  159. package/src/components/screens/Login.tsx +0 -68
  160. package/src/decorators/Cell.ts +0 -34
  161. package/src/decorators/Input.ts +0 -50
  162. package/src/hooks/useScreens.tsx +0 -36
  163. /package/dist/components/{ErrorBoundary.d.ts → components/ErrorBoundary.d.ts} +0 -0
  164. /package/dist/components/{ErrorComponent.d.ts → components/ErrorComponent.d.ts} +0 -0
  165. /package/dist/components/{Label.d.ts → components/Label.d.ts} +0 -0
  166. /package/src/components/{ErrorBoundary.tsx → components/ErrorBoundary.tsx} +0 -0
  167. /package/src/components/{ErrorComponent.tsx → components/ErrorComponent.tsx} +0 -0
  168. /package/src/components/{Label.tsx → components/Label.tsx} +0 -0
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../../types/Screen";
3
- export declare function ControllerDetails({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../../types/Screen";
3
- export declare function ControllerEdit({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../../types/Screen";
3
- export declare function ControllerList({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare function Login(): React.JSX.Element;
@@ -1,9 +0,0 @@
1
- import "reflect-metadata";
2
- export interface CellOptions {
3
- name?: string;
4
- title?: string;
5
- type?: "string" | "number" | "date";
6
- placeHolder?: string;
7
- }
8
- export declare function Cell(options?: CellOptions): PropertyDecorator;
9
- export declare function getCellFields(entityClass: any): CellOptions[];
@@ -1,13 +0,0 @@
1
- import "reflect-metadata";
2
- export interface InputOptions {
3
- name?: string;
4
- label?: string;
5
- placeholder?: string;
6
- editable?: boolean;
7
- inputType?: "text" | "email" | "tel" | "password" | "number" | "date";
8
- type?: "input" | "select" | "textarea";
9
- selectOptions?: string[];
10
- cancelPasswordValidationOnEdit?: boolean;
11
- }
12
- export declare function Input(options?: InputOptions): PropertyDecorator;
13
- export declare function getInputFields(entityClass: any): InputOptions[];
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare function useScreens(): React.JSX.Element;
@@ -1,8 +0,0 @@
1
- type AnyClass = abstract new (...args: any[]) => any;
2
- export interface InitPanelOptions {
3
- crud: Record<string, AnyClass>;
4
- fetch: {
5
- baseURL: string;
6
- };
7
- }
8
- export {};
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import { Screen } from '../types/Screen';
3
- export declare function ControllerCreate({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../types/Screen";
3
- export declare function ControllerDetails({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../types/Screen";
3
- export declare function ControllerEdit({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../types/Screen";
3
- export declare function ControllerList({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,6 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../types/Screen";
3
- export declare function Form({ data, screen }: {
4
- data?: any;
5
- screen: Screen;
6
- }): React.JSX.Element;
@@ -1,6 +0,0 @@
1
- export declare const CrudApi: {
2
- getList: (api: string, page: number) => Promise<any>;
3
- create: (api: string, data: any) => Promise<any>;
4
- details(api: string, id: any): Promise<any>;
5
- edit(api: string, data: any): Promise<any>;
6
- };
@@ -1,9 +0,0 @@
1
- import React from "react";
2
- type AppProps = {
3
- children: React.ReactNode;
4
- setFetchSettings: () => {
5
- baseUrl: string;
6
- };
7
- };
8
- export declare function Panel({ children, setFetchSettings }: AppProps): React.JSX.Element;
9
- export {};
@@ -1,11 +0,0 @@
1
- import React from "react";
2
- import { ScreenCreatorData } from "../../types/ScreenCreatorData";
3
- export declare function Layout<IconType>({ children, menu, getIcons, }: {
4
- children?: React.ReactNode;
5
- menu?: (screens: Record<string, ScreenCreatorData<any>>) => {
6
- name: string;
7
- path: string;
8
- iconType: IconType;
9
- }[];
10
- getIcons?: (iconType: IconType) => React.ReactNode;
11
- }): React.JSX.Element;
@@ -1,10 +0,0 @@
1
- import React from "react";
2
- import { ScreenCreatorData } from "../../types/ScreenCreatorData";
3
- export declare function SideBar<IconType>({ menu, getIcons, }: {
4
- menu?: (screens: Record<string, ScreenCreatorData<any>>) => {
5
- name: string;
6
- path: string;
7
- iconType: IconType;
8
- }[];
9
- getIcons?: (iconType: IconType) => React.ReactNode;
10
- }): React.JSX.Element;
@@ -1,10 +0,0 @@
1
- import React from "react";
2
- import { CellOptions } from "../../decorators/Cell";
3
- import { Screen } from "../../types/Screen";
4
- interface ListProps<T> {
5
- data: T[];
6
- cells: CellOptions<T>[];
7
- screen: Screen;
8
- }
9
- export declare function List<T>({ data, cells, screen }: ListProps<T>): React.JSX.Element;
10
- export {};
@@ -1,10 +0,0 @@
1
- import 'reflect-metadata';
2
- export interface CellOptions<T> {
3
- name?: string;
4
- title?: string;
5
- type?: 'string' | 'number' | 'date';
6
- placeHolder?: string;
7
- linkTo?: (item: T) => string;
8
- }
9
- export declare function Cell<T>(options?: CellOptions<T>): PropertyDecorator;
10
- export declare function getCellFields<T>(entityClass: any): CellOptions<T>[];
@@ -1,6 +0,0 @@
1
- import 'reflect-metadata';
2
- export interface CrudOptions {
3
- controller: string;
4
- }
5
- export declare function Crud(options?: CrudOptions): ClassDecorator;
6
- export declare function getClassCrudData(entityClass: any): CrudOptions | undefined;
@@ -1,8 +0,0 @@
1
- export { type ScreenCreatorData } from "./types/ScreenCreatorData";
2
- export { createScreens } from "./utils/createScreens";
3
- export { getFields } from "./utils/getFields";
4
- export { getScreens } from "./utils/getScreens";
5
- export { Crud } from "./decorators/Crud";
6
- export { Cell } from "./decorators/Cell";
7
- export { Layout } from "./components/layout/Layout";
8
- export { Panel } from "./components/Panel";
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import { Screen } from '../types/Screen';
3
- export declare function ControllerCreate({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import { Screen } from '../types/Screen';
3
- export declare function ControllerEdit({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../types/Screen";
3
- export declare function ControllerList({ screen }: {
4
- screen: Screen;
5
- }): React.JSX.Element;
@@ -1,6 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../types/Screen";
3
- export declare function Form({ data, screen }: {
4
- data?: any;
5
- screen: Screen;
6
- }): React.JSX.Element;
@@ -1,19 +0,0 @@
1
- import { ScreenCreatorData } from "../types/ScreenCreatorData";
2
- interface AppState {
3
- screens: Record<string, ScreenCreatorData<any>> | null;
4
- fetchSettings: {
5
- baseUrl: string;
6
- } | null;
7
- }
8
- export declare const useAppStore: import("zustand/traditional").UseBoundStoreWithEqualityFn<Omit<import("zustand/vanilla").StoreApi<AppState>, "persist"> & {
9
- persist: {
10
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<AppState, unknown>>) => void;
11
- clearStorage: () => void;
12
- rehydrate: () => Promise<void> | void;
13
- hasHydrated: () => boolean;
14
- onHydrate: (fn: (state: AppState) => void) => () => void;
15
- onFinishHydration: (fn: (state: AppState) => void) => () => void;
16
- getOptions: () => Partial<import("zustand/middleware").PersistOptions<AppState, unknown>>;
17
- };
18
- }>;
19
- export {};
@@ -1,4 +0,0 @@
1
- export interface Screen {
2
- key: string;
3
- controller: string;
4
- }
@@ -1,8 +0,0 @@
1
- import { CellOptions } from "../decorators/Cell";
2
- import { CrudOptions } from "../decorators/Crud";
3
- export interface ScreenCreatorData<T> {
4
- resolver: any;
5
- fields: string[];
6
- cells: CellOptions<T>[];
7
- crud: CrudOptions;
8
- }
@@ -1 +0,0 @@
1
- export declare function createScreens(screens: Record<string, any>): void;
@@ -1,2 +0,0 @@
1
- import { ScreenCreatorData } from "../types/ScreenCreatorData";
2
- export declare function getFields<T>(entityClass: T): ScreenCreatorData<T>;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare function getScreens(): React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare function CrudScreens(): React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare function getScreens(): React.JSX.Element;
@@ -1,14 +0,0 @@
1
- export const AuthApi = {
2
- login: (fetchSettings: { baseUrl: string }, username: string, password: string) => {
3
- return fetch(`${fetchSettings.baseUrl}/auth/login`, {
4
- method: "POST",
5
- body: JSON.stringify({ username, password }),
6
- headers: { "Content-Type": "application/json" },
7
- }).then((res) => {
8
- if (res.ok) {
9
- return res.json();
10
- }
11
- throw res;
12
- });
13
- },
14
- };
@@ -1,70 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { Screen } from "../types/Screen";
3
- import { useForm } from "react-hook-form";
4
- import { useNavigate } from "react-router";
5
- import { CrudApi } from "../api/CrudApi";
6
- import { useAppStore } from "../store/store";
7
- import { InputOptions } from "../decorators/Input";
8
- import { FormField } from "./FormField";
9
-
10
- export function Form({ data, screen }: { data?: any; screen: Screen }) {
11
- const { screens, fetchSettings } = useAppStore((s) => ({
12
- screens: s.screens ?? {},
13
- fetchSettings: s.fetchSettings,
14
- }));
15
- const isEditForm = !!data;
16
- const {
17
- register,
18
- handleSubmit,
19
- reset,
20
- formState: { errors },
21
- } = useForm<any>({
22
- resolver: screens[screen.controller].resolver,
23
- //TODO: remove __formEdit from api
24
- defaultValues: { ...data, __formEdit: isEditForm },
25
- });
26
- const navigate = useNavigate();
27
- //const fields = screens[screen.controller].fields;
28
- const inputs = screens[screen.controller].inputs;
29
- useEffect(() => {
30
- reset({ ...data, __formEdit: isEditForm });
31
- }, [isEditForm, data, reset]);
32
-
33
- return (
34
- <div className="form-wrapper">
35
- <form
36
- onSubmit={handleSubmit((dataForm) => {
37
- if (!fetchSettings) {
38
- return;
39
- }
40
- delete dataForm.__formEdit;
41
- if (isEditForm) {
42
- CrudApi.edit(fetchSettings, screen.controller, dataForm).then(() => {
43
- navigate("/" + screen.controller, {
44
- replace: true,
45
- });
46
- });
47
- } else {
48
- CrudApi.create(fetchSettings, screen.controller, dataForm).then(() => {
49
- navigate("/" + screen.controller, {
50
- replace: true,
51
- });
52
- });
53
- }
54
- })}>
55
- {inputs.map((input: InputOptions) => (
56
- <FormField
57
- key={input.name || ""}
58
- input={input}
59
- register={register}
60
- isEditForm={isEditForm}
61
- error={errors[input.name || ""]}
62
- />
63
- ))}
64
- <button type="submit" className="submit-button">
65
- Submit
66
- </button>
67
- </form>
68
- </div>
69
- );
70
- }
@@ -1,60 +0,0 @@
1
- import React from "react";
2
- import { InputOptions } from "../decorators/Input";
3
- import { Label } from "./Label";
4
- import { UseFormRegister } from "react-hook-form";
5
-
6
- interface FormFieldProps {
7
- input: InputOptions;
8
- register: UseFormRegister<any>;
9
- isEditForm: boolean;
10
- error?: { message?: string };
11
- }
12
-
13
- export function FormField({ input, register, isEditForm, error }: FormFieldProps) {
14
- const fieldName = input.name || "";
15
-
16
- const renderField = () => {
17
- switch (input.type) {
18
- case "textarea":
19
- return (
20
- <textarea
21
- {...register(fieldName)}
22
- placeholder={input.placeholder}
23
- id={fieldName}
24
- disabled={isEditForm && input.editable === false}
25
- />
26
- );
27
- case "select":
28
- return (
29
- <select {...register(fieldName)} id={fieldName} disabled={isEditForm && input.editable === false}>
30
- <option value="">Select {fieldName}</option>
31
- {input.selectOptions?.map((option) => (
32
- <option key={option} value={option}>
33
- {option}
34
- </option>
35
- ))}
36
- </select>
37
- );
38
- case "input":
39
- default: {
40
- return (
41
- <input
42
- type={input.inputType}
43
- {...register(fieldName)}
44
- placeholder={input.placeholder}
45
- id={fieldName}
46
- disabled={isEditForm && input.editable === false}
47
- />
48
- );
49
- }
50
- }
51
- };
52
-
53
- return (
54
- <div className="form-field">
55
- <Label htmlFor={fieldName} label={input.label} fieldName={fieldName} />
56
- {renderField()}
57
- {error && <span className="error-message">{error.message}</span>}
58
- </div>
59
- );
60
- }
@@ -1,81 +0,0 @@
1
- import React from "react";
2
- import { CellOptions } from "../../decorators/Cell";
3
- import { Link } from "react-router";
4
- import { Screen } from "../../types/Screen";
5
-
6
- interface ListProps<T> {
7
- data: T[];
8
- cells: CellOptions[];
9
- screen: Screen;
10
- }
11
-
12
- export function List<T>({ data, cells }: ListProps<T>) {
13
- if (!data || data.length === 0) {
14
- return <div>No items available</div>;
15
- }
16
-
17
- return (
18
- <div className="list-wrapper">
19
- <div className="header">List</div>
20
- <table className="list-table">
21
- <thead>
22
- <tr>
23
- {cells.map((cellOptions) => (
24
- <th key={cellOptions.name}>{cellOptions.title ?? cellOptions.name}</th>
25
- ))}
26
- <th />
27
- </tr>
28
- </thead>
29
- <tbody>
30
- {data.map((item, index) => (
31
- <tr key={index}>
32
- {cells.map((cellOptions) => {
33
- // @ts-ignore
34
- const value = item[cellOptions.name];
35
- let formattedValue = value ?? "-"; // Default value if the field is undefined or null
36
-
37
- switch (cellOptions.type) {
38
- case "date":
39
- if (value) {
40
- const date = new Date(value);
41
- formattedValue = `${date.getDate().toString().padStart(2, "0")}/${(
42
- date.getMonth() + 1
43
- )
44
- .toString()
45
- .padStart(
46
- 2,
47
- "0"
48
- )}/${date.getFullYear()} ${date.getHours().toString().padStart(2, "0")}:${date
49
- .getMinutes()
50
- .toString()
51
- .padStart(2, "0")}`;
52
- }
53
- break;
54
-
55
- case "number":
56
- case "string":
57
- default:
58
- formattedValue = value ? value.toString() : (cellOptions?.placeHolder ?? "-"); // Handles string type or default fallback
59
- break;
60
- }
61
- let render = formattedValue;
62
- /*
63
- if (cellOptions.linkTo) {
64
- render = <Link to={cellOptions.linkTo(item)}>{formattedValue}</Link>;
65
- }
66
- */
67
- return <td key={cellOptions.name}>{render}</td>;
68
- })}
69
- <td>
70
- {/*@ts-ignore*/}
71
- <Link to={"edit/" + (item?.id ?? "-")}>Edit</Link>
72
- {/*@ts-ignore*/}
73
- <Link to={"details/" + (item?.id ?? "-")}>Details</Link>
74
- </td>
75
- </tr>
76
- ))}
77
- </tbody>
78
- </table>
79
- </div>
80
- );
81
- }
@@ -1,7 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../../types/Screen";
3
- import { Form } from "../Form";
4
-
5
- export function ControllerCreate({ screen }: { screen: Screen }) {
6
- return <Form screen={screen} />;
7
- }
@@ -1,40 +0,0 @@
1
- import { useParams } from "react-router";
2
- import React, { useEffect, useState } from "react";
3
- import { CrudApi } from "../../api/CrudApi";
4
- import { Screen } from "../../types/Screen";
5
- import { useAppStore } from "../../store/store";
6
- import { ErrorComponent } from "../ErrorComponent";
7
-
8
- export function ControllerDetails({ screen }: { screen: Screen }) {
9
- const { fetchSettings } = useAppStore((s) => ({
10
- fetchSettings: s.fetchSettings,
11
- }));
12
- const { id } = useParams();
13
- const [data, setData] = useState<any>(null);
14
- const [error, setError] = useState(null);
15
-
16
- useEffect(() => {
17
- if (fetchSettings && screen.controller && id) {
18
- CrudApi.details(fetchSettings, screen.controller, id)
19
- .then((res) => {
20
- setData(res);
21
- })
22
- .catch((e: any) => {
23
- setError(e);
24
- console.error(e);
25
- });
26
- }
27
- }, [fetchSettings, id, screen]);
28
-
29
- if (error) {
30
- return <ErrorComponent error={error} />;
31
- }
32
-
33
- return (
34
- <p
35
- dangerouslySetInnerHTML={{
36
- __html: JSON.stringify(data, null, " " + "<br/>"),
37
- }}
38
- />
39
- );
40
- }
@@ -1,35 +0,0 @@
1
- import { Form } from "../Form";
2
- import React, { useEffect, useState } from "react";
3
- import { Screen } from "../../types/Screen";
4
- import { useParams } from "react-router";
5
- import { CrudApi } from "../../api/CrudApi";
6
- import { useAppStore } from "../../store/store";
7
- import { ErrorComponent } from "../ErrorComponent";
8
-
9
- export function ControllerEdit({ screen }: { screen: Screen }) {
10
- const { fetchSettings } = useAppStore((s) => ({
11
- fetchSettings: s.fetchSettings,
12
- }));
13
- const { id } = useParams();
14
- const [data, setData] = useState<any>(null);
15
- const [error, setError] = useState(null);
16
-
17
- useEffect(() => {
18
- if (fetchSettings && screen.controller && id) {
19
- CrudApi.details(fetchSettings, screen.controller, id)
20
- .then((res) => {
21
- setData(res);
22
- })
23
- .catch((e: any) => {
24
- setError(e);
25
- console.error(e);
26
- });
27
- }
28
- }, [fetchSettings, id, screen]);
29
-
30
- if (error) {
31
- return <ErrorComponent error={error} />;
32
- }
33
-
34
- return <Form data={data} screen={screen} />;
35
- }
@@ -1,45 +0,0 @@
1
- import React from "react";
2
- import { Screen } from "../../types/Screen";
3
- import { useEffect, useState } from "react";
4
- import { CrudApi } from "../../api/CrudApi";
5
- import { Link } from "react-router";
6
- import { List } from "../list/List";
7
- import { useAppStore } from "../../store/store";
8
- import { ErrorComponent } from "../ErrorComponent";
9
-
10
- export function ControllerList({ screen }: { screen: Screen }) {
11
- const { screens, fetchSettings, token } = useAppStore((s) => ({
12
- screens: s.screens ?? {},
13
- fetchSettings: s.fetchSettings,
14
- token: s.token,
15
- }));
16
- const [page, setPage] = useState(0);
17
- const [data, setData] = useState<any>(null);
18
- const [error, setError] = useState(null);
19
-
20
- useEffect(() => {
21
- if (screen.controller && fetchSettings && token) {
22
- CrudApi.getList({ ...fetchSettings, token }, screen.controller)
23
- .then((res) => {
24
- setData(res);
25
- })
26
- .catch((e: any) => {
27
- setError(e);
28
- console.error(e);
29
- });
30
- }
31
- }, [page, screen.controller, fetchSettings]);
32
-
33
- if (error) {
34
- return <ErrorComponent error={error} />;
35
- }
36
- return (
37
- <div>
38
- <Link to={"create"}>Create</Link>
39
- {/*
40
- {error ? <p>Error {error}</p> : <></>}
41
- */}
42
- <List screen={screen} cells={screens[screen.key].cells} data={data} />
43
- </div>
44
- );
45
- }