diff --git a/packages/api-v2/src/student/student.service.ts b/packages/api-v2/src/student/student.service.ts index 0da0199c6..69c9589aa 100644 --- a/packages/api-v2/src/student/student.service.ts +++ b/packages/api-v2/src/student/student.service.ts @@ -16,7 +16,12 @@ import { UpdateStudentDto, } from "@graduate/common"; import { Student } from "./entities/student.entity"; -import { EmailAlreadyExists, NewPasswordsDontMatch, WeakPassword, WrongPassword } from "./student.errors"; +import { + EmailAlreadyExists, + NewPasswordsDontMatch, + WeakPassword, + WrongPassword, +} from "./student.errors"; @Injectable() export class StudentService { @@ -25,14 +30,13 @@ export class StudentService { constructor( @InjectRepository(Student) private studentRepository: Repository - ) { } + ) {} async create( createStudentDto: SignUpStudentDto ): Promise { // 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( @@ -50,11 +54,6 @@ export class StudentService { return new WeakPassword(); } - let fullName; - if (firstName && lastName) { - fullName = `${firstName} ${lastName}`; - } - const newStudent = this.studentRepository.create({ fullName, email, @@ -161,8 +160,12 @@ export class StudentService { return formatServiceCtx(StudentService.name, methodName); } - async changePassword(uuid: any, changePasswordDto: ChangePasswordDto): Promise { - const { currentPassword, newPassword, newPasswordConfirm } = changePasswordDto; + async changePassword( + uuid: any, + changePasswordDto: ChangePasswordDto + ): Promise { + const { currentPassword, newPassword, newPasswordConfirm } = + changePasswordDto; const student = await this.findByUuid(uuid); if (newPassword !== newPasswordConfirm) { @@ -170,40 +173,50 @@ export class StudentService { } const { password: trueHashedPassword } = student; - const isValidPassword = await bcrypt.compare(currentPassword, trueHashedPassword); + const isValidPassword = await bcrypt.compare( + currentPassword, + trueHashedPassword + ); if (!isValidPassword) { - this.logger.debug( - { message: "Invalid password", oldPassword: currentPassword }, - ); + this.logger.debug({ + message: "Invalid password", + oldPassword: currentPassword, + }); return new WrongPassword(); } if (!isStrongPassword(newPassword)) { - this.logger.debug( - { message: "weak password", oldPassword: currentPassword }, - ); + this.logger.debug({ + message: "weak password", + oldPassword: currentPassword, + }); return new WeakPassword(); } - await this.studentRepository.save(Object.assign(student, { password: newPassword })); + await this.studentRepository.save( + Object.assign(student, { password: newPassword }) + ); } - async resetPassword(email, resetPasswordData: ResetPasswordDto): Promise { + async resetPassword( + email, + resetPasswordData: ResetPasswordDto + ): Promise { const { password, passwordConfirm } = resetPasswordData; - const student = await this.findByEmail(email) + const student = await this.findByEmail(email); if (password !== passwordConfirm) { return new NewPasswordsDontMatch(); } if (!isStrongPassword(password)) { - this.logger.debug( - { message: "weak password", password }, - ); + this.logger.debug({ message: "weak password", password }); return new WeakPassword(); } - return await this.studentRepository.save(Object.assign(student, { password })) + return await this.studentRepository.save( + Object.assign(student, { password }) + ); } } diff --git a/packages/common/src/api-dtos.ts b/packages/common/src/api-dtos.ts index 30529d506..2e17c61f7 100644 --- a/packages/common/src/api-dtos.ts +++ b/packages/common/src/api-dtos.ts @@ -68,11 +68,7 @@ export class UpdatePlanDto { export class SignUpStudentDto { @IsOptional() @IsString() - firstName: string; - - @IsOptional() - @IsString() - lastName: string; + fullName: string; @IsNotEmpty() @IsEmail() @@ -229,7 +225,7 @@ export class ForgotPasswordDto { export class ResetPasswordDto { @IsNotEmpty() @IsString() - token: string + token: string; @IsString() @IsNotEmpty() @@ -238,4 +234,4 @@ export class ResetPasswordDto { @IsString() @IsNotEmpty() passwordConfirm: string; -} \ No newline at end of file +} diff --git a/packages/frontend-v2/components/Header/AccountOverview.tsx b/packages/frontend-v2/components/Header/AccountOverview.tsx index 64b227d92..2f6d14793 100644 --- a/packages/frontend-v2/components/Header/AccountOverview.tsx +++ b/packages/frontend-v2/components/Header/AccountOverview.tsx @@ -31,8 +31,7 @@ interface AccountOverviewProps { } interface UpdateName { - firstName: string; - lastName: string; + fullName: string; } export const AccountOverview: React.FC = ({ @@ -45,8 +44,6 @@ export const AccountOverview: React.FC = ({ register, handleSubmit, formState: { errors, isSubmitting }, - watch, - trigger, reset, } = useForm({ mode: "onChange", @@ -56,19 +53,16 @@ export const AccountOverview: React.FC = ({ 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 = { ...student, - fullName: `${payload.firstName} ${payload.lastName}`, + fullName: payload.fullName, }; mutateStudent(async () => { await API.student.update(newStudent); @@ -103,28 +97,11 @@ export const AccountOverview: React.FC = ({ trigger("lastName"), - pattern: noLeadOrTrailWhitespacePattern, - })} - /> - { - 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, })} /> diff --git a/packages/frontend-v2/pages/signup.tsx b/packages/frontend-v2/pages/signup.tsx index 48414d5fc..674006795 100644 --- a/packages/frontend-v2/pages/signup.tsx +++ b/packages/frontend-v2/pages/signup.tsx @@ -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 { @@ -76,38 +75,22 @@ const SignUpForm: React.FC = () => { inputs={ <> + + + + Name is optional. + + trigger("lastName"), + id="fullName" + placeholder="Full Name" + error={errors.fullName} + {...register("fullName", { pattern: noLeadOrTrailWhitespacePattern, })} /> - { - if (lastName !== "" && firstName === "") { - return "Please enter your first name along with your last name."; - } - return true; - }, - pattern: noLeadOrTrailWhitespacePattern, - })} - /> - - - - - Name is optional. If provided, enter at least your first name. -