Skip to content

Commit

Permalink
Performance monitoring ...
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyG11 committed Feb 24, 2024
1 parent ac0ed86 commit 19445cc
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 86 deletions.
34 changes: 34 additions & 0 deletions app/api/profile/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { auth } from "@clerk/nextjs";
import { prisma } from "@/libs/prisma";
import { NextResponse } from "next/server";

export async function PATCH(req: Request) {
try {
const { userId } = auth();
const updates = await req.json();
if (!userId) {
throw new Error("Unauthorized");
}
const profile = await prisma.profile.findFirst({
where: {
userId,
},
});

if (!profile || profile.userId !== userId) {
throw new Error("Profile not found");
}
await prisma.profile.update({
where: {
userId: profile.userId,
},
data: {
...updates,
},
});

return new NextResponse("Profile Patched", { status: 200 });
} catch (error: any) {
return new NextResponse("Profile Patch Error", { status: 500 });
}
}
2 changes: 1 addition & 1 deletion components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function Navbar({ profile }: NavbarProps) {
</li>
{[
{ title: "Jobs", path: "#" },
{ title: "Go Pro", path: "#" },
{ title: "Go Pro", path: "/pro" },
].map((item, idx) => {
return (
<li
Expand Down
4 changes: 2 additions & 2 deletions components/Profile/Edit/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export default function EditContent({ profile }: EditProps) {
title={activeLink}
subtitle="Update your username and manage your account"
/>
<div className="pt-8 flex justify-between max-w-5xl mx-auto px-4 md:px-8 ">
<div className="pt-8 md:flex md:justify-between md:max-w-5xl mx-auto px-4 md:px-8 ">
<EditNavLink activeLink={activeLink} setActiveLink={setActiveLink} />
<div className="w-full rounded py-2 px-10 flex flex-col">
<div className="w-full rounded py-2 md:px-10 flex flex-col">
<FieldsRenderer title={activeLink} profile={profile} />
</div>
</div>
Expand Down
18 changes: 18 additions & 0 deletions components/Profile/Edit/EditBlocks/Edit.general.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client";
import { Profile } from "@prisma/client";
import InputField from "@/components/shared/InputField";

interface GeneralProps {
profile: Profile;
}
export const General: React.FC<GeneralProps> = ({ profile }) => {
return (
<div>
<InputField
label="Username"
placeholder={profile?.name?.split(" ")?.join()}
/>
<InputField label="Email" placeholder={profile?.email} />
</div>
);
};
84 changes: 84 additions & 0 deletions components/Profile/Edit/EditBlocks/Edit.profile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"use client";
import { z } from "zod";
import Image from "next/image";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";

import { Profile } from "@prisma/client";
import { cn } from "@/libs/utils/tw.util";
import { Button } from "@/components/shared/Button";
import TextField from "@/components/shared/TextField";
import InputField from "@/components/shared/InputField";

interface GeneralProps {
profile: Profile;
}

export const EditProfileBlock: React.FC<GeneralProps> = ({ profile }) => {
const [toggle, setToggle] = useState(false);
const profileImageSchema = z.object({
imageUrl: z.string().url(),
});
const { formState, handleSubmit } = useForm({
resolver: zodResolver(profileImageSchema),
});

const onSubmit = async (data: any) => {
console.log(data);
};

return (
<div className="space-y-4 py-8">
<div className={cn("flex items-center mb-4", toggle && "")}>
<div className="relative rounded-full h-20 w-20">
<Image src={profile.imageUrl} alt="" className="rounded-full" fill />
</div>
<div className="mx-4 ">
{!toggle ? (
<Button
onClick={() => setToggle(true)}
className="text-sm py-2 px-6 font-medium text-gray-900 xl:block rounded-full border border-gray-200"
>
Upload new picture
</Button>
) : null}
</div>
<div className="">
<Button className="text-sm py-2 px-6 font-medium text-gray-900 xl:block rounded-full bg-gray-100">
Delete
</Button>
</div>
</div>
{toggle && (
<form onSubmit={handleSubmit(onSubmit)} className="flex items-center">
<input
type="file"
className="block cursor-pointer w-full max-w-sm px-3 py-5 mt-2 text-sm text-gray-600 bg-white border border-gray-200 rounded-lg file:bg-gray-200 file:text-gray-700 file:text-sm file:px-4 file:py-1 file:border-none file:rounded-full"
/>
<Button
disabled={formState.isSubmitting}
className="text-sm py-2 mx-3 px-6 font-semibold text-gray-900 xl:block rounded-full bg-gray-100"
>
Upload Now
</Button>
</form>
)}
<InputField
label="Name *"
placeholder={profile?.name?.split(" ")?.join(" ")}
/>
<InputField label="Email" placeholder={profile?.email} />
<InputField
label="Location"
placeholder={profile?.address || "eg. Addis Ababa"}
/>
<TextField rows={4} label="Bio" />

<h2 className="mt-10">ONLINE PRESENCE</h2>
<Button className="text-sm py-2.5 mx-3 px-6 font-semibold text-white xl:block rounded-full bg-gray-800">
Save profile
</Button>
</div>
);
};
63 changes: 48 additions & 15 deletions components/Profile/Edit/EditNavLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use client";
import React, { Dispatch, SetStateAction } from "react";
import React, { Dispatch, SetStateAction, useState } from "react";

import { EditNavLinks } from "@/libs/definitions";
import DropDownButton from "@/components/shared/DropDownButton";
import { cn } from "@/libs/utils/tw.util";

interface EditNavbarProps {
activeLink: EditNavLinks;
Expand All @@ -23,21 +25,52 @@ export default function EditNavLink({
{ title: "Applications" },
{ title: "Data Export" },
];
const [isOpened, setIsOpened] = useState(false);

return (
<ul className="w-full xl:w-1/4">
{links.map((item, i) => (
<li
key={i}
className={`py-1 ${
item.title === activeLink ? "active font-semibold" : ""
} cursor-pointer`}
onClick={() => setActiveLink(item.title as EditNavLinks)}
>
{item.title}
</li>
))}
<li className="text-red-500 py-4 my-4 border-t">Delete Account</li>
</ul>
<>
<DropDownButton
title={activeLink}
isOpened={isOpened}
setIsOpened={setIsOpened}
className="md:hidden flex items-center w-full justify-between border text-gray-600 py-2.5 rounded-lg hover:bg-gray-50 active:bg-gray-100 duration-150"
/>
{isOpened && (
<div className="my-3 md:mt-0 text-gray-500">
<ul className="w-full xl:w-1/4">
{links.map((item, i) => (
<li
key={i}
className={`py-1 ${
item.title === activeLink ? "active font-semibold" : ""
} cursor-pointer`}
onClick={() => {
setActiveLink(item.title as EditNavLinks);
setIsOpened(false);
}}
>
{item.title}
</li>
))}
<li className="text-red-500 py-4 my-4 border-t">Delete Account</li>
</ul>
</div>
)}
<ul className="hidden md:block w-full xl:w-1/4">
{links.map((item, i) => (
<li
key={i}
className={cn(
"py-1 cursor-pointer text-gray-500 hover:text-gray-800 duration-150",
item.title === activeLink && "active font-bold text-black"
)}
onClick={() => setActiveLink(item.title as EditNavLinks)}
>
{item.title}
</li>
))}
<li className="text-red-500 py-4 my-4 border-t">Delete Account</li>
</ul>
</>
);
}
11 changes: 7 additions & 4 deletions components/Profile/Edit/EditNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ export default function EditNavbar({
subtitle,
}: EditNavbarProps) {
return (
<div className="pt-14 flex justify-between max-w-5xl mx-auto px-4 md:px-8 ">
<div className="flex">
<div className="pt-14 flex space-y-2 flex-col-reverse md:flex-row justify-between max-w-5xl mx-auto px-4 md:px-8 ">
<div className="flex py-4">
<div className="relative rounded-full h-14 w-14">
<Image src={profile.imageUrl} alt="" className="rounded-full" fill />
</div>
<div className="mx-4">
<h3 className="text-xl">{profile.name + "/" + title}</h3>
<h3 className="text-xl text-black">
{profile.name} <span className="mx-0.5 text-gray-500">/</span>
{title}
</h3>
<p className=" text-gray-600 ">{subtitle} </p>
</div>
</div>
<Link
href="/pro"
className="border rounded py-2 px-10 flex items-center justify-center flex-col hover:bg-gray-100 hover:text-primary"
className="border h-[60px] rounded py-2 md:py-0 md:px-10 flex items-center justify-center flex-col hover:bg-gray-100 hover:text-primary"
>
<p>
Go<span className="mx-2 text-primary font-bold">Pro</span>
Expand Down
61 changes: 4 additions & 57 deletions components/Profile/Edit/FieldsRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"use client";
import React from "react";
import { Profile } from "@prisma/client";

import InputField from "@/components/shared/InputField";
import TextField from "@/components/shared/TextField.";
import Image from "next/image";
import { Button } from "@/components/shared/Button";
import { Profile } from "@prisma/client";
import { General } from "./EditBlocks/Edit.general";
import { EditProfileBlock } from "./EditBlocks/Edit.profile";

type FieldsRendererProps = {
title:
Expand All @@ -28,7 +25,7 @@ export default function FieldsRenderer({
}: FieldsRendererProps) {
const titleMap = {
General: <General profile={profile} />,
"Edit Profile": <EditProfile profile={profile} />,
"Edit Profile": <EditProfileBlock profile={profile} />,
Password: <div>Password</div>,
"Social Profiles": <div>Social Profiles</div>,
"Email Notifications": <div>Email Notifications</div>,
Expand All @@ -41,53 +38,3 @@ export default function FieldsRenderer({

return titleMap[title] || null;
}

type GeneralProps = {
profile: Profile;
};

const General: React.FC<GeneralProps> = ({ profile }) => {
return (
<div>
<InputField
label="Username"
placeholder={profile?.name?.split(" ")?.join()}
/>
<InputField label="Email" placeholder={profile?.email} />
</div>
);
};

const EditProfile: React.FC<GeneralProps> = ({ profile }) => {
return (
<div className="space-y-4">
<div className="flex items-center mb-4">
<div className="relative rounded-full h-20 w-20">
<Image src={profile.imageUrl} alt="" className="rounded-full" fill />
</div>
<div className="mx-4">
<Button className="text-sm py-2 px-6 font-medium text-gray-900 xl:block rounded-full border border-gray-200">
Upload new picture
</Button>
</div>
<div className="">
<Button className="text-sm py-2 px-6 font-medium text-gray-900 xl:block rounded-full bg-gray-100">
Delete
</Button>
</div>
</div>
<InputField
label="Name"
placeholder={profile?.name?.split(" ")?.join()}
/>
<InputField label="Email" placeholder={profile?.email} />
<InputField
label="Location"
placeholder={profile?.address || "eg. Addis Ababa"}
/>
<TextField rows={4} label="Bio" />

<h2>ONLINE PRESENCE</h2>
</div>
);
};
4 changes: 2 additions & 2 deletions components/Profile/PublishShotModal.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"use client";
import React from "react";
import Image from "next/image";
import { useForm } from "react-hook-form";
import { useRouter } from "next/navigation";

import Modal from "../shared/Modal";
import { useModal } from "@/hooks/modal";
import ProfFeatures from "./ProFeatures";
import { cn } from "@/libs/utils/tw.util";
import { useForm } from "react-hook-form";
import { Button } from "../shared/Button";
import TagsInput from "../shared/InputTag";
import { useBlock } from "@/hooks/zustandStore";
import { TBoardData } from "@/libs/definitions";
import { publishShot } from "@/libs/actions/shot.actions";
import { uploadFilesAndReturnUrls } from "@/libs/utils/uploadFilesAndReturnUrls";
import { TBoardData } from "@/libs/definitions";

export function PublishShotModal() {
const { isOpen, type, onClose, data } = useModal();
Expand Down
9 changes: 6 additions & 3 deletions components/shared/MediaDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ const MediaDisplay: React.FC<MediaDisplayProps> = ({ files }) => {
return (
<>
{files.map((fileUrl, index) => (
<div key={index} className="w-96 h-96">
<div
key={index}
className="rounded-md overflow-hidden relative w-full h-[500px] "
>
{fileUrl.endsWith(".mp4") ? (
<video
key={index}
className=" h-[500px] w-[1100px]"
className=" h-full w-full object-cover"
autoPlay
loop
muted
Expand All @@ -27,7 +30,7 @@ const MediaDisplay: React.FC<MediaDisplayProps> = ({ files }) => {
<div className="relative h-full w-full">
<Image
key={index}
className="h-96 w-96"
className="h-full w-full object-cover"
src={fileUrl}
alt=""
onError={(e) => {
Expand Down
Loading

0 comments on commit 19445cc

Please sign in to comment.