1- import { useState , useEffect } from 'react'
1+ import { useState , useEffect , useRef } from 'react'
22import { TextField , Button , Box } from '@mui/material'
33import { useTranslation } from 'react-i18next'
44import { useDispatch , useSelector } from 'react-redux'
55import ReactMarkdown from 'react-markdown'
6- import { getLockHttp } from '../../../util/redux/formReducer'
6+ import { clearFormState , getLockHttp , updateFormField } from '../../../util/redux/formReducer'
77import { RootState } from '../../../util/store'
8- import { wsJoinRoom } from '../../../util/redux/websocketReducer'
98import { releaseFieldLocally } from '../../../util/redux/currentEditorsReducer'
109import { deepCheck } from '../../Generic/Textarea'
11- import { updateReportHttp , getReports } from '../../../util/redux/reportsReducer'
10+ import { updateReportHttp } from '../../../util/redux/reportsReducer'
1211
13- const TextFieldComponent = ( { id } : { id : string } ) => {
12+ const TextFieldComponent = ( { id, type } : { id : string , type : string } ) => {
1413 const { t } = useTranslation ( )
1514 const dispatch = useDispatch ( )
1615
@@ -22,12 +21,6 @@ const TextFieldComponent = ({ id }: { id: string }) => {
2221 const dataFromRedux = useSelector ( ( { form } : { form : any } ) => form . data [ id ] || '' )
2322 const currentEditors = useSelector ( ( { currentEditors } : { currentEditors : any } ) => currentEditors . data , deepCheck )
2423 const currentUser = useSelector ( ( { currentUser } : { currentUser : any } ) => currentUser . data )
25- const form = 10
26-
27- useEffect ( ( ) => {
28- dispatch ( getReports ( 'KH50_005' ) )
29- dispatch ( wsJoinRoom ( 'KH50_005' , form ) )
30- } , [ ] )
3124
3225 useEffect ( ( ) => {
3326 const gotTheLock = ( currentEditors && currentEditors [ id ] && currentEditors [ id ] . uid === currentUser . uid )
@@ -54,34 +47,34 @@ const TextFieldComponent = ({ id }: { id: string }) => {
5447 }
5548 }
5649
57- const handleStartEditing = ( ) => {
58- askForLock ( )
59- }
60-
6150 return (
6251 < Box sx = { { display : 'flex' , flexDirection : 'column' , gap : 2 , alignItems : 'start' } } >
63- < TextField
64- disabled = { ! hasLock }
65- type = "text"
66- defaultValue = { content }
67- variant = "outlined"
68- multiline
69- minRows = { 8 }
70- fullWidth
71- label = "Testattava tekstikenttä"
72- value = { content }
73- onChange = { e => setContent ( e . target . value ) }
74- />
7552 { hasLock ? (
76- < Button variant = "contained" onClick = { handleStopEditing } >
77- { t ( 'stopEditing' ) }
78- </ Button >
53+ < >
54+ < TextField
55+ type = "text"
56+ defaultValue = { content }
57+ variant = "outlined"
58+ multiline
59+ minRows = { type === 'comment' ? 3 : 10 }
60+ fullWidth
61+ label = "Koulutusohjelman kommentti"
62+ value = { content }
63+ onChange = { e => setContent ( e . target . value ) }
64+ onClick = { askForLock }
65+ />
66+ < Button variant = "outlined" onClick = { handleStopEditing } >
67+ { t ( 'generic:kludgeButton' ) }
68+ </ Button >
69+ </ >
7970 ) : (
80- < Button variant = "contained" onClick = { handleStartEditing } >
81- { t ( 'edit' ) }
82- </ Button >
71+ < >
72+ < ReactMarkdown > { content } </ ReactMarkdown >
73+ < Button variant = "outlined" onClick = { askForLock } >
74+ { t ( 'edit' ) }
75+ </ Button >
76+ </ >
8377 ) }
84- < ReactMarkdown > { content } </ ReactMarkdown >
8578 </ Box >
8679 )
8780}
0 commit comments