Skip to content
6 changes: 2 additions & 4 deletions app/(app)/alpha/additional-details/_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ export async function slideOneSubmitAction(dataInput: TypeSlideOneSchema) {
}

try {
const { firstName, surname, username, location } =
slideOneSchema.parse(dataInput);
const { name, username, location } = slideOneSchema.parse(dataInput);

await db
.update(user)
.set({
firstName,
surname,
name,
username,
location,
})
Expand Down
43 changes: 12 additions & 31 deletions app/(app)/alpha/additional-details/_client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ import { Divider } from "@/components/ui-components/divider";

type UserDetails = {
username: string;
firstName: string;
surname: string;
name: string;
gender: string;
dateOfBirth: string;
location: string;
Expand All @@ -63,8 +62,7 @@ export default function AdditionalSignUpDetails({
const searchParams = useSearchParams();

const {
surname,
firstName,
name,
username,
location,
dateOfBirth,
Expand All @@ -75,7 +73,7 @@ export default function AdditionalSignUpDetails({
let slide: number;
if (searchParams.get("slide")) {
slide = Number(searchParams.get("slide"));
} else if (!surname || !firstName || !username || !location) {
} else if (!name || !username || !location) {
slide = 1;
} else if (!dateOfBirth || !gender) {
slide = 2;
Expand All @@ -102,15 +100,15 @@ export default function AdditionalSignUpDetails({
function SlideOne({ details }: { details: UserDetails }) {
const router = useRouter();

const { username, firstName, surname, location } = details;
const { username, name, location } = details;

const {
register,
handleSubmit,
formState: { errors, isSubmitting },
} = useForm<TypeSlideOneSchema>({
resolver: zodResolver(slideOneSchema),
defaultValues: { username, firstName, surname, location },
defaultValues: { username, name, location },
});

const onFormSubmit = async (data: TypeSlideOneSchema) => {
Expand Down Expand Up @@ -139,33 +137,16 @@ function SlideOne({ details }: { details: UserDetails }) {
<Divider className="my-4 mt-4" />
<div className="mx-4">
<Field>
<Label>First Name</Label>
<Label>Full Name</Label>
<Input
id="first-name"
placeholder="Enter first name"
invalid={!!errors?.firstName}
{...register("firstName")}
id="full-name"
placeholder="Enter full name"
invalid={!!errors?.name}
{...register("name")}
/>
{errors?.firstName && (
{errors?.name && (
<ErrorMessage className="text-red-500">
{errors.firstName.message}
</ErrorMessage>
)}
</Field>
</div>

<div className="mx-4 mt-4 ">
<Field>
<Label>Surname</Label>
<Input
id="surname"
placeholder="Enter surname"
invalid={!!errors?.surname}
{...register("surname")}
/>
{errors?.surname && (
<ErrorMessage className="text-red-500">
{errors.surname.message}
{errors.name.message}
</ErrorMessage>
)}
</Field>
Expand Down
6 changes: 2 additions & 4 deletions app/(app)/alpha/additional-details/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export default async function Page() {
const details = await db.query.user.findFirst({
columns: {
username: true,
firstName: true,
surname: true,
name: true,
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 7, 2024

Choose a reason for hiding this comment

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

💡 Codebase verification

Remaining references to firstName and surname found. Please update all instances to use the new name field.

  • app/(app)/alpha/settings/profile.ts contains references to firstName and surname.
🔗 Analysis chain

LGTM! Verify database schema consistency.

The change from separate firstName and surname fields to a single name field in the database query aligns with the PR objectives. This modification correctly reflects the consolidation of user name information.

To ensure consistency across the codebase, please run the following script to verify that all references to firstName and surname have been updated:


Copy link
Member

Choose a reason for hiding this comment

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

This can be safely ignored, since this alpha/settings page is legacy and will be deleted.

Copy link
Contributor

Choose a reason for hiding this comment

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

@John-Paul-Larkin, understood. I'll note that the app/(app)/alpha/settings page is legacy and will be deleted.

(_/)
(._.)
/


✏️ Learnings added
Learnt from: John-Paul-Larkin
PR: codu-code/codu#1084
File: app/(app)/alpha/additional-details/page.tsx:16-16
Timestamp: 2024-10-07T18:36:02.876Z
Learning: The `app/(app)/alpha/settings` page is legacy and will be deleted.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

gender: true,
dateOfBirth: true,
location: true,
Expand All @@ -29,8 +28,7 @@ export default async function Page() {

const detailsWithNullsRemoved = {
username: details?.username || "",
firstName: details?.firstName || "",
surname: details?.surname || "",
name: details?.name || "",
gender: details?.gender || "",
dateOfBirth: details?.dateOfBirth || "",
location: details?.location || "",
Expand Down
9 changes: 2 additions & 7 deletions schema/additionalUserDetails.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import z from "zod";

export const slideOneSchema = z.object({
firstName: z
name: z
.string()
.trim()
.min(2, "Min name length is 2 characters.")
.max(50, "Max name length is 50 characters."),
surname: z
.string()
.trim()
.min(2, "Min name length is 2 characters.")
.min(1, "Min name length is 1 characters.")
.max(50, "Max name length is 50 characters."),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider adjusting the minimum length for the name field

The current minimum length of 1 character for the name field might be too permissive for a full name. This could potentially allow invalid or incomplete name entries.

Consider increasing the minimum length to ensure more meaningful name entries. For example:

-    .min(1, "Min name length is 1 characters.")
+    .min(2, "Min name length is 2 characters.")

Additionally, you might want to consider adding a regex pattern to ensure the name contains at least two words for a full name, similar to the username field.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: z
.string()
.trim()
.min(2, "Min name length is 2 characters.")
.max(50, "Max name length is 50 characters."),
surname: z
.string()
.trim()
.min(2, "Min name length is 2 characters.")
.min(1, "Min name length is 1 characters.")
.max(50, "Max name length is 50 characters."),
name: z
.string()
.trim()
.min(2, "Min name length is 2 characters.")
.max(50, "Max name length is 50 characters."),

💡 Codebase verification

Issues Found:

  • firstName and surname are still referenced in app/(app)/alpha/settings/profile.ts.

Please update all occurrences of firstName and surname to use the new name field to ensure consistency and prevent potential bugs.

🔗 Analysis chain

Verify impact on existing data and functionality

The change from separate firstName and surname fields to a single name field might affect existing data structures and functionality throughout the application.

Please run the following script to check for any other occurrences of firstName or surname in the codebase that might need updating:

Ensure that all relevant parts of the application are updated to use the new name field instead of firstName and surname.


Apologies for the errors in the previous script. Let's run a corrected script to search for occurrences of firstName and surname in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for occurrences of firstName and surname in the codebase

echo "Checking for 'firstName' occurrences:"
rg --type typescript --type javascript 'firstName'

echo "Checking for 'surname' occurrences:"
rg --type typescript --type javascript 'surname'

Length of output: 318


Script:

#!/bin/bash
# Description: Check for occurrences of firstName and surname in the codebase

echo "Checking for 'firstName' occurrences in .ts and .js files:"
rg 'firstName' --glob '*.ts' --glob '*.js'

echo "Checking for 'surname' occurrences in .ts and .js files:"
rg 'surname' --glob '*.ts' --glob '*.js'

Length of output: 445

username: z
.string()
Expand Down
2 changes: 0 additions & 2 deletions server/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ export const user = pgTable(
websiteUrl: text("websiteUrl").default("").notNull(),
emailNotifications: boolean("emailNotifications").default(true).notNull(),
newsletter: boolean("newsletter").default(true).notNull(),
firstName: text("firstName"),
surname: text("surname"),
gender: text("gender"),
dateOfBirth: timestamp("dateOfBirth", {
precision: 3,
Expand Down