Skip to content

Commit

Permalink
Fixed with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobellerbrock committed Sep 10, 2024
1 parent 3b54765 commit 15d90c7
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 162 deletions.
68 changes: 58 additions & 10 deletions apps/web/src/actions/user-profile-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,55 @@ export const modifyRegistrationData = authenticatedAction(
LinkedIn: z.string().nullish(),
PersonalWebsite: z.string().nullish(),
}),
async ({ age, gender, race, ethnicity, wantsToReceiveMLHEmails, university, major, levelOfStudy, shortID, hackathonsAttended, softwareExperience, heardFrom, shirtSize, dietRestrictions, accommodationNote, GitHub, LinkedIn, PersonalWebsite }, { 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({
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 })
.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,
Expand Down Expand Up @@ -79,7 +120,7 @@ export const modifyResume = authenticatedAction(
.where(eq(registrationData.clerkID, user.clerkID));
return {
success: true,
newResume: resume
newResume: resume,
};
},
);
Expand All @@ -92,21 +133,25 @@ export const modifyProfileData = authenticatedAction(
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));
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({ pronouns, bio, skills, discordUsername })
.where(eq(profileData.hackerTag, user[0].profile_data.hackerTag))
.where(eq(profileData.hackerTag, user[0].profile_data.hackerTag));
return {
success: true,
newPronouns: pronouns,
newBio: bio,
newSkills: skills,
newDiscord: discordUsername,
}
};
},
);

Expand All @@ -116,9 +161,12 @@ export const modifyAccountSettings = authenticatedAction(
lastName: z.string().min(1).max(50),
//email: z.string().min(1).max(50),
hackerTag: z.string().min(1).max(50),
hasSearchableProfile: z.boolean()
hasSearchableProfile: z.boolean(),
}),
async ({ firstName, lastName, hackerTag, hasSearchableProfile }, { userId }) => {
async (
{ firstName, lastName, hackerTag, hasSearchableProfile },
{ userId },
) => {
const user = await db.query.users.findFirst({
where: eq(users.clerkID, userId),
});
Expand All @@ -132,7 +180,7 @@ export const modifyAccountSettings = authenticatedAction(
return {
success: false,
message: "hackertag_not_unique",
}
};
}
}
await db
Expand All @@ -142,7 +190,7 @@ export const modifyAccountSettings = authenticatedAction(
await db
.update(profileData) // see above comment
.set({ hackerTag })
.where(eq(profileData.hackerTag, oldHackerTag))
.where(eq(profileData.hackerTag, oldHackerTag));
return {
success: true,
newFirstName: firstName,
Expand Down
9 changes: 6 additions & 3 deletions apps/web/src/app/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ export default async function ({ children }: { children: ReactNode }) {
</div>
</div>
</div>
<aside className="sticky top-20 h-screen hidden md:block">
<aside className="sticky top-20 hidden h-screen md:block">
{/* <SettingsSection name="Settings" path="/settings" /> */}
<SettingsSection name="Account" path="/settings#account" />
<SettingsSection name="Account" path="/settings#account" />
<SettingsSection name="Profile" path="/settings#profile" />
<SettingsSection name="Registration" path="/settings#registration" />
<SettingsSection
name="Registration"
path="/settings#registration"
/>
</aside>
<div className="col-span-4 mb-20 ml-5">{children}</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export default async function Page() {

function Header({ tag }: { tag: string }) {
return (
<h1 id={tag.toLowerCase()} className="mt-10 pb-5 text-4xl font-bold">
<h1
id={tag.toLowerCase()}
className="mt-10 pb-5 text-4xl font-bold"
>
{tag}
</h1>
);
Expand All @@ -32,7 +35,7 @@ export default async function Page() {
<Header tag="Account" />
<AccountSettings user={user} />
<Header tag="Profile" />
<ProfileSettings profile={user.profileData}/>
<ProfileSettings profile={user.profileData} />
<Header tag={"Registration"} />
<RegistrationSettings />
</div>
Expand Down
9 changes: 3 additions & 6 deletions apps/web/src/app/settings/registration/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import RegisterFormSettings from "@/components/settings/RegistrationForm/RegisterFormSettings"
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) throw new Error("User not found");
const user = await db.query.users.findFirst({
Expand All @@ -18,7 +17,5 @@ export default async function Page() {
});
if (!user) return redirect("/sign-in");

return (
<RegisterFormSettings data={user.registrationData} />
)
}
return <RegisterFormSettings data={user.registrationData} />;
}
1 change: 0 additions & 1 deletion apps/web/src/components/registration/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ export default function RegisterForm({ defaultEmail }: RegisterFormProps) {
: "grid-cols-1 md:grid-cols-5"
} gap-x-2 gap-y-4`}
>

<FormField
control={form.control}
name="university"
Expand Down
85 changes: 52 additions & 33 deletions apps/web/src/components/settings/AccountSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,32 @@ export default function AccountSettings({ user }: AccountSettingsProps) {
const [newLastName, setNewLastName] = useState(user.lastName);
//const [newEmail, setNewEmail] = useState(user.email);
const [newHackerTag, setNewHackerTag] = useState(user.hackerTag);
const [newIsProfileSearchable, setNewIsProfileSearchable] = useState(user.hasSearchableProfile);
const [hackerTagTakenAlert, setHackerTagTakenAlert] = useState(false)
const [newIsProfileSearchable, setNewIsProfileSearchable] = useState(
user.hasSearchableProfile,
);
const [hackerTagTakenAlert, setHackerTagTakenAlert] = useState(false);

const [isLoading, setIsLoading] = useState(false);

const { execute: runModifyAccountSettings } = useAction(
modifyAccountSettings,
{
onSuccess: ({ success, message }) => {
setIsLoading(false)
setIsLoading(false);
toast.dismiss();
if (!success) {
if (message == "hackertag_not_unique") {toast.error("Hackertag already exists"); setHackerTagTakenAlert(true);}
} else
toast.success("Account updated successfully!");
if (message == "hackertag_not_unique") {
toast.error("Hackertag already exists");
setHackerTagTakenAlert(true);
}
} else toast.success("Account updated successfully!");
},
onError: () => {
setIsLoading(false)
setIsLoading(false);
toast.dismiss();
toast.error("An error occurred while updating your account settings!");
toast.error(
"An error occurred while updating your account settings!",
);
},
},
);
Expand All @@ -67,9 +73,11 @@ export default function AccountSettings({ user }: AccountSettingsProps) {
value={newFirstName}
onChange={(e) => setNewFirstName(e.target.value)}
/>
{(!newFirstName) ?
<div className={"mt-1 text-sm text-red-500"}>This field can't be empty!</div> : null
}
{!newFirstName ? (
<div className={"mt-1 text-sm text-red-500"}>
This field can't be empty!
</div>
) : null}
</div>
<div>
<Label htmlFor={"lastname"}>Last Name</Label>
Expand All @@ -79,9 +87,11 @@ export default function AccountSettings({ user }: AccountSettingsProps) {
value={newLastName}
onChange={(e) => setNewLastName(e.target.value)}
/>
{(!newLastName) ?
<div className={"mt-1 text-sm text-red-500"}>This field can't be empty!</div> : null
}
{!newLastName ? (
<div className={"mt-1 text-sm text-red-500"}>
This field can't be empty!
</div>
) : null}
</div>
{/*<div className={"col-span-full"}>*/}
{/* <Label htmlFor="email">Email</Label>*/}
Expand All @@ -97,46 +107,55 @@ export default function AccountSettings({ user }: AccountSettingsProps) {
{/* }*/}
{/*</div>*/}
</div>
<h2 className="pt-7 pb-5 text-3xl font-semibold">
<h2 className="pb-5 pt-7 text-3xl font-semibold">
Public Information
</h2>
<div className="grid max-w-[500px] grid-cols-1 gap-x-2 gap-y-2">
<div>
<Label htmlFor="hackertag">HackerTag</Label>
<div className="flex mt-2">
<div
className="flex h-10 w-10 items-center justify-center rounded-l bg-accent text-lg font-light text-primary">
<div className="mt-2 flex">
<div className="flex h-10 w-10 items-center justify-center rounded-l bg-accent text-lg font-light text-primary">
@
</div>
<Input
className="rounded-l-none"
placeholder={`${c.hackathonName.toLowerCase()}`}
value={newHackerTag}
onChange={(e) => {
setNewHackerTag(e.target.value)
setHackerTagTakenAlert(false)
setNewHackerTag(e.target.value);
setHackerTagTakenAlert(false);
}}
/>
</div>
{(hackerTagTakenAlert) ?
<div
className={"text-sm text-red-500"}
>
{hackerTagTakenAlert ? (
<div className={"text-sm text-red-500"}>
HackerTag is already taken!
</div>
:
) : (
""
}
{(!newHackerTag) ?
<div className={"mt-1 text-sm text-red-500"}>This field can't be empty!</div> : null
}
)}
{!newHackerTag ? (
<div className={"mt-1 text-sm text-red-500"}>
This field can't be empty!
</div>
) : null}
</div>
<div className={"flex max-w-[600px] flex-row items-start space-x-3 space-y-0 rounded-md border p-4"}>
<div
className={
"flex max-w-[600px] flex-row items-start space-x-3 space-y-0 rounded-md border p-4"
}
>
<Checkbox
checked={newIsProfileSearchable}
onCheckedChange={() => setNewIsProfileSearchable(!newIsProfileSearchable)}
onCheckedChange={() =>
setNewIsProfileSearchable(
!newIsProfileSearchable,
)
}
/>
<Label htmlFor="profileIsSearchable">Make my profile searchable by other Hackers</Label>
<Label htmlFor="profileIsSearchable">
Make my profile searchable by other Hackers
</Label>
</div>
</div>
<Button
Expand All @@ -156,7 +175,7 @@ export default function AccountSettings({ user }: AccountSettingsProps) {
>
{isLoading ? (
<>
<Loader2 className={"mr-2 h-4 w-4 animate-spin"}/>
<Loader2 className={"mr-2 h-4 w-4 animate-spin"} />
<div>Updating</div>
</>
) : (
Expand Down
Loading

0 comments on commit 15d90c7

Please sign in to comment.