proje-react-panel 1.0.14-test-3 → 1.0.15
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/.cursor/rules.md +122 -0
- package/.cursor/settings.json +57 -0
- package/.eslintrc.js +5 -0
- package/.eslintrc.json +26 -0
- package/.prettierrc +10 -0
- package/.vscode/launch.json +17 -0
- package/.vscode/settings.json +8 -0
- package/PTD.md +234 -0
- package/README.md +62 -28
- package/dist/api/CrudApi.d.ts +12 -0
- package/dist/components/Panel.d.ts +2 -2
- package/dist/components/components/Checkbox.d.ts +6 -0
- package/dist/components/components/Counter.d.ts +9 -0
- package/dist/components/components/FormField.d.ts +12 -0
- package/dist/components/components/ImageUploader.d.ts +15 -0
- package/dist/components/components/InnerForm.d.ts +12 -0
- package/dist/components/components/LoadingScreen.d.ts +2 -0
- package/dist/components/components/index.d.ts +8 -0
- package/dist/components/layout/Layout.d.ts +2 -1
- package/dist/components/layout/SideBar.d.ts +4 -3
- package/dist/components/layout/index.d.ts +2 -0
- package/dist/components/list/Datagrid.d.ts +8 -0
- package/dist/components/list/Pagination.d.ts +11 -0
- package/dist/components/list/index.d.ts +0 -0
- package/dist/{src/screens → components/pages}/ControllerDetails.d.ts +1 -1
- package/dist/components/pages/FormPage.d.ts +11 -0
- package/dist/components/pages/ListPage.d.ts +17 -0
- package/dist/components/pages/Login.d.ts +13 -0
- package/dist/decorators/form/Form.d.ts +6 -0
- package/dist/decorators/form/FormOptions.d.ts +7 -0
- package/dist/decorators/form/Input.d.ts +13 -0
- package/dist/decorators/form/getFormFields.d.ts +3 -0
- package/dist/decorators/{Cell.d.ts → list/Cell.d.ts} +2 -2
- package/dist/decorators/list/GetCellFields.d.ts +2 -0
- package/dist/decorators/list/ImageCell.d.ts +6 -0
- package/dist/decorators/list/List.d.ts +5 -0
- package/dist/decorators/list/ListData.d.ts +6 -0
- package/dist/decorators/list/getListFields.d.ts +2 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +19 -10
- package/dist/index.esm.js +1 -1
- package/dist/initPanel.d.ts +2 -2
- package/dist/store/store.d.ts +1 -5
- package/dist/types/AnyClass.d.ts +1 -0
- package/dist/types/ScreenCreatorData.d.ts +5 -3
- package/dist/types/initPanelOptions.d.ts +0 -6
- package/dist/utils/format.d.ts +1 -0
- package/dist/utils/getFields.d.ts +2 -1
- package/package.json +5 -4
- package/src/api/CrudApi.ts +30 -11
- package/src/components/Panel.tsx +11 -11
- package/src/components/components/Checkbox.tsx +9 -0
- package/src/components/components/Counter.tsx +51 -0
- package/src/components/components/FormField.tsx +60 -0
- package/src/components/components/ImageUploader.tsx +301 -0
- package/src/components/components/InnerForm.tsx +75 -0
- package/src/components/components/LoadingScreen.tsx +12 -0
- package/src/components/components/index.ts +8 -0
- package/src/components/layout/Layout.tsx +7 -3
- package/src/components/layout/SideBar.tsx +103 -31
- package/src/components/layout/index.ts +2 -0
- package/src/components/list/Datagrid.tsx +101 -0
- package/src/components/list/Pagination.tsx +110 -0
- package/src/components/list/index.ts +1 -0
- package/src/components/pages/ControllerDetails.tsx +37 -0
- package/src/components/pages/FormPage.tsx +32 -0
- package/src/components/pages/ListPage.tsx +85 -0
- package/src/components/pages/Login.tsx +79 -0
- package/src/decorators/form/Form.ts +18 -0
- package/src/decorators/form/FormOptions.ts +8 -0
- package/src/decorators/form/Input.ts +52 -0
- package/src/decorators/form/getFormFields.ts +13 -0
- package/src/decorators/{Cell.ts → list/Cell.ts} +2 -14
- package/src/decorators/list/GetCellFields.ts +13 -0
- package/src/decorators/list/ImageCell.ts +13 -0
- package/src/decorators/list/List.ts +17 -0
- package/src/decorators/list/ListData.ts +7 -0
- package/src/decorators/list/getListFields.ts +10 -0
- package/src/index.ts +23 -10
- package/src/initPanel.ts +4 -12
- package/src/store/store.ts +23 -28
- package/src/styles/_scrollbar.scss +19 -0
- package/src/styles/counter.scss +42 -0
- package/src/styles/image-uploader.scss +94 -0
- package/src/styles/index.scss +30 -7
- package/src/styles/layout.scss +1 -6
- package/src/styles/list.scss +32 -5
- package/src/styles/loading-screen.scss +42 -0
- package/src/styles/pagination.scss +66 -0
- package/src/styles/sidebar.scss +64 -0
- package/src/types/AnyClass.ts +1 -0
- package/src/types/ScreenCreatorData.ts +5 -3
- package/src/types/initPanelOptions.ts +1 -7
- package/src/utils/format.ts +7 -0
- package/src/utils/getFields.ts +11 -9
- package/dist/api/crudApi.d.ts +0 -17
- package/dist/components/Form.d.ts +0 -6
- package/dist/components/FormField.d.ts +0 -13
- package/dist/components/list/List.d.ts +0 -10
- package/dist/components/screens/ControllerCreate.d.ts +0 -5
- package/dist/components/screens/ControllerDetails.d.ts +0 -5
- package/dist/components/screens/ControllerEdit.d.ts +0 -5
- package/dist/components/screens/ControllerList.d.ts +0 -5
- package/dist/components/screens/Login.d.ts +0 -2
- package/dist/decorators/Input.d.ts +0 -13
- package/dist/hooks/useScreens.d.ts +0 -2
- package/dist/initPanelOptions.d.ts +0 -8
- package/dist/screens/ControllerCreate.d.ts +0 -5
- package/dist/screens/ControllerDetails.d.ts +0 -5
- package/dist/screens/ControllerEdit.d.ts +0 -5
- package/dist/screens/ControllerList.d.ts +0 -5
- package/dist/screens/Form.d.ts +0 -6
- package/dist/src/api/crudApi.d.ts +0 -6
- package/dist/src/components/Panel.d.ts +0 -9
- package/dist/src/components/layout/Layout.d.ts +0 -11
- package/dist/src/components/layout/SideBar.d.ts +0 -10
- package/dist/src/components/list/List.d.ts +0 -10
- package/dist/src/decorators/Cell.d.ts +0 -10
- package/dist/src/decorators/Crud.d.ts +0 -6
- package/dist/src/index.d.ts +0 -8
- package/dist/src/screens/ControllerCreate.d.ts +0 -5
- package/dist/src/screens/ControllerEdit.d.ts +0 -5
- package/dist/src/screens/ControllerList.d.ts +0 -5
- package/dist/src/screens/Form.d.ts +0 -6
- package/dist/src/store/store.d.ts +0 -19
- package/dist/src/types/Screen.d.ts +0 -4
- package/dist/src/types/ScreenCreatorData.d.ts +0 -8
- package/dist/src/utils/createScreens.d.ts +0 -1
- package/dist/src/utils/getFields.d.ts +0 -2
- package/dist/src/utils/getScreens.d.ts +0 -2
- package/dist/utils/crudScreens.d.ts +0 -2
- package/dist/utils/getScreens.d.ts +0 -2
- package/src/api/AuthApi.ts +0 -14
- package/src/components/Form.tsx +0 -80
- package/src/components/FormField.tsx +0 -60
- package/src/components/list/List.tsx +0 -81
- package/src/components/screens/ControllerCreate.tsx +0 -7
- package/src/components/screens/ControllerDetails.tsx +0 -40
- package/src/components/screens/ControllerEdit.tsx +0 -35
- package/src/components/screens/ControllerList.tsx +0 -45
- package/src/components/screens/Login.tsx +0 -68
- package/src/decorators/Input.ts +0 -50
- package/src/hooks/useScreens.tsx +0 -36
- /package/dist/components/{ErrorBoundary.d.ts → components/ErrorBoundary.d.ts} +0 -0
- /package/dist/components/{ErrorComponent.d.ts → components/ErrorComponent.d.ts} +0 -0
- /package/dist/components/{Label.d.ts → components/Label.d.ts} +0 -0
- /package/src/components/{ErrorBoundary.tsx → components/ErrorBoundary.tsx} +0 -0
- /package/src/components/{ErrorComponent.tsx → components/ErrorComponent.tsx} +0 -0
- /package/src/components/{Label.tsx → components/Label.tsx} +0 -0
package/dist/screens/Form.d.ts
DELETED
@@ -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>[];
|
package/dist/src/index.d.ts
DELETED
@@ -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,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 +0,0 @@
|
|
1
|
-
export declare function createScreens(screens: Record<string, any>): void;
|
package/src/api/AuthApi.ts
DELETED
@@ -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
|
-
};
|
package/src/components/Form.tsx
DELETED
@@ -1,80 +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
|
-
console.log("form started");
|
16
|
-
const isEditForm = !!data;
|
17
|
-
const {
|
18
|
-
register,
|
19
|
-
handleSubmit,
|
20
|
-
reset,
|
21
|
-
formState: { errors },
|
22
|
-
} = useForm<any>({
|
23
|
-
resolver: screens[screen.controller].resolver,
|
24
|
-
//TODO: remove __formEdit from api
|
25
|
-
defaultValues: { ...data, __formEdit: isEditForm },
|
26
|
-
});
|
27
|
-
const navigate = useNavigate();
|
28
|
-
//const fields = screens[screen.controller].fields;
|
29
|
-
const inputs = screens[screen.controller].inputs;
|
30
|
-
useEffect(() => {
|
31
|
-
reset({ ...data, __formEdit: isEditForm });
|
32
|
-
}, [isEditForm, data, reset]);
|
33
|
-
|
34
|
-
return (
|
35
|
-
<div className="form-wrapper">
|
36
|
-
<form
|
37
|
-
onSubmit={handleSubmit(
|
38
|
-
(dataForm) => {
|
39
|
-
console.log("fetch started");
|
40
|
-
if (!fetchSettings) {
|
41
|
-
console.log("cancelled due to fetchSettings null");
|
42
|
-
return;
|
43
|
-
}
|
44
|
-
delete dataForm.__formEdit;
|
45
|
-
if (isEditForm) {
|
46
|
-
console.log("CrudApi.edit called");
|
47
|
-
CrudApi.edit(fetchSettings, screen.controller, dataForm).then(() => {
|
48
|
-
navigate("/" + screen.controller, {
|
49
|
-
replace: true,
|
50
|
-
});
|
51
|
-
});
|
52
|
-
} else {
|
53
|
-
console.log("CrudApi.create called");
|
54
|
-
CrudApi.create(fetchSettings, screen.controller, dataForm).then(() => {
|
55
|
-
navigate("/" + screen.controller, {
|
56
|
-
replace: true,
|
57
|
-
});
|
58
|
-
});
|
59
|
-
}
|
60
|
-
},
|
61
|
-
(errors, event) => {
|
62
|
-
console.log("error creating creation", errors, event);
|
63
|
-
}
|
64
|
-
)}>
|
65
|
-
{inputs.map((input: InputOptions) => (
|
66
|
-
<FormField
|
67
|
-
key={input.name || ""}
|
68
|
-
input={input}
|
69
|
-
register={register}
|
70
|
-
isEditForm={isEditForm}
|
71
|
-
error={errors[input.name || ""]}
|
72
|
-
/>
|
73
|
-
))}
|
74
|
-
<button type="submit" className="submit-button">
|
75
|
-
Submit
|
76
|
-
</button>
|
77
|
-
</form>
|
78
|
-
</div>
|
79
|
-
);
|
80
|
-
}
|
@@ -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,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
|
-
}
|
@@ -1,68 +0,0 @@
|
|
1
|
-
import React from "react";
|
2
|
-
import { useForm } from "react-hook-form";
|
3
|
-
import { FormField } from "../FormField";
|
4
|
-
import { AuthApi } from "../../api/AuthApi";
|
5
|
-
import { useAppStore } from "../../store/store";
|
6
|
-
import { useNavigate } from "react-router";
|
7
|
-
|
8
|
-
interface LoginFormData {
|
9
|
-
username: string;
|
10
|
-
password: string;
|
11
|
-
}
|
12
|
-
|
13
|
-
export function Login() {
|
14
|
-
const {
|
15
|
-
register,
|
16
|
-
handleSubmit,
|
17
|
-
formState: { errors },
|
18
|
-
} = useForm<LoginFormData>();
|
19
|
-
const { fetchSettings } = useAppStore((s) => ({ fetchSettings: s.fetchSettings }));
|
20
|
-
const navigate = useNavigate();
|
21
|
-
const onSubmit = async (data: LoginFormData) => {
|
22
|
-
AuthApi.login(fetchSettings!, data.username, data.password).then((dataInner) => {
|
23
|
-
const { access_token, admin } = dataInner;
|
24
|
-
useAppStore.setState({ user: admin, token: access_token });
|
25
|
-
navigate("/");
|
26
|
-
});
|
27
|
-
};
|
28
|
-
|
29
|
-
return (
|
30
|
-
<div className="login-container">
|
31
|
-
<div className="login-panel">
|
32
|
-
<div className="login-header">
|
33
|
-
<h1>Welcome Back</h1>
|
34
|
-
<p>Please sign in to continue</p>
|
35
|
-
</div>
|
36
|
-
<form onSubmit={handleSubmit(onSubmit)} className="login-form">
|
37
|
-
<FormField
|
38
|
-
input={{
|
39
|
-
name: "username",
|
40
|
-
label: "Username",
|
41
|
-
inputType: "text",
|
42
|
-
placeholder: "Enter your username",
|
43
|
-
}}
|
44
|
-
register={register}
|
45
|
-
isEditForm={false}
|
46
|
-
error={errors.username}
|
47
|
-
/>
|
48
|
-
<FormField
|
49
|
-
input={{
|
50
|
-
name: "password",
|
51
|
-
label: "Password",
|
52
|
-
inputType: "password",
|
53
|
-
placeholder: "Enter your password",
|
54
|
-
}}
|
55
|
-
register={register}
|
56
|
-
isEditForm={false}
|
57
|
-
error={errors.password}
|
58
|
-
/>
|
59
|
-
<div className="form-actions">
|
60
|
-
<button type="submit" className="submit-button">
|
61
|
-
Sign In
|
62
|
-
</button>
|
63
|
-
</div>
|
64
|
-
</form>
|
65
|
-
</div>
|
66
|
-
</div>
|
67
|
-
);
|
68
|
-
}
|
package/src/decorators/Input.ts
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
import "reflect-metadata";
|
2
|
-
|
3
|
-
const INPUT_KEY = Symbol("input");
|
4
|
-
|
5
|
-
const isFieldSensitive = (fieldName: string): boolean => {
|
6
|
-
return ["password"].some((term) => fieldName.toLowerCase().includes(term));
|
7
|
-
};
|
8
|
-
|
9
|
-
export interface InputOptions {
|
10
|
-
name?: string;
|
11
|
-
label?: string;
|
12
|
-
placeholder?: string;
|
13
|
-
editable?: boolean;
|
14
|
-
inputType?: "text" | "email" | "tel" | "password" | "number" | "date";
|
15
|
-
type?: "input" | "select" | "textarea";
|
16
|
-
selectOptions?: string[]; //TODO: label/value
|
17
|
-
cancelPasswordValidationOnEdit?: boolean;
|
18
|
-
}
|
19
|
-
|
20
|
-
export function Input(options?: InputOptions): PropertyDecorator {
|
21
|
-
return (target, propertyKey) => {
|
22
|
-
const existingInputs: string[] = Reflect.getMetadata(INPUT_KEY, target) || [];
|
23
|
-
Reflect.defineMetadata(INPUT_KEY, [...existingInputs, propertyKey.toString()], target);
|
24
|
-
|
25
|
-
if (options) {
|
26
|
-
const keyString = `${INPUT_KEY.toString()}:${propertyKey.toString()}:options`;
|
27
|
-
Reflect.defineMetadata(keyString, options, target);
|
28
|
-
}
|
29
|
-
};
|
30
|
-
}
|
31
|
-
|
32
|
-
export function getInputFields(entityClass: any): InputOptions[] {
|
33
|
-
const prototype = entityClass.prototype;
|
34
|
-
const inputFields: string[] = Reflect.getMetadata(INPUT_KEY, prototype) || [];
|
35
|
-
return inputFields.map((field) => {
|
36
|
-
const fields = Reflect.getMetadata(`${INPUT_KEY.toString()}:${field}:options`, prototype) || {};
|
37
|
-
const inputType = fields?.inputType ?? (isFieldSensitive(field) ? "password" : "text");
|
38
|
-
return {
|
39
|
-
...fields,
|
40
|
-
editable: fields.editable ?? true,
|
41
|
-
sensitive: fields.sensitive,
|
42
|
-
name: fields?.name ?? field,
|
43
|
-
label: fields?.label ?? field,
|
44
|
-
placeholder: fields?.placeholder ?? field,
|
45
|
-
inputType: inputType,
|
46
|
-
selectOptions: fields?.selectOptions ?? [],
|
47
|
-
cancelPasswordValidationOnEdit: fields?.cancelPasswordValidationOnEdit ?? inputType === "password",
|
48
|
-
};
|
49
|
-
});
|
50
|
-
}
|