Skip to content

Commit 008f756

Browse files
committed
couple minor changes
1 parent 96a42dd commit 008f756

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

app/routes/settings+/profile.index.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '~/utils/user-validation.ts'
2323
import { twoFAVerificationType } from './profile.two-factor.tsx'
2424

25-
const profileFormSchema = z.object({
25+
const ProfileFormSchema = z.object({
2626
name: nameSchema.optional(),
2727
username: usernameSchema,
2828
currentPassword: z
@@ -58,8 +58,19 @@ export async function action({ request }: DataFunctionArgs) {
5858
const formData = await request.formData()
5959
const submission = await parse(formData, {
6060
async: true,
61-
schema: profileFormSchema.superRefine(
61+
schema: ProfileFormSchema.superRefine(
6262
async ({ username, currentPassword, newPassword }, ctx) => {
63+
const existingUser = await prisma.user.findUnique({
64+
where: { username },
65+
select: { id: true },
66+
})
67+
if (existingUser && existingUser.id !== userId) {
68+
ctx.addIssue({
69+
path: ['username'],
70+
code: 'custom',
71+
message: 'A user already exists with this username',
72+
})
73+
}
6374
if (newPassword && !currentPassword) {
6475
ctx.addIssue({
6576
path: ['newPassword'],
@@ -116,10 +127,10 @@ export default function EditUserProfile() {
116127

117128
const [form, fields] = useForm({
118129
id: 'edit-profile',
119-
constraint: getFieldsetConstraint(profileFormSchema),
130+
constraint: getFieldsetConstraint(ProfileFormSchema),
120131
lastSubmission: actionData?.submission,
121132
onValidate({ formData }) {
122-
return parse(formData, { schema: profileFormSchema })
133+
return parse(formData, { schema: ProfileFormSchema })
123134
},
124135
defaultValue: {
125136
username: data.user.username,

app/routes/settings+/profile.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { json, type DataFunctionArgs } from '@remix-run/node'
22
import { Link, Outlet, useMatches } from '@remix-run/react'
3-
import React from 'react'
43
import { Spacer } from '~/components/spacer.tsx'
54
import { Icon } from '~/components/ui/icon.tsx'
65
import { authenticator, requireUserId } from '~/utils/auth.server.ts'

app/routes/users+/$username_+/notes.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ export default function NotesRoute() {
112112
</ul>
113113
</div>
114114
</div>
115-
<main className="relative col-span-3 bg-accent md:rounded-r-3xl">
115+
<div className="relative col-span-3 bg-accent md:rounded-r-3xl">
116116
<Outlet />
117-
</main>
117+
</div>
118118
</div>
119119
</main>
120120
)

0 commit comments

Comments
 (0)