Skip to content

Commit

Permalink
check old safety training google sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
rlho committed Feb 14, 2024
1 parent 33fbbec commit 4a45a8c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import FormInput, { Inputs } from './FormInput';
// This is a wrapper for google.script.run that lets us use promises.
import { serverFunctions } from '../../utils/serverFunctions';
import { DateSelectArg } from '@fullcalendar/core';
import { RoomUsage } from './RoomUsage';
import { Header } from './Header';
import { MultipleCalendars } from './MultipleCalendars';
import { InitialModal } from './InitialModal';
Expand Down Expand Up @@ -185,16 +184,25 @@ const SheetEditor = () => {

// safety training users
const getSafetyTrainingStudents = () => {
const students = serverFunctions
.getSheetRows(SAFTY_TRAINING_SHEET_NAME)
.then((rows) => {
if (!isSafetyTrained) {
serverFunctions.getSheetRows(SAFTY_TRAINING_SHEET_NAME).then((rows) => {
const emails = rows.reduce(
(accumulator, value) => accumulator.concat(value),
[]
);
const trained = emails.includes(userEmail);
setIsSafetyTrained(trained);
});
serverFunctions.getOldSafetyTrainingEmails().then((rows) => {
console.log('old emails', rows);
const emails = rows.reduce(
(accumulator, value) => accumulator.concat(value),
[]
);
const trained = emails.includes(userEmail);
setIsSafetyTrained(trained);
});
}
};

const getBannedStudents = () => {
Expand Down
2 changes: 2 additions & 0 deletions media_commons_booking_app/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
fetchById,
fetchRows_,
getFutureDates,
getOldSafetyTrainingEmails,
} from './sheets';

// Public functions must be exported as named exports
Expand Down Expand Up @@ -73,4 +74,5 @@ export {
removeFromList,
getFutureDates,
getCalendarEvents,
getOldSafetyTrainingEmails,
};
16 changes: 16 additions & 0 deletions media_commons_booking_app/src/server/sheets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const ACTIVE_SHEET_ID = '1MnWbn6bvNyMiawddtYYx0tRW4NMgvugl0I8zBO3sy68';
export const OLD_SHEET_ID = '1Debe5qF-2qXJhqP0AMy5etEvwAPd3mNFiTswytsbKxQ';
export const OLD_SHEET_SAFETY_TRAINING_NAME = 'Sheet1';

export const fetchRows_ = (sheetName) => {
return SpreadsheetApp.openById(ACTIVE_SHEET_ID)
Expand Down Expand Up @@ -51,6 +53,20 @@ function fetchById(sheetName, id) {
return messages;
}

export const getOldSafetyTrainingEmails = (email) => {
const activeSpreadSheet = SpreadsheetApp.openById(OLD_SHEET_ID);
const activeSheet = activeSpreadSheet.getSheetByName(
OLD_SHEET_SAFETY_TRAINING_NAME
);
var lastRow = activeSheet.getLastRow();

// get all row3(email) data
var range = activeSheet.getRange(1, 5, lastRow);
var values = range.getValues();

return values;
};

export const getSheetRows = (sheetName) => {
const activeSpreadSheet = SpreadsheetApp.openById(ACTIVE_SHEET_ID);
const activeSheet = activeSpreadSheet.getSheetByName(sheetName);
Expand Down

0 comments on commit 4a45a8c

Please sign in to comment.