create-mercato-app 0.6.4-develop.4363.1.2f376570ae → 0.6.4-develop.4371.1.8f3030407e
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/template/src/modules/example/backend/todos/[id]/edit/page.tsx +28 -4
- package/template/src/modules/example/i18n/de.json +1 -0
- package/template/src/modules/example/i18n/en.json +1 -0
- package/template/src/modules/example/i18n/es.json +1 -0
- package/template/src/modules/example/i18n/pl.json +1 -0
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import * as React from 'react'
|
|
|
3
3
|
import { useRouter } from 'next/navigation'
|
|
4
4
|
import { Page, PageBody } from '@open-mercato/ui/backend/Page'
|
|
5
5
|
import { CrudForm, type CrudField, type CrudFormGroup } from '@open-mercato/ui/backend/CrudForm'
|
|
6
|
+
import { ErrorMessage, RecordNotFoundState } from '@open-mercato/ui/backend/detail'
|
|
6
7
|
import { fetchCrudList, updateCrud, deleteCrud } from '@open-mercato/ui/backend/utils/crud'
|
|
7
8
|
import { pushWithFlash } from '@open-mercato/ui/backend/utils/flash'
|
|
8
9
|
import { SendObjectMessageDialog } from '@open-mercato/ui/backend/messages'
|
|
@@ -25,6 +26,7 @@ export default function EditTodoPage({ params }: { params?: { id?: string } }) {
|
|
|
25
26
|
const [initial, setInitial] = React.useState<TodoFormValues | null>(null)
|
|
26
27
|
const [loading, setLoading] = React.useState(true)
|
|
27
28
|
const [err, setErr] = React.useState<string | null>(null)
|
|
29
|
+
const [isNotFound, setIsNotFound] = React.useState(false)
|
|
28
30
|
// Memoize fields to avoid recreating arrays/objects each render (prevents focus loss)
|
|
29
31
|
const baseFields = React.useMemo<CrudField[]>(() => [
|
|
30
32
|
{
|
|
@@ -76,10 +78,14 @@ export default function EditTodoPage({ params }: { params?: { id?: string } }) {
|
|
|
76
78
|
if (!id) return
|
|
77
79
|
setLoading(true)
|
|
78
80
|
setErr(null)
|
|
81
|
+
setIsNotFound(false)
|
|
79
82
|
try {
|
|
80
83
|
const data = await fetchCrudList<TodoItem>('example/todos', { id: String(id), pageSize: 1 })
|
|
81
84
|
const item = data?.items?.[0]
|
|
82
|
-
if (!item)
|
|
85
|
+
if (!item) {
|
|
86
|
+
if (!cancelled) setIsNotFound(true)
|
|
87
|
+
return
|
|
88
|
+
}
|
|
83
89
|
// Map to form initial values
|
|
84
90
|
const extended = item as TodoItem & Record<string, unknown>
|
|
85
91
|
const cfInit = extractCustomFieldEntries(extended) as Partial<TodoCustomFieldValues>
|
|
@@ -92,8 +98,12 @@ export default function EditTodoPage({ params }: { params?: { id?: string } }) {
|
|
|
92
98
|
if (!cancelled) setInitial(init)
|
|
93
99
|
} catch (error: unknown) {
|
|
94
100
|
if (!cancelled) {
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
if ((error as { status?: number }).status === 404) {
|
|
102
|
+
setIsNotFound(true)
|
|
103
|
+
} else {
|
|
104
|
+
const message = error instanceof Error && error.message ? error.message : t('example.todos.form.error.load')
|
|
105
|
+
setErr(message)
|
|
106
|
+
}
|
|
97
107
|
}
|
|
98
108
|
} finally {
|
|
99
109
|
if (!cancelled) setLoading(false)
|
|
@@ -111,11 +121,25 @@ export default function EditTodoPage({ params }: { params?: { id?: string } }) {
|
|
|
111
121
|
|
|
112
122
|
if (!id) return null
|
|
113
123
|
|
|
124
|
+
if (isNotFound) {
|
|
125
|
+
return (
|
|
126
|
+
<Page>
|
|
127
|
+
<PageBody>
|
|
128
|
+
<RecordNotFoundState
|
|
129
|
+
label={t('example.todos.form.error.notFound')}
|
|
130
|
+
backHref="/backend/todos"
|
|
131
|
+
backLabel={t('example.todos.form.actions.backToList', 'Back to todos')}
|
|
132
|
+
/>
|
|
133
|
+
</PageBody>
|
|
134
|
+
</Page>
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
114
138
|
return (
|
|
115
139
|
<Page>
|
|
116
140
|
<PageBody>
|
|
117
141
|
{err ? (
|
|
118
|
-
<
|
|
142
|
+
<ErrorMessage label={err} />
|
|
119
143
|
) : (
|
|
120
144
|
<CrudForm<TodoFormValues>
|
|
121
145
|
title={t('example.todos.form.edit.title')}
|
|
@@ -208,6 +208,7 @@
|
|
|
208
208
|
"example.salesTodos.tabLabel": "Aufgaben (Beispiel)",
|
|
209
209
|
"example.todos.create.title": "To-do erstellen",
|
|
210
210
|
"example.todos.edit.title": "To-do bearbeiten",
|
|
211
|
+
"example.todos.form.actions.backToList": "Zurück zu Aufgaben",
|
|
211
212
|
"example.todos.form.create.submit": "To-do erstellen",
|
|
212
213
|
"example.todos.form.create.title": "To-do erstellen",
|
|
213
214
|
"example.todos.form.edit.submit": "Speichern",
|
|
@@ -208,6 +208,7 @@
|
|
|
208
208
|
"example.salesTodos.tabLabel": "Todos (example)",
|
|
209
209
|
"example.todos.create.title": "Create Todo",
|
|
210
210
|
"example.todos.edit.title": "Edit Todo",
|
|
211
|
+
"example.todos.form.actions.backToList": "Back to todos",
|
|
211
212
|
"example.todos.form.create.submit": "Create Todo",
|
|
212
213
|
"example.todos.form.create.title": "Create Todo",
|
|
213
214
|
"example.todos.form.edit.submit": "Save",
|
|
@@ -208,6 +208,7 @@
|
|
|
208
208
|
"example.salesTodos.tabLabel": "Tareas (ejemplo)",
|
|
209
209
|
"example.todos.create.title": "Crear tarea",
|
|
210
210
|
"example.todos.edit.title": "Editar tarea",
|
|
211
|
+
"example.todos.form.actions.backToList": "Volver a tareas",
|
|
211
212
|
"example.todos.form.create.submit": "Crear tarea",
|
|
212
213
|
"example.todos.form.create.title": "Crear tarea",
|
|
213
214
|
"example.todos.form.edit.submit": "Guardar",
|
|
@@ -208,6 +208,7 @@
|
|
|
208
208
|
"example.salesTodos.tabLabel": "Zadania (przykład)",
|
|
209
209
|
"example.todos.create.title": "Utwórz zadanie",
|
|
210
210
|
"example.todos.edit.title": "Edytuj zadanie",
|
|
211
|
+
"example.todos.form.actions.backToList": "Powrót do zadań",
|
|
211
212
|
"example.todos.form.create.submit": "Utwórz zadanie",
|
|
212
213
|
"example.todos.form.create.title": "Utwórz zadanie",
|
|
213
214
|
"example.todos.form.edit.submit": "Zapisz",
|