Skip to content

Commit

Permalink
Added volunteer name to kiosk.
Browse files Browse the repository at this point in the history
Resolves #23
  • Loading branch information
Stardog committed Aug 12, 2021
1 parent 0664349 commit 22ed790
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
5 changes: 3 additions & 2 deletions class/Controller/User/Punch.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ protected function logInHtml(Request $request)
protected function clockInReasonPost(Request $request)
{
$sponsorId = $request->pullPostInteger('sponsorId');
$volunteerId = $request->pullPOstInteger('volunteerId');
$volunteerId = $request->pullPostInteger('volunteerId');
$reasonId = $request->pullPostInteger('reasonId');
$volunteer = VolunteerFactory::build($volunteerId);
$volunteerName = $volunteer->getPreferred();
$reason = ReasonFactory::build($reasonId);
PunchFactory::in($volunteer, $sponsorId, $reasonId);
return ['success' => true, 'attendanceOnly' => $reason->forceAttended];
return ['success' => true, 'attendanceOnly' => $reason->forceAttended, 'volunteerId' => $volunteerId, 'volunteerName' => $volunteerName];
}

protected function swipeInJson(Request $request)
Expand Down
14 changes: 8 additions & 6 deletions class/Factory/PunchFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ public static function punchReply(Volunteer $volunteer, int $sponsorId, bool $in
{
$punch = PunchFactory::currentPunch($volunteer);
$sponsor = SponsorFactory::build($sponsorId);
$volunteerName = $volunteer->getPreferred();
$volunteerId = $volunteer->id;
if ($punch) {
if ((int) $punch->sponsorId !== (int) $sponsorId) {
return ['success' => false, 'result' => 'punchedInElsewhere'];
return ['success' => false, 'result' => 'punchedInElsewhere', 'volunteerName' => $volunteerName, 'volunteerId' => $volunteerId];
} else {
PunchFactory::out($punch);
return ['success' => true, 'result' => 'out'];
return ['success' => true, 'result' => 'out', 'volunteerName' => $volunteerName, 'volunteerId' => $volunteerId];
}
} else {
if ($sponsor->useReasons) {
Expand All @@ -92,16 +94,16 @@ public static function punchReply(Volunteer $volunteer, int $sponsorId, bool $in
$reasons = ReasonFactory::listing(['sponsorId' => $sponsor->id]);
if (empty($reasons)) {
PunchFactory::in($volunteer, $sponsorId);
return ['success' => true, 'result' => 'in', 'reasons' => []];
return ['success' => true, 'result' => 'in', 'reasons' => [], 'volunteerName' => $volunteerName, 'volunteerId' => $volunteerId];
} else {
return ['success' => true, 'result' => 'reason', 'reasons' => $reasons, 'volunteerId' => $volunteer->id];
return ['success' => true, 'result' => 'reason', 'reasons' => $reasons, 'volunteerName' => $volunteerName, 'volunteerId' => $volunteerId];
}
} else {
return ['success' => true, 'result' => 'reason', 'volunteerId' => $volunteer->id];
return ['success' => true, 'result' => 'reason', 'volunteerId' => $volunteer->id, 'volunteerName' => $volunteerName, 'volunteerId' => $volunteerId];
}
} else {
PunchFactory::in($volunteer, $sponsorId);
return ['success' => true, 'result' => 'in', 'reasons' => []];
return ['success' => true, 'result' => 'in', 'reasons' => [], 'volunteerName' => $volunteerName, 'volunteerId' => $volunteerId];
}
}
}
Expand Down
22 changes: 15 additions & 7 deletions javascript/Kiosk/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ const Kiosk = ({sponsor}) => {
const [showVisitorModal, setShowVisitorModal] = useState(false)
const [volunteerId, setVolunteerId] = useState(0)
const [email, setEmail] = useState('')
const [volunteerName, setVolunteerName] = useState('')
const [goodEmail, setGoodEmail] = useState(0)

useEffect(() => {
if (reasonId > 0) {
clockInReason(sponsor.id, volunteerId, reasonId).then((response) => {
if (response.data.attendanceOnly) {
setMessage(
'Thank you for being here today. You do not need to clock out.'
`Thank you for being here today, ${response.data.volunteerName}. You do not need to clock out.`
)
} else {
setMessage('Thank you. Please clock out when you leave.')
setMessage(
`Thank you, ${response.data.volunteerName}. Please clock out when you leave.`
)
}
setShowReasonModal(false)
pauseAndReset()
Expand All @@ -58,6 +61,7 @@ const Kiosk = ({sponsor}) => {
const resetVisitor = () => {
setEmail('')
setGoodEmail(0)
setVolunteerName('')
setShowVisitorModal(false)
}

Expand Down Expand Up @@ -115,22 +119,23 @@ const Kiosk = ({sponsor}) => {

const determineResponse = (response) => {
const {success, result} = response.data
const responseVolName = response.data.volunteerName
if (success) {
switch (result) {
case 'in':
if (sponsor.attendanceOnly == 1) {
setMessage(
'Thank you for being with us today. You do not need to clock out.'
`Thank you for being with us today, ${responseVolName}. You do not need to clock out.`
)
} else {
setMessage(
'Thank you for being with us today. Remember to clock out when you leave.'
`Thank you for being with us today, ${responseVolName}. Remember to clock out when you leave.`
)
}
pauseAndReset()
break
case 'out':
setMessage('Thank you, you have clocked out.')
setMessage(`Thank you ${responseVolName}, you have clocked out.`)
pauseAndReset()
break
case 'reason':
Expand All @@ -142,14 +147,17 @@ const Kiosk = ({sponsor}) => {
setReasonsLoaded(true)
setReasons(response.data.reasons)
}
setVolunteerName(responseVolName)
setVolunteerId(response.data.volunteerId)
setShowReasonModal(true)
break
}
} else {
switch (result) {
case 'punchedInElsewhere':
setError('You are currently clocked in elsewhere.')
setError(
`${responseVolName}, you are currently clocked in elsewhere.`
)
pauseAndReset()
break
case 'notfound':
Expand Down Expand Up @@ -216,7 +224,7 @@ const Kiosk = ({sponsor}) => {
<Overlay
show={showReasonModal}
close={() => setShowReasonModal(false)}
title="Reason for visit"
title={`Hello ${volunteerName}, what is the reason for your visit?`}
width="80%">
<ReasonList
reasons={reasons}
Expand Down

0 comments on commit 22ed790

Please sign in to comment.