import React, { useEffect, useState } from "react"; // next import Image from "next/image"; import type { NextPage } from "next"; // react hook form import { useForm } from "react-hook-form"; // react dropzone import Dropzone, { useDropzone } from "react-dropzone"; // hooks import useUser from "lib/hooks/useUser"; // hoc import withAuth from "lib/hoc/withAuthWrapper"; // layouts import AppLayout from "layouts/AppLayout"; // services import userService from "lib/services/user.service"; import fileServices from "lib/services/file.service"; // ui import { BreadcrumbItem, Breadcrumbs, Button, Input, Spinner } from "ui"; // types import type { IIssue, IUser, IWorkspaceMemberInvitation } from "types"; import { ChevronRightIcon, ClipboardDocumentListIcon, PencilIcon, RectangleStackIcon, UserIcon, UserPlusIcon, XMarkIcon, } from "@heroicons/react/24/outline"; import useSWR from "swr"; import { USER_ISSUE, USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys"; import useToast from "lib/hooks/useToast"; import Link from "next/link"; import workspaceService from "lib/services/workspace.service"; const defaultValues: Partial = { avatar: "", first_name: "", last_name: "", email: "", }; const Profile: NextPage = () => { const [image, setImage] = useState(null); const [isImageUploading, setIsImageUploading] = useState(false); const [isEditing, setIsEditing] = useState(false); const { user: myProfile, mutateUser, projects } = useUser(); const { setToastAlert } = useToast(); const onSubmit = (formData: IUser) => { userService .updateUser(formData) .then((response) => { mutateUser(response, false); setIsEditing(false); setToastAlert({ title: "Success", type: "success", message: "Profile updated successfully", }); }) .catch((error) => { console.log(error); }); }; const { register, handleSubmit, reset, watch, setValue, formState: { errors, isSubmitting }, } = useForm({ defaultValues }); const { data: myIssues } = useSWR( myProfile ? USER_ISSUE : null, myProfile ? () => userService.userIssues() : null ); const { data: invitations } = useSWR( USER_WORKSPACE_INVITATIONS, () => workspaceService.userWorkspaceInvitations() ); useEffect(() => { reset({ ...defaultValues, ...myProfile }); }, [myProfile, reset]); const quickLinks = [ { icon: RectangleStackIcon, title: "My Issues", number: myIssues?.length ?? 0, description: "View the list of issues assigned to you across the workspace.", href: "/me/my-issues", }, { icon: ClipboardDocumentListIcon, title: "My Projects", number: projects?.length ?? 0, description: "View the list of projects of the workspace.", href: "/projects", }, { icon: UserPlusIcon, title: "Workspace Invitations", number: invitations?.length ?? 0, description: "View your workspace invitations.", href: "/invitations", }, ]; return (
{myProfile ? ( <>
setIsEditing((prevData) => !prevData)} > {isEditing ? ( ) : ( )}
{ setImage(files[0]); }} > {({ getRootProps, getInputProps, open }) => (
{(!watch("avatar") || watch("avatar") === "") && (!image || image === null) ? ( ) : (
{myProfile.first_name}
)}

Max file size is 500kb.
Supported file types are .jpg and .png.

)}

First Name

{isEditing ? ( ) : (

{myProfile.first_name}

)}

Last Name

{isEditing ? ( ) : (

{myProfile.last_name}

)}

Email ID

{isEditing ? ( ) : (

{myProfile.email}

)}
{isEditing && (
)}

Quick Links

{quickLinks.map((item, index) => (

{item.title}

{item.number}

{item.description}

))}
) : (
)}
); }; export default withAuth(Profile);