Skip to content

Commit

Permalink
Merge pull request #48 from hacksu/dev-main
Browse files Browse the repository at this point in the history
Staff dashboard upgrade
  • Loading branch information
Struck713 authored Apr 4, 2024
2 parents e0d461e + 41741ba commit 9fe1f46
Show file tree
Hide file tree
Showing 23 changed files with 1,431 additions and 720 deletions.
14 changes: 13 additions & 1 deletion global-includes/email-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export enum EmailSource {
Early2023 = "2023EarlySignup",
}

export enum EmailTemplates {
Application = "application",
Approved = "approved",
Welcome = "welcome"
}

// TODO: maybe replace with zod's email validation, for consistency
export const isEmailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

Expand Down Expand Up @@ -61,7 +67,13 @@ export class Email {

@BackendMethod({ allowed: true })
static async addEmailAndSendWelcome(email: Partial<Email>) {
RemoteProcedures.sendWelcome((await remult.repo(Email).insert(email)).address);
RemoteProcedures.sendTemplateEmail(EmailTemplates.Welcome, (await remult.repo(Email).insert(email)).address);
}

// TODO: should this be here?????
@BackendMethod({ allowed: [ UserRole.Admin, UserRole.Staff ] })
static async sendTemplateEmail(template: EmailTemplates, email: string) {
RemoteProcedures.sendTemplateEmail(template, email);
}

@BackendMethod({ allowed: [UserRole.Admin, UserRole.Staff] })
Expand Down
12 changes: 3 additions & 9 deletions global-includes/rpc-declarations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MailDataRequired } from "@sendgrid/mail";
import { AttachmentData } from "@sendgrid/helpers/classes/attachment";
import { Email } from "./email-address.ts";
import { Email, EmailTemplates } from "./email-address.ts";
import { SupportTicket, TicketMessage } from "./support-ticket.ts";

/**
Expand All @@ -22,10 +22,7 @@ export class RemoteProcedures {
/** General function to send KHE emails based on files, with the "KHE 2024
* Updates" unsubscribe group */
static sendUpdate: (emailHtmlFile: string, address: string) => Promise<void>;
/** Specifically sends an email sign-up welcome email */
static sendWelcome: (address: string) => Promise<void>;
/** Specifically sends an application acknowledgement email */
static sendApplicationAcknowledgement: (address: string) => Promise<void>;
static sendTemplateEmail: (template: EmailTemplates, address: string) => Promise<void>;
static getDistinct: (collection: string, field: string) => Promise<string[]>;
static bulkDelete: (collection: string, filter: any) => Promise<void>;
static sendTo: (
Expand All @@ -41,8 +38,5 @@ export class RemoteProcedures {
static sanitizeMessage: (message: TicketMessage) => TicketMessage;
static deleteGridImages: (paths: string[]) => Promise<void>;
static getUserResumeFilename: (userID: string) => Promise<string>;
/**
* If `base64Resume` is empty, any existing resume will be deleted
*/
static setUserResume: (userID: string, base64Resume: string | "", resumeFilename: string) => Promise<void>;
static setUserResume: (userID: string, base64Resume: string | "", resumeFilename: string) => Promise<void>; // If `base64Resume` is empty, any existing resume will be deleted
}
16 changes: 7 additions & 9 deletions global-includes/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BackendMethod, Entity, Fields, EntityBase, remult } from "remult";
import { VFields } from "./adaptations.ts";
import { UserRole } from "./common.ts";
import { z } from "zod";
import { isEmailRegex } from "./email-address.ts";
import { EmailTemplates, isEmailRegex } from "./email-address.ts";
import crypto from "crypto";
import { RemoteProcedures } from "./rpc-declarations.ts";

Expand Down Expand Up @@ -197,10 +197,8 @@ const noUpdate = { allowApiUpdate: false };
@Entity<User>("users", {
allowApiCrud: true,
apiPrefilter: () => (
remult.isAllowed([UserRole.Admin, UserRole.Staff]) ?
{} :
{ id: remult.user?.id }
),
remult.isAllowed([UserRole.Admin, UserRole.Staff]) ? {} : { id: remult.user?.id }
),
})
export class User extends EntityBase {
@Fields.uuid()
Expand Down Expand Up @@ -387,7 +385,8 @@ export class User extends EntityBase {
user.submittedApplication = true;
user.applicationApproved = false;
await remult.repo(User).save(user);
RemoteProcedures.sendApplicationAcknowledgement(
RemoteProcedures.sendTemplateEmail(
EmailTemplates.Application,
user.registration.email || user.email
);
}
Expand All @@ -402,14 +401,13 @@ export class User extends EntityBase {
}
}

@BackendMethod({allowed: true})
@BackendMethod({ allowed: true })
static async getExistingResumeName() {
const user = remult.user as User;
if (!user) {
throw "Not logged in";
} else {
return await RemoteProcedures.getUserResumeFilename(user.id);
}
return await RemoteProcedures.getUserResumeFilename(user.id);
}

@BackendMethod({ allowed: true })
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"html-to-text": "^9.0.5",
"mongodb": "^5.1.0",
"multer": "^1.4.5-lts.1",
"nanoid": "^4.0.2",
"nanoid": "^5.0.6",
"next": "^13.2.4",
"next-usequerystate": "^1.7.2",
"octokit": "^2.0.14",
Expand All @@ -52,6 +52,7 @@
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-quill": "^2.0.0",
"recharts": "^2.12.2",
"remult": "0.24.1",
"sass": "^1.60.0",
"serve-static": "^1.15.0",
Expand Down
2 changes: 1 addition & 1 deletion public-frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
width=device-width, initial-scale=1.0,
minimum-scale=1.0, maximum-scale=1.0,
user-scalable=no, target-densitydpi=device-dpi">
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
<link rel="shortcut icon" type="image/ico" href="/favicon.png">
<!-- <link rel="apple-touch-icon" sizes="180x180" href="/favicon_package/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon_package/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon_package/favicon-16x16.png">
Expand Down
Binary file added public-frontend/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public-frontend/src/assets/bawls.webp
Binary file not shown.
Binary file added public-frontend/src/assets/kentdisplays.webp
Binary file not shown.
Loading

0 comments on commit 9fe1f46

Please sign in to comment.