make user full name mandatory

This commit is contained in:
m5r 2021-09-25 22:16:31 +08:00
parent 9d30930f96
commit 9cec49f255
8 changed files with 26 additions and 17 deletions

View File

@ -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,

View File

@ -40,7 +40,7 @@ const SignUp: BlitzPage = () => {
}
}}
>
<LabeledTextField name="name" label="Name" type="text" />
<LabeledTextField name="fullName" label="Full name" type="text" />
<LabeledTextField name="email" label="Email" type="email" />
<LabeledTextField name="password" label="Password" type="password" />
</Form>

View File

@ -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,
});

View File

@ -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 = () => {
<div className="shadow sm:rounded-md sm:overflow-hidden">
<div className="px-4 py-5 bg-white space-y-6 sm:p-6">
<div className="col-span-3 sm:col-span-2">
<label htmlFor="name" className="block text-sm font-medium leading-5 text-gray-700">
Name
<label htmlFor="fullName" className="block text-sm font-medium leading-5 text-gray-700">
Full name
</label>
<div className="mt-1 rounded-md shadow-sm">
<input
id="name"
id="fullName"
type="text"
tabIndex={1}
className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md placeholder-gray-400 focus:outline-none focus:shadow-outline-primary focus:border-primary-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"
{...register("name")}
{...register("fullName")}
required
/>
</div>

View File

@ -6,17 +6,17 @@ import notifyEmailChangeQueue from "../api/queue/notify-email-change";
const Body = z.object({
email: z.string().email(),
name: z.string(),
fullName: z.string(),
});
export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ email, name }, ctx) => {
export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ email, fullName }, ctx) => {
const user = await db.user.findFirst({ where: { id: ctx.session.userId! } });
if (!user) throw new NotFoundError();
const oldEmail = user.email;
await db.user.update({
where: { id: user.id },
data: { email, name },
data: { email, fullName },
});
if (oldEmail !== email) {

View File

@ -9,7 +9,7 @@ export default async function getCurrentUser(_ = null, { session }: Ctx) {
where: { id: session.userId },
select: {
id: true,
name: true,
fullName: true,
email: true,
role: true,
memberships: {

View File

@ -0,0 +1,9 @@
/*
Warnings:
- You are about to drop the column `name` on the `User` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "User" DROP COLUMN "name",
ADD COLUMN "fullName" TEXT NOT NULL DEFAULT E'';

View File

@ -69,7 +69,7 @@ model User {
id String @id @default(uuid())
createdAt DateTime @default(now()) @db.Timestamptz
updatedAt DateTime @updatedAt @db.Timestamptz
name String?
fullName String @default("")
email String @unique
hashedPassword String?
role GlobalRole @default(CUSTOMER)