Skip to content
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

Feat/registration quality of life additions #131

Draft
wants to merge 36 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0c1f7fc
adds zod and drizzle-zod
christianhelp Sep 14, 2024
2831ceb
removes uneeded types file
christianhelp Sep 14, 2024
c921ad6
creates db zod
christianhelp Sep 20, 2024
fe8e76f
adds new registration validator
christianhelp Sep 20, 2024
6088fe3
adds new helpers
christianhelp Sep 20, 2024
b2fdb9f
chore: renames configurables
christianhelp Sep 20, 2024
69a7ce5
exports zod
christianhelp Sep 20, 2024
78a893a
adds register form to registration
christianhelp Sep 20, 2024
200ce38
Merge remote-tracking branch 'origin/dev' into feat/registration-qual…
christianhelp Sep 20, 2024
698da73
updates gender options
christianhelp Sep 20, 2024
51a6841
adds dynamic listing for all form fields
christianhelp Sep 20, 2024
791c1cd
updates regist validator
christianhelp Sep 20, 2024
56ef4a8
adds alert dialog
christianhelp Sep 23, 2024
2457df9
adds registration new configs
christianhelp Sep 23, 2024
5760825
adds new registration form
christianhelp Sep 23, 2024
749b32b
updates for configs
christianhelp Sep 23, 2024
107a27b
updates loading for registration
christianhelp Sep 23, 2024
0dcde18
adds user id to props
christianhelp Sep 23, 2024
c04e4cc
updates for config
christianhelp Sep 23, 2024
570b6f7
runs format
christianhelp Sep 23, 2024
5287623
updates registration form
christianhelp Sep 26, 2024
ec584ee
adds feedback alert
christianhelp Sep 26, 2024
d0bfdb6
updates university id regex
christianhelp Sep 26, 2024
f8dde4e
updates registration route
christianhelp Sep 26, 2024
1812221
updates creating registration
christianhelp Sep 26, 2024
c06c04a
updates registration schema
christianhelp Sep 26, 2024
f57a9ff
updates registration form
christianhelp Sep 26, 2024
b91e17d
runs formatter
christianhelp Sep 26, 2024
777d4f3
moves regex to constants
christianhelp Oct 1, 2024
6104b69
updates dietary restrictions
christianhelp Oct 5, 2024
c87ab6e
Merge remote-tracking branch 'origin/dev' into feat/registration-qual…
christianhelp Oct 5, 2024
c4ac3e7
commit for the night
christianhelp Oct 6, 2024
64d1212
adds constants
christianhelp Oct 19, 2024
ad7598a
adds register form w/ action
christianhelp Oct 19, 2024
5a5cf7d
updates
christianhelp Oct 21, 2024
85901f4
this is broken rn lol
christianhelp Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@internationalized/date": "^3.5.4",
"@planetscale/database": "^1.18.0",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.1.1",
"@radix-ui/react-avatar": "^1.0.3",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.4",
Expand Down
141 changes: 141 additions & 0 deletions apps/web/src/actions/registration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
"use server"
import { authenticatedAction } from "@/lib/safe-action"
import { db,sql } from "db"
import { put } from "@vercel/blob"
import { bucketResumeBaseUploadUrl } from "config"
import z from "zod"
import { returnValidationErrors } from "next-safe-action"
import { updateUserResume } from "db/functions"
import { hackerRegistrationFormValidator } from "@/validators/shared/registration"
import { userCommonData, userHackerData } from "db/schema"
import { currentUser } from "@clerk/nextjs/server"
import c from "config"
import { DatabaseError } from "db/types"
import { DUPLICATE_KEY_ERROR_CODE,UNIQUE_KEY_MAPPER_DEFAULT_KEY } from "@/lib/constants"


const uploadResumeSchema = z.object({
resumeFile: z.any()
// .instanceof(File, { message: "Required" })
// .refine((file) => file.size > 0, "Required"),
});

const registerUserSchema = hackerRegistrationFormValidator;


export const uploadResume = authenticatedAction
.schema(uploadResumeSchema).
action(
async ({ ctx:{ userId}, parsedInput:{resumeFile} }) =>{
const fileLocation = `${bucketResumeBaseUploadUrl}/${resumeFile.name}`;
const newBlob = await put(fileLocation, resumeFile, {
access: "public",
});

await updateUserResume(userId,newBlob.url);

return {
success:true,
resume_url:newBlob.url
}
}
);

export const registerUser = authenticatedAction
.schema(registerUserSchema)
.action(
async ( { ctx:{ userId }, parsedInput}) =>{
// Reccomended: Destructure out your unique constraints / primary keys ahead of time to ensure that they can be cause short circuit logic if a unique constraint is violated
const { resumeFile, hackerTag, email,
university,major,schoolID,levelOfStudy,hackathonsAttended,softwareExperience, heardFrom,GitHub,LinkedIn,PersonalWebsite,hasAcceptedMLHCoC,hasSharedDataWithMLH,isEmailable,
...userData
} = parsedInput;

const currUser = await currentUser();

console.log('resume file is',resumeFile);
throw new Error('test');
if (!currUser) {
returnValidationErrors(z.null(), {
_errors: ["User does not exist"],
});
}
const totalUserCount = await db
.select({ count: sql<number>`count(*)`.mapWith(Number) })
.from(userCommonData);

try{
await db.transaction(async (tx) => {
// Add user common insertion
await tx.insert(userCommonData).values({
// Slight optimization to short circuit is to add all of your unique keys at the top
clerkID: userId,
hackerTag: hackerTag.toLocaleLowerCase(),
email,
...userData,
profilePhoto: currUser.imageUrl,
skills: userData.skills.map((v) => v.text.toLowerCase()),
isFullyRegistered: true,
dietRestrictions: userData.dietRestrictions,
});

await tx
.insert(userHackerData)
.values({
clerkID: userId,
university,
major,
schoolID,
levelOfStudy,
hackathonsAttended,
softwareExperience,
heardFrom,
GitHub,
LinkedIn,
PersonalWebsite,
resume:undefined,
group:
totalUserCount[0].count % Object.keys(c.groups).length,
hasAcceptedMLHCoC,
hasSharedDataWithMLH,
isEmailable,
})
});
}catch(e){
// Catch duplicates because they will be based off of the error code 23505
if (e instanceof DatabaseError && e.code === DUPLICATE_KEY_ERROR_CODE){
console.error(e);
const constraintKeyIndex = e.constraint as keyof typeof c.db.UniqueKeyMapper;
return {
success: false,
message: c.db.UniqueKeyMapper[constraintKeyIndex ?? UNIQUE_KEY_MAPPER_DEFAULT_KEY] ?? e.detail,
};
}else{
throw e;
}
}
console.log('Contents of resumeFile',resumeFile);
// Determine upload stuff
// if (resumeFile){
// console.log("Uploading blob");
// const res = await uploadResume({resumeFile});
// if (res?.serverError){
// return {
// success: true,
// message:
// "Registration created successfully but there was an error uploading your resume.",
// };
// }
// console.log("Success posting");
// }

return {
success:true,
message:"Registration created successfully"
}

}
)



1 change: 1 addition & 0 deletions apps/web/src/actions/user-profile-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { decodeBase64AsFile } from "@/lib/utils/shared/files";
import { returnValidationErrors } from "next-safe-action";
import { revalidatePath } from "next/cache";
import { getUser } from "db/functions";
import c from "config";

// TODO: Add skill updating
export const modifyRegistrationData = authenticatedAction
Expand Down
Loading