@kaspernj/api-maker 1.0.306 → 1.0.307
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/package.json +1 -1
- package/src/super-admin/index.jsx +35 -11
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {digg} from "diggerize"
|
|
2
1
|
import EditPage from "./edit-page"
|
|
3
2
|
import IndexPage from "./index-page"
|
|
4
3
|
import Layout from "./layout"
|
|
5
4
|
import Link from "../link"
|
|
6
5
|
import {memo, useMemo} from "react"
|
|
7
6
|
import * as modelsModule from "@kaspernj/api-maker/src/models.mjs.erb"
|
|
7
|
+
import {useCallback} from "react"
|
|
8
8
|
import ShowPage from "./show-page"
|
|
9
9
|
import ShowReflectionPage from "./show-reflection-page"
|
|
10
10
|
import useQueryParams from "on-location-changed/src/use-query-params"
|
|
@@ -15,6 +15,9 @@ const ApiMakerSuperAdmin = () => {
|
|
|
15
15
|
|
|
16
16
|
if (queryParams.model) modelClass = modelsModule[queryParams.model]
|
|
17
17
|
|
|
18
|
+
const modelId = queryParams.model_id
|
|
19
|
+
const modelName = modelClass?.modelClassData()?.name
|
|
20
|
+
|
|
18
21
|
if (queryParams.model && queryParams.model_id && queryParams.model_reflection) {
|
|
19
22
|
pageToShow = "show_reflection"
|
|
20
23
|
} else if (queryParams.model && queryParams.model_id && queryParams.mode == "edit") {
|
|
@@ -29,17 +32,38 @@ const ApiMakerSuperAdmin = () => {
|
|
|
29
32
|
pageToShow = "welcome"
|
|
30
33
|
}
|
|
31
34
|
|
|
35
|
+
const onDestroyClicked = useCallback(async (e) => {
|
|
36
|
+
e.preventDefault()
|
|
37
|
+
|
|
38
|
+
if (!confirm("Are you sure?")) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const model = await modelClass.find(modelId)
|
|
44
|
+
|
|
45
|
+
await model.destroy()
|
|
46
|
+
} catch (error) {
|
|
47
|
+
FlashMessage.errorResponse(error)
|
|
48
|
+
}
|
|
49
|
+
}, [modelName, modelId])
|
|
50
|
+
|
|
32
51
|
const actions = useMemo(
|
|
33
52
|
() => <>
|
|
34
53
|
{modelClass && pageToShow == "index" &&
|
|
35
|
-
<Link className="create-new-model-link" to={Params.withParams({model:
|
|
54
|
+
<Link className="create-new-model-link" to={Params.withParams({model: modelName, mode: "new"})}>
|
|
36
55
|
Create new
|
|
37
56
|
</Link>
|
|
38
57
|
}
|
|
39
58
|
{modelClass && pageToShow == "show" &&
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
<>
|
|
60
|
+
<Link to={Params.withParams({model: modelName, model_id: modelId, mode: "edit"})}>
|
|
61
|
+
Edit
|
|
62
|
+
</Link>
|
|
63
|
+
<a href="#" onClick={onDestroyClicked}>
|
|
64
|
+
Delete
|
|
65
|
+
</a>
|
|
66
|
+
</>
|
|
43
67
|
}
|
|
44
68
|
</>,
|
|
45
69
|
[modelClass, pageToShow]
|
|
@@ -49,27 +73,27 @@ const ApiMakerSuperAdmin = () => {
|
|
|
49
73
|
<Layout actions={actions} active={queryParams.model} headerTitle={modelClass?.modelName()?.human({count: 2})}>
|
|
50
74
|
{pageToShow == "index" &&
|
|
51
75
|
<IndexPage
|
|
52
|
-
key={`index-page-${
|
|
76
|
+
key={`index-page-${modelName}`}
|
|
53
77
|
modelClass={modelClass}
|
|
54
78
|
/>
|
|
55
79
|
}
|
|
56
80
|
{pageToShow == "show" &&
|
|
57
81
|
<ShowPage
|
|
58
|
-
key={`show-page-${
|
|
82
|
+
key={`show-page-${modelName}-${modelId}`}
|
|
59
83
|
modelClass={modelClass}
|
|
60
|
-
modelId={
|
|
84
|
+
modelId={modelId}
|
|
61
85
|
/>
|
|
62
86
|
}
|
|
63
87
|
{pageToShow == "show_reflection" &&
|
|
64
88
|
<ShowReflectionPage
|
|
65
|
-
key={`show-reflection-page-${
|
|
89
|
+
key={`show-reflection-page-${modelName}-${modelId}`}
|
|
66
90
|
modelClass={modelClass}
|
|
67
|
-
modelId={
|
|
91
|
+
modelId={modelId}
|
|
68
92
|
/>
|
|
69
93
|
}
|
|
70
94
|
{pageToShow == "edit" &&
|
|
71
95
|
<EditPage
|
|
72
|
-
key={`edit-page-${
|
|
96
|
+
key={`edit-page-${modelName}-${modelId}`}
|
|
73
97
|
modelClass={modelClass}
|
|
74
98
|
/>
|
|
75
99
|
}
|