From e70cfee550388a4e172788dfe7f153485502360d Mon Sep 17 00:00:00 2001 From: onehanddev Date: Sat, 14 Dec 2024 18:04:05 +0530 Subject: [PATCH] Hide My custom projects tab in navigation sidebar when user is not logged and Re-organize My custom projects in Profile section --- client/src/containers/nav/index.tsx | 55 ++++++++++--------- .../containers/profile/user-details/index.tsx | 52 +++++++++++++----- 2 files changed, 66 insertions(+), 41 deletions(-) diff --git a/client/src/containers/nav/index.tsx b/client/src/containers/nav/index.tsx index 9dc71067..5f5d97d4 100644 --- a/client/src/containers/nav/index.tsx +++ b/client/src/containers/nav/index.tsx @@ -83,33 +83,34 @@ export default function MainNav() { - {!isLoading && navItems.main - .filter( - (item) => !item.requireAuth || status === "authenticated" - ) - .map((item) => { - const isActive = item.match(pathname); - return ( - - - - {item.icon && } - {item.title} - - - - ); - })} + {!isLoading && + navItems.main + .filter( + (item) => !item.requireAuth || status === "authenticated", + ) + .map((item) => { + const isActive = item.match(pathname); + return ( + + + + {item.icon && } + {item.title} + + + + ); + })} diff --git a/client/src/containers/profile/user-details/index.tsx b/client/src/containers/profile/user-details/index.tsx index d3a5c77d..8cd550f2 100644 --- a/client/src/containers/profile/user-details/index.tsx +++ b/client/src/containers/profile/user-details/index.tsx @@ -1,5 +1,7 @@ import { FC, KeyboardEvent, useCallback, useRef } from "react"; -import { useForm } from "react-hook-form"; + +import { useForm, UseFormReturn, FieldValues } from "react-hook-form"; + import { zodResolver } from "@hookform/resolvers/zod"; import { useQueryClient } from "@tanstack/react-query"; import { useSession } from "next-auth/react"; @@ -9,6 +11,7 @@ import { client } from "@/lib/query-client"; import { queryKeys } from "@/lib/query-keys"; import { Button } from "@/components/ui/button"; +import { Card } from "@/components/ui/card"; import { Form, FormControl, @@ -16,14 +19,14 @@ import { FormItem, FormLabel, FormMessage, - FormDescription, + // FormDescription, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { useToast } from "@/components/ui/toast/use-toast"; -import { Card } from "@/components/ui/card"; import { accountDetailsSchema } from "../account-details/schema"; import { changePasswordSchema } from "../edit-password/form/schema"; +import { accountDetailsSchema as emailSchema } from "../update-email/schema"; const UserDetails: FC = () => { const queryClient = useQueryClient(); @@ -53,8 +56,8 @@ const UserDetails: FC = () => { mode: "onSubmit", }); - const emailForm = useForm>({ - resolver: zodResolver(accountDetailsSchema), + const emailForm = useForm>({ + resolver: zodResolver(emailSchema), defaultValues: { email: user?.email, }, @@ -106,7 +109,7 @@ const UserDetails: FC = () => { const onSubmitEmail = useCallback( async (data: FormData) => { const formData = Object.fromEntries(data); - const parsed = accountDetailsSchema.safeParse(formData); + const parsed = emailSchema.safeParse(formData); if (parsed.success) { try { @@ -185,7 +188,11 @@ const UserDetails: FC = () => { ); const handleEnterKey = useCallback( - (evt: KeyboardEvent, form: any, onSubmit: (data: FormData) => Promise) => { + ( + evt: KeyboardEvent, + form: UseFormReturn, + onSubmit: (data: FormData) => Promise, + ) => { if (evt.code === "Enter" && form.formState.isValid) { form.handleSubmit(async () => { await onSubmit(new FormData(formRef.current!)); @@ -223,7 +230,9 @@ const UserDetails: FC = () => { handleEnterKey(e, accountForm, onSubmitAccount)} + onKeyDown={(e) => + handleEnterKey(e, accountForm, onSubmitAccount) + } {...field} /> @@ -253,7 +262,11 @@ const UserDetails: FC = () => { )} />
-
@@ -348,7 +365,9 @@ const UserDetails: FC = () => { handleEnterKey(e, passwordForm, onSubmitPassword)} + onKeyDown={(e) => + handleEnterKey(e, passwordForm, onSubmitPassword) + } {...field} /> @@ -368,7 +387,9 @@ const UserDetails: FC = () => { handleEnterKey(e, passwordForm, onSubmitPassword)} + onKeyDown={(e) => + handleEnterKey(e, passwordForm, onSubmitPassword) + } {...field} /> @@ -378,7 +399,10 @@ const UserDetails: FC = () => { )} />
-