From d912fe7bab6659b479b7fd5cb2b63e029b0f9b9e Mon Sep 17 00:00:00 2001 From: Asel Peiris Date: Sat, 12 Oct 2024 00:29:42 +0530 Subject: [PATCH 1/3] Refactor settings page to include catalyst components (#1108) * Refactor settings page to include catalyst components * Fixes requested by coderabbitai --- app/(app)/settings/_client.tsx | 622 ++++++++++++++-------------- components/ui-components/avatar.tsx | 2 +- 2 files changed, 322 insertions(+), 302 deletions(-) diff --git a/app/(app)/settings/_client.tsx b/app/(app)/settings/_client.tsx index bafb4b1b..eb3dd37b 100644 --- a/app/(app)/settings/_client.tsx +++ b/app/(app)/settings/_client.tsx @@ -1,7 +1,6 @@ "use client"; -import { useEffect, useState } from "react"; -import { Description, Field, Label, Switch } from "@headlessui/react"; +import { useEffect, useState, useRef } from "react"; import { zodResolver } from "@hookform/resolvers/zod"; import type { SubmitHandler } from "react-hook-form"; import { useForm } from "react-hook-form"; @@ -14,6 +13,16 @@ import { uploadFile } from "@/utils/s3helpers"; import type { user } from "@/server/db/schema"; import { Button } from "@/components/ui-components/button"; import { CheckCheck, Loader2 } from "lucide-react"; +import { Heading } from "@/components/ui-components/heading"; +import { Avatar } from "@/components/ui-components/avatar"; +import { Input } from "@/components/ui-components/input"; +import { + ErrorMessage, + Field, + Label, +} from "@/components/ui-components/fieldset"; +import { Textarea } from "@/components/ui-components/textarea"; +import { Switch } from "@/components/ui-components/switch"; function classNames(...classes: string[]) { return classes.filter(Boolean).join(" "); @@ -43,6 +52,7 @@ const Settings = ({ profile }: { profile: User }) => { register, handleSubmit, watch, + reset, formState: { errors }, } = useForm({ resolver: zodResolver(saveSettingsSchema), @@ -52,9 +62,6 @@ const Settings = ({ profile }: { profile: User }) => { }, }); - const bio = watch("bio"); - const username = watch("username"); - const { emailNotifications: eNotifications, newsletter } = profile; const [emailNotifications, setEmailNotifications] = useState(eNotifications); @@ -62,6 +69,7 @@ const Settings = ({ profile }: { profile: User }) => { const [newEmail, setNewEmail] = useState(""); const [sendForVerification, setSendForVerification] = useState(false); const [loading, setLoading] = useState(false); + const [emailError, setEmailError] = useState(""); const [profilePhoto, setProfilePhoto] = useState({ status: "idle", @@ -75,6 +83,8 @@ const Settings = ({ profile }: { profile: User }) => { api.profile.updateProfilePhotoUrl.useMutation(); const { mutate: updateEmail } = api.profile.updateEmail.useMutation(); + const fileInputRef = useRef(null); + useEffect(() => { if (isSuccess) { toast.success("Saved"); @@ -164,242 +174,292 @@ const Settings = ({ profile }: { profile: User }) => {
{/* Profile section */} -
-
-

- Profile Settings -

-

- This information will be displayed publicly so be careful what - you share. -

-
- +
-
-
-
- - Profile Information +
+ + {/* Photo upload */} + +
+ + {/* Container for Label and Subheading */} +
+ +
+ This will be displayed on your public profile +
+
+ +
+
+ - {errors.name && ( -

- {`${errors.name.message || "Required"}`} -

- )}
-
- -
- - codu.co/ - - +
+ + + + +
+ JPG, GIF or PNG. 1MB max.
- {errors.username && ( -

- {`${errors.username.message || "Required"}`} -

- )}
- {/* Photo upload */} + {/* Input field */} + +
-
- -
-
- +
+ + {/* Container for Label and Subheading */} +
+ +
+ This will be displayed on your public profile
+
-
- {profilePhoto.status === "error" || - profilePhoto.status === "loading" ? ( -
- ) : ( - // TODO: review this - // eslint-disable-next-line jsx-a11y/img-redundant-alt - Profile photo upload section - )} - + {/* Input field */} +
+ + + {/* Error message */} + {errors?.name && ( + + {errors.name.message} + + )} +
+ +
+ + {/* User name */} +
+ + {/* Container for Label and Subheading */} +
+ +
+ This will be how you share your profile
+
+ + {/* Input field */} +
+ - {/* Photo end */} + {/* Error message */} + {errors?.username && ( + + {errors.username.message} + + )}
- {/* */} -
-
- -
-