namirasoft-account-react 1.3.77 → 1.3.78
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/config-overrides.js +72 -72
- package/dist/App.css +57 -0
- package/dist/IAccountProps.d.ts +22 -0
- package/dist/IAccountProps.js +3 -0
- package/dist/IAccountProps.js.map +10 -0
- package/dist/IRouterMaker.d.ts +8 -0
- package/dist/IRouterMaker.js +3 -0
- package/dist/IRouterMaker.js.map +1 -0
- package/dist/IRouterState.d.ts +5 -0
- package/dist/IRouterState.js +3 -0
- package/dist/IRouterState.js.map +1 -0
- package/dist/IStorageCookie.d.ts +10 -0
- package/dist/IStorageCookie.js +27 -0
- package/dist/IStorageCookie.js.map +1 -0
- package/dist/Messenger.d.ts +16 -0
- package/dist/Messenger.js +78 -0
- package/dist/Messenger.js.map +1 -0
- package/dist/Notification.d.ts +6 -0
- package/dist/Notification.js +3 -0
- package/dist/Notification.js.map +1 -0
- package/dist/NotificationType.d.ts +6 -0
- package/dist/NotificationType.js +11 -0
- package/dist/NotificationType.js.map +1 -0
- package/dist/RouterMaker.d.ts +25 -0
- package/dist/RouterMaker.js +125 -0
- package/dist/RouterMaker.js.map +1 -0
- package/dist/RouterMaker.jsx +118 -0
- package/dist/RouterMaker.jsx.map +1 -0
- package/dist/components/NSALayoutAction.d.ts +17 -0
- package/dist/components/NSALayoutAction.js +6 -0
- package/dist/components/NSALayoutAction.js.map +1 -0
- package/dist/components/NSALayoutAction.module.css +0 -0
- package/dist/components/NSAMessageDialog.module.css +62 -62
- package/dist/index.css +0 -0
- package/dist/layouts/NSALayoutList.d.ts +17 -0
- package/dist/layouts/NSALayoutList.js +19 -0
- package/dist/layouts/NSALayoutList.js.map +1 -0
- package/dist/layouts/NSASectionList.js +1 -1
- package/dist/layouts/NSASectionList.js.map +1 -1
- package/dist/layouts/NSASectionNew.d.ts +9 -0
- package/dist/layouts/NSASectionNew.js +5 -0
- package/dist/layouts/NSASectionNew.js.map +1 -0
- package/dist/pages/NSALoginPage.module.css +19 -19
- package/package.json +64 -64
- package/public/index.html +21 -21
- package/src/App.css +56 -56
- package/src/App.tsx +10 -10
- package/src/IEntityInfo.ts +23 -23
- package/src/INSARouterMaker.ts +8 -8
- package/src/INSARouterProps.ts +17 -17
- package/src/INSARouterState.ts +5 -5
- package/src/Info.ts +20 -20
- package/src/NSARouterMaker.tsx +138 -138
- package/src/components/NSADeleteModal.tsx +24 -24
- package/src/components/NSAMessageDialog.module.css +62 -62
- package/src/components/NSAMessageDialog.tsx +65 -65
- package/src/index.tsx +7 -7
- package/src/layouts/Actions.ts +92 -92
- package/src/layouts/NSALayout.tsx +193 -193
- package/src/layouts/NSASectionEdit.tsx +97 -97
- package/src/layouts/NSASectionList.tsx +105 -105
- package/src/layouts/NSASectionTabs.tsx +36 -36
- package/src/layouts/NSASectionView.tsx +15 -15
- package/src/main.ts +16 -16
- package/src/pages/NSALoginPage.module.css +19 -19
- package/src/pages/NSALoginPage.tsx +37 -37
- package/tsconfig.json +43 -43
|
@@ -1,194 +1,194 @@
|
|
|
1
|
-
import { IBaseComponentProps, INSBarActionProps, INSBarHeroBannerProps, INSBarNotificationProps, INSBarTitleProps, NSButtonRed, NSModal } from 'namirasoft-site-react';
|
|
2
|
-
import { NSLayout } from 'namirasoft-site-react';
|
|
3
|
-
import { NSASectionList, NSASectionListProps } from './NSASectionList';
|
|
4
|
-
import { NSASectionEdit, NSASectionEditProps, onApply as NSASectionEdit_onApply } from './NSASectionEdit';
|
|
5
|
-
import { NSASectionView, NSASectionViewProps } from './NSASectionView';
|
|
6
|
-
import { IHeaderProps } from 'namirasoft-site-react';
|
|
7
|
-
import { ReactNode, useRef, useState } from 'react';
|
|
8
|
-
import { Actions } from './Actions';
|
|
9
|
-
import { INSARouterProps } from '../INSARouterProps';
|
|
10
|
-
import { useParams } from 'react-router-dom';
|
|
11
|
-
import { NamingConvention } from 'namirasoft-core';
|
|
12
|
-
import { IEntityInfo } from '../IEntityInfo';
|
|
13
|
-
import { NSAMessageDialog } from '../main';
|
|
14
|
-
|
|
15
|
-
export interface NSALayoutProps<EntityType extends { id: string }, EntityTypeInput = EntityType> extends IBaseComponentProps, INSARouterProps
|
|
16
|
-
{
|
|
17
|
-
scope: string;
|
|
18
|
-
logo: string;
|
|
19
|
-
background?: string;
|
|
20
|
-
header?: IHeaderProps;
|
|
21
|
-
notifications: INSBarNotificationProps[];
|
|
22
|
-
action?: INSBarActionProps;
|
|
23
|
-
banner?: INSBarHeroBannerProps;
|
|
24
|
-
title?: INSBarTitleProps;
|
|
25
|
-
pages?: {
|
|
26
|
-
entity: IEntityInfo<EntityType, EntityTypeInput>;
|
|
27
|
-
ui?: {
|
|
28
|
-
action?: {
|
|
29
|
-
menus: {
|
|
30
|
-
view?: boolean,
|
|
31
|
-
viewHistory?: boolean,
|
|
32
|
-
copy?: boolean,
|
|
33
|
-
edit?: boolean,
|
|
34
|
-
delete?: boolean,
|
|
35
|
-
apply?: boolean,
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
list?: NSASectionListProps;
|
|
40
|
-
edit?: NSASectionEditProps<EntityType, EntityTypeInput>;
|
|
41
|
-
view?: NSASectionViewProps;
|
|
42
|
-
}
|
|
43
|
-
children: ReactNode;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface NSALayoutState
|
|
47
|
-
{
|
|
48
|
-
showDeleteModal: boolean;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function NSALayout<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSALayoutProps<EntityType, EntityTypeInput>)
|
|
52
|
-
{
|
|
53
|
-
const Section_List = useRef<NSASectionList<EntityType, EntityTypeInput>>(null);
|
|
54
|
-
const Message_Dialog = useRef<NSAMessageDialog>(null);
|
|
55
|
-
|
|
56
|
-
const [state, setState] = useState<NSALayoutState>({ showDeleteModal: false });
|
|
57
|
-
const hideDeleteModal = () => { setState(prevState => ({ ...prevState, showDeleteModal: false })); };
|
|
58
|
-
const showDeleteModal = () => { setState(prevState => ({ ...prevState, showDeleteModal: true })); };
|
|
59
|
-
|
|
60
|
-
let icons = [
|
|
61
|
-
{
|
|
62
|
-
src: "https://static.namirasoft.com/image/concept/logout/white.svg", alt: "Logout", onClicked: () =>
|
|
63
|
-
{
|
|
64
|
-
props.account.server.session.Logout().then(() =>
|
|
65
|
-
{
|
|
66
|
-
props.notifier.onSuccess("You have successfully logged out");
|
|
67
|
-
props.url.redirect("https://account.namirasoft.com/login", {});
|
|
68
|
-
}).catch(() => { });
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
src: "https://static.namirasoft.com/image/concept/message/white.svg", alt: "Message", onClicked: () =>
|
|
73
|
-
{
|
|
74
|
-
Message_Dialog.current?.show();
|
|
75
|
-
},
|
|
76
|
-
children: <NSAMessageDialog ref={Message_Dialog} />,
|
|
77
|
-
count: 1
|
|
78
|
-
},
|
|
79
|
-
{ src: "https://static.namirasoft.com/image/namirasoft/access/logo/base.png", alt: "Access", onClicked: () => { }, },
|
|
80
|
-
];
|
|
81
|
-
let name = "";
|
|
82
|
-
if (props.pages)
|
|
83
|
-
name = NamingConvention.Pascal_Case.convert(props.pages.entity.name, NamingConvention.Pascal_Case_Space);
|
|
84
|
-
|
|
85
|
-
let user_name = props.account.token_manager.getUserData(user => [user.first_name, user.last_name].filter(n => n).join(" "), "");
|
|
86
|
-
|
|
87
|
-
let action: INSBarActionProps | undefined = props.action;
|
|
88
|
-
if (!action)
|
|
89
|
-
action = { title: "", description: "", menus: {} };
|
|
90
|
-
|
|
91
|
-
let name_apply = "Apply";
|
|
92
|
-
let name_actions = "Actions";
|
|
93
|
-
action.menus[name_apply] = [];
|
|
94
|
-
action.menus[name_actions] = [];
|
|
95
|
-
|
|
96
|
-
let getIDs: (() => string[]) | null = null;
|
|
97
|
-
|
|
98
|
-
if (props.pages?.list)
|
|
99
|
-
getIDs = () => { return Section_List.current?.getSelectedIDs() ?? []; };
|
|
100
|
-
|
|
101
|
-
if (props.pages?.edit)
|
|
102
|
-
{
|
|
103
|
-
let { id } = useParams();
|
|
104
|
-
getIDs = () => [id].filter(id => id) as string[];
|
|
105
|
-
|
|
106
|
-
if (!action.title)
|
|
107
|
-
action.title = (props.pages.edit.isEdit ? "Edit" : "New") + " " + name;
|
|
108
|
-
|
|
109
|
-
// Menu
|
|
110
|
-
if (props.pages.edit.ui.action?.menus.apply ?? true)
|
|
111
|
-
action.menus[name_apply].push(Actions.apply(() =>
|
|
112
|
-
{
|
|
113
|
-
if (props.pages?.edit)
|
|
114
|
-
NSASectionEdit_onApply(props.pages?.edit, props.pages.entity, id);
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
else if (props.pages)
|
|
118
|
-
action.menus[name_apply].push(Actions.new(props, props.pages.entity));
|
|
119
|
-
|
|
120
|
-
if (props.pages?.view)
|
|
121
|
-
{
|
|
122
|
-
getIDs = () => [].filter(id => id) as string[];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (getIDs)
|
|
126
|
-
if (props.pages)
|
|
127
|
-
{
|
|
128
|
-
if (props.pages.ui?.action?.menus.view ?? true)
|
|
129
|
-
action.menus[name_actions].push(Actions.view(props, props.pages.entity, getIDs));
|
|
130
|
-
if (props.pages.ui?.action?.menus.viewHistory ?? true)
|
|
131
|
-
action.menus[name_actions].push(Actions.viewHistory(getIDs));
|
|
132
|
-
if (props.pages.ui?.action?.menus.copy ?? true)
|
|
133
|
-
action.menus[name_actions].push(Actions.copy(props, props.pages.entity, getIDs));
|
|
134
|
-
if (props.pages.ui?.action?.menus.edit ?? true)
|
|
135
|
-
action.menus[name_actions].push(Actions.edit(props, props.pages.entity, getIDs));
|
|
136
|
-
if (props.pages.ui?.action?.menus.delete ?? true)
|
|
137
|
-
action.menus[name_actions].push(Actions.delete(getIDs, showDeleteModal));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let content;
|
|
141
|
-
if (props.pages?.list)
|
|
142
|
-
content = <NSASectionList<EntityType, EntityTypeInput> ref={Section_List} {...props.pages.list} entity={props.pages.entity} />
|
|
143
|
-
else if (props.pages?.edit)
|
|
144
|
-
content = <NSASectionEdit<EntityType, EntityTypeInput> {...props.pages.edit} entity={props.pages.entity}>{props.children}</NSASectionEdit>;
|
|
145
|
-
else if (props.pages?.view)
|
|
146
|
-
content = <NSASectionView {...props.pages.view} entity={props.pages.entity} />;
|
|
147
|
-
else
|
|
148
|
-
content = props.children;
|
|
149
|
-
|
|
150
|
-
return (
|
|
151
|
-
<NSLayout
|
|
152
|
-
{...props}
|
|
153
|
-
header={{
|
|
154
|
-
title: (user_name + " " + (props.header?.title ?? "")).trim(),
|
|
155
|
-
icons: [...icons, ...(props.header?.icons ?? [])]
|
|
156
|
-
}}
|
|
157
|
-
action={{
|
|
158
|
-
title: action?.title ?? "",
|
|
159
|
-
description: action?.description,
|
|
160
|
-
menus: action.menus
|
|
161
|
-
}}
|
|
162
|
-
>
|
|
163
|
-
<div className="container-fluid">
|
|
164
|
-
<NSModal title={`Are you sure you want to delete ${name}?`} description={""} show={state.showDeleteModal}
|
|
165
|
-
onClose={hideDeleteModal} children={<NSButtonRed title="Yes" onClick={async () =>
|
|
166
|
-
{
|
|
167
|
-
try
|
|
168
|
-
{
|
|
169
|
-
if (props.pages)
|
|
170
|
-
if (getIDs)
|
|
171
|
-
{
|
|
172
|
-
let ids = getIDs();
|
|
173
|
-
if (ids.length == 0)
|
|
174
|
-
throw new Error("Nothing was found to delete.");
|
|
175
|
-
if (ids.length == 1)
|
|
176
|
-
{
|
|
177
|
-
await props.pages.entity.server.delete(ids[0]);
|
|
178
|
-
props.notifier.onSuccess(`${name} was deleted successfully.`);
|
|
179
|
-
}
|
|
180
|
-
else
|
|
181
|
-
// todo support multiple ids deletion
|
|
182
|
-
throw new Error("Multiple deletion is not supported yet.");
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
} catch (error: any)
|
|
186
|
-
{
|
|
187
|
-
props.notifier.onError(error);
|
|
188
|
-
}
|
|
189
|
-
}} />} />
|
|
190
|
-
{content}
|
|
191
|
-
</div>
|
|
192
|
-
</NSLayout>
|
|
193
|
-
);
|
|
1
|
+
import { IBaseComponentProps, INSBarActionProps, INSBarHeroBannerProps, INSBarNotificationProps, INSBarTitleProps, NSButtonRed, NSModal } from 'namirasoft-site-react';
|
|
2
|
+
import { NSLayout } from 'namirasoft-site-react';
|
|
3
|
+
import { NSASectionList, NSASectionListProps } from './NSASectionList';
|
|
4
|
+
import { NSASectionEdit, NSASectionEditProps, onApply as NSASectionEdit_onApply } from './NSASectionEdit';
|
|
5
|
+
import { NSASectionView, NSASectionViewProps } from './NSASectionView';
|
|
6
|
+
import { IHeaderProps } from 'namirasoft-site-react';
|
|
7
|
+
import { ReactNode, useRef, useState } from 'react';
|
|
8
|
+
import { Actions } from './Actions';
|
|
9
|
+
import { INSARouterProps } from '../INSARouterProps';
|
|
10
|
+
import { useParams } from 'react-router-dom';
|
|
11
|
+
import { NamingConvention } from 'namirasoft-core';
|
|
12
|
+
import { IEntityInfo } from '../IEntityInfo';
|
|
13
|
+
import { NSAMessageDialog } from '../main';
|
|
14
|
+
|
|
15
|
+
export interface NSALayoutProps<EntityType extends { id: string }, EntityTypeInput = EntityType> extends IBaseComponentProps, INSARouterProps
|
|
16
|
+
{
|
|
17
|
+
scope: string;
|
|
18
|
+
logo: string;
|
|
19
|
+
background?: string;
|
|
20
|
+
header?: IHeaderProps;
|
|
21
|
+
notifications: INSBarNotificationProps[];
|
|
22
|
+
action?: INSBarActionProps;
|
|
23
|
+
banner?: INSBarHeroBannerProps;
|
|
24
|
+
title?: INSBarTitleProps;
|
|
25
|
+
pages?: {
|
|
26
|
+
entity: IEntityInfo<EntityType, EntityTypeInput>;
|
|
27
|
+
ui?: {
|
|
28
|
+
action?: {
|
|
29
|
+
menus: {
|
|
30
|
+
view?: boolean,
|
|
31
|
+
viewHistory?: boolean,
|
|
32
|
+
copy?: boolean,
|
|
33
|
+
edit?: boolean,
|
|
34
|
+
delete?: boolean,
|
|
35
|
+
apply?: boolean,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
list?: NSASectionListProps;
|
|
40
|
+
edit?: NSASectionEditProps<EntityType, EntityTypeInput>;
|
|
41
|
+
view?: NSASectionViewProps;
|
|
42
|
+
}
|
|
43
|
+
children: ReactNode;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface NSALayoutState
|
|
47
|
+
{
|
|
48
|
+
showDeleteModal: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function NSALayout<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSALayoutProps<EntityType, EntityTypeInput>)
|
|
52
|
+
{
|
|
53
|
+
const Section_List = useRef<NSASectionList<EntityType, EntityTypeInput>>(null);
|
|
54
|
+
const Message_Dialog = useRef<NSAMessageDialog>(null);
|
|
55
|
+
|
|
56
|
+
const [state, setState] = useState<NSALayoutState>({ showDeleteModal: false });
|
|
57
|
+
const hideDeleteModal = () => { setState(prevState => ({ ...prevState, showDeleteModal: false })); };
|
|
58
|
+
const showDeleteModal = () => { setState(prevState => ({ ...prevState, showDeleteModal: true })); };
|
|
59
|
+
|
|
60
|
+
let icons = [
|
|
61
|
+
{
|
|
62
|
+
src: "https://static.namirasoft.com/image/concept/logout/white.svg", alt: "Logout", onClicked: () =>
|
|
63
|
+
{
|
|
64
|
+
props.account.server.session.Logout().then(() =>
|
|
65
|
+
{
|
|
66
|
+
props.notifier.onSuccess("You have successfully logged out");
|
|
67
|
+
props.url.redirect("https://account.namirasoft.com/login", {});
|
|
68
|
+
}).catch(() => { });
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
src: "https://static.namirasoft.com/image/concept/message/white.svg", alt: "Message", onClicked: () =>
|
|
73
|
+
{
|
|
74
|
+
Message_Dialog.current?.show();
|
|
75
|
+
},
|
|
76
|
+
children: <NSAMessageDialog ref={Message_Dialog} />,
|
|
77
|
+
count: 1
|
|
78
|
+
},
|
|
79
|
+
{ src: "https://static.namirasoft.com/image/namirasoft/access/logo/base.png", alt: "Access", onClicked: () => { }, },
|
|
80
|
+
];
|
|
81
|
+
let name = "";
|
|
82
|
+
if (props.pages)
|
|
83
|
+
name = NamingConvention.Pascal_Case.convert(props.pages.entity.name, NamingConvention.Pascal_Case_Space);
|
|
84
|
+
|
|
85
|
+
let user_name = props.account.token_manager.getUserData(user => [user.first_name, user.last_name].filter(n => n).join(" "), "");
|
|
86
|
+
|
|
87
|
+
let action: INSBarActionProps | undefined = props.action;
|
|
88
|
+
if (!action)
|
|
89
|
+
action = { title: "", description: "", menus: {} };
|
|
90
|
+
|
|
91
|
+
let name_apply = "Apply";
|
|
92
|
+
let name_actions = "Actions";
|
|
93
|
+
action.menus[name_apply] = [];
|
|
94
|
+
action.menus[name_actions] = [];
|
|
95
|
+
|
|
96
|
+
let getIDs: (() => string[]) | null = null;
|
|
97
|
+
|
|
98
|
+
if (props.pages?.list)
|
|
99
|
+
getIDs = () => { return Section_List.current?.getSelectedIDs() ?? []; };
|
|
100
|
+
|
|
101
|
+
if (props.pages?.edit)
|
|
102
|
+
{
|
|
103
|
+
let { id } = useParams();
|
|
104
|
+
getIDs = () => [id].filter(id => id) as string[];
|
|
105
|
+
|
|
106
|
+
if (!action.title)
|
|
107
|
+
action.title = (props.pages.edit.isEdit ? "Edit" : "New") + " " + name;
|
|
108
|
+
|
|
109
|
+
// Menu
|
|
110
|
+
if (props.pages.edit.ui.action?.menus.apply ?? true)
|
|
111
|
+
action.menus[name_apply].push(Actions.apply(() =>
|
|
112
|
+
{
|
|
113
|
+
if (props.pages?.edit)
|
|
114
|
+
NSASectionEdit_onApply(props.pages?.edit, props.pages.entity, id);
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
else if (props.pages)
|
|
118
|
+
action.menus[name_apply].push(Actions.new(props, props.pages.entity));
|
|
119
|
+
|
|
120
|
+
if (props.pages?.view)
|
|
121
|
+
{
|
|
122
|
+
getIDs = () => [].filter(id => id) as string[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (getIDs)
|
|
126
|
+
if (props.pages)
|
|
127
|
+
{
|
|
128
|
+
if (props.pages.ui?.action?.menus.view ?? true)
|
|
129
|
+
action.menus[name_actions].push(Actions.view(props, props.pages.entity, getIDs));
|
|
130
|
+
if (props.pages.ui?.action?.menus.viewHistory ?? true)
|
|
131
|
+
action.menus[name_actions].push(Actions.viewHistory(getIDs));
|
|
132
|
+
if (props.pages.ui?.action?.menus.copy ?? true)
|
|
133
|
+
action.menus[name_actions].push(Actions.copy(props, props.pages.entity, getIDs));
|
|
134
|
+
if (props.pages.ui?.action?.menus.edit ?? true)
|
|
135
|
+
action.menus[name_actions].push(Actions.edit(props, props.pages.entity, getIDs));
|
|
136
|
+
if (props.pages.ui?.action?.menus.delete ?? true)
|
|
137
|
+
action.menus[name_actions].push(Actions.delete(getIDs, showDeleteModal));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let content;
|
|
141
|
+
if (props.pages?.list)
|
|
142
|
+
content = <NSASectionList<EntityType, EntityTypeInput> ref={Section_List} {...props.pages.list} entity={props.pages.entity} />
|
|
143
|
+
else if (props.pages?.edit)
|
|
144
|
+
content = <NSASectionEdit<EntityType, EntityTypeInput> {...props.pages.edit} entity={props.pages.entity}>{props.children}</NSASectionEdit>;
|
|
145
|
+
else if (props.pages?.view)
|
|
146
|
+
content = <NSASectionView {...props.pages.view} entity={props.pages.entity} />;
|
|
147
|
+
else
|
|
148
|
+
content = props.children;
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<NSLayout
|
|
152
|
+
{...props}
|
|
153
|
+
header={{
|
|
154
|
+
title: (user_name + " " + (props.header?.title ?? "")).trim(),
|
|
155
|
+
icons: [...icons, ...(props.header?.icons ?? [])]
|
|
156
|
+
}}
|
|
157
|
+
action={{
|
|
158
|
+
title: action?.title ?? "",
|
|
159
|
+
description: action?.description,
|
|
160
|
+
menus: action.menus
|
|
161
|
+
}}
|
|
162
|
+
>
|
|
163
|
+
<div className="container-fluid">
|
|
164
|
+
<NSModal title={`Are you sure you want to delete ${name}?`} description={""} show={state.showDeleteModal}
|
|
165
|
+
onClose={hideDeleteModal} children={<NSButtonRed title="Yes" onClick={async () =>
|
|
166
|
+
{
|
|
167
|
+
try
|
|
168
|
+
{
|
|
169
|
+
if (props.pages)
|
|
170
|
+
if (getIDs)
|
|
171
|
+
{
|
|
172
|
+
let ids = getIDs();
|
|
173
|
+
if (ids.length == 0)
|
|
174
|
+
throw new Error("Nothing was found to delete.");
|
|
175
|
+
if (ids.length == 1)
|
|
176
|
+
{
|
|
177
|
+
await props.pages.entity.server.delete(ids[0]);
|
|
178
|
+
props.notifier.onSuccess(`${name} was deleted successfully.`);
|
|
179
|
+
}
|
|
180
|
+
else
|
|
181
|
+
// todo support multiple ids deletion
|
|
182
|
+
throw new Error("Multiple deletion is not supported yet.");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
} catch (error: any)
|
|
186
|
+
{
|
|
187
|
+
props.notifier.onError(error);
|
|
188
|
+
}
|
|
189
|
+
}} />} />
|
|
190
|
+
{content}
|
|
191
|
+
</div>
|
|
192
|
+
</NSLayout>
|
|
193
|
+
);
|
|
194
194
|
}
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
import { IBaseComponentProps } from "namirasoft-site-react";
|
|
2
|
-
import { NSSection, NSPanel, NSButtonBlue, NSLine, NSSpace, NSSpaceSizeType } from 'namirasoft-site-react';
|
|
3
|
-
import { INSARouterProps } from "../INSARouterProps";
|
|
4
|
-
import { ReactNode, useEffect } from "react";
|
|
5
|
-
import { useParams } from "react-router-dom";
|
|
6
|
-
import { IEntityInfo } from "../IEntityInfo";
|
|
7
|
-
import { NamingConvention } from "namirasoft-core";
|
|
8
|
-
import { NSASectionTabs } from "./NSASectionTabs";
|
|
9
|
-
|
|
10
|
-
export interface NSASectionEditProps<EntityType extends { id: string }, EntityTypeInput = EntityType> extends IBaseComponentProps, INSARouterProps
|
|
11
|
-
{
|
|
12
|
-
isEdit: boolean;
|
|
13
|
-
ui: {
|
|
14
|
-
getEntity: (entity: EntityType | null) => EntityTypeInput;
|
|
15
|
-
setEntity: (entity: EntityType) => void;
|
|
16
|
-
action?: {
|
|
17
|
-
menus: {
|
|
18
|
-
apply?: boolean,
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function onApply<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSASectionEditProps<EntityType, EntityTypeInput>, entity: IEntityInfo<EntityType, EntityTypeInput>, id: string | undefined): void
|
|
25
|
-
{
|
|
26
|
-
try
|
|
27
|
-
{
|
|
28
|
-
let name = NamingConvention.Pascal_Case.convert(entity.name, NamingConvention.Pascal_Case_Space);
|
|
29
|
-
|
|
30
|
-
let onSuccess = (new_entity: EntityType, message: string) =>
|
|
31
|
-
{
|
|
32
|
-
props.notifier.onSuccess(message);
|
|
33
|
-
if (entity.client.onSuccess)
|
|
34
|
-
entity.client.onSuccess(new_entity);
|
|
35
|
-
else
|
|
36
|
-
{
|
|
37
|
-
let url = entity.client.getViewURL(new_entity.id);
|
|
38
|
-
if (!url)
|
|
39
|
-
url = entity.client.getListURL();
|
|
40
|
-
props.url.redirect(url, {});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
let old_entity: EntityType | null = null;
|
|
44
|
-
let cur_entity = props.ui.getEntity(old_entity);
|
|
45
|
-
if (props.isEdit)
|
|
46
|
-
{
|
|
47
|
-
if (id)
|
|
48
|
-
entity.server.update(id, cur_entity).then((new_entity) =>
|
|
49
|
-
{
|
|
50
|
-
onSuccess(new_entity, name + " has been updated successfully");
|
|
51
|
-
}).catch(() => { });
|
|
52
|
-
else
|
|
53
|
-
throw new Error("ID was not provided.");
|
|
54
|
-
}
|
|
55
|
-
else
|
|
56
|
-
{
|
|
57
|
-
entity.server.create(cur_entity).then((new_entity) =>
|
|
58
|
-
{
|
|
59
|
-
onSuccess(new_entity, name + " has been created successfully");
|
|
60
|
-
}).catch(() => { });
|
|
61
|
-
}
|
|
62
|
-
} catch (error: any)
|
|
63
|
-
{
|
|
64
|
-
props.notifier.onError(error);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function NSASectionEdit<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSASectionEditProps<EntityType, EntityTypeInput> & { entity: IEntityInfo<EntityType, EntityTypeInput>, children: ReactNode; })
|
|
69
|
-
{
|
|
70
|
-
let { id } = useParams();
|
|
71
|
-
|
|
72
|
-
useEffect(() =>
|
|
73
|
-
{
|
|
74
|
-
if (id)
|
|
75
|
-
props.entity.server.get(id).then((entity) =>
|
|
76
|
-
{
|
|
77
|
-
props.ui.setEntity(entity);
|
|
78
|
-
}).catch(() => { });
|
|
79
|
-
}, [id]);
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<NSSection
|
|
83
|
-
id={props.id}
|
|
84
|
-
classList={[`${props.classList?.join(" ")}`]}
|
|
85
|
-
center_items={true}
|
|
86
|
-
>
|
|
87
|
-
<NSPanel grid={false}>
|
|
88
|
-
{props.children}
|
|
89
|
-
</NSPanel>
|
|
90
|
-
<NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
|
|
91
|
-
<NSButtonBlue title="Apply" onClick={() => { onApply(props, props.entity, id); }} />
|
|
92
|
-
<NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
|
|
93
|
-
{props.isEdit && <NSLine />}
|
|
94
|
-
{props.isEdit && <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>}
|
|
95
|
-
{props.isEdit && <NSASectionTabs entity={props.entity} id={id ?? ""} />}
|
|
96
|
-
</NSSection>
|
|
97
|
-
);
|
|
1
|
+
import { IBaseComponentProps } from "namirasoft-site-react";
|
|
2
|
+
import { NSSection, NSPanel, NSButtonBlue, NSLine, NSSpace, NSSpaceSizeType } from 'namirasoft-site-react';
|
|
3
|
+
import { INSARouterProps } from "../INSARouterProps";
|
|
4
|
+
import { ReactNode, useEffect } from "react";
|
|
5
|
+
import { useParams } from "react-router-dom";
|
|
6
|
+
import { IEntityInfo } from "../IEntityInfo";
|
|
7
|
+
import { NamingConvention } from "namirasoft-core";
|
|
8
|
+
import { NSASectionTabs } from "./NSASectionTabs";
|
|
9
|
+
|
|
10
|
+
export interface NSASectionEditProps<EntityType extends { id: string }, EntityTypeInput = EntityType> extends IBaseComponentProps, INSARouterProps
|
|
11
|
+
{
|
|
12
|
+
isEdit: boolean;
|
|
13
|
+
ui: {
|
|
14
|
+
getEntity: (entity: EntityType | null) => EntityTypeInput;
|
|
15
|
+
setEntity: (entity: EntityType) => void;
|
|
16
|
+
action?: {
|
|
17
|
+
menus: {
|
|
18
|
+
apply?: boolean,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function onApply<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSASectionEditProps<EntityType, EntityTypeInput>, entity: IEntityInfo<EntityType, EntityTypeInput>, id: string | undefined): void
|
|
25
|
+
{
|
|
26
|
+
try
|
|
27
|
+
{
|
|
28
|
+
let name = NamingConvention.Pascal_Case.convert(entity.name, NamingConvention.Pascal_Case_Space);
|
|
29
|
+
|
|
30
|
+
let onSuccess = (new_entity: EntityType, message: string) =>
|
|
31
|
+
{
|
|
32
|
+
props.notifier.onSuccess(message);
|
|
33
|
+
if (entity.client.onSuccess)
|
|
34
|
+
entity.client.onSuccess(new_entity);
|
|
35
|
+
else
|
|
36
|
+
{
|
|
37
|
+
let url = entity.client.getViewURL(new_entity.id);
|
|
38
|
+
if (!url)
|
|
39
|
+
url = entity.client.getListURL();
|
|
40
|
+
props.url.redirect(url, {});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
let old_entity: EntityType | null = null;
|
|
44
|
+
let cur_entity = props.ui.getEntity(old_entity);
|
|
45
|
+
if (props.isEdit)
|
|
46
|
+
{
|
|
47
|
+
if (id)
|
|
48
|
+
entity.server.update(id, cur_entity).then((new_entity) =>
|
|
49
|
+
{
|
|
50
|
+
onSuccess(new_entity, name + " has been updated successfully");
|
|
51
|
+
}).catch(() => { });
|
|
52
|
+
else
|
|
53
|
+
throw new Error("ID was not provided.");
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
{
|
|
57
|
+
entity.server.create(cur_entity).then((new_entity) =>
|
|
58
|
+
{
|
|
59
|
+
onSuccess(new_entity, name + " has been created successfully");
|
|
60
|
+
}).catch(() => { });
|
|
61
|
+
}
|
|
62
|
+
} catch (error: any)
|
|
63
|
+
{
|
|
64
|
+
props.notifier.onError(error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function NSASectionEdit<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSASectionEditProps<EntityType, EntityTypeInput> & { entity: IEntityInfo<EntityType, EntityTypeInput>, children: ReactNode; })
|
|
69
|
+
{
|
|
70
|
+
let { id } = useParams();
|
|
71
|
+
|
|
72
|
+
useEffect(() =>
|
|
73
|
+
{
|
|
74
|
+
if (id)
|
|
75
|
+
props.entity.server.get(id).then((entity) =>
|
|
76
|
+
{
|
|
77
|
+
props.ui.setEntity(entity);
|
|
78
|
+
}).catch(() => { });
|
|
79
|
+
}, [id]);
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<NSSection
|
|
83
|
+
id={props.id}
|
|
84
|
+
classList={[`${props.classList?.join(" ")}`]}
|
|
85
|
+
center_items={true}
|
|
86
|
+
>
|
|
87
|
+
<NSPanel grid={false}>
|
|
88
|
+
{props.children}
|
|
89
|
+
</NSPanel>
|
|
90
|
+
<NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
|
|
91
|
+
<NSButtonBlue title="Apply" onClick={() => { onApply(props, props.entity, id); }} />
|
|
92
|
+
<NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
|
|
93
|
+
{props.isEdit && <NSLine />}
|
|
94
|
+
{props.isEdit && <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>}
|
|
95
|
+
{props.isEdit && <NSASectionTabs entity={props.entity} id={id ?? ""} />}
|
|
96
|
+
</NSSection>
|
|
97
|
+
);
|
|
98
98
|
}
|