@@ -2,9 +2,10 @@ import {useRenameFolderMutation} from "@/features/nodes/apiSlice"
2
2
import type { EditEntityTitle } from "@/types"
3
3
import type { I18NEditNodeTitleModal } from "kommon"
4
4
import { EditNodeTitleModal } from "kommon"
5
- import { ChangeEvent , useEffect , useRef , useState } from "react"
5
+ import { ChangeEvent , useEffect , useState } from "react"
6
6
7
7
import { useTranslation } from "react-i18next"
8
+ import { useEnterSubmit } from "./useEnterSubmit"
8
9
9
10
interface Args {
10
11
node : EditEntityTitle
@@ -21,34 +22,14 @@ export const EditNodeTitleModalContainer = ({
21
22
} : Args ) => {
22
23
const txt = useI18nText ( )
23
24
const [ renameFolder , { isLoading} ] = useRenameFolderMutation ( )
24
- const ref = useRef < HTMLButtonElement > ( null )
25
25
const [ title , setTitle ] = useState ( node . title )
26
26
const [ error , setError ] = useState ( "" )
27
27
28
- useEffect ( ( ) => {
29
- // handle "enter" keyboard press
30
- document . addEventListener ( "keydown" , handleKeydown , false )
31
-
32
- return ( ) => {
33
- document . removeEventListener ( "keydown" , handleKeydown , false )
34
- }
35
- } , [ ] )
36
-
37
28
const handleTitleChanged = ( event : ChangeEvent < HTMLInputElement > ) => {
38
29
let value = event . currentTarget . value
39
30
setTitle ( value )
40
31
}
41
32
42
- const handleKeydown = async ( e : KeyboardEvent ) => {
43
- switch ( e . code ) {
44
- case "Enter" :
45
- if ( ref . current ) {
46
- ref . current . click ( )
47
- }
48
- break
49
- }
50
- }
51
-
52
33
const onLocalSubmit = async ( ) => {
53
34
const data = {
54
35
title : title ,
@@ -60,11 +41,12 @@ export const EditNodeTitleModalContainer = ({
60
41
onSubmit ( )
61
42
reset ( ) // sets error message back to empty string
62
43
} catch ( error : any ) {
63
- // @ts -ignore
64
- setError ( err . data . detail )
44
+ setError ( error ?. data ?. detail ?? "Something went wrong" )
65
45
}
66
46
}
67
47
48
+ useEnterSubmit ( onLocalSubmit )
49
+
68
50
const onLocalCancel = ( ) => {
69
51
onCancel ( )
70
52
reset ( )
@@ -110,34 +92,3 @@ function useI18nText(): I18NEditNodeTitleModal | undefined {
110
92
}
111
93
112
94
export default EditNodeTitleModalContainer
113
-
114
- /****
115
- *
116
- *
117
- * <Modal title={"Edit Title"} opened={opened} onClose={onLocalCancel}>
118
- <TextInput
119
- data-autofocus
120
- onChange={handleTitleChanged}
121
- value={title}
122
- label="New Title"
123
- placeholder="title"
124
- mt="md"
125
- />
126
- {error && <Error message={error} /> }
127
-
128
- <Group justify="space-between" mt="md">
129
- <Button variant="default" onClick={onLocalCancel}>
130
- {t("common.cancel")}
131
- </Button>
132
- <Group>
133
- {isLoading && <Loader size="sm" />}
134
- <Button ref={ref} disabled={isLoading} onClick={onLocalSubmit}>
135
- {t("common.submit")}
136
- </Button>
137
- </Group>
138
- </Group>
139
- </Modal>
140
- *
141
- *
142
- *
143
- */
0 commit comments