-
Notifications
You must be signed in to change notification settings - Fork 19
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
Safities User Settings #102
Changes from all commits
1273865
f6d6296
47ae8c5
ed3b305
92e2b00
acd7be2
f9eef0a
5db824b
cf1084d
909ac01
3c68817
3b54765
15d90c7
5198638
fc1890e
7c62ff3
5e58266
d7e474e
3cb3c04
0aa79dd
1e66114
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,6 @@ yarn-error.log* | |
|
||
# vscode | ||
.vscode | ||
|
||
#Jetbrians | ||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,40 +12,192 @@ import { revalidatePath } from "next/cache"; | |
// TODO: Add skill updating | ||
export const modifyRegistrationData = authenticatedAction( | ||
z.object({ | ||
bio: z.string().max(500), | ||
skills: z.string().max(100), | ||
age: z.number(), | ||
gender: z.string(), | ||
race: z.string(), | ||
ethnicity: z.string(), | ||
wantsToReceiveMLHEmails: z.boolean(), | ||
university: z.string(), | ||
major: z.string(), | ||
levelOfStudy: z.string(), | ||
shortID: z.string(), | ||
hackathonsAttended: z.number(), | ||
softwareExperience: z.string(), | ||
heardFrom: z.string().nullish(), | ||
shirtSize: z.string(), | ||
dietRestrictions: z.string().array(), | ||
accommodationNote: z.string().nullish(), | ||
GitHub: z.string().nullish(), | ||
LinkedIn: z.string().nullish(), | ||
PersonalWebsite: z.string().nullish(), | ||
}), | ||
async ({ bio, skills }, { userId }) => { | ||
async ( | ||
{ | ||
age, | ||
gender, | ||
race, | ||
ethnicity, | ||
wantsToReceiveMLHEmails, | ||
university, | ||
major, | ||
levelOfStudy, | ||
shortID, | ||
hackathonsAttended, | ||
softwareExperience, | ||
heardFrom, | ||
shirtSize, | ||
dietRestrictions, | ||
accommodationNote, | ||
GitHub, | ||
LinkedIn, | ||
PersonalWebsite, | ||
}, | ||
{ userId }, | ||
) => { | ||
const user = await db.query.users.findFirst({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we created a safe action for this check. Non-blocking for now. |
||
where: eq(users.clerkID, userId), | ||
}); | ||
if (!user) throw new Error("User not found"); | ||
await db | ||
.update(registrationData) | ||
.set({ | ||
age, | ||
gender, | ||
race, | ||
ethnicity, | ||
wantsToReceiveMLHEmails, | ||
university, | ||
major, | ||
levelOfStudy, | ||
shortID, | ||
hackathonsAttended, | ||
softwareExperience, | ||
heardFrom, | ||
shirtSize, | ||
dietRestrictions, | ||
accommodationNote, | ||
GitHub, | ||
LinkedIn, | ||
PersonalWebsite, | ||
}) | ||
.where(eq(registrationData.clerkID, user.clerkID)); | ||
return { | ||
success: true, | ||
christianhelp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
newAge: age, | ||
newGender: gender, | ||
newRace: race, | ||
newEthnicity: ethnicity, | ||
newWantsToReceiveMLHEmails: wantsToReceiveMLHEmails, | ||
newUniversity: university, | ||
newMajor: major, | ||
newLevelOfStudy: levelOfStudy, | ||
newShortID: shortID, | ||
newHackathonsAttended: hackathonsAttended, | ||
newSoftwareExperience: softwareExperience, | ||
newHeardFrom: heardFrom, | ||
newShirtSize: shirtSize, | ||
newDietaryRestrictions: dietRestrictions, | ||
newAccommodationNote: accommodationNote, | ||
newGitHub: GitHub, | ||
newLinkedIn: LinkedIn, | ||
newPersonalWebsite: PersonalWebsite, | ||
}; | ||
}, | ||
); | ||
|
||
export const modifyResume = authenticatedAction( | ||
z.object({ | ||
resume: z.string(), | ||
}), | ||
async ({ resume }, { userId }) => { | ||
const user = await db.query.users.findFirst({ | ||
where: eq(users.clerkID, userId), | ||
}); | ||
if (!user) throw new Error("User not found"); | ||
await db | ||
.update(registrationData) | ||
.set({ resume }) | ||
.where(eq(registrationData.clerkID, user.clerkID)); | ||
return { | ||
success: true, | ||
newResume: resume, | ||
}; | ||
}, | ||
); | ||
|
||
export const modifyProfileData = authenticatedAction( | ||
z.object({ | ||
pronouns: z.string(), | ||
bio: z.string(), | ||
skills: z.string().array(), | ||
discordUsername: z.string(), | ||
}), | ||
async ({ pronouns, bio, skills, discordUsername }, { userId }) => { | ||
const user = await db | ||
.select() | ||
.from(users) | ||
.leftJoin(profileData, eq(users.hackerTag, profileData.hackerTag)) | ||
.where(eq(users.clerkID, userId)); | ||
if (!user || !user[0].profile_data) { | ||
throw new Error("User not found"); | ||
} | ||
await db | ||
.update(profileData) | ||
.set({ bio }) | ||
.where(eq(profileData.hackerTag, user.hackerTag)); | ||
return { success: true, newbio: bio }; | ||
.set({ pronouns, bio, skills, discordUsername }) | ||
.where(eq(profileData.hackerTag, user[0].profile_data.hackerTag)); | ||
return { | ||
success: true, | ||
newPronouns: pronouns, | ||
newBio: bio, | ||
newSkills: skills, | ||
newDiscord: discordUsername, | ||
}; | ||
}, | ||
); | ||
|
||
export const modifyAccountSettings = authenticatedAction( | ||
z.object({ | ||
firstName: z.string().min(1).max(50), | ||
lastName: z.string().min(1).max(50), | ||
//email: z.string().min(1).max(50), | ||
hackerTag: z.string().min(1).max(50), | ||
hasSearchableProfile: z.boolean(), | ||
}), | ||
async ({ firstName, lastName }, { userId }) => { | ||
async ( | ||
{ firstName, lastName, hackerTag, hasSearchableProfile }, | ||
{ userId }, | ||
) => { | ||
const user = await db.query.users.findFirst({ | ||
where: eq(users.clerkID, userId), | ||
}); | ||
if (!user) throw new Error("User not found"); | ||
let oldHackerTag = user.hackerTag; // change when hackertag is not PK on profileData table | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: This is fine for now, but you can also have an |
||
if (oldHackerTag != hackerTag) { | ||
const lookupByHackerTag = await db.query.users.findFirst({ | ||
where: eq(users.hackerTag, hackerTag.toLowerCase()), | ||
}); // copied from /api/registration/create | ||
if (lookupByHackerTag) { | ||
return { | ||
success: false, | ||
message: "hackertag_not_unique", | ||
}; | ||
} | ||
} | ||
await db | ||
.update(users) | ||
.set({ firstName, lastName }) | ||
.set({ firstName, lastName, hackerTag, hasSearchableProfile }) | ||
.where(eq(users.clerkID, userId)); | ||
await db | ||
.update(profileData) // see above comment | ||
.set({ hackerTag }) | ||
.where(eq(profileData.hackerTag, oldHackerTag)); | ||
return { | ||
success: true, | ||
newFirstName: firstName, | ||
newLastName: lastName, | ||
//newEmail: email, | ||
newHackerTag: hackerTag, | ||
newHasSearchableProfile: hasSearchableProfile, | ||
}; | ||
}, | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,43 @@ | ||
export default function Page() { | ||
return <span>howdy</span>; | ||
import AccountSettings from "@/components/settings/AccountSettings"; | ||
import { users } from "db/schema"; | ||
import { eq } from "db/drizzle"; | ||
import { auth } from "@clerk/nextjs"; | ||
import { db } from "db"; | ||
import { redirect } from "next/navigation"; | ||
import ProfileSettings from "@/components/settings/ProfileSettings"; | ||
import RegistrationSettings from "@/components/settings/RegistrationSettings"; | ||
|
||
export default async function Page() { | ||
const { userId } = auth(); | ||
if (!userId) return redirect("/sign-in"); | ||
const user = await db.query.users.findFirst({ | ||
with: { | ||
registrationData: true, | ||
profileData: true, | ||
}, | ||
where: eq(users.clerkID, userId!), | ||
}); | ||
if (!user) return redirect("/sign-in"); | ||
|
||
function Header({ tag }: { tag: string }) { | ||
return ( | ||
<h1 | ||
id={tag.toLowerCase()} | ||
className="mt-10 pb-5 text-4xl font-bold" | ||
> | ||
{tag} | ||
</h1> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<Header tag="Account" /> | ||
<AccountSettings user={user} /> | ||
<Header tag="Profile" /> | ||
<ProfileSettings profile={user.profileData} /> | ||
<Header tag={"Registration"} /> | ||
<RegistrationSettings /> | ||
</div> | ||
); | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import AccountSettings from "@/components/settings/AccountSettings"; | ||
import { users } from "db/schema"; | ||
import { eq } from "db/drizzle"; | ||
import RegisterFormSettings from "@/components/settings/RegistrationForm/RegisterFormSettings"; | ||
import { auth } from "@clerk/nextjs"; | ||
import { db } from "db"; | ||
import { eq } from "db/drizzle"; | ||
import { users } from "db/schema"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default async function Page() { | ||
const { userId } = auth(); | ||
if (!userId) return redirect("/sign-in"); | ||
const user = await db.query.users.findFirst({ | ||
with: { registrationData: true }, | ||
with: { | ||
registrationData: true, | ||
profileData: true, | ||
}, | ||
where: eq(users.clerkID, userId!), | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: why does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was to appease TypeScript. It thinks user may be undefined in the props argument. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will take a look at this. |
||
if (!user) return redirect("/sign-in"); | ||
return <AccountSettings user={user} />; | ||
} | ||
|
||
export const runtime = "edge"; | ||
return <RegisterFormSettings data={user.registrationData} />; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit and non-blocking: As stated before, common types should be in their own types and also use the types of the tables instead of manually adding them.