Skip to content

Commit

Permalink
feat:drag and drop functionallity added
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank-dev07 committed Oct 30, 2024
1 parent 6e62270 commit 9778ac9
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 81 deletions.
178 changes: 178 additions & 0 deletions src/app/(pages)/listunescrowed/component/Tab2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
"use client";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import React, { useState } from "react";
import {
ArrowBigLeft,
ArrowBigRight,
Camera,
Upload,
User2Icon,
} from "lucide-react";
import NextButton from "@/components/Button/NextButton";

type Props = {
onPrev: () => void;
onNext: () => void;
};

const Tab2 = ({ onPrev, onNext }: Props) => {
const [avatar, setAvatar] = useState<string | null>("");
const [isDragging, setIsDragging] = useState(false);

const handleAvatarChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
const reader = new FileReader();
reader.onloadend = () => {
setAvatar(reader.result as string);
};
reader.readAsDataURL(file);
}
};

const handleDrop = (event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault();
setIsDragging(false);
const file = event.dataTransfer.files[0];
if (file && file.type.startsWith("image/")) {
const reader = new FileReader();
reader.onloadend = () => {
setAvatar(reader.result as string);
};
reader.readAsDataURL(file);
}
};

const handleDragOver = (event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault();
if (!isDragging) {
setIsDragging(true);
}
};

const handleDragLeave = () => {
setIsDragging(false);
};
return (
<Card className="">
<CardHeader>
<CardTitle>Profile</CardTitle>
<CardDescription>
Make changes to your account here. Click save when you're done.
</CardDescription>
</CardHeader>
<CardContent className="py-4 px-12">
<div className="flex flex-col gap-4">
<div
className="relative flex gap-12 w-full border-[1px] border-gray-900 rounded-lg p-4 cursor-pointer"
onClick={() => document.getElementById("avatar-upload")?.click()}
onDrop={handleDrop}
onDragOver={handleDragOver}
>
<Avatar>
<AvatarImage src={avatar || ""} alt="User avatar" />
<AvatarFallback>
<User2Icon size={40} />
</AvatarFallback>
<label
htmlFor="avatar-upload"
className="absolute bottom-0 right-0 bg-white p-1 rounded-full shadow-md cursor-pointer"
>
<Camera size={16} className="text-gray-500" />
</label>
</Avatar>
<input
id="avatar-upload"
type="file"
accept="image/*"
className="hidden"
onChange={handleAvatarChange}
/>
<div className="w-full flex justify-center items-center mr-12">
{isDragging ? (
<div className="text-blue-500 flex items-center gap-2">
<Upload size={20} />
<p>You can drop here</p>
</div>
) : (
<p>Choose or drag and drop media</p>
)}
</div>
</div>
<div className="w-full grid grid-cols-1 gap-4">
<div className=" grid grid-cols-2 gap-6">
<div className="space-y-1">
<Label htmlFor="first-name">Name</Label>
<Input id="first-name" placeholder="Enter your name" />
</div>
<div className="space-y-1">
<Label htmlFor="first-name">Website link</Label>
<Input id="first-name" placeholder="Enter your Website link" />
</div>
</div>
</div>
{/* </div> */}
<div className=" grid grid-cols-1 gap-6">
<div className="space-y-1">
<Label htmlFor="first-name">Description</Label>
<Input
id="first-name"
placeholder="Enter your Project Description"
/>
</div>
</div>{" "}
<div className=" grid grid-cols-2 gap-6">
<div className="space-y-1">
<Label htmlFor="first-name">Github</Label>
<Input id="first-name" placeholder="https://github.com/...." />
</div>
<div className="space-y-1">
<Label htmlFor="first-name">Twitter</Label>
<Input id="first-name" placeholder="@your_twitter_handle" />
</div>
</div>
<div className=" grid grid-cols-2 gap-6">
<div className="space-y-1">
<Label htmlFor="first-name">Telegram</Label>
<Input id="first-name" placeholder="@your_telegram_handle" />
</div>
<div className="space-y-1">
<Label htmlFor="first-name">Discord</Label>
<Input id="first-name" placeholder="your_discord_handle" />
</div>
</div>
</div>
</CardContent>

<CardFooter>
<div className="w-full flex justify-between items-center">
<NextButton onClick={onPrev}>
<div className="flex gap-2 items-center">
<ArrowBigLeft size={20} />
PREV
</div>
</NextButton>

<NextButton onClick={onNext}>
<div className="flex gap-2 items-center">
NEXT
<ArrowBigRight size={20} />
</div>
</NextButton>
</div>
</CardFooter>
</Card>
);
};

export default Tab2;
30 changes: 0 additions & 30 deletions src/app/(pages)/listunescrowed/component/TabNavigation.tsx

This file was deleted.

55 changes: 6 additions & 49 deletions src/app/(pages)/listunescrowed/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
"use client";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { useState } from "react";
import Tab1 from "./component/Tab1";
import TabNavigation from "./component/TabNavigation";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import Tab2 from "./component/Tab2";

export default function ListUnescrowed() {
const [activeTab, setActiveTab] = useState<string>("personal_Details");
Expand All @@ -31,7 +20,7 @@ export default function ListUnescrowed() {
<Tabs
value={activeTab}
onValueChange={setActiveTab}
className="container px-5"
className="w-11/12 md:w-10/12 lg:w-8/12 px-0 md:px-5"
>
<TabsList className="grid w-full h-full grid-cols-1 grid-rows-3 md:grid-cols-5 md:grid-rows-1 mb-12">
<TabsTrigger value="personal_Details" className="pointer-events-none">
Expand All @@ -45,42 +34,10 @@ export default function ListUnescrowed() {
<Tab1 onNext={() => handleNextClick("password")} />
</TabsContent>
<TabsContent value="password">
<Card className="">
<CardHeader>
<CardTitle>Profile</CardTitle>
<CardDescription>
Make changes to your account here. Click save when you're done.
</CardDescription>
</CardHeader>
<CardContent className="py-8">
<div className="flex gap-12 items-center">
<Avatar>
<AvatarImage
src="https://github.com/shadcn.png"
alt="@shadcn"
/>
<AvatarFallback>CN</AvatarFallback>
</Avatar>
<div className="w-full grid grid-cols-1 grid-rows-2 md:grid-cols-2 md:grid-rows-1 gap-4 md:gap-12">
<div className="space-y-1">
<Label htmlFor="current">Current password</Label>
<Input id="current" type="password" />
</div>
<div className="space-y-1">
<Label htmlFor="new">New password</Label>
<Input id="new" type="password" />
</div>
</div>
</div>
</CardContent>

<CardFooter>
<TabNavigation
onPrev={() => handlePrevClick("personal_Details")}
onNext={() => handleNextClick("")}
/>
</CardFooter>
</Card>
<Tab2
onPrev={() => handlePrevClick("personal_Details")}
onNext={() => handleNextClick("password")}
/>
</TabsContent>
</Tabs>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Avatar = React.forwardRef<
<AvatarPrimitive.Root
ref={ref}
className={cn(
"relative flex h-16 w-16 shrink-0 overflow-hidden rounded-full",
"relative flex h-24 w-24 shrink-0 overflow-hidden rounded-lg",
className
)}
{...props}
Expand All @@ -39,7 +39,7 @@ const AvatarFallback = React.forwardRef<
<AvatarPrimitive.Fallback
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-muted",
"flex h-full w-full items-center justify-center rounded-md bg-muted",
className
)}
{...props}
Expand Down

0 comments on commit 9778ac9

Please sign in to comment.