Skip to content

Commit

Permalink
Use full name instead of first/last (#635)
Browse files Browse the repository at this point in the history
* use full name instead of first/last

* linting

* Move tool tip to top
  • Loading branch information
daisykucharski authored Nov 2, 2023
1 parent 57af9f6 commit a719fbe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 72 deletions.
8 changes: 1 addition & 7 deletions packages/api-v2/src/student/student.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export class StudentService {
createStudentDto: SignUpStudentDto
): Promise<Student | EmailAlreadyExists | WeakPassword> {
// make sure the user doesn't already exists
const { email, firstName, lastName, password, passwordConfirm } =
createStudentDto;
const { email, fullName, password, passwordConfirm } = createStudentDto;
const userInDb = await this.studentRepository.findOne({ where: { email } });
if (userInDb) {
this.logger.debug(
Expand All @@ -55,11 +54,6 @@ export class StudentService {
return new WeakPassword();
}

let fullName;
if (firstName && lastName) {
fullName = `${firstName} ${lastName}`;
}

const newStudent = this.studentRepository.create({
fullName,
email,
Expand Down
10 changes: 3 additions & 7 deletions packages/common/src/api-dtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ export class UpdatePlanDto {
export class SignUpStudentDto {
@IsOptional()
@IsString()
firstName: string;

@IsOptional()
@IsString()
lastName: string;
fullName: string;

@IsNotEmpty()
@IsEmail()
Expand Down Expand Up @@ -229,7 +225,7 @@ export class ForgotPasswordDto {
export class ResetPasswordDto {
@IsNotEmpty()
@IsString()
token: string
token: string;

@IsString()
@IsNotEmpty()
Expand All @@ -238,4 +234,4 @@ export class ResetPasswordDto {
@IsString()
@IsNotEmpty()
passwordConfirm: string;
}
}
39 changes: 8 additions & 31 deletions packages/frontend-v2/components/Header/AccountOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ interface AccountOverviewProps {
}

interface UpdateName {
firstName: string;
lastName: string;
fullName: string;
}

export const AccountOverview: React.FC<AccountOverviewProps> = ({
Expand All @@ -45,8 +44,6 @@ export const AccountOverview: React.FC<AccountOverviewProps> = ({
register,
handleSubmit,
formState: { errors, isSubmitting },
watch,
trigger,
reset,
} = useForm<UpdateName>({
mode: "onChange",
Expand All @@ -56,19 +53,16 @@ export const AccountOverview: React.FC<AccountOverviewProps> = ({
useEffect(() => {
if (student.fullName) {
reset({
firstName: student.fullName.split(" ")[0],
lastName: student.fullName.split(" ")[1],
fullName: student.fullName,
});
}
}, [reset, student]);

const firstName = watch("firstName", "");

const onSubmitHandler = async (payload: UpdateName) => {
try {
const newStudent: StudentModel<string> = {
...student,
fullName: `${payload.firstName} ${payload.lastName}`,
fullName: payload.fullName,
};
mutateStudent(async () => {
await API.student.update(newStudent);
Expand Down Expand Up @@ -103,28 +97,11 @@ export const AccountOverview: React.FC<AccountOverviewProps> = ({
<Flex columnGap="md">
<GraduateInput
type="text"
formLabel="First Name"
id="firstName"
placeholder="Cooper"
error={errors.firstName}
{...register("firstName", {
onBlur: () => trigger("lastName"),
pattern: noLeadOrTrailWhitespacePattern,
})}
/>
<GraduateInput
error={errors.lastName}
type="text"
formLabel="Last Name"
id="lastName"
placeholder="The Dog"
{...register("lastName", {
validate: (lastName) => {
if (lastName !== "" && firstName === "") {
return "Please enter your first name along with your last name.";
}
return true;
},
formLabel="Full Name"
id="fullName"
placeholder="Cooper The Dog"
error={errors.fullName}
{...register("fullName", {
pattern: noLeadOrTrailWhitespacePattern,
})}
/>
Expand Down
37 changes: 10 additions & 27 deletions packages/frontend-v2/pages/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const SignUpForm: React.FC = () => {

// Need to keep track of these values for validation
const password = watch("password", "");
const firstName = watch("firstName", "");

const onSubmitHandler = async (payload: SignUpStudentDto) => {
try {
Expand Down Expand Up @@ -76,38 +75,22 @@ const SignUpForm: React.FC = () => {
inputs={
<>
<Flex direction="column" rowGap="xs">
<Flex alignItems="center" columnGap="sm" color="gray">
<InfoOutlineIcon />
<Text color="gray" lineHeight="1">
Name is optional.
</Text>
</Flex>
<Flex columnGap="md">
<GraduateInput
type="text"
id="firstName"
placeholder="First Name"
error={errors.firstName}
{...register("firstName", {
onBlur: () => trigger("lastName"),
id="fullName"
placeholder="Full Name"
error={errors.fullName}
{...register("fullName", {
pattern: noLeadOrTrailWhitespacePattern,
})}
/>
<GraduateInput
type="text"
id="lastName"
placeholder="Last Name"
error={errors.lastName}
{...register("lastName", {
validate: (lastName) => {
if (lastName !== "" && firstName === "") {
return "Please enter your first name along with your last name.";
}
return true;
},
pattern: noLeadOrTrailWhitespacePattern,
})}
/>
</Flex>
<Flex alignItems="center" columnGap="sm" color="gray">
<InfoOutlineIcon />
<Text color="gray" lineHeight="1">
Name is optional. If provided, enter at least your first name.
</Text>
</Flex>
</Flex>
<GraduateInput
Expand Down

0 comments on commit a719fbe

Please sign in to comment.