diff --git a/client/app/[id]/edit/page.tsx b/client/app/[id]/edit/page.tsx index 539247f..5e8a239 100644 --- a/client/app/[id]/edit/page.tsx +++ b/client/app/[id]/edit/page.tsx @@ -1,6 +1,5 @@ "use client"; - import React, { useState, useEffect } from "react"; import { fetchBusinessesByslug, @@ -205,11 +204,10 @@ export default function EditBusinessPage() { } }; - const handleImageUpload = (assetpath: string, field: 'avatar' | 'banner') => { - console.log('Image uploaded:', assetpath); + const handleImageUpload = (assetpath: string, field: "avatar" | "banner") => { + console.log("Image uploaded:", assetpath); // console.log('Field:', field); handleFieldSave(field, assetpath); - }; // Replace handleChange with immediate save @@ -232,10 +230,10 @@ export default function EditBusinessPage() { await deletebusinessMedia(businessData.profile.id, mediaId); } fetchData(); - toast.success('Media item deleted successfully'); + toast.success("Media item deleted successfully"); } catch (error) { - console.error('Error deleting media:', error); - toast.error('Failed to delete media item'); + console.error("Error deleting media:", error); + toast.error("Failed to delete media item"); } }; @@ -294,8 +292,10 @@ export default function EditBusinessPage() { return (
-
-

Edit Business Profile

+
+

+ Edit Business Profile +

diff --git a/client/app/[id]/page.tsx b/client/app/[id]/page.tsx index e306f29..804ce61 100644 --- a/client/app/[id]/page.tsx +++ b/client/app/[id]/page.tsx @@ -102,6 +102,9 @@ export const runtime = "edge"; const DevMorphixWebsite = () => { const [isMenuOpen, setIsMenuOpen] = useState(false); + const [hoveredIcon, setHoveredIcon] = useState<{ + platform: string; + } | null>(null); const [businessData, setBusinessData] = useState(null); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); @@ -623,14 +626,13 @@ const DevMorphixWebsite = () => { - {businessData?.user.phone || "Not available"} + +91 {businessData?.user.phone || "Not available"}
-
- +
+ - {" "} {`${businessData?.profile.address}, ${businessData?.profile.city}, ${businessData?.profile.state}, ${businessData?.profile.country}`} @@ -713,42 +715,54 @@ const DevMorphixWebsite = () => { "No description available"}

- {businessData?.profile.socials && Object.values(businessData.profile.socials).some(url => url) && ( -
-

- Our Social Media Connects -

-
+ {businessData?.profile.socials && + Object.values(businessData.profile.socials).some( + (url) => url + ) && ( +
+

+ Our Social Media Connects +

+
{Object.entries(businessData.profile.socials).map( - ([platform, url]) => { - if (url) { - const iconSrc = socialIcons[platform.toLowerCase()]; - return ( - - {iconSrc ? ( - {platform} - ) : ( - platform - )} - - ); - } - return null; - } + ([platform, url]) => { + if (url) { + const iconSrc = socialIcons[platform.toLowerCase()]; + + return ( + + + {hoveredIcon?.platform === platform && ( +
+ {platform.charAt(0).toUpperCase() + platform.slice(1)} +
+ )}
- )} + ); + } + return null; + } + )} +
+
+ )} diff --git a/client/app/api/index.ts b/client/app/api/index.ts index c6cf65a..4bf9b74 100644 --- a/client/app/api/index.ts +++ b/client/app/api/index.ts @@ -512,7 +512,7 @@ export const updateBusiness = async (businessId: string, updateData: Record void; - category: 'media' | 'avatar' | 'banner'; + category: 'media' | 'avatar' | 'banner' |'identity'; label?: string; showPreview?: boolean; currentImage?: string; @@ -63,7 +63,7 @@ const ImageUploadButton = ({ await uploadToPresignedUrl(urlResponse.presignedUrl, file); console.log(`File ${file.name} uploaded successfully to storage`); - if (category === 'avatar' || category === 'banner') { + if (category === 'avatar' || category === 'banner' || category === 'identity') { console.log(`Completing ${category} upload with assetpath:`, urlResponse.assetpath); onUploadComplete(urlResponse.assetpath); } else { diff --git a/client/app/components/OperatingHours.tsx b/client/app/components/OperatingHours.tsx index 0358f10..e50fe5c 100644 --- a/client/app/components/OperatingHours.tsx +++ b/client/app/components/OperatingHours.tsx @@ -148,64 +148,74 @@ export default function OperatingHours({ hours, onUpdate }: OperatingHoursProps) return (
{DAYS.map((day) => { - const times = parseHours(operatingHours[day] || 'Closed'); - const isClosed = operatingHours[day] === 'Closed'; - - return ( -
-
- {DAY_NAMES[day]} -
- -
- toggleClosed(day, e.target.checked)} - className="h-4 w-4 cursor-pointer" - id={`closed-${day}`} - /> - -
- - {!isClosed && ( - <> - - - to - - - - )} + const times = parseHours(operatingHours[day] || 'Closed') + const isClosed = operatingHours[day] === 'Closed' + + return ( +
+
+
+ {DAY_NAMES[day]} +
+ +
+
+ toggleClosed(day, e.target.checked)} + className="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500 cursor-pointer" + id={`closed-${day}`} + /> + +
+ + {!isClosed && ( +
+ + + to + +
- ); - })} + )} +
+
+
+ ) + })}
); } -- knotmirror 0.0.1 From d85a940a1c64f02d11491875fd223a396a461b44 Mon Sep 17 00:00:00 2001 From: Abhishek V Gopal Date: Thu, 9 Jan 2025 00:38:06 +0530 Subject: [PATCH 02/11] added / --- client/app/api/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/app/api/index.ts b/client/app/api/index.ts index 4bf9b74..e65aff8 100644 --- a/client/app/api/index.ts +++ b/client/app/api/index.ts @@ -512,7 +512,7 @@ export const updateBusiness = async (businessId: string, updateData: Record Date: Thu, 9 Jan 2025 00:49:57 +0530 Subject: [PATCH 03/11] added / --- client/app/api/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/app/api/index.ts b/client/app/api/index.ts index e65aff8..e07bcca 100644 --- a/client/app/api/index.ts +++ b/client/app/api/index.ts @@ -512,7 +512,7 @@ export const updateBusiness = async (businessId: string, updateData: Record Date: Thu, 9 Jan 2025 01:08:08 +0530 Subject: [PATCH 04/11] added --- client/app/[id]/edit/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/app/[id]/edit/page.tsx b/client/app/[id]/edit/page.tsx index 5e8a239..c7d9370 100644 --- a/client/app/[id]/edit/page.tsx +++ b/client/app/[id]/edit/page.tsx @@ -357,8 +357,8 @@ export default function EditBusinessPage() { multiple={false} onUploadComplete={(assetpath) => { if (assetpath) { - handleImageUpload(assetpath, "avatar"); - businessData.profile.avatar = assetpath; + handleImageUpload(assetpath, "banner"); + businessData.profile.banner = assetpath; } }} /> -- knotmirror 0.0.1 From 91665c875d0da06f0323d38060318b43a6883b52 Mon Sep 17 00:00:00 2001 From: Abhishek V Gopal Date: Thu, 9 Jan 2025 10:57:44 +0530 Subject: [PATCH 05/11] added login and ui bug fix --- client/app/[id]/page.tsx | 121 +++++++++++++++++++++---------- client/app/api/index.ts | 20 ++++- client/app/components/imgsec.tsx | 2 +- 3 files changed, 101 insertions(+), 42 deletions(-) diff --git a/client/app/[id]/page.tsx b/client/app/[id]/page.tsx index 804ce61..3ac9103 100644 --- a/client/app/[id]/page.tsx +++ b/client/app/[id]/page.tsx @@ -25,7 +25,12 @@ import { FooterSection } from "@/app/components/FooterSection"; import { div } from "framer-motion/client"; import DynamicQRCode from "@/app/components/QrSection"; import ScrollToTopButton from "@/app/components/ScrollToTop"; -import { fetchBusinessesByslug, ASSET_BASE_URL, GetURL } from "@/app/api"; +import { + fetchBusinessesByslug, + ASSET_BASE_URL, + GetURL, + UserLogout, +} from "@/app/api"; import { useParams, useRouter } from "next/navigation"; // Add this interface with other interfaces @@ -165,6 +170,31 @@ const DevMorphixWebsite = () => { router.push(`/${params.id}/edit`); }; + const handlelogout = async () => { + try { + const token = Cookies.get("token"); + // console.log("Raw JWT Token:", token); + + if (!token) { + console.log("No JWT token found in cookies"); + return null; + } + const res = await UserLogout(token); + + if (res.message === "User logged out successfully") { + Cookies.remove("token"); + localStorage.removeItem("userData"); + localStorage.removeItem("userProfiles"); + router.push("/"); + }else{ + console.log("Error logging out:", res); + } + + } catch (err) { + console.error("Error logging out:", err); + } + }; + // Modify your existing fetchData function to include token handling useEffect(() => { const fetchData = async () => { @@ -434,13 +464,23 @@ const DevMorphixWebsite = () => { />
+ {isOwner && ( + + )} + {isOwner && ( )} @@ -724,42 +764,45 @@ const DevMorphixWebsite = () => { Our Social Media Connects
- {Object.entries(businessData.profile.socials).map( - ([platform, url]) => { - if (url) { - const iconSrc = socialIcons[platform.toLowerCase()]; - - return ( -
- setHoveredIcon({ platform })} - onMouseLeave={() => setHoveredIcon(null)} - > - {iconSrc ? ( - {platform} - ) : ( - platform - )} - - {hoveredIcon?.platform === platform && ( -
- {platform.charAt(0).toUpperCase() + platform.slice(1)} -
- )} -
- ); - } - return null; - } - )} + {Object.entries(businessData.profile.socials).map( + ([platform, url]) => { + if (url) { + const iconSrc = socialIcons[platform.toLowerCase()]; + + return ( +
+ + setHoveredIcon({ platform }) + } + onMouseLeave={() => setHoveredIcon(null)} + > + {iconSrc ? ( + {platform} + ) : ( + platform + )} + + {hoveredIcon?.platform === platform && ( +
+ {platform.charAt(0).toUpperCase() + + platform.slice(1)} +
+ )} +
+ ); + } + return null; + } + )}
)} diff --git a/client/app/api/index.ts b/client/app/api/index.ts index e07bcca..5e7a4a7 100644 --- a/client/app/api/index.ts +++ b/client/app/api/index.ts @@ -333,13 +333,29 @@ export const VerifyRegisterOTP = async (data: any) => { export const UserLogout = async (data: any) => { try { + + const token = document.cookie + .split('; ') + .find(row => row.startsWith('token=')) + ?.split('=')[1]; + + if (!token) { + throw new Error('No token provided'); + } + + const response = await axios.post( `${BASE_URL}/auth/logout`, - data + data, + { + headers: { + Authorization: `Bearer ${token}` + }, + } ); return response.data; } catch (error) { - console.error('Error verifying OTP:', error); + console.error('Error in logout:', error); throw error; } }; diff --git a/client/app/components/imgsec.tsx b/client/app/components/imgsec.tsx index da7e292..10ee817 100644 --- a/client/app/components/imgsec.tsx +++ b/client/app/components/imgsec.tsx @@ -157,7 +157,7 @@ const ImageSection = ({ images = defaultImages, media = [], className }: ImageSe return ( <>
Date: Thu, 9 Jan 2025 11:14:53 +0530 Subject: [PATCH 06/11] added --- client/app/[id]/page.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/app/[id]/page.tsx b/client/app/[id]/page.tsx index 3ac9103..b34d984 100644 --- a/client/app/[id]/page.tsx +++ b/client/app/[id]/page.tsx @@ -467,7 +467,7 @@ const DevMorphixWebsite = () => { {isOwner && ( )} -- knotmirror 0.0.1 From 3e9be7b4470bc950da7cd517a5cc9d0ac241c72c Mon Sep 17 00:00:00 2001 From: Abhishek V Gopal Date: Thu, 9 Jan 2025 22:23:16 +0530 Subject: [PATCH 07/11] added --- client/app/[id]/edit/page.tsx | 289 ++++++++++++++-------------------- 1 file changed, 115 insertions(+), 174 deletions(-) diff --git a/client/app/[id]/edit/page.tsx b/client/app/[id]/edit/page.tsx index c7d9370..45f28ac 100644 --- a/client/app/[id]/edit/page.tsx +++ b/client/app/[id]/edit/page.tsx @@ -7,26 +7,14 @@ import { updateBusiness, } from "@/app/api"; import { useParams, useRouter } from "next/navigation"; -import { - Pencil, - Save, - X, - Facebook, - Instagram, - Twitter, - Linkedin, - Youtube, - Globe, -} from "lucide-react"; +import { Pencil, Save, X, Facebook, Instagram, Twitter, Linkedin, Youtube, Globe } from 'lucide-react'; import ImageGrid from "@/app/components/imgsec"; import ImageUploadButton from "@/app/components/ImageUploadButton"; import MediaGallery from "@/app/components/MediaGallery"; import OperatingHours from "@/app/components/OperatingHours"; import { deletebusinessMedia } from "@/app/api"; -import { toast } from "react-hot-toast"; // Add toast for notifications -import { s } from "framer-motion/client"; +import { toast } from "react-hot-toast"; -// Add License interface before other interfaces interface License { name: string; number: string; @@ -34,7 +22,6 @@ interface License { description: string; } -// Add MediaItem interface interface MediaItem { id: string; url: string; @@ -61,15 +48,15 @@ interface BusinessProfile { twitter?: string; linkedin?: string; youtube?: string; - [key: string]: string | undefined; // Add index signature for socials + [key: string]: string | undefined; }; avatar: string; banner: string; type: string; additional_services: string; gstin: string; - id: string; // Add this field - [key: string]: any; // Add index signature to allow dynamic access + id: string; + [key: string]: any; } interface BusinessData { @@ -79,17 +66,19 @@ interface BusinessData { phone: string; }; _id: string; - media: MediaItem[]; // Add this field + media: MediaItem[]; category: string; subCategory: string; subCategoryOption: string; - licenses: License[]; // Now License is defined + licenses: License[]; tags: string[]; } -export const runtime = "edge"; +interface Changes { + [key: string]: any; +} -// Add this social media config object near the top of your component +export const runtime = "edge"; const socialMediaConfig = { website: { label: "Website URL", icon: "/icon/globe.svg" }, @@ -106,15 +95,16 @@ const socialMediaConfig = { github: { label: "GitHub Profile", icon: "/icon/github.svg" }, medium: { label: "Medium Profile", icon: "/icon/medium.svg" }, }; + export default function EditBusinessPage() { const [businessData, setBusinessData] = useState(null); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); - const [changes, setChanges] = useState>({}); + const [changes, setChanges] = useState({}); + const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); const params = useParams(); const router = useRouter(); - // Move fetchData outside useEffect so it can be referenced anywhere in the component const fetchData = async () => { try { setIsLoading(true); @@ -131,7 +121,6 @@ export default function EditBusinessPage() { } }; - // Check authorization useEffect(() => { const token = document.cookie .split("; ") @@ -143,87 +132,78 @@ export default function EditBusinessPage() { } }, [params.id, router]); - // Initial data fetch useEffect(() => { if (params.id) { fetchData(); } }, [params.id]); - const handleFieldSave = async (field: string, value: any) => { - try { - if (!businessData?.profile.id) return; + useEffect(() => { + setHasUnsavedChanges(Object.keys(changes).length > 0); + }, [changes]); + const handleFieldChange = (field: string, value: any) => { + setChanges((prev) => { const fieldParts = field.split("."); - let updateData: Record = {}; - if (fieldParts.length > 1 && fieldParts[0] === "socials") { - // Handle social media fields specifically - updateData.socials = { - ...(businessData.profile.socials || {}), - [fieldParts[1]]: value, + return { + ...prev, + socials: { + ...(prev.socials || {}), + [fieldParts[1]]: value, + }, }; - } else { - // Handle regular fields - updateData[field] = value; - } - - // Ensure updateData is not empty before making the API call - if (Object.keys(updateData).length === 0) { - console.warn("No values to update"); - return; } - - // Log the updateData object - console.log("Updating business with data:", updateData); - - await updateBusiness(businessData.profile.id, updateData); - toast.success(`${field} updated successfully`); - - // Update local state - setBusinessData((prev) => { - if (!prev) return null; + return { + ...prev, + [field]: value, + }; + }); + + // Update UI immediately + setBusinessData((prev) => { + if (!prev) return null; + const fieldParts = field.split("."); + if (fieldParts.length > 1 && fieldParts[0] === "socials") { return { ...prev, profile: { ...prev.profile, - ...(fieldParts[0] === "socials" - ? { - socials: { - ...prev.profile.socials, - [fieldParts[1]]: value, - }, - } - : updateData), + socials: { + ...prev.profile.socials, + [fieldParts[1]]: value, + }, }, }; - }); - } catch (error) { - console.error("Error updating field:", error); - toast.error(`Failed to update ${field}`); - } - }; - - const handleImageUpload = (assetpath: string, field: "avatar" | "banner") => { - console.log("Image uploaded:", assetpath); - // console.log('Field:', field); - handleFieldSave(field, assetpath); - }; - - // Replace handleChange with immediate save - const handleChange = async (field: string, value: string) => { - await handleFieldSave(field, value); + } + return { + ...prev, + profile: { + ...prev.profile, + [field]: value, + }, + }; + }); }; - const handleSave = async () => { + const handleSaveAllChanges = async () => { try { - // TODO: Implement API call to save all changes + if (!businessData?.profile.id || Object.keys(changes).length === 0) return; + + await updateBusiness(businessData.profile.id, changes); + toast.success("All changes saved successfully"); + setChanges({}); router.push(`/${params.id}`); } catch (error) { console.error("Error saving changes:", error); + toast.error("Failed to save changes"); } }; + const handleImageUpload = (assetpath: string, field: "avatar" | "banner") => { + handleFieldChange(field, assetpath); + }; + const handleMediaDelete = async (mediaId: string) => { try { if (businessData?.profile.id) { @@ -237,32 +217,8 @@ export default function EditBusinessPage() { } }; - const handleOperatingHoursUpdate = async (newHours: { - [key: string]: string; - }) => { - try { - if (!businessData?.profile.id) return; - - await updateBusiness(businessData.profile.id, { - operating_hours: newHours, - }); - toast.success("Operating hours updated successfully"); - - // Update local state - setBusinessData((prev) => { - if (!prev) return null; - return { - ...prev, - profile: { - ...prev.profile, - operating_hours: newHours, - }, - }; - }); - } catch (error) { - console.error("Error updating operating hours:", error); - toast.error("Failed to update operating hours"); - } + const handleOperatingHoursUpdate = (newHours: { [key: string]: string }) => { + handleFieldChange("operating_hours", newHours); }; if (isLoading) { @@ -295,6 +251,11 @@ export default function EditBusinessPage() {

Edit Business Profile + {hasUnsavedChanges && ( + + (Unsaved changes) + + )}

@@ -319,11 +285,10 @@ export default function EditBusinessPage() {

Profile Images

- {/* Profile Avatar */}

Profile Image

{ if (assetpath) { handleImageUpload(assetpath, "avatar"); - businessData.profile.avatar = assetpath; } }} />
- {/* Banner Image */}

Banner Image

{ if (assetpath) { handleImageUpload(assetpath, "banner"); - businessData.profile.banner = assetpath; } }} /> @@ -377,7 +339,7 @@ export default function EditBusinessPage() { handleFieldSave("name", e.target.value)} + onChange={(e) => handleFieldChange("name", e.target.value)} className="w-full p-2 border rounded-lg" />
@@ -387,7 +349,9 @@ export default function EditBusinessPage() {