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

Safities User Settings #102

Merged
merged 21 commits into from
Sep 11, 2024
Merged

Safities User Settings #102

merged 21 commits into from
Sep 11, 2024

Conversation

jacobellerbrock
Copy link
Contributor

@jacobellerbrock jacobellerbrock commented Sep 9, 2024

Added settings menu, allowing for updating for user data, profile data, and most of registration data.
Note: had to jump around some typescript for assumed types

  • Still want to add more UI/UX components, but general gist is there.

Will need to adjust for schema changes

Satisfies (#42)

# Account
## Personal Information
- First Name
- Last Name
## Public Information
- Hacker Tag (must be unique)
- Check if profile is searchable
# Profile
## Profile Photo
## Profile Data
- Bio
- Skills (tags)
- Discord Username
# Registration
- Separate page, WIP
# Account
## Personal Information
- First Name
- Last Name
## Public Information
- Hacker Tag (must be unique)
- Check if profile is searchable
# Profile
## Profile Photo
## Profile Data
- Bio
- Skills (tags)
- Discord Username
# Registration
- Separate page, WIP
TODO:
- Fix resume
- Make the registration page prettier
- Add a way to go back easier
- Just better UI/UX
- Figure out these TypeScript errors but it works?
TODO:
- Fix resume
- Make the registration page prettier
- Add a way to go back easier
- Just better UI/UX
- Figure out RegisterFormSettings.tsx errors
TODO:
- Fix resume
- Fix sidebar
- Add a way to go back easier
- Loading buttons when updating
TODO:
- Fix sidebar
- Add a way to go back easier
- Loading buttons when updating
TODO:
- Fix sidebar
- Add a way to go back easier
- Loading buttons when updating
Copy link

vercel bot commented Sep 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hack-kit-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 11, 2024 5:55am

@christianhelp
Copy link
Collaborator

Will take a look at the files themselves tomorrow. However, looking at the build it could use a bit of mobile optimization at least from what I saw on my phone. Functionality looks good though.

# Conflicts:
#	pnpm-lock.yaml
@jacobellerbrock jacobellerbrock changed the title Feat/user settings Safities User Settings Sep 9, 2024
- Improved mobile
  - Got rid of aside on mobile
  - Added more left margin
 - Added spinners to buttons
Added a button to go back from registration
Added profile picture viewer
@jacobellerbrock
Copy link
Contributor Author

Fixed the mobile optimization. Should be good now. Added a large amount of UI/UX ease, fixed resume, and drop downs.

with: {
registrationData: true,
profileData: true,
},
where: eq(users.clerkID, userId!),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why does userId need to have the ! behind it? It should already be not null at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look at this.

import { useAction } from "next-safe-action/hook";
import { modifyAccountSettings } from "@/actions/user-profile-mod";
import { Checkbox } from "@/components/shadcn/ui/checkbox";
import c from "config";
import { Loader2 } from "lucide-react";

interface UserProps {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: There is an easier way to do this with just importing the table itself and using the inferSelect or using zod through the z.infer I believe. This serves to benefit us in the fact that it also becomes dynamic so this interface will never need to be updated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding on to this, and non-blocking for now, but super common types like this should live in a types.ts inside of our db package. For now, keep it in this file though. Just something worth noting.

}

interface AccountSettingsProps {
user: UserProps;
}

export default function AccountSettings({ user }: AccountSettingsProps) {
const [newFirstName, setNewFirstName] = useState(user.firstName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking. When you have a lot of different useState hooks like this, it is better to use React Hook form as it handles a lot of the state changes, zod resolving, etc for you. The registration form uses them and also something good to note for later.

);
const [hackerTagTakenAlert, setHackerTagTakenAlert] = useState(false);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit and non-blocking: useAction should come with loading state as well. However, our action is a bit older here so that may not be the case.

}

export default function ProfileSettings({ profile }: ProfileSettingsProps) {
const [newPronouns, setNewPronouns] = useState<string>(profile.pronouns);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking and nit: Same as before. Please use React Hook for in future forms.

});
const [uploadedFile, setUploadedFile] = useState<File | null>(null);
const resumeLink: string = data.resume ?? c.noResumeProvidedURL;
// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why did this you have to use ts-ignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resumeLink thinks it could be undefined, but I thought the line above, the ?? operator will set resumeLink to c.noResumeProvidedURL if data.resume is nullish (including undefined, right?), so therefor, resumeLink will never be undefined, but I couldn't figure out how to make it think that without the build failing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take a look at this.

}

export default function RegisterForm({ data }: RegisterFormSettingsProps) {
if (data.heardFrom === null) data.heardFrom = undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: What is the purpose of this? null and undefined should be handled the same in nullish or truthy coalescing as well as the database should treat them the same I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out how to get around TypeScript handling them differently. I'll do more research on it.

import { Loader2 } from "lucide-react";

export default function RegistrationSettings() {
const [isLoading, setIsLoading] = useState(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Still don't think these need loading states

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had times where the loading between pages has taken a while, thus to verify their click was registered.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you seen this on the deployment? Or just local.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both. On deployment, it's usually first load, but then it's instant. Looking into it rn

@@ -12,40 +12,192 @@ import { revalidatePath } from "next/cache";
// TODO: Add skill updating
export const modifyRegistrationData = authenticatedAction(
z.object({
Copy link
Collaborator

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.

PersonalWebsite,
},
{ userId },
) => {
const user = await db.query.users.findFirst({
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This is fine for now, but you can also have an onConflict statement so the db can handle this for you. With less lookups.

Copy link
Collaborator

@christianhelp christianhelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all of your .idea before merging. Also please look over and be aware of my notes. As for now, it works from what it seems and that is what matters,

Took out Back button loader to simplify process.
Copy link
Collaborator

@christianhelp christianhelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more nits that need to be cleaned up later, but for now we have all functionality so merging due to time constraints.

@christianhelp christianhelp merged commit 9b001c4 into dev Sep 11, 2024
3 checks passed
Lermatroid added a commit that referenced this pull request Sep 11, 2024
Lermatroid added a commit that referenced this pull request Sep 11, 2024
@christianhelp christianhelp deleted the feat/user-settings branch November 26, 2024 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants