11import React , { Component } from 'react' ;
22import './SettingsBox.css' ;
33import InputBox from '../Inputs/InputBox' ;
4- import CheckBox from '../Inputs/CheckBox' ;
4+ import Checkbox from '@mui/material/Checkbox' ;
5+
56import { headerDefinitions , types } from '../../util/data' ;
67import FHIR from 'fhirclient' ;
8+ import { Box , Button , FormControlLabel , Grid , TextField } from '@mui/material' ;
9+ import CloseIcon from '@mui/icons-material/Close' ;
710
811const clearQuestionnaireResponses =
912 ( { ehrUrl, defaultUser, access_token } , consoleLog ) =>
@@ -89,7 +92,7 @@ const resetRemsAdmin =
8992
9093const resetHeaderDefinitions = [
9194 {
92- display : 'Clear EHR QuestionnaireResponses ' ,
95+ display : 'Clear In-Progress Forms ' ,
9396 key : 'clearQuestionnaireResponses' ,
9497 reset : clearQuestionnaireResponses
9598 } ,
@@ -108,12 +111,44 @@ const resetHeaderDefinitions = [
108111export default class SettingsBox extends Component {
109112 constructor ( props ) {
110113 super ( props ) ;
114+ this . state = {
115+ originalValues : [ ]
116+ } ;
117+ this . cancelSettings = this . cancelSettings . bind ( this ) ;
118+ this . closeSettings = this . closeSettings . bind ( this ) ;
119+ this . saveSettings = this . saveSettings . bind ( this ) ;
120+ }
121+
122+ componentDidMount ( ) {
123+ const headers = Object . keys ( headerDefinitions ) . map ( key => ( [ key , this . props . state [ key ] ] ) ) ;
124+ this . setState ( { originalValues : headers } ) ;
125+ }
126+
127+ closeSettings ( ) {
128+ this . props . updateCB ( 'showSettings' , false ) ;
129+ }
130+ saveSettings ( ) {
131+ const headers = Object . keys ( headerDefinitions ) . map ( key => ( [ key , this . props . state [ key ] ] ) ) ;
132+ console . log ( headers ) ;
133+ localStorage . setItem ( 'reqgenSettings' , JSON . stringify ( headers ) ) ;
134+ this . closeSettings ( ) ;
111135 }
112136
113- componentDidMount ( ) { }
137+ cancelSettings ( ) {
138+ this . state . originalValues . forEach ( ( e ) => {
139+ try {
140+ this . props . updateCB ( e [ 0 ] , e [ 1 ] ) ;
141+ } catch {
142+ console . log ( 'Failed to reset setting value' ) ;
143+ }
144+ } ) ;
145+ this . closeSettings ( ) ;
146+ }
114147
115148 render ( ) {
116149 const { state, consoleLog, updateCB } = this . props ;
150+ let firstCheckbox = true ;
151+ let showBreak = true ;
117152
118153 const headers = Object . keys ( headerDefinitions )
119154 . map ( key => ( { ...headerDefinitions [ key ] , key } ) )
@@ -125,35 +160,46 @@ export default class SettingsBox extends Component {
125160
126161 return (
127162 < div >
163+ < Box flexGrow = { 1 } >
164+ < h4 className = 'setting-header' > Settings</ h4 >
165+ < Grid container spacing = { 2 } sx = { { padding : '20px' } } >
128166 { headers . map ( ( { key, type, display } ) => {
167+
129168 switch ( type ) {
130169 case 'input' :
131170 return (
132- < div key = { key } >
133- < p className = "setting-header" > { display } </ p >
134- < InputBox
135- extraClass = "setting-input"
136- value = { state [ key ] }
137- updateCB = { updateCB }
138- elementName = { key }
171+ < Grid key = { key } item xs = { 6 } >
172+ < div >
173+ < TextField
174+ label = { display }
175+ variant = "outlined"
176+ value = { state [ key ] }
177+ onChange = { ( event ) => { updateCB ( key , event . target . value ) ; } }
178+ sx = { { width :'100%' } }
139179 />
140180 </ div >
181+ </ Grid >
141182 ) ;
142183 case 'check' :
184+ if ( firstCheckbox ) {
185+ firstCheckbox = false ;
186+ showBreak = true ;
187+ } else {
188+ showBreak = false ;
189+ }
143190 return (
144- < div key = { key } >
145- < p className = "setting-header" >
146- { display }
147- < CheckBox
148- extraClass = "setting-checkbox"
149- extraInnerClass = "setting-inner-checkbox"
150- toggle = { state [ key ] }
151- updateCB = { updateCB }
152- elementName = { key }
191+ < React . Fragment key = { key } >
192+ { showBreak ? < Grid item xs = { 12 } > </ Grid > : '' }
193+ < Grid item xs = { 3 } >
194+ < FormControlLabel control = {
195+ < Checkbox
196+ value = { state [ key ] }
197+ onChange = { ( event ) => { updateCB ( key , event . target . value ) ; } } />
198+ }
199+ label = { display }
153200 />
154- </ p >
155- < p > </ p >
156- </ div >
201+ </ Grid >
202+ </ React . Fragment >
157203 ) ;
158204 default :
159205 return (
@@ -163,15 +209,29 @@ export default class SettingsBox extends Component {
163209 ) ;
164210 }
165211 } ) }
166- { resetHeaderDefinitions . map ( ( { key, display, reset } ) => {
167- return (
168- < div key = { key } >
169- < button className = { 'setting-btn btn btn-class' } onClick = { reset ( state , consoleLog ) } >
170- { display }
171- </ button >
172- </ div >
173- ) ;
174- } ) }
212+ { resetHeaderDefinitions . map ( ( { key, display, reset } ) => {
213+ return (
214+ < Grid item key = { key } xs = { 4 } >
215+ < Button variant = 'outlined' onClick = { reset ( state , consoleLog ) } >
216+ { display }
217+ </ Button >
218+ </ Grid >
219+ ) ;
220+ } ) }
221+ { /* spacer */ }
222+ < hr style = { {
223+ 'width' :'100%'
224+ } } />
225+ < Grid item xs = { 8 } />
226+
227+ < Grid item xs = { 2 } >
228+ < Button variant = 'outlined' onClick = { this . cancelSettings } > Cancel</ Button >
229+ </ Grid >
230+ < Grid item xs = { 2 } >
231+ < Button variant = 'contained' onClick = { this . saveSettings } > Save</ Button >
232+ </ Grid >
233+ </ Grid >
234+ </ Box >
175235 </ div >
176236 ) ;
177237 }
0 commit comments