remove username and refactor code
This commit is contained in:
parent
5694ea6ce9
commit
c4598a7f07
@ -9,15 +9,6 @@ export const loginUserSchema = z.object({
|
||||
|
||||
export const registerUserSchema = z
|
||||
.object({
|
||||
username: z
|
||||
.string({ required_error: "Username is required" })
|
||||
.regex(/^[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*$/, {
|
||||
message:
|
||||
"Username can only contain letters, numbers, and special characters.",
|
||||
}) // Updated regex pattern
|
||||
.min(3, { message: "Username must be at least 2 characters" })
|
||||
.max(64, { message: "Username must be less than 64 characters" })
|
||||
.trim(),
|
||||
email: z
|
||||
.string({ required_error: "Email is required" })
|
||||
.email({ message: "Email must be a valid email" }),
|
||||
@ -55,143 +46,8 @@ export const registerUserSchema = z
|
||||
}
|
||||
});
|
||||
|
||||
export const createPostTextSchema = z.object({
|
||||
title: z
|
||||
.string({ required_error: "Title is required" })
|
||||
.min(1, { message: "Title is required" })
|
||||
.max(300, { message: "Title must be 300 characters or less" })
|
||||
.trim(),
|
||||
|
||||
//url: z.string().optional().url({ message: 'URL must be a valid URL' }),
|
||||
tagline: z.string(),
|
||||
tagTopic: z.string(),
|
||||
atLeastOneTag: z
|
||||
.string({ required_error: "At least 1 tag is required" })
|
||||
.min(1, { message: "At least 1 tag is required" }),
|
||||
description: z.string(),
|
||||
postType: z.string({ required_error: "PostType is required." }),
|
||||
user: z.string({ required_error: "User is required." }),
|
||||
});
|
||||
|
||||
const imageTypes = [
|
||||
"image/jpeg",
|
||||
"image/jpg",
|
||||
"image/png",
|
||||
"image/webp",
|
||||
"image/svg+xml",
|
||||
"image/gif",
|
||||
];
|
||||
|
||||
const videoTypes = ["video/mp4", "video/gif"];
|
||||
|
||||
export const createPostImageSchema = z.object({
|
||||
title: z
|
||||
.string({ required_error: "Title is required" })
|
||||
.min(1, { message: "Title is required" })
|
||||
.max(300, { message: "Title must be 300 characters or less" })
|
||||
.trim(),
|
||||
tagTopic: z.string(),
|
||||
tagline: z.string(),
|
||||
atLeastOneTag: z
|
||||
.string({ required_error: "At least 1 tag is required" })
|
||||
.min(1, { message: "At least 1 tag is required" }),
|
||||
thumbnail: z.instanceof(File).superRefine((val, ctx) => {
|
||||
if (val) {
|
||||
if (val.size > 5121440) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "File must be less than 5MB",
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
val.type &&
|
||||
!imageTypes.includes(val.type) &&
|
||||
!videoTypes.includes(val.type)
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
"Unsupported file type. Supported formats: jpeg, jpg, png, webp, svg",
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
postType: z.string({ required_error: "PostType is required." }),
|
||||
user: z.string({ required_error: "User is required." }),
|
||||
});
|
||||
|
||||
export const createPostLinkSchema = z.object({
|
||||
title: z
|
||||
.string({ required_error: "Title is required" })
|
||||
.min(1, { message: "Title is required" })
|
||||
.max(300, { message: "Title must be 300 characters or less" })
|
||||
.trim(),
|
||||
tagTopic: z.string(),
|
||||
tagline: z.string(),
|
||||
atLeastOneTag: z
|
||||
.string({ required_error: "At least 1 tag is required" })
|
||||
.min(1, { message: "At least 1 tag is required" }),
|
||||
link: z.string().url({ message: "URL must be a valid URL" }),
|
||||
description: z.string(),
|
||||
/*
|
||||
thumbnail: z
|
||||
.instanceof(Blob)
|
||||
.superRefine((val, ctx) => {
|
||||
if (val) {
|
||||
if (val.size > 5242880) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Image must be less than 5MB'
|
||||
});
|
||||
}
|
||||
|
||||
if (!imageTypes.includes(val.type)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Unsupported file type. Supported formats: jpeg, jpg, png, webp, svg, gif'
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
*/
|
||||
postType: z.string({ required_error: "PostType is required." }),
|
||||
user: z.string({ required_error: "User is required." }),
|
||||
});
|
||||
|
||||
//export const updatePostSchema = createPostSchema.omit({ user: true });
|
||||
|
||||
export const updatePersonalDataSchema = z.object({
|
||||
/*
|
||||
email: z
|
||||
.string({ required_error: 'Email is required' })
|
||||
.email({ message: 'Email must be a valid email' }),
|
||||
*/
|
||||
username: z
|
||||
.string({ required_error: "Username is required" })
|
||||
.min(2, { message: "Username must be at least 2 characters" })
|
||||
.max(24, { message: "Username must be 24 characters or less" })
|
||||
.regex(/^[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*$/, {
|
||||
message:
|
||||
"Username can only contain letters, numbers, and special characters.",
|
||||
}), // Updated regex pattern
|
||||
});
|
||||
|
||||
export const updateEmailSchema = z.object({
|
||||
email: z
|
||||
.string({ required_error: "Email is required" })
|
||||
.email({ message: "Email must be a valid email" }),
|
||||
});
|
||||
|
||||
export const updateUsernameSchema = z.object({
|
||||
username: z
|
||||
.string({ required_error: "Username is required" })
|
||||
.min(2, { message: "Username must be at least 2 characters" })
|
||||
.max(24, { message: "Username must be 24 characters or less" })
|
||||
.regex(/^[a-zA-Z0-9]*$/, {
|
||||
message: "Username can only contain letters or numbers.",
|
||||
}),
|
||||
});
|
||||
|
||||
export const updatePasswordSchema = z
|
||||
.object({
|
||||
@ -230,120 +86,8 @@ export const updatePasswordSchema = z
|
||||
}
|
||||
});
|
||||
|
||||
export const updateProfileSchema = z.object({
|
||||
name: z
|
||||
.string({ required_error: "Name is required" })
|
||||
.min(1, { message: "Name is required" })
|
||||
.max(64, { message: "Name must be 64 characters or less" })
|
||||
.trim(),
|
||||
avatar: z
|
||||
.instanceof(Blob)
|
||||
.optional()
|
||||
.superRefine((val, ctx) => {
|
||||
if (val) {
|
||||
if (val.size > 5242880) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Avatar must be less than 5MB",
|
||||
});
|
||||
}
|
||||
|
||||
if (!imageTypes.includes(val.type)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
"Unsupported file type. Supported formats: jpeg, jpg, png, webp, svg, gif",
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
export const updateAvatarSchema = z.object({
|
||||
avatar: z.instanceof(File).superRefine((val, ctx) => {
|
||||
if (val) {
|
||||
if (val.size > 5242880) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Avatar must be less than 5MB",
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
val.type &&
|
||||
!imageTypes.includes(val.type) &&
|
||||
!videoTypes.includes(val.type)
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
"Unsupported file type. Supported formats: jpeg, jpg, png, webp, svg, gif",
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
export const createCommentTextSchema = z.object({
|
||||
comment: z
|
||||
.string({ required_error: "Comment cannot be empty" })
|
||||
.min(1, { message: "Comment cannot be empty" })
|
||||
//.max(40000, { message: 'Comment is too long. Keep it simple and concise bruv!' })
|
||||
.trim(),
|
||||
user: z.string({ required_error: "User is required." }),
|
||||
post: z.string({ required_error: "Post is required." }),
|
||||
reply: z.string(),
|
||||
});
|
||||
|
||||
export const updateCommentTextSchema = z.object({
|
||||
comment: z
|
||||
.string({ required_error: "Comment cannot be empty" })
|
||||
.min(1, { message: "Comment cannot be empty" })
|
||||
//.max(40000, { message: 'Comment is too long. Keep it simple and concise bruv!' })
|
||||
.trim(),
|
||||
});
|
||||
|
||||
export const createCommentImageSchema = z.object({
|
||||
comment: z
|
||||
.string({ required_error: "Comment cannot be empty" })
|
||||
.min(1, { message: "Comment cannot be empty" })
|
||||
//.max(40000, { message: 'Comment is too long. Keep it simple and concise bruv!' })
|
||||
.trim(),
|
||||
image: z
|
||||
.instanceof(Blob, { message: "Image is required" })
|
||||
.superRefine((val, ctx) => {
|
||||
if (val) {
|
||||
if (val.size > 5242880) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Image must be less than 5MB",
|
||||
});
|
||||
}
|
||||
|
||||
if (!imageTypes.includes(val.type)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
"Unsupported file type. Supported formats: jpeg, jpg, png, webp, svg, gif",
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
user: z.string({ required_error: "User is required." }),
|
||||
post: z.string({ required_error: "Post is required." }),
|
||||
reply: z.string(),
|
||||
});
|
||||
|
||||
export const createNotebookSchema = z.object({
|
||||
title: z
|
||||
.string({ required_error: "Title cannot be empty" })
|
||||
.min(1, { message: "Title cannot be empty" })
|
||||
.max(100, {
|
||||
message: "Title is too long. Keep it simple and concise bruv!",
|
||||
})
|
||||
.trim(),
|
||||
user: z.string({ required_error: "User is required." }),
|
||||
});
|
||||
|
||||
export const createStrategySchema = z.object({
|
||||
title: z
|
||||
|
||||
@ -324,6 +324,39 @@
|
||||
</a>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="mt-6 rounded-md border border-gray-600 p-4 text-base xs:p-4 xs:text-lg text-white"
|
||||
>
|
||||
<h2 class="text-white text-2xl font-semibold mb-3">Need help?</h2>
|
||||
<div class="mt-1">
|
||||
<strong>Here's how to get support:</strong>
|
||||
</div>
|
||||
<div class="mt-2 mb-1">
|
||||
<ul class="list-disc pl-5">
|
||||
<li>Send an email to support@stocknear.com.</li>
|
||||
<li>
|
||||
Join our official Subreddit
|
||||
<a
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
href="https://www.reddit.com/r/stocknear/"
|
||||
class="text-blue-400"
|
||||
>
|
||||
r/stocknear</a
|
||||
>.
|
||||
</li>
|
||||
<li>
|
||||
Join our official <a
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
href="https://discord.com/invite/hCwZMMZ2MT"
|
||||
class="text-blue-400">Discord Channel</a
|
||||
>.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -35,7 +35,7 @@ export const actions = {
|
||||
//let username = generateUsername(formData.name.split(' ').join('')).toLowerCase();
|
||||
|
||||
try {
|
||||
const newUser = await locals.pb.collection("users").create(formData);
|
||||
await locals.pb.collection("users").create(formData);
|
||||
/*
|
||||
await locals.pb?.collection('users').update(
|
||||
newUser?.id, {
|
||||
|
||||
@ -124,13 +124,7 @@
|
||||
class="flex flex-col items-center space-y-2 w-full max-w-lg pt-4 pl-3 pr-3 sm:pl-0 sm:pr-0 ml-auto mr-auto"
|
||||
>
|
||||
<!--<Input id="name" label="Your first and last name" value={form?.data?.name} errors={form?.errors?.name} />-->
|
||||
<Input
|
||||
id="username"
|
||||
label="Username"
|
||||
value={form?.data?.username}
|
||||
errors={form?.errors?.username}
|
||||
disabled={loading}
|
||||
/>
|
||||
|
||||
<Input
|
||||
type="email"
|
||||
id="email"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user