11import React , { useContext , useEffect , useState } from 'react' ;
22import { styled } from '@mui/material/styles' ;
3- import { Avatar , Typography , Button , Dialog , DialogTitle , DialogContent , DialogActions , TextField } from '@mui/material' ;
3+ import { Avatar , Typography } from '@mui/material' ;
44import { AppContext } from '../../context/AppContext' ;
55import { selectProfileMap } from '../../context/selectors' ;
66import { getAvatarURL } from '../../api/api.js' ;
77import { getMember } from '../../api/member' ;
8- import { saveNewOrganization , saveNewEvent } from '../../api/volunteer' ; // Importing the functions from volunteer.js
98
109const PREFIX = 'Profile' ;
1110
@@ -53,30 +52,28 @@ const Root = styled('div')(() => ({
5352 }
5453} ) ) ;
5554
56- const Profile = ( { memberId, pdlId, checkinPdlId, showButtons = true } ) => { // Add showButtons prop with default as true
55+ const Profile = ( { memberId, pdlId, checkinPdlId } ) => {
5756 const { state } = useContext ( AppContext ) ;
5857 const { csrf } = state ;
5958 const userProfile = selectProfileMap ( state ) [ memberId ] ;
6059
61- const { workEmail, name, title, location, supervisorid } = userProfile ? userProfile : { } ;
60+ const { workEmail, name, title, location, supervisorid } = userProfile
61+ ? userProfile
62+ : { } ;
6263
6364 const [ pdl , setPDL ] = useState ( '' ) ;
6465 const [ checkinPdl , setCheckinPdl ] = useState ( '' ) ;
6566 const [ supervisor , setSupervisor ] = useState ( '' ) ;
6667
67- const [ organizationDialogOpen , setOrganizationDialogOpen ] = useState ( false ) ;
68- const [ eventDialogOpen , setEventDialogOpen ] = useState ( false ) ;
69- const [ newOrganization , setNewOrganization ] = useState ( { name : '' , description : '' , website : '' } ) ;
70- const [ newEvent , setNewEvent ] = useState ( { relationshipId : '' , eventDate : '' , hours : 0 , notes : '' } ) ;
71-
7268 const areSamePdls = checkinPdl && pdl && checkinPdl === pdl ;
7369
7470 // Get PDL's name
7571 useEffect ( ( ) => {
7672 async function getPDLName ( ) {
7773 if ( pdlId ) {
7874 let res = await getMember ( pdlId , csrf ) ;
79- let pdlProfile = res . payload . data && ! res . error ? res . payload . data : undefined ;
75+ let pdlProfile =
76+ res . payload . data && ! res . error ? res . payload . data : undefined ;
8077 setPDL ( pdlProfile ? pdlProfile . name : '' ) ;
8178 }
8279 }
@@ -90,7 +87,8 @@ const Profile = ({ memberId, pdlId, checkinPdlId, showButtons = true }) => { //
9087 async function getCheckinPDLName ( ) {
9188 if ( checkinPdlId ) {
9289 let res = await getMember ( checkinPdlId , csrf ) ;
93- let checkinPdlProfile = res . payload . data && ! res . error ? res . payload . data : undefined ;
90+ let checkinPdlProfile =
91+ res . payload . data && ! res . error ? res . payload . data : undefined ;
9492 setCheckinPdl ( checkinPdlProfile ? checkinPdlProfile . name : '' ) ;
9593 }
9694 }
@@ -104,7 +102,8 @@ const Profile = ({ memberId, pdlId, checkinPdlId, showButtons = true }) => { //
104102 async function getSupervisorName ( ) {
105103 if ( supervisorid ) {
106104 let res = await getMember ( supervisorid , csrf ) ;
107- let supervisorProfile = res . payload . data && ! res . error ? res . payload . data : undefined ;
105+ let supervisorProfile =
106+ res . payload . data && ! res . error ? res . payload . data : undefined ;
108107 setSupervisor ( supervisorProfile ? supervisorProfile . name : '' ) ;
109108 }
110109 }
@@ -113,24 +112,6 @@ const Profile = ({ memberId, pdlId, checkinPdlId, showButtons = true }) => { //
113112 }
114113 } , [ csrf , supervisorid ] ) ;
115114
116- const handleSaveNewOrganization = async ( ) => {
117- const result = await saveNewOrganization ( csrf , newOrganization ) ; // Use the imported API call
118- if ( result . error ) {
119- // Handle error
120- return ;
121- }
122- setOrganizationDialogOpen ( false ) ;
123- } ;
124-
125- const handleSaveNewEvent = async ( ) => {
126- const result = await saveNewEvent ( csrf , newEvent ) ; // Use the imported API call
127- if ( result . error ) {
128- // Handle error
129- return ;
130- }
131- setEventDialogOpen ( false ) ;
132- } ;
133-
134115 return (
135116 < Root className = { classes . flexRow } >
136117 < Avatar
@@ -157,7 +138,11 @@ const Profile = ({ memberId, pdlId, checkinPdlId, showButtons = true }) => { //
157138 </ div >
158139 </ div >
159140 < Typography variant = "body2" color = "textSecondary" component = "p" >
160- < a href = { `mailto:${ workEmail } ` } target = "_blank" rel = "noopener noreferrer" >
141+ < a
142+ href = { `mailto:${ workEmail } ` }
143+ target = "_blank"
144+ rel = "noopener noreferrer"
145+ >
161146 { workEmail }
162147 </ a >
163148 < br />
@@ -167,100 +152,14 @@ const Profile = ({ memberId, pdlId, checkinPdlId, showButtons = true }) => { //
167152 < br />
168153 Current PDL: { pdl }
169154 < br />
170- { checkinPdl && ! areSamePdls && `PDL @ Time of Check-In: ${ checkinPdl } ` }
155+ { checkinPdl &&
156+ ! areSamePdls &&
157+ `PDL @ Time of Check-In: ${ checkinPdl } ` }
171158 </ Typography >
172-
173- { /* Conditionally render the buttons based on showButtons prop */ }
174- { showButtons && (
175- < >
176- < Button
177- variant = "contained"
178- onClick = { ( ) => setOrganizationDialogOpen ( true ) }
179- style = { { marginTop : '20px' } }
180- aria-label = "Add New Organization"
181- >
182- Add New Organization
183- </ Button >
184-
185- < Button
186- variant = "contained"
187- onClick = { ( ) => setEventDialogOpen ( true ) }
188- style = { { marginTop : '20px' , marginLeft : '10px' } }
189- aria-label = "Add New Event"
190- >
191- Add New Event
192- </ Button >
193- </ >
194- ) }
195159 </ div >
196160 </ div >
197-
198- { /* Organization Creation Dialog */ }
199- < Dialog open = { organizationDialogOpen } onClose = { ( ) => setOrganizationDialogOpen ( false ) } >
200- < DialogTitle > Create New Organization</ DialogTitle >
201- < DialogContent >
202- < TextField
203- label = "Name"
204- fullWidth
205- margin = "dense"
206- value = { newOrganization . name }
207- onChange = { e => setNewOrganization ( { ...newOrganization , name : e . target . value } ) }
208- />
209- < TextField
210- label = "Description"
211- fullWidth
212- margin = "dense"
213- value = { newOrganization . description }
214- onChange = { e => setNewOrganization ( { ...newOrganization , description : e . target . value } ) }
215- />
216- < TextField
217- label = "Website URL"
218- fullWidth
219- margin = "dense"
220- value = { newOrganization . website }
221- onChange = { e => setNewOrganization ( { ...newOrganization , website : e . target . value } ) }
222- />
223- </ DialogContent >
224- < DialogActions >
225- < Button onClick = { ( ) => setOrganizationDialogOpen ( false ) } > Cancel</ Button >
226- < Button onClick = { handleSaveNewOrganization } > Save</ Button >
227- </ DialogActions >
228- </ Dialog >
229-
230- { /* Event Creation Dialog */ }
231- < Dialog open = { eventDialogOpen } onClose = { ( ) => setEventDialogOpen ( false ) } >
232- < DialogTitle > Create New Event</ DialogTitle >
233- < DialogContent >
234- < TextField
235- label = "Event Date"
236- fullWidth
237- margin = "dense"
238- value = { newEvent . eventDate }
239- onChange = { e => setNewEvent ( { ...newEvent , eventDate : e . target . value } ) }
240- />
241- < TextField
242- label = "Hours"
243- fullWidth
244- margin = "dense"
245- type = "number"
246- value = { newEvent . hours }
247- onChange = { e => setNewEvent ( { ...newEvent , hours : e . target . value } ) }
248- />
249- < TextField
250- label = "Notes"
251- fullWidth
252- margin = "dense"
253- value = { newEvent . notes }
254- onChange = { e => setNewEvent ( { ...newEvent , notes : e . target . value } ) }
255- />
256- </ DialogContent >
257- < DialogActions >
258- < Button onClick = { ( ) => setEventDialogOpen ( false ) } > Cancel</ Button >
259- < Button onClick = { handleSaveNewEvent } > Save</ Button >
260- </ DialogActions >
261- </ Dialog >
262161 </ Root >
263162 ) ;
264163} ;
265164
266- export default Profile ;
165+ export default Profile ;
0 commit comments