diff --git a/app/db/models/users/findByIdentifier.sql b/app/db/models/users/findByIdentifier.sql index c99d54ab0..4c148ef0d 100644 --- a/app/db/models/users/findByIdentifier.sql +++ b/app/db/models/users/findByIdentifier.sql @@ -6,4 +6,5 @@ from left join "PlusTier" on "PlusTier"."userId" = "User"."id" where "discordId" = @identifier - or "id" = @identifier \ No newline at end of file + or "id" = @identifier + or "customUrl" = @identifier diff --git a/app/db/seed.ts b/app/db/seed.ts index 41056f8a6..96ca3d9a0 100644 --- a/app/db/seed.ts +++ b/app/db/seed.ts @@ -34,7 +34,7 @@ const basicSeeds = [ adminUser, nzapUser, users, - userBios, + userProfiles, lastMonthsVoting, lastMonthSuggestions, thisMonthsSuggestions, @@ -107,7 +107,39 @@ function users() { new Array(500).fill(null).map(fakeUser(usedNames)).forEach(db.users.upsert); } -function userBios() { +function userProfiles() { + for (const args of [ + { + userId: 1, + country: "FI", + customUrl: "sendou", + motionSens: 50, + stickSens: 5, + inGameName: "Sendou#1234", + }, + { + userId: 2, + country: "SE", + customUrl: "nzap", + motionSens: -40, + stickSens: 0, + inGameName: "N-ZAP#5678", + }, + ]) { + sql + .prepare( + ` + UPDATE "User" SET + country = $country, + customUrl = $customUrl, + motionSens = $motionSens, + stickSens = $stickSens, + inGameName = $inGameName + WHERE id = $userId` + ) + .run(args); + } + for (let id = 3; id < 500; id++) { if (Math.random() < 0.25) continue; // 75% have bio diff --git a/app/routes/u.$identifier/edit.tsx b/app/routes/u.$identifier/edit.tsx index 011e1bad5..2be21bde7 100644 --- a/app/routes/u.$identifier/edit.tsx +++ b/app/routes/u.$identifier/edit.tsx @@ -15,6 +15,7 @@ import { useTranslation } from "react-i18next"; import invariant from "tiny-invariant"; import { z } from "zod"; import { Button } from "~/components/Button"; +import { Input } from "~/components/Input"; import { Label } from "~/components/Label"; import { Main } from "~/components/Main"; import { USER } from "~/constants"; @@ -46,17 +47,25 @@ const userEditActionSchema = z.object({ falsyToNull, z.string().max(USER.BIO_MAX_LENGTH).nullable() ), + // xxx: return error if using duplicate custom url customUrl: z.preprocess( falsyToNull, z .string() .max(USER.CUSTOM_URL_MAX_LENGTH) + .nullable() .refine( (val) => val === null || Number.isNaN(Number(val)), // xxx: translate "Name in the custom URL can't only contain numbers" ) - .nullable() + .refine( + // validate val only contains numbers and letters + (val) => val === null || /^[a-zA-Z0-9-_]+$/.test(val), + // xxx: translate + "Custom URL can't contain special characters" + ) + .transform((val) => val?.toLowerCase()) ), stickSens: z.preprocess( undefinedToNull, @@ -134,6 +143,7 @@ export default function UserEditPage() { return (
+