Skip to content

Commit

Permalink
Fixed styles
Browse files Browse the repository at this point in the history
  • Loading branch information
clr-li committed May 10, 2024
1 parent 5a1a333 commit 8cc571e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
39 changes: 31 additions & 8 deletions public/calendar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GET, PUT } from './util/Client.js';
import { GET, PUT, POST } from './util/Client.js';
import { requireLogin } from './util/Auth.js';
import { sanitizeText } from './util/util.js';
import { Popup } from './components/Popup.js';
Expand Down Expand Up @@ -144,14 +144,37 @@ window.markAbsent = async (businessId, eventId) => {
const absentEmail = await GET(`/businesses/${businessId}/settings/absentemail`).then(res =>
res.json(),
);
const res = await PUT(
`/businesses/${businessId}/events/${eventId}/absentemail/${absentEmail.absentemail}/attendance/markabsent`,
);
if (!res.ok) {
await Popup.alert(await res.text(), 'var(--error)');
return;
if (absentEmail.absentemail === 1) {
const popup = new Popup();
popup.innerHTML = /* html */ `
<h2>Reason for Absence</h2>
<textarea type="text" id="reason" class="stylish" style="min-height: 5lh; width: 100%; margin-left: auto; margin-right: auto;" placeholder="Reason for absence"></textarea><br>
<button id="reason-submit" class="button">Submit</button>
`;
document.body.appendChild(popup);
document.getElementById('reason-submit').onclick = async () => {
const reason = document.getElementById('reason').value;
popup.close();
const res = await POST(
`/businesses/${businessId}/events/${eventId}/absentemail/${1}/attendance/markabsent`,
{ reason: reason },
);
if (!res.ok) {
await Popup.alert(await res.text(), 'var(--error)');
return;
}
await Popup.alert('You have been marked absent!', 'var(--success)');
};
} else {
const res = await PUT(
`/businesses/${businessId}/events/${eventId}/absentemail/${0}/attendance/markabsent`,
);
if (!res.ok) {
await Popup.alert(await res.text(), 'var(--error)');
return;
}
await Popup.alert('You have been marked absent!', 'var(--success)');
}
await Popup.alert('You have been marked absent!', 'var(--success)');

// manually change html since evo-calendar is broken when adding/removing or updating events
const badge = document.createElement('span');
Expand Down
20 changes: 16 additions & 4 deletions server/Attendance.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,17 @@ router.patch('/businesses/:businessId/events/:eventId/attendance', async (reques
* @requiredPrivileges member of the business
* @response 200 OK if successful
*/
router.put(
router.post(
'/businesses/:businessId/events/:eventId/absentemail/:absentEmail/attendance/markabsent',
async (request, response) => {
const uid = await handleAuth(request, response, request.params.businessId, {});
if (!uid) return;

const businessId = request.params.businessId;
const eventId = request.params.eventId;
const absentEmail = request.params.absentEmail;
const absentEmail = await db().get(
...SQL`SELECT absentEmail FROM Businesses WHERE id = ${businessId}`,
);

const existingRecord = await db().get(
...SQL`SELECT R.status, E.endtimestamp
Expand All @@ -124,8 +126,12 @@ router.put(
);

// Send email notification to business owner and admins if setting is enabled
if (absentEmail === '1') {
if (absentEmail.absentemail === 1) {
const user = await db().get(...SQL`SELECT name FROM Users WHERE id = ${uid}`);
const reason = request.body.reason || '(No reason provided)';
const eventInfo = await db().get(
...SQL`SELECT * FROM Events WHERE business_id = ${businessId} AND id = ${eventId}`,
);

const writeMembers = await db().all(
...SQL`
Expand All @@ -139,7 +145,13 @@ router.put(
const message = {
to_email: member.email,
subject: 'Notification of Absence',
text: `Hi ${member.name}, \n\n${user.name} has marked themselves absent from the event.\n\n(automatically sent via Attendance Scanner QR)`,
text: `Hi ${member.name}, \n\n<b>${
user.name
}</b> has marked themselves absent from the event named <b>${
eventInfo.name
}</b> starting on <b>${new Date(
+eventInfo.starttimestamp,
).toLocaleDateString()}</b>. Reason for absence: ${reason}\n\n(automatically sent via Attendance Scanner QR)`,
};

const res = await email(message.to_email, message.subject, message.text);
Expand Down

0 comments on commit 8cc571e

Please sign in to comment.