1-
2- import { Button , Fab , Skeleton , Stack , TextField , Tooltip , Typography } from "@mui/material" ;
1+ import {
2+ Button ,
3+ Fab ,
4+ Skeleton ,
5+ Stack ,
6+ TextField ,
7+ Tooltip ,
8+ Typography ,
9+ } from "@mui/material" ;
310import { useState } from "react" ;
411import { DateTimePicker , LocalizationProvider } from "@mui/x-date-pickers" ;
512import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFnsV3" ;
@@ -9,20 +16,17 @@ import CustomNumberInput from "@/app/components/input/CustomNumberInput";
916import locale from "date-fns/locale/en-GB" ;
1017import { CalendarToday , PunchClock } from "@mui/icons-material" ;
1118
12- export default function workLogInput (
13- session ,
14- users ,
15- workGroups ,
16- setRefresh
17- ) {
19+ export default function workLogInput ( session , users , workGroups , setRefresh ) {
1820 const [ registeredFor , setRegisteredFor ] = useState ( [ ] ) ;
1921 const [ selectedGroup , setSelectedGroup ] = useState ( null ) ;
2022 const [ selectedDateTime , setSelectedDateTime ] = useState ( new Date ( ) ) ;
2123 const [ endDateTime , setEndDateTime ] = useState ( new Date ( ) ) ;
2224 const [ hours , setHours ] = useState ( 0 ) ;
2325 const [ description , setDescription ] = useState ( "" ) ;
2426 const [ shouldInputHours , setShouldInputHours ] = useState ( false ) ;
25- const [ endInputMethodTooltip , setEndInputMethodTooltip ] = useState ( "Change to 'End of work'" ) ;
27+ const [ endInputMethodTooltip , setEndInputMethodTooltip ] = useState (
28+ "Change to 'End of work'"
29+ ) ;
2630
2731 const [ registeredForError , setRegisteredForError ] = useState ( false ) ;
2832 const [ selectedGroupError , setSelectedGroupError ] = useState ( false ) ;
@@ -52,7 +56,7 @@ export default function workLogInput(
5256 fetch ( "/api/v2/workLogs" , {
5357 method : "POST" ,
5458 headers : {
55- "content-type" : "application/json"
59+ "content-type" : "application/json" ,
5660 } ,
5761 body : JSON . stringify ( {
5862 loggedBy : session . data . user . id ,
@@ -62,25 +66,25 @@ export default function workLogInput(
6266 description : description ,
6367 semesterId : session . data . semester . id ,
6468 } ) ,
65- } ) ;
66-
69+ } ) ;
70+
6771 fetch ( "/api/v2/workGroups" , {
6872 method : "POST" ,
6973 headers : {
70- "content-type" : "application/json"
74+ "content-type" : "application/json" ,
7175 } ,
7276 body : JSON . stringify ( {
73- userId : registeredFor . id ,
74- workGroupId : selectedGroup . id
75- } )
76- } )
77+ userId : user . id ,
78+ workGroupId : selectedGroup . id ,
79+ } ) ,
80+ } ) ;
7781 }
7882 setRegisteredFor ( [ ] ) ;
7983 setSelectedGroup ( null ) ;
8084 setHours ( 0 ) ;
8185 setDescription ( "" ) ;
8286 setRefresh ( "" ) ;
83-
87+
8488 setRequestResponse ( "Work registered." ) ;
8589 setTimeout ( ( ) => {
8690 setRequestResponse ( "" ) ;
@@ -90,21 +94,24 @@ export default function workLogInput(
9094 const switchEndInputMethod = ( ) => {
9195 if ( ! shouldInputHours ) {
9296 setShouldInputHours ( true ) ;
93- document . querySelector ( ".endDateTime" ) . setAttribute ( "style" , "display: inline" ) ;
97+ document
98+ . querySelector ( ".endDateTime" )
99+ . setAttribute ( "style" , "display: inline" ) ;
94100 document . querySelector ( ".hours" ) . setAttribute ( "style" , "display: none" ) ;
95101 setEndInputMethodTooltip ( "Change to 'Hours worked'" ) ;
96-
97102 } else {
98103 setShouldInputHours ( false ) ;
99- document . querySelector ( ".endDateTime" ) . setAttribute ( "style" , "display: none" ) ;
104+ document
105+ . querySelector ( ".endDateTime" )
106+ . setAttribute ( "style" , "display: none" ) ;
100107 document . querySelector ( ".hours" ) . setAttribute ( "style" , "display: inline" ) ;
101108 setEndInputMethodTooltip ( "Change to 'End of work'" ) ;
102109 }
103110 } ;
104111
105112 return (
106113 < Stack direction = "column" spacing = { 1 } >
107- < Stack direction = "column" spacing = { 2 } >
114+ < Stack direction = "column" spacing = { 2 } >
108115 < CustomMultiAutoComplete
109116 label = "Registered for"
110117 dataLabel = "name"
@@ -122,21 +129,24 @@ export default function workLogInput(
122129 callback = { setSelectedGroup }
123130 error = { selectedGroupError }
124131 />
125- < LocalizationProvider dateAdapter = { AdapterDateFns } adapterLocale = { locale } >
132+ < LocalizationProvider
133+ dateAdapter = { AdapterDateFns }
134+ adapterLocale = { locale }
135+ >
126136 < DateTimePicker
127137 label = "Start of work"
128138 defaultValue = { selectedDateTime }
129139 slotProps = { { textField : { fullWidth : true , size : "small" } } }
130140 ampm = { false }
131141 disableOpenPicker
132142 onChange = { ( e ) => setSelectedDateTime ( e ) }
133- />
143+ />
134144 </ LocalizationProvider >
135- < Stack
136- direction = "row"
137- alignItems = { "stretch" }
138- >
139- < LocalizationProvider dateAdapter = { AdapterDateFns } adapterLocale = { locale } >
145+ < Stack direction = "row" alignItems = { "stretch" } >
146+ < LocalizationProvider
147+ dateAdapter = { AdapterDateFns }
148+ adapterLocale = { locale }
149+ >
140150 < DateTimePicker
141151 className = "endDateTime"
142152 sx = { { display : "none" } }
@@ -148,21 +158,25 @@ export default function workLogInput(
148158 onChange = { ( e ) => {
149159 if ( e < selectedDateTime ) return ; // Prevent endDateTime from being before startDateTime
150160 setEndDateTime ( e ) ;
151- setHours ( Math . round ( ( ( e - selectedDateTime ) / 3600000 ) * 10 ) / 10 ) // Update hours
161+ setHours (
162+ Math . round ( ( ( e - selectedDateTime ) / 3600000 ) * 10 ) / 10
163+ ) ; // Update hours
152164 } }
153165 />
154166 </ LocalizationProvider >
155167 < CustomNumberInput
156168 className = "hours"
157169 label = "Hours worked"
158170 value = { hours }
159- setValue = { ( value ) => { setHours ( value ) ; } }
171+ setValue = { ( value ) => {
172+ setHours ( value ) ;
173+ } }
160174 check = { ( data ) => data . match ( / [ ^ 0 - 9 . ] / ) || data . match ( / [ . ] { 2 , } / g) }
161175 error = { hoursError }
162176 />
163177 < Tooltip
164178 className = "endInputMethodTooltip"
165- title = { endInputMethodTooltip }
179+ title = { endInputMethodTooltip }
166180 >
167181 < Fab
168182 className = "endInputMethodChangeButton"
@@ -171,10 +185,12 @@ export default function workLogInput(
171185 style = { {
172186 marginLeft : "10px" ,
173187 padding : "10px" ,
174- } }
175- onClick = { ( ) => { switchEndInputMethod ( ) ; } }
188+ } }
189+ onClick = { ( ) => {
190+ switchEndInputMethod ( ) ;
191+ } }
176192 >
177- { shouldInputHours ? < PunchClock /> : < CalendarToday /> }
193+ { shouldInputHours ? < PunchClock /> : < CalendarToday /> }
178194 </ Fab >
179195 </ Tooltip >
180196 </ Stack >
@@ -218,7 +234,6 @@ function validateWorkLogRequest(
218234 setHoursError ,
219235 setDescriptionError
220236) {
221-
222237 // Define an object to store the errors
223238 const errors = {
224239 registeredForError : registeredFor . length == 0 ,
0 commit comments