From 51e8d99793f2833e5dabcb0408340a08f62aa7e6 Mon Sep 17 00:00:00 2001 From: NancyAanchal Date: Sun, 11 Aug 2024 09:48:13 +0545 Subject: [PATCH] changed frontend --- .../src/components/ProfileEditForm.tsx | 139 ++++++++++++------ 1 file changed, 91 insertions(+), 48 deletions(-) diff --git a/nepalingo-web/src/components/ProfileEditForm.tsx b/nepalingo-web/src/components/ProfileEditForm.tsx index 05351c9..b666df5 100644 --- a/nepalingo-web/src/components/ProfileEditForm.tsx +++ b/nepalingo-web/src/components/ProfileEditForm.tsx @@ -1,27 +1,58 @@ import React, { useState } from "react"; +import { useNavigate } from "react-router-dom"; import { supabaseClient } from "@/config/supabase-client"; import { useAuth } from "@/hooks/Auth"; +import CustomTextInput from "./CustomTextInput"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { faUser, faPen, faCamera } from "@fortawesome/free-solid-svg-icons"; const ProfileEditForm: React.FC = () => { + const navigate = useNavigate(); const { user } = useAuth(); - const [avatarUrl, setAvatarUrl] = useState(user?.user_metadata.avatar_url || ""); + const [avatarUrl, setAvatarUrl] = useState( + user?.user_metadata.avatar_url || "" + ); const [username, setUsername] = useState(user?.user_metadata.username || ""); - const [bio, setBio] = useState(user?.user_metadata.bio || ""); const [status, setStatus] = useState(user?.user_metadata.status || ""); - const [password, setPassword] = useState(""); + const [isDragging, setIsDragging] = useState(false); + + const handleAvatarChange = async (e: React.ChangeEvent) => { + if (e.target.files && e.target.files[0]) { + const file = e.target.files[0]; + const uploadedAvatarUrl = URL.createObjectURL(file); + setAvatarUrl(uploadedAvatarUrl); + // Implement file upload logic here if needed + } + }; - const handleSubmit = async () => { + const handleDrop = (e: React.DragEvent) => { + e.preventDefault(); + setIsDragging(false); + if (e.dataTransfer.files && e.dataTransfer.files[0]) { + const file = e.dataTransfer.files[0]; + const uploadedAvatarUrl = URL.createObjectURL(file); + setAvatarUrl(uploadedAvatarUrl); + // Implement file upload logic here if needed + } + }; + + const handleDragOver = (e: React.DragEvent) => { + e.preventDefault(); + setIsDragging(true); + }; + + const handleDragLeave = () => setIsDragging(false); + + const handleSaveChanges = async () => { if (!user) return; - // Update user metadata - const { data, error } = await supabaseClient.auth.updateUser({ + // Update user metadata in Supabase + const { error } = await supabaseClient.auth.updateUser({ data: { + username, // Update username directly in Supabase avatar_url: avatarUrl, - username, - bio, status, }, - password: password || undefined, // Optional password update }); if (error) { @@ -29,58 +60,70 @@ const ProfileEditForm: React.FC = () => { return; } - console.log("Profile updated successfully"); + // Navigate to the home page + navigate("/"); }; return ( -
-
- +
+
+ User Avatar +
+ +
setAvatarUrl(e.target.value)} - className="w-full p-2 border border-gray-300 rounded" + type="file" + accept="image/*" + onChange={handleAvatarChange} + className="absolute inset-0 opacity-0 cursor-pointer" />
-
- - + setUsername(e.target.value)} - className="w-full p-2 border border-gray-300 rounded" - /> -
-
- -