From 9cec49f255f0575740c4829121f07f3148a7690d Mon Sep 17 00:00:00 2001 From: m5r Date: Sat, 25 Sep 2021 22:16:31 +0800 Subject: [PATCH] make user full name mandatory --- app/auth/mutations/signup.ts | 4 ++-- app/auth/pages/sign-up.tsx | 2 +- app/auth/validations.ts | 2 +- app/settings/components/profile-informations.tsx | 16 ++++++++-------- app/settings/mutations/update-user.ts | 6 +++--- app/users/queries/get-current-user.ts | 2 +- .../migration.sql | 9 +++++++++ db/schema.prisma | 2 +- 8 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 db/migrations/20210925140956_make_full_name_mandatory/migration.sql diff --git a/app/auth/mutations/signup.ts b/app/auth/mutations/signup.ts index 6ebbca6..de100a1 100644 --- a/app/auth/mutations/signup.ts +++ b/app/auth/mutations/signup.ts @@ -4,12 +4,12 @@ import db, { GlobalRole, MembershipRole } from "../../../db"; import { Signup } from "../validations"; import { computeEncryptionKey } from "../../../db/_encryption"; -export default resolver.pipe(resolver.zod(Signup), async ({ email, password, name }, ctx) => { +export default resolver.pipe(resolver.zod(Signup), async ({ email, password, fullName }, ctx) => { const hashedPassword = await SecurePassword.hash(password.trim()); const encryptionKey = computeEncryptionKey(email.toLowerCase().trim()).toString("hex"); const user = await db.user.create({ data: { - name: name.trim(), + fullName: fullName.trim(), email: email.toLowerCase().trim(), hashedPassword, role: GlobalRole.CUSTOMER, diff --git a/app/auth/pages/sign-up.tsx b/app/auth/pages/sign-up.tsx index 291f01a..1494629 100644 --- a/app/auth/pages/sign-up.tsx +++ b/app/auth/pages/sign-up.tsx @@ -40,7 +40,7 @@ const SignUp: BlitzPage = () => { } }} > - + diff --git a/app/auth/validations.ts b/app/auth/validations.ts index 2710400..5b12cbb 100644 --- a/app/auth/validations.ts +++ b/app/auth/validations.ts @@ -3,7 +3,7 @@ import { z } from "zod"; export const password = z.string().min(10).max(100); export const Signup = z.object({ - name: z.string(), + fullName: z.string(), email: z.string().email(), password, }); diff --git a/app/settings/components/profile-informations.tsx b/app/settings/components/profile-informations.tsx index 8f1888f..d4fbcaf 100644 --- a/app/settings/components/profile-informations.tsx +++ b/app/settings/components/profile-informations.tsx @@ -12,7 +12,7 @@ import useCurrentUser from "../../core/hooks/use-current-user"; import appLogger from "../../../integrations/logger"; type Form = { - name: string; + fullName: string; email: string; }; @@ -30,17 +30,17 @@ const ProfileInformations: FunctionComponent = () => { const [errorMessage, setErrorMessage] = useState(""); useEffect(() => { - setValue("name", user?.name ?? ""); + setValue("fullName", user?.fullName ?? ""); setValue("email", user?.email ?? ""); }, [setValue, user]); - const onSubmit = handleSubmit(async ({ name, email }) => { + const onSubmit = handleSubmit(async ({ fullName, email }) => { if (isSubmitting) { return; } try { - await updateUserMutation({ email, name }); + await updateUserMutation({ email, fullName }); } catch (error: any) { logger.error(error.response, "error updating user infos"); setErrorMessage(error.response.data.errorMessage); @@ -68,16 +68,16 @@ const ProfileInformations: FunctionComponent = () => {
-