account settings actions, account deletion left
This commit is contained in:
@ -2,6 +2,7 @@ import { type ActionFunction, json } from "@remix-run/node";
|
||||
import { GlobalRole, MembershipRole } from "@prisma/client";
|
||||
|
||||
import db from "~/utils/db.server";
|
||||
import logger from "~/utils/logger.server";
|
||||
import { authenticate, hashPassword } from "~/utils/auth.server";
|
||||
import { type FormError, validate } from "~/utils/validation.server";
|
||||
import { Register } from "../validations";
|
||||
@ -17,7 +18,7 @@ const action: ActionFunction = async ({ request }) => {
|
||||
return json<RegisterActionData>({ errors: validation.errors });
|
||||
}
|
||||
|
||||
const { orgName, fullName, email, password } = validation.data;
|
||||
const { fullName, email, password } = validation.data;
|
||||
const hashedPassword = await hashPassword(password.trim());
|
||||
try {
|
||||
await db.user.create({
|
||||
@ -30,13 +31,15 @@ const action: ActionFunction = async ({ request }) => {
|
||||
create: {
|
||||
role: MembershipRole.OWNER,
|
||||
organization: {
|
||||
create: { name: orgName },
|
||||
create: {}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
logger.error(error);
|
||||
|
||||
if (error.code === "P2002") {
|
||||
if (error.meta.target[0] === "email") {
|
||||
return json<RegisterActionData>({
|
||||
|
@ -37,21 +37,13 @@ export default function RegisterPage() {
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<LabeledTextField
|
||||
name="orgName"
|
||||
type="text"
|
||||
label="Organization name"
|
||||
disabled={isSubmitting}
|
||||
error={actionData?.errors?.orgName}
|
||||
tabIndex={1}
|
||||
/>
|
||||
<LabeledTextField
|
||||
name="fullName"
|
||||
type="text"
|
||||
label="Full name"
|
||||
disabled={isSubmitting}
|
||||
error={actionData?.errors?.fullName}
|
||||
tabIndex={2}
|
||||
tabIndex={1}
|
||||
/>
|
||||
<LabeledTextField
|
||||
name="email"
|
||||
@ -59,7 +51,7 @@ export default function RegisterPage() {
|
||||
label="Email"
|
||||
disabled={isSubmitting}
|
||||
error={actionData?.errors?.email}
|
||||
tabIndex={3}
|
||||
tabIndex={2}
|
||||
/>
|
||||
<LabeledTextField
|
||||
name="password"
|
||||
@ -67,13 +59,13 @@ export default function RegisterPage() {
|
||||
label="Password"
|
||||
disabled={isSubmitting}
|
||||
error={actionData?.errors?.password}
|
||||
tabIndex={4}
|
||||
tabIndex={3}
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={transition.state === "submitting"}
|
||||
tabIndex={5}
|
||||
tabIndex={4}
|
||||
>
|
||||
Register
|
||||
</Button>
|
||||
|
@ -3,7 +3,6 @@ import { z } from "zod";
|
||||
export const password = z.string().min(10).max(100);
|
||||
|
||||
export const Register = z.object({
|
||||
orgName: z.string().nonempty(),
|
||||
fullName: z.string().nonempty(),
|
||||
email: z.string().email(),
|
||||
password,
|
||||
|
Reference in New Issue
Block a user