1
1
import { useState } from 'react'
2
+ import { GoPencil , GrPencil } from '@react-icons/all-files/go/GoPencil'
3
+ import { GoCheck } from '@react-icons/all-files/go/GoCheck'
2
4
import { graphql , useFragment , useMutation } from 'react-relay'
3
5
import { Bio_user$key } from '../../queries/__generated__/Bio_user.graphql'
4
6
@@ -18,6 +20,7 @@ const Bio = ({ user }: BioProps) => {
18
20
)
19
21
20
22
const [ bio , setBio ] = useState ( data . bio )
23
+ const [ editMode , setEditMode ] = useState ( false )
21
24
22
25
const [ commitMutation , isMutationInFlight ] = useMutation (
23
26
graphql `
@@ -29,8 +32,10 @@ const Bio = ({ user }: BioProps) => {
29
32
}
30
33
`
31
34
)
32
- const onChange = ( evt : any ) => setBio ( evt . target . value )
35
+ const onChange = ( evt : React . ChangeEvent < HTMLInputElement > ) =>
36
+ setBio ( evt . target . value )
33
37
const onSubmit = ( ) => {
38
+ setEditMode ( false )
34
39
commitMutation ( {
35
40
variables : {
36
41
input : { id : data . id , bio : bio } ,
@@ -39,13 +44,30 @@ const Bio = ({ user }: BioProps) => {
39
44
}
40
45
41
46
return (
42
- < input
43
- onChange = { onChange }
44
- onBlur = { onSubmit }
45
- className = "dark:text-gray-300"
46
- type = "text"
47
- defaultValue = { data . bio }
48
- />
47
+ < div >
48
+ { editMode ? (
49
+ < div className = "flex justify-between" >
50
+ < input
51
+ onChange = { onChange }
52
+ onBlur = { onSubmit }
53
+ className = "dark:text-gray-300 dark:bg-dark-600"
54
+ type = "text"
55
+ disabled = { isMutationInFlight }
56
+ defaultValue = { data . bio }
57
+ />
58
+ < button onClick = { ( ) => setEditMode ( false ) } >
59
+ < GoCheck />
60
+ </ button >
61
+ </ div >
62
+ ) : (
63
+ < div className = "flex justify-between" >
64
+ < span > { data . bio } </ span >
65
+ < button onClick = { ( ) => setEditMode ( true ) } >
66
+ < GoPencil />
67
+ </ button >
68
+ </ div >
69
+ ) }
70
+ </ div >
49
71
)
50
72
}
51
73
0 commit comments