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

replace "First name" and "Surname" input fields with a single "Full Name" field #1084

Merged
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
2 changes: 2 additions & 0 deletions drizzle/0008_remove_firstName_and_surname.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "user" DROP COLUMN IF EXISTS "firstName";--> statement-breakpoint
ALTER TABLE "user" DROP COLUMN IF EXISTS "surname";
Loading