-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add functionality to allow for multiple TEC attendance picture submission #576
Changes from 6 commits
24f3524
3dfdbf0
acd4a44
f98494d
c893e70
8a851c8
5a013b2
76d6cfc
f090fa5
b1004e2
0687d78
43ec54e
6415dbf
fdb9236
868276b
883d482
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,7 @@ | |
display: flex; | ||
justify-content: flex-end; | ||
} | ||
|
||
.modalContent { | ||
max-height: 60vh !important; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
const [pendingAttendance, setPendingAttendance] = useState<TeamEventAttendance[]>([]); | ||
const [rejectedAttendance, setRejectedAttendance] = useState<TeamEventAttendance[]>([]); | ||
const [isAttendanceLoading, setIsAttendanceLoading] = useState<boolean>(true); | ||
const [imageIndex, setImageIndex] = useState<number[]>([0]); | ||
const [images, setImages] = useState<string[]>([]); | ||
|
||
useEffect(() => { | ||
TeamEventsAPI.getAllTeamEventInfo().then((teamEvents) => setTeamEventInfoList(teamEvents)); | ||
|
@@ -30,17 +32,25 @@ | |
}); | ||
}, []); | ||
|
||
const handleAddIconClick = () => { | ||
const newIndex = imageIndex.length; | ||
setImageIndex([...imageIndex, newIndex]); | ||
}; | ||
|
||
const handleNewImage = (e: React.ChangeEvent<HTMLInputElement>): void => { | ||
if (!e.target.files) return; | ||
const newImage = URL.createObjectURL(e.target.files[0]); | ||
setImage(newImage); | ||
setImages([...images, newImage]); | ||
}; | ||
|
||
const requestTeamEventCredit = async (eventCreditRequest: TeamEventAttendance) => { | ||
const requestTeamEventCredit = async ( | ||
eventCreditRequest: TeamEventAttendance, | ||
uploadedImage: string | ||
) => { | ||
const createdAttendance = await TeamEventsAPI.requestTeamEventCredit(eventCreditRequest); | ||
|
||
// upload image | ||
const blob = await fetch(image).then((res) => res.blob()); | ||
const blob = await fetch(uploadedImage).then((res) => res.blob()); | ||
const imageURL: string = window.URL.createObjectURL(blob); | ||
await ImagesAPI.uploadEventProofImage(blob, eventCreditRequest.image).then(() => | ||
setImage(imageURL) | ||
|
@@ -70,7 +80,25 @@ | |
contentMsg: 'Team events must be logged for at least 0.5 hours!' | ||
}); | ||
} else { | ||
|
||
images.map(async (image, index) => { | ||
const newTeamEventAttendance: TeamEventAttendance = { | ||
member: userInfo, | ||
hoursAttended: teamEvent.hasHours ? Number(hours) : undefined, | ||
image: `eventProofs/${getNetIDFromEmail(userInfo.email)}/${new Date().toISOString()}`, | ||
eventUuid: teamEvent.uuid, | ||
pending: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type checker should catch this: we killed off the |
||
status: 'pending' as Status, | ||
reason: '', | ||
uuid: '' | ||
}; | ||
|
||
const createdAttendance = await requestTeamEventCredit( | ||
newTeamEventAttendance, | ||
images[index] | ||
); | ||
|
||
const newTeamEventAttendance: TeamEventAttendance = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrew032011 the check that did not pass said There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but those two variables look almost the exact same, do we need both? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see what you meant! I removed one of them as I was cleaning up code |
||
member: userInfo, | ||
hoursAttended: teamEvent.hasHours ? Number(hours) : undefined, | ||
image: `eventProofs/${getNetIDFromEmail(userInfo.email)}/${new Date().toISOString()}`, | ||
|
@@ -80,7 +108,7 @@ | |
uuid: '' | ||
}; | ||
|
||
requestTeamEventCredit(newTeamEventAttendance).then((createdAttendance) => { | ||
|
||
if (createdAttendance) { | ||
const updatedAttendance = { ...newTeamEventAttendance, uuid: createdAttendance.uuid }; | ||
setPendingAttendance((pending) => [...pending, updatedAttendance]); | ||
|
@@ -198,15 +226,27 @@ | |
Please include a picture of yourself (and others) and/or an email chain only if the | ||
former is not possible. | ||
</p> | ||
<input | ||
id="newImage" | ||
type="file" | ||
accept="image/png, image/jpeg" | ||
defaultValue="" | ||
value={image ? undefined : ''} | ||
onChange={handleNewImage} | ||
/> | ||
{imageIndex.map((item, index) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above, I don't think you're using |
||
<div className="input_container" style={{ marginBottom: '10px' }} key={index}> | ||
<input | ||
id="newImage" | ||
type="file" | ||
accept="image/png, image/jpeg" | ||
defaultValue="" | ||
value={image ? undefined : ''} | ||
onChange={handleNewImage} | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
<Form.Button | ||
floated="right" | ||
size="mini" | ||
style={{ marginBottom: '10px' }} | ||
onClick={handleAddIconClick} | ||
> | ||
+ | ||
</Form.Button> | ||
<Form.Button floated="right" onClick={submitTeamEventCredit}> | ||
Submit | ||
</Form.Button> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this
imageIndex, setImageIndex
hook to be an array. How about just a number to say how many image upload slots you have?