@devvistatech/devvista-kit 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. package/CHANGELOG.md +12 -12
  2. package/LICENSE +6 -6
  3. package/README.md +15 -15
  4. package/app/about/page.tsx +298 -298
  5. package/app/adRequest/page.tsx +549 -549
  6. package/app/analytics/page.tsx +346 -346
  7. package/app/api/about/route.ts +306 -306
  8. package/app/api/adRequest/route.ts +567 -567
  9. package/app/api/analytics/[reportType]/route.ts +337 -337
  10. package/app/api/bio/route.ts +313 -313
  11. package/app/api/blog/route.ts +306 -306
  12. package/app/api/chat/route.ts +14 -14
  13. package/app/api/contact/route.ts +409 -409
  14. package/app/api/contacts/route.ts +224 -224
  15. package/app/api/files/route.ts +429 -429
  16. package/app/api/gallery-data/route.ts +735 -735
  17. package/app/api/schedule/route.ts +455 -455
  18. package/app/api/sync-user/route.ts +131 -131
  19. package/app/api/trial-request/route.ts +297 -297
  20. package/app/blog/[id]/page.tsx +288 -288
  21. package/app/blog/page.tsx +216 -216
  22. package/app/contact/page.tsx +284 -284
  23. package/app/faq/page.tsx +191 -191
  24. package/app/gallery/page.tsx +315 -315
  25. package/app/globals.css +58 -58
  26. package/app/layout.tsx +110 -110
  27. package/app/not-found.tsx +20 -20
  28. package/app/page.tsx +338 -338
  29. package/app/schedule/page.tsx +660 -660
  30. package/bin/init.js +219 -219
  31. package/components/addOns/functional/BioEditor.tsx +446 -446
  32. package/components/addOns/functional/CalendlyWidget.tsx +107 -107
  33. package/components/addOns/functional/ClassList.tsx +145 -145
  34. package/components/addOns/functional/ClassPopup.tsx +398 -398
  35. package/components/addOns/functional/ContactForm.tsx +284 -284
  36. package/components/addOns/functional/FileUploader.tsx +294 -294
  37. package/components/addOns/functional/ImageDescCarousel.tsx +730 -730
  38. package/components/addOns/functional/NewUserAnalytics.tsx +100 -100
  39. package/components/addOns/functional/ScheduleCarousel.tsx +171 -171
  40. package/components/addOns/functional/aboutSections/AboutSection.tsx +544 -544
  41. package/components/addOns/functional/aboutSections/constants/aboutSection.ts +65 -65
  42. package/components/addOns/functional/blogSections/BlogDashboard.tsx +184 -184
  43. package/components/addOns/functional/blogSections/BlogFormPopUp.tsx +554 -554
  44. package/components/addOns/functional/blogSections/BlogList.tsx +148 -148
  45. package/components/addOns/functional/blogSections/BlogSidebar.tsx +58 -58
  46. package/components/addOns/functional/blogSections/constants/blogDashboard.ts +28 -28
  47. package/components/addOns/functional/blogSections/constants/blogFormPopUp.ts +97 -97
  48. package/components/addOns/functional/blogSections/constants/blogList.ts +22 -22
  49. package/components/addOns/functional/blogSections/constants/blogSidebar.ts +15 -15
  50. package/components/addOns/functional/contactsDashboard/ContactsDashboard.tsx +366 -366
  51. package/components/addOns/functional/contactsDashboard/constants/contactsDashboard.ts +70 -70
  52. package/components/addOns/functional/galleries/GalleryComplex.tsx +836 -836
  53. package/components/addOns/functional/galleries/GallerySimple.tsx +509 -509
  54. package/components/addOns/functional/galleries/constants/galleryComplex.ts +106 -106
  55. package/components/addOns/functional/galleries/constants/gallerySimple.ts +76 -76
  56. package/components/addOns/functional/schedules/ScheduleGridOne.tsx +262 -262
  57. package/components/addOns/functional/schedules/ScheduleGridTwo.tsx +294 -294
  58. package/components/addOns/functional/schedules/ScheduleGridTwoBasic.tsx +288 -288
  59. package/components/addOns/functional/schedules/SchedulerForm.tsx +428 -428
  60. package/components/addOns/functional/schedules/constants/ScheduleGridTwo.ts +40 -40
  61. package/components/addOns/functional/schedules/constants/ScheduleGridTwoBasic.ts +40 -40
  62. package/components/addOns/functional/schedules/constants/SchedulerForm.ts +65 -65
  63. package/components/addOns/functional/schedules/constants/scheduleGridOne.ts +54 -54
  64. package/components/addOns/non-functional/AnnouncementBanner.tsx +46 -46
  65. package/components/addOns/non-functional/FeaturesSection.tsx +62 -62
  66. package/components/addOns/non-functional/Heros/HeroSection.tsx +142 -142
  67. package/components/addOns/non-functional/IconBubble.tsx +49 -49
  68. package/components/addOns/non-functional/SampleCarousel.tsx +204 -204
  69. package/components/addOns/non-functional/Testimonials.tsx +334 -334
  70. package/components/addOns/non-functional/ThreeSetGallery.tsx +63 -63
  71. package/components/addOns/non-functional/aboutSections/AboutSection.tsx +62 -62
  72. package/components/addOns/non-functional/aboutSections/constants/aboutSection.ts +24 -24
  73. package/components/addOns/non-functional/imageCarousels/ProductSlider.tsx +117 -117
  74. package/components/addOns/non-functional/imageCarousels/ProgramCarousel.tsx +232 -232
  75. package/components/addOns/non-functional/imageCarousels/constants/programCarousel.ts +39 -39
  76. package/components/addOns/non-functional/imageCarousels/constants/programSlider.ts +36 -36
  77. package/components/addOns/non-functional/spinner.tsx +21 -21
  78. package/components/footers/footer.tsx +453 -453
  79. package/components/navBars/navbar.tsx +310 -310
  80. package/components/other/accordion.tsx +58 -58
  81. package/components/other/admin-menu.tsx +68 -68
  82. package/components/other/alert-dialog.tsx +141 -141
  83. package/components/other/alert.tsx +59 -59
  84. package/components/other/aspect-ratio.tsx +7 -7
  85. package/components/other/avatar.tsx +50 -50
  86. package/components/other/badge.tsx +36 -36
  87. package/components/other/breadcrumb.tsx +115 -115
  88. package/components/other/button.tsx +738 -738
  89. package/components/other/calendar.tsx +66 -66
  90. package/components/other/card.tsx +86 -86
  91. package/components/other/carousel.tsx +274 -274
  92. package/components/other/chart.tsx +363 -363
  93. package/components/other/checkbox.tsx +30 -30
  94. package/components/other/collapsible.tsx +11 -11
  95. package/components/other/command.tsx +155 -155
  96. package/components/other/context-menu.tsx +200 -200
  97. package/components/other/dialog.tsx +122 -122
  98. package/components/other/drawer.tsx +118 -118
  99. package/components/other/dropdown-menu.tsx +200 -200
  100. package/components/other/form.tsx +179 -179
  101. package/components/other/hover-card.tsx +29 -29
  102. package/components/other/input-otp.tsx +71 -71
  103. package/components/other/input.tsx +25 -25
  104. package/components/other/label.tsx +26 -26
  105. package/components/other/menubar.tsx +236 -236
  106. package/components/other/mobile-icon.tsx +21 -21
  107. package/components/other/navigation-menu.tsx +128 -128
  108. package/components/other/pagination.tsx +117 -117
  109. package/components/other/popover.tsx +31 -31
  110. package/components/other/progress.tsx +28 -28
  111. package/components/other/radio-group.tsx +44 -44
  112. package/components/other/resizable.tsx +45 -45
  113. package/components/other/scroll-area.tsx +48 -48
  114. package/components/other/select.tsx +160 -160
  115. package/components/other/separator.tsx +31 -31
  116. package/components/other/sheet.tsx +140 -140
  117. package/components/other/skeleton.tsx +15 -15
  118. package/components/other/slider.tsx +28 -28
  119. package/components/other/social-icons.tsx +39 -39
  120. package/components/other/sonner.tsx +31 -31
  121. package/components/other/switch.tsx +29 -29
  122. package/components/other/table.tsx +117 -117
  123. package/components/other/tabs.tsx +55 -55
  124. package/components/other/textarea.tsx +24 -24
  125. package/components/other/toast.tsx +122 -122
  126. package/components/other/toaster.tsx +35 -35
  127. package/components/other/toggle-group.tsx +61 -61
  128. package/components/other/toggle.tsx +45 -45
  129. package/components/other/tooltip.tsx +30 -30
  130. package/components/theme-provider.tsx +8 -8
  131. package/components/types.ts +49 -49
  132. package/dist/.next/types/app/api/about/route.js +52 -0
  133. package/dist/.next/types/app/api/blog/route.js +52 -0
  134. package/dist/.next/types/app/api/files/route.js +52 -0
  135. package/dist/.next/types/app/api/schedule/route.js +52 -0
  136. package/dist/.next/types/app/api/sync-user/route.js +52 -0
  137. package/dist/.next/types/app/layout.js +22 -0
  138. package/dist/.next/types/app/page.js +22 -0
  139. package/dist/app/about/page.jsx +258 -0
  140. package/dist/app/adRequest/page.jsx +531 -0
  141. package/dist/app/analytics/page.jsx +298 -0
  142. package/dist/app/api/about/route.js +285 -0
  143. package/dist/app/api/adRequest/route.js +440 -0
  144. package/dist/app/api/analytics/[reportType]/route.js +357 -0
  145. package/dist/app/api/bio/route.js +293 -0
  146. package/dist/app/api/blog/route.js +366 -0
  147. package/dist/app/api/chat/route.js +58 -0
  148. package/dist/app/api/contact/route.js +163 -0
  149. package/dist/app/api/contacts/route.js +234 -0
  150. package/dist/app/api/files/route.js +444 -0
  151. package/dist/app/api/gallery-data/route.js +719 -0
  152. package/dist/app/api/schedule/route.js +461 -0
  153. package/dist/app/api/sync-user/route.js +186 -0
  154. package/dist/app/api/trial-request/route.js +165 -0
  155. package/dist/app/blog/[id]/page.jsx +312 -0
  156. package/dist/app/blog/page.jsx +210 -0
  157. package/dist/app/constants/about.js +32 -0
  158. package/dist/app/constants/adRequest.js +113 -0
  159. package/dist/app/constants/contact.js +40 -0
  160. package/dist/app/constants/faq.js +36 -0
  161. package/dist/app/constants/gallery.js +42 -0
  162. package/dist/app/constants/page.js +69 -0
  163. package/dist/app/constants/schedule.js +71 -0
  164. package/dist/app/contact/page.jsx +119 -0
  165. package/dist/app/faq/page.jsx +97 -0
  166. package/dist/app/gallery/page.jsx +281 -0
  167. package/dist/app/layout.jsx +45 -0
  168. package/dist/app/not-found.jsx +14 -0
  169. package/dist/app/page.jsx +324 -0
  170. package/dist/app/schedule/page.jsx +500 -0
  171. package/dist/components/addOns/functional/BioEditor.jsx +187 -0
  172. package/dist/components/addOns/functional/CalendlyWidget.jsx +61 -0
  173. package/dist/components/addOns/functional/ClassList.jsx +158 -0
  174. package/dist/components/addOns/functional/ClassPopup.jsx +300 -0
  175. package/dist/components/addOns/functional/ContactForm.jsx +219 -0
  176. package/dist/components/addOns/functional/FileUploader.jsx +222 -0
  177. package/dist/components/addOns/functional/ImageDescCarousel.jsx +491 -0
  178. package/dist/components/addOns/functional/NewUserAnalytics.jsx +71 -0
  179. package/dist/components/addOns/functional/ScheduleCarousel.jsx +68 -0
  180. package/dist/components/addOns/functional/aboutSections/AboutSection.jsx +372 -0
  181. package/dist/components/addOns/functional/aboutSections/constants/aboutSection.js +65 -0
  182. package/dist/components/addOns/functional/blogSections/BlogDashboard.jsx +111 -0
  183. package/dist/components/addOns/functional/blogSections/BlogFormPopUp.jsx +465 -0
  184. package/dist/components/addOns/functional/blogSections/BlogList.jsx +170 -0
  185. package/dist/components/addOns/functional/blogSections/BlogSidebar.jsx +35 -0
  186. package/dist/components/addOns/functional/blogSections/constants/blogDashboard.js +28 -0
  187. package/dist/components/addOns/functional/blogSections/constants/blogFormPopUp.js +97 -0
  188. package/dist/components/addOns/functional/blogSections/constants/blogList.js +22 -0
  189. package/dist/components/addOns/functional/blogSections/constants/blogSidebar.js +15 -0
  190. package/dist/components/addOns/functional/contactsDashboard/ContactsDashboard.jsx +355 -0
  191. package/dist/components/addOns/functional/contactsDashboard/constants/contactsDashboard.js +70 -0
  192. package/dist/components/addOns/functional/galleries/GalleryComplex.jsx +605 -0
  193. package/dist/components/addOns/functional/galleries/GallerySimple.jsx +363 -0
  194. package/dist/components/addOns/functional/galleries/constants/galleryComplex.js +106 -0
  195. package/dist/components/addOns/functional/galleries/constants/gallerySimple.js +76 -0
  196. package/dist/components/addOns/functional/schedules/ScheduleGridOne.jsx +167 -0
  197. package/dist/components/addOns/functional/schedules/ScheduleGridTwo.jsx +100 -0
  198. package/dist/components/addOns/functional/schedules/ScheduleGridTwoBasic.jsx +97 -0
  199. package/dist/components/addOns/functional/schedules/SchedulerForm.jsx +188 -0
  200. package/dist/components/addOns/functional/schedules/constants/ScheduleGridTwo.js +40 -0
  201. package/dist/components/addOns/functional/schedules/constants/ScheduleGridTwoBasic.js +40 -0
  202. package/dist/components/addOns/functional/schedules/constants/SchedulerForm.js +65 -0
  203. package/dist/components/addOns/functional/schedules/constants/scheduleGridOne.js +54 -0
  204. package/dist/components/addOns/non-functional/AnnouncementBanner.jsx +24 -0
  205. package/dist/components/addOns/non-functional/FeaturesSection.jsx +38 -0
  206. package/dist/components/addOns/non-functional/HeroSection.jsx +71 -0
  207. package/dist/components/addOns/non-functional/Heros/HeroSection.jsx +71 -0
  208. package/dist/components/addOns/non-functional/IconBubble.jsx +36 -0
  209. package/dist/components/addOns/non-functional/SampleCarousel.jsx +114 -0
  210. package/dist/components/addOns/non-functional/Testimonials.jsx +177 -0
  211. package/dist/components/addOns/non-functional/ThreeSetGallery.jsx +40 -0
  212. package/dist/components/addOns/non-functional/aboutSections/AboutSection.jsx +35 -0
  213. package/dist/components/addOns/non-functional/aboutSections/constants/aboutSection.js +24 -0
  214. package/dist/components/addOns/non-functional/imageCarousels/ProductSlider.jsx +80 -0
  215. package/dist/components/addOns/non-functional/imageCarousels/ProgramCarousel.jsx +155 -0
  216. package/dist/components/addOns/non-functional/imageCarousels/constants/programCarousel.js +39 -0
  217. package/dist/components/addOns/non-functional/imageCarousels/constants/programSlider.js +36 -0
  218. package/dist/components/addOns/non-functional/spinner.jsx +13 -0
  219. package/dist/components/footers/footer.jsx +217 -0
  220. package/dist/components/navBars/navbar.jsx +159 -0
  221. package/dist/components/other/accordion.jsx +40 -0
  222. package/dist/components/other/admin-menu.jsx +34 -0
  223. package/dist/components/other/alert-dialog.jsx +64 -0
  224. package/dist/components/other/alert.jsx +41 -0
  225. package/dist/components/other/aspect-ratio.jsx +4 -0
  226. package/dist/components/other/avatar.jsx +31 -0
  227. package/dist/components/other/badge.jsx +32 -0
  228. package/dist/components/other/breadcrumb.jsx +57 -0
  229. package/dist/components/other/button.jsx +322 -0
  230. package/dist/components/other/calendar.jsx +43 -0
  231. package/dist/components/other/card.jsx +44 -0
  232. package/dist/components/other/carousel.jsx +140 -0
  233. package/dist/components/other/chart.jsx +182 -0
  234. package/dist/components/other/checkbox.jsx +26 -0
  235. package/dist/components/other/collapsible.jsx +6 -0
  236. package/dist/components/other/command.jsx +68 -0
  237. package/dist/components/other/context-menu.jsx +88 -0
  238. package/dist/components/other/dialog.jsx +60 -0
  239. package/dist/components/other/drawer.jsx +60 -0
  240. package/dist/components/other/dropdown-menu.jsx +90 -0
  241. package/dist/components/other/form.jsx +89 -0
  242. package/dist/components/other/hover-card.jsx +23 -0
  243. package/dist/components/other/input-otp.jsx +46 -0
  244. package/dist/components/other/input.jsx +19 -0
  245. package/dist/components/other/label.jsx +23 -0
  246. package/dist/components/other/login-popup.jsx +1 -0
  247. package/dist/components/other/menubar.jsx +96 -0
  248. package/dist/components/other/mobile-icon.jsx +11 -0
  249. package/dist/components/other/navigation-menu.jsx +62 -0
  250. package/dist/components/other/pagination.jsx +63 -0
  251. package/dist/components/other/popover.jsx +25 -0
  252. package/dist/components/other/progress.jsx +23 -0
  253. package/dist/components/other/radio-group.jsx +31 -0
  254. package/dist/components/other/resizable.jsx +29 -0
  255. package/dist/components/other/scroll-area.jsx +36 -0
  256. package/dist/components/other/select.jsx +83 -0
  257. package/dist/components/other/separator.jsx +21 -0
  258. package/dist/components/other/sheet.jsx +74 -0
  259. package/dist/components/other/signup-popup.jsx +1 -0
  260. package/dist/components/other/skeleton.jsx +17 -0
  261. package/dist/components/other/slider.jsx +26 -0
  262. package/dist/components/other/social-icons.jsx +15 -0
  263. package/dist/components/other/sonner.jsx +27 -0
  264. package/dist/components/other/switch.jsx +23 -0
  265. package/dist/components/other/table.jsx +56 -0
  266. package/dist/components/other/tabs.jsx +32 -0
  267. package/dist/components/other/textarea.jsx +19 -0
  268. package/dist/components/other/toast.jsx +58 -0
  269. package/dist/components/other/toaster.jsx +31 -0
  270. package/dist/components/other/toggle-group.jsx +41 -0
  271. package/dist/components/other/toggle.jsx +39 -0
  272. package/dist/components/other/tooltip.jsx +24 -0
  273. package/dist/components/theme-provider.jsx +18 -0
  274. package/dist/components/types.js +1 -0
  275. package/dist/hooks/use-toast.js +135 -0
  276. package/dist/lib/auth-context.jsx +144 -0
  277. package/dist/lib/constants/about.js +32 -0
  278. package/dist/lib/constants/adRequest.js +113 -0
  279. package/dist/lib/constants/contact.js +40 -0
  280. package/dist/lib/constants/faq.js +36 -0
  281. package/dist/lib/constants/gallery.js +42 -0
  282. package/dist/lib/constants/page.js +69 -0
  283. package/dist/lib/constants/schedule.js +71 -0
  284. package/dist/lib/google-analytics.jsx +148 -0
  285. package/dist/lib/utils.js +9 -0
  286. package/dist/lib/verify-user.js +142 -0
  287. package/dist/middleware.js +37 -0
  288. package/dist/tailwind.config.js +86 -0
  289. package/dist/tsconfig.tsbuildinfo +1 -0
  290. package/hooks/use-toast.ts +188 -188
  291. package/lib/auth-context.tsx +130 -130
  292. package/lib/constants/about.ts +34 -34
  293. package/lib/constants/adRequest.ts +113 -113
  294. package/lib/constants/contact.ts +40 -40
  295. package/lib/constants/faq.ts +34 -21
  296. package/lib/constants/gallery.ts +42 -42
  297. package/lib/constants/page.ts +69 -69
  298. package/lib/constants/schedule.ts +71 -71
  299. package/lib/google-analytics.tsx +97 -97
  300. package/lib/verify-user.ts +117 -117
  301. package/middleware.ts +42 -42
  302. package/netlify.toml +5 -5
  303. package/next.config.js +10 -10
  304. package/package.json +115 -115
  305. package/tailwind.config.ts +89 -89
  306. package/tsconfig.json +23 -23
@@ -1,837 +1,837 @@
1
- "use client";
2
-
3
- import { useState, useRef, useEffect } from "react";
4
- import { Card } from "@/components/other/card";
5
- import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/other/tabs";
6
- import { motion, useScroll, useTransform } from "framer-motion";
7
- import Image from "next/image";
8
- import { ActionButton, EditIconButton, TrashIconButton, CloseButton, SubmitButton, CancelButton, FilterButton, DeleteButton } from "@/components/other/button";
9
- import { Upload, X } from "lucide-react";
10
- import { useUser, useAuth } from "@clerk/nextjs";
11
- import { useStrapiAuth } from "@/lib/auth-context";
12
- import { GALLERY_COMPLEX } from "./constants/galleryComplex";
13
- import { StrapiUser, UploadedImage, EditFormState, Category } from "@/components/types";
14
-
15
- interface GallerySectionProps {
16
- user: StrapiUser | null;
17
- setUser: (user: StrapiUser | null) => void;
18
- authLoading: boolean;
19
- uploadedImages: UploadedImage[];
20
- setUploadedImages: (images: UploadedImage[]) => void;
21
- error: string | null;
22
- setError: (error: string | null) => void;
23
- isLoading: boolean;
24
- setIsLoading: (isLoading: boolean) => void;
25
- handleImageUpload: (
26
- e: React.FormEvent<HTMLFormElement>,
27
- file: File | null,
28
- title: string,
29
- description: string,
30
- category: Category
31
- ) => Promise<void>;
32
- handleDeleteImage: (documentId: string) => Promise<void>;
33
- }
34
-
35
- export function GallerySection({
36
- user,
37
- setUser,
38
- authLoading,
39
- uploadedImages,
40
- setUploadedImages,
41
- error,
42
- setError,
43
- isLoading,
44
- setIsLoading,
45
- handleImageUpload,
46
- handleDeleteImage,
47
- }: GallerySectionProps) {
48
- const { isSignedIn } = useUser();
49
- const { getToken } = useAuth();
50
- const { checkSession } = useStrapiAuth();
51
- const isAdmin = isSignedIn && !!user?.businessAdminId || false;
52
- const [activeTab, setActiveTab] = useState("photos");
53
- const [activeSubTab, setActiveSubTab] = useState("all");
54
- const [selectedImage, setSelectedImage] = useState<UploadedImage | null>(null);
55
- const [isMobile, setIsMobile] = useState(false);
56
- const [visiblePhotos, setVisiblePhotos] = useState(12);
57
- const [isConfirmDeleteOpen, setIsConfirmDeleteOpen] = useState(false);
58
- const [documentIdToDelete, setDocumentIdToDelete] = useState<string | null>(null);
59
- const [isEditModalOpen, setIsEditModalOpen] = useState(false);
60
- const [isUploadModalOpen, setIsUploadModalOpen] = useState(false);
61
- const [editForm, setEditForm] = useState<EditFormState>({
62
- id: 0,
63
- documentId: "",
64
- title: "",
65
- description: "",
66
- category: "none",
67
- file: null,
68
- });
69
- const [uploadForm, setUploadForm] = useState<{
70
- file: File | null;
71
- title: string;
72
- description: string;
73
- category: Category;
74
- }>({ file: null, title: "", description: "", category: "none" });
75
- const containerRef = useRef<HTMLDivElement>(null);
76
- const { scrollYProgress } = useScroll({
77
- target: containerRef,
78
- offset: ["start end", "end start"],
79
- });
80
- const parallaxY = useTransform(scrollYProgress, [0, 1], [0, -50]);
81
-
82
- const filteredImages = activeTab === "photos"
83
- ? activeSubTab === "all"
84
- ? uploadedImages
85
- : uploadedImages.filter((img) => (img.category || "none") === activeSubTab)
86
- : uploadedImages.filter((img) => (img.category || "none") === activeTab);
87
-
88
- useEffect(() => {
89
- const handleLogin = () => checkSession();
90
- const handleLogout = () => checkSession();
91
- window.addEventListener("user-login", handleLogin);
92
- window.removeEventListener("user-logout", handleLogout);
93
- return () => {
94
- window.removeEventListener("user-login", handleLogin);
95
- window.removeEventListener("user-logout", handleLogout);
96
- };
97
- }, [checkSession]);
98
-
99
- useEffect(() => {
100
- const checkMobile = () => setIsMobile(window.innerWidth < 768);
101
- checkMobile();
102
- window.addEventListener("resize", checkMobile);
103
- return () => window.removeEventListener("resize", checkMobile);
104
- }, []);
105
-
106
- useEffect(() => {
107
- if (selectedImage || isConfirmDeleteOpen || isEditModalOpen || isUploadModalOpen) {
108
- document.body.classList.add("overflow-hidden");
109
- } else {
110
- document.body.classList.remove("overflow-hidden");
111
- }
112
- return () => {
113
- document.body.classList.remove("overflow-hidden");
114
- };
115
- }, [selectedImage, isConfirmDeleteOpen, isEditModalOpen, isUploadModalOpen]);
116
-
117
- useEffect(() => {
118
- const event = new CustomEvent("modalStateChange", {
119
- detail: { isOpen: !!selectedImage || isConfirmDeleteOpen || isEditModalOpen || isUploadModalOpen },
120
- });
121
- window.dispatchEvent(event);
122
- }, [selectedImage, isConfirmDeleteOpen, isEditModalOpen, isUploadModalOpen]);
123
-
124
- useEffect(() => {
125
- const handleEsc = (e: KeyboardEvent) => {
126
- if (e.key === "Escape") {
127
- if (isConfirmDeleteOpen) {
128
- handleCancelDelete();
129
- } else if (selectedImage) {
130
- handleCloseModal();
131
- } else if (isEditModalOpen) {
132
- handleCloseEditModal();
133
- } else if (isUploadModalOpen) {
134
- handleCloseUploadModal();
135
- }
136
- }
137
- };
138
- window.addEventListener("keydown", handleEsc);
139
- return () => window.removeEventListener("keydown", handleEsc);
140
- }, [isConfirmDeleteOpen, selectedImage, isEditModalOpen, isUploadModalOpen]);
141
-
142
- const openConfirmDelete = (documentId: string) => {
143
- if (!isAdmin) {
144
- setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_DELETE);
145
- return;
146
- }
147
- setDocumentIdToDelete(documentId);
148
- setIsConfirmDeleteOpen(true);
149
- };
150
-
151
- const handleConfirmDelete = async () => {
152
- if (!isAdmin) {
153
- setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_DELETE);
154
- setIsConfirmDeleteOpen(false);
155
- return;
156
- }
157
- if (documentIdToDelete !== null) {
158
- setIsLoading(true);
159
- try {
160
- await handleDeleteImage(documentIdToDelete);
161
- } finally {
162
- setIsLoading(false);
163
- setIsConfirmDeleteOpen(false);
164
- setDocumentIdToDelete(null);
165
- }
166
- }
167
- };
168
-
169
- const handleCancelDelete = () => {
170
- setIsConfirmDeleteOpen(false);
171
- setDocumentIdToDelete(null);
172
- };
173
-
174
- const handleImageClick = (image: UploadedImage) => {
175
- setSelectedImage(image);
176
- };
177
-
178
- const handleCloseModal = () => {
179
- setSelectedImage(null);
180
- };
181
-
182
- const openEditModal = (image: UploadedImage) => {
183
- if (!isAdmin) {
184
- setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_EDIT);
185
- return;
186
- }
187
- setEditForm({
188
- id: image.id,
189
- documentId: image.documentId,
190
- title: image.title?.trim() && !image.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) ? image.title : "",
191
- description: image.description || "",
192
- category: image.category || "none",
193
- file: null,
194
- });
195
- setIsEditModalOpen(true);
196
- };
197
-
198
- const handleCloseEditModal = () => {
199
- setIsEditModalOpen(false);
200
- setEditForm({ id: 0, documentId: "", title: "", description: "", category: "none", file: null });
201
- };
202
-
203
- const handleCloseUploadModal = () => {
204
- setIsUploadModalOpen(false);
205
- setUploadForm({ file: null, title: "", description: "", category: "none" });
206
- };
207
-
208
- const handleEditImage = async (e: React.FormEvent<HTMLFormElement>) => {
209
- e.preventDefault();
210
- if (!isAdmin) {
211
- console.error("GallerySection: Unauthorized edit attempt", {
212
- isSignedIn,
213
- businessAdminId: user?.businessAdminId,
214
- });
215
- setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_EDIT);
216
- return;
217
- }
218
-
219
- try {
220
- setIsLoading(true);
221
- const token = await getToken();
222
- if (!token) {
223
- console.error("GallerySection: No authentication token available");
224
- setError(GALLERY_COMPLEX.ERRORS.AUTHENTICATION_ERROR);
225
- setUser(null);
226
- return;
227
- }
228
-
229
- const formData = new FormData();
230
- formData.append("documentId", editForm.documentId);
231
- formData.append("title", editForm.title || `Image ${new Date().toISOString()}`);
232
- formData.append("description", editForm.description || "");
233
- formData.append("category", editForm.category || "none");
234
- if (editForm.file) {
235
- formData.append("file", editForm.file);
236
- }
237
-
238
- const response = await fetch("/api/gallery-data", {
239
- method: "PUT",
240
- headers: {
241
- Authorization: `Bearer ${token}`,
242
- },
243
- body: formData,
244
- });
245
-
246
- if (!response.ok) {
247
- const errorData = await response.json();
248
- console.error("GallerySection: Edit failed", { status: response.status, errorData });
249
- if (response.status === 401) {
250
- setError(GALLERY_COMPLEX.ERRORS.AUTHENTICATION_ERROR);
251
- setUser(null);
252
- return;
253
- }
254
- throw new Error(errorData.error || GALLERY_COMPLEX.ERRORS.EDIT_FAILED_STATUS.replace("${response.status}", response.status.toString()));
255
- }
256
-
257
- const { data } = await response.json();
258
- setUploadedImages(data || []);
259
- setError(null);
260
- setIsEditModalOpen(false);
261
- setEditForm({ id: 0, documentId: "", title: "", description: "", category: "none", file: null });
262
- } catch (err) {
263
- console.error("GallerySection: Edit Error", err);
264
- setError(err instanceof Error ? err.message : GALLERY_COMPLEX.ERRORS.EDIT_FAILED);
265
- } finally {
266
- setIsLoading(false);
267
- }
268
- };
269
-
270
- const handleUploadSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
271
- e.preventDefault();
272
- if (!isAdmin) {
273
- console.error("GallerySection: Unauthorized upload attempt", {
274
- isSignedIn,
275
- businessAdminId: user?.businessAdminId,
276
- });
277
- setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_UPLOAD);
278
- return;
279
- }
280
- setIsLoading(true);
281
- try {
282
- await handleImageUpload(
283
- e,
284
- uploadForm.file,
285
- uploadForm.title,
286
- uploadForm.description,
287
- uploadForm.category || "none"
288
- );
289
- setUploadForm({ file: null, title: "", description: "", category: "none" });
290
- setIsUploadModalOpen(false);
291
- } catch (err) {
292
- console.error("GallerySection: Upload Error", err);
293
- setError(err instanceof Error ? err.message : GALLERY_COMPLEX.ERRORS.UPLOAD_FAILED);
294
- } finally {
295
- setIsLoading(false);
296
- }
297
- };
298
-
299
- const loadMore = () => {
300
- setVisiblePhotos((prev) => prev + 12);
301
- };
302
-
303
- const sectionVariants = {
304
- hidden: { opacity: 0 },
305
- visible: {
306
- opacity: 1,
307
- transition: { duration: 0.8, ease: [0.16, 1, 0.3, 1], staggerChildren: 0.1 },
308
- },
309
- };
310
-
311
- const cardVariants = {
312
- hidden: { opacity: 0, y: 30 },
313
- visible: {
314
- opacity: 1,
315
- y: 0,
316
- transition: { duration: 0.5 },
317
- },
318
- };
319
-
320
- const modalVariants = {
321
- hidden: { opacity: 0, y: "100vh" },
322
- visible: { opacity: 1, y: 0, transition: { duration: 0.5, ease: [0.16, 1, 0.3, 1] } },
323
- exit: { opacity: 0, y: "100vh", transition: { duration: 0.3, ease: "easeIn" } },
324
- };
325
-
326
- return (
327
- <div className="w-full font-inter">
328
- <motion.div
329
- variants={sectionVariants}
330
- initial="hidden"
331
- whileInView="visible"
332
- viewport={{ once: true }}
333
- className="p-4 sm:p-8 lg:p-12"
334
- ref={containerRef}
335
- >
336
- <Tabs defaultValue="photos" className="w-full" onValueChange={(value) => setActiveTab(value)}>
337
- <TabsList className="grid w-full md:w-3/4 mx-auto grid-cols-2 mb-12 bg-white/10 backdrop-blur-lg border-2 border-transparent shadow-xl rounded-[2rem] p-4 h-24 supports-[not(backdrop-filter:blur(10px))]:bg-white/20">
338
- {["photos", "videos"].map((tab) => (
339
- <TabsTrigger
340
- key={tab}
341
- value={tab}
342
- className="rounded-[1.5rem] text-xl sm:text-2xl font-bold text-gray-700 data-[state=active]:text-white data-[state=active]:bg-blue-600 h-full flex items-center justify-center transition-all duration-300"
343
- >
344
- {tab === "photos" ? GALLERY_COMPLEX.UI.PHOTOS_TAB : GALLERY_COMPLEX.UI.VIDEOS_TAB}
345
- </TabsTrigger>
346
- ))}
347
- </TabsList>
348
- <TabsContent value="photos">
349
- <Tabs defaultValue="all" onValueChange={(value) => setActiveSubTab(value)}>
350
- {isMobile ? (
351
- <div className="flex justify-center mb-6 max-w-2xl mx-auto">
352
- <select
353
- value={activeSubTab}
354
- onChange={(e) => setActiveSubTab(e.target.value)}
355
- className="px-4 py-2 text-base font-medium text-gray-600 bg-white rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 w-full max-w-xs"
356
- >
357
- {["all", "indoor", "outdoor", "commercial"].map((subTab) => (
358
- <option key={subTab} value={subTab}>
359
- {subTab === "all" ? GALLERY_COMPLEX.UI.ALL_SUB_TAB :
360
- subTab === "indoor" ? GALLERY_COMPLEX.UI.INDOOR_SUB_TAB :
361
- subTab === "outdoor" ? GALLERY_COMPLEX.UI.OUTDOOR_SUB_TAB :
362
- GALLERY_COMPLEX.UI.COMMERCIAL_SUB_TAB}
363
- </option>
364
- ))}
365
- </select>
366
- </div>
367
- ) : (
368
- <div className="flex justify-center gap-4 mb-12 max-w-2xl mx-auto">
369
- {["all", "indoor", "outdoor", "commercial"].map((subTab) => (
370
- <FilterButton
371
- key={subTab}
372
- isActive={activeSubTab === subTab}
373
- useBlueActive={true}
374
- onClick={() => setActiveSubTab(subTab)}
375
- >
376
- {subTab === "all" ? GALLERY_COMPLEX.UI.ALL_SUB_TAB :
377
- subTab === "indoor" ? GALLERY_COMPLEX.UI.INDOOR_SUB_TAB :
378
- subTab === "outdoor" ? GALLERY_COMPLEX.UI.OUTDOOR_SUB_TAB :
379
- GALLERY_COMPLEX.UI.COMMERCIAL_SUB_TAB}
380
- </FilterButton>
381
- ))}
382
- </div>
383
- )}
384
-
385
- {["all", "indoor", "outdoor", "commercial"].map((subTab) => (
386
- <TabsContent key={subTab} value={subTab}>
387
- <div className="space-y-6">
388
- {error && (
389
- <p className="text-red-400 text-base sm:text-lg md:text-xl text-center">{error}</p>
390
- )}
391
- {isAdmin && (
392
- <div className="flex justify-center pb-12">
393
- <ActionButton
394
- onClick={() => setIsUploadModalOpen(true)}
395
- className="flex items-center gap-2"
396
- disabled={isLoading}
397
- >
398
- <Upload className="h-4 w-4 sm:h-5 sm:w-5" />
399
- {GALLERY_COMPLEX.BUTTONS.UPLOAD_IMAGE_BUTTON}
400
- </ActionButton>
401
- </div>
402
- )}
403
- {filteredImages.length > 0 ? (
404
- <>
405
- <motion.div
406
- className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2 sm:gap-8"
407
- style={{ y: isMobile ? 0 : parallaxY }}
408
- >
409
- {filteredImages.slice(0, visiblePhotos).map((image, index) => (
410
- <motion.div
411
- key={image.documentId}
412
- variants={cardVariants}
413
- initial="hidden"
414
- whileInView="visible"
415
- viewport={{ once: true, amount: 0.2 }}
416
- onClick={() => handleImageClick(image)}
417
- className="cursor-pointer will-change-transform will-change-opacity"
418
- >
419
- <Card className="overflow-hidden bg-white/10 backdrop-blur-lg border-2 border-transparent shadow-xl rounded-[1.5rem] p-2 sm:p-4 relative supports-[not(backdrop-filter:blur(10px))]:bg-white/20">
420
- <div className="relative w-full aspect-[3/2]">
421
- <Image
422
- src={image.url}
423
- alt={
424
- image.title?.trim() &&
425
- !image.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/)
426
- ? image.title
427
- : GALLERY_COMPLEX.UI.DEFAULT_IMAGE_ALT
428
- }
429
- fill
430
- className="object-cover object-center rounded-[1rem] transition-all duration-300"
431
- priority={index === 0}
432
- loading={index === 0 ? "eager" : "lazy"}
433
- quality={85}
434
- />
435
- </div>
436
- {isAdmin && (
437
- <div className="absolute top-2 right-2 flex space-x-2">
438
- <EditIconButton
439
- onClick={(e) => {
440
- e.stopPropagation();
441
- openEditModal(image);
442
- }}
443
- />
444
- <TrashIconButton
445
- onClick={(e) => {
446
- e.stopPropagation();
447
- openConfirmDelete(image.documentId);
448
- }}
449
- />
450
- </div>
451
- )}
452
- {(image.title?.trim() &&
453
- !image.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) ||
454
- image.description?.trim()) && (
455
- <div className="p-4">
456
- {image.title?.trim() &&
457
- !image.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) && (
458
- <h3 className="text-lg font-semibold text-gray-700">{image.title}</h3>
459
- )}
460
- {image.description?.trim() && (
461
- <p className="text-sm text-gray-600 line-clamp-2">{image.description}</p>
462
- )}
463
- </div>
464
- )}
465
- </Card>
466
- </motion.div>
467
- ))}
468
- </motion.div>
469
- {visiblePhotos < filteredImages.length && (
470
- <div className="mt-8 text-center">
471
- <ActionButton
472
- onClick={loadMore}
473
- className="flex items-center gap-2"
474
- >
475
- {GALLERY_COMPLEX.BUTTONS.LOAD_MORE_BUTTON}
476
- </ActionButton>
477
- </div>
478
- )}
479
- </>
480
- ) : (
481
- <p className="text-center text-gray-700 font-bold text-base sm:text-lg md:text-xl">
482
- {GALLERY_COMPLEX.UI.NO_IMAGES_MESSAGE}
483
- </p>
484
- )}
485
- </div>
486
- </TabsContent>
487
- ))}
488
- </Tabs>
489
- </TabsContent>
490
-
491
- <TabsContent value="videos">
492
- <div className="space-y-6">
493
- <p className="text-center text-gray-700 font-bold text-base sm:text-lg md:text-xl">
494
- {GALLERY_COMPLEX.UI.NO_VIDEOS_MESSAGE || "No videos are available"}
495
- </p>
496
- </div>
497
- </TabsContent>
498
- </Tabs>
499
- <div className="mt-4 text-center">
500
- {authLoading || isLoading ? (
501
- <p className="text-gray-400 text-sm font-medium">{GALLERY_COMPLEX.UI.LOADING_MESSAGE}</p>
502
- ) : isAdmin ? (
503
- <p className="text-gray-400 text-sm font-medium">{GALLERY_COMPLEX.UI.ADMIN_LOGGED_IN_MESSAGE}</p>
504
- ) : user ? (
505
- <p className="text-gray-400 text-sm font-medium"></p>
506
- ) : (
507
- <p className="text-gray-400 text-sm font-medium"></p>
508
- )}
509
- </div>
510
- </motion.div>
511
- {selectedImage && (
512
- <motion.div
513
- variants={modalVariants}
514
- initial="hidden"
515
- animate="visible"
516
- exit="exit"
517
- className="fixed inset-0 bg-black/90 flex items-center justify-center z-[10000] p-2 sm:p-4 isolate"
518
- onClick={handleCloseModal}
519
- role="dialog"
520
- aria-modal="true"
521
- aria-labelledby="modal-image"
522
- >
523
- <div
524
- className="relative max-w-5xl w-full mx-2 sm:mx-4 max-h-[90vh] bg-gray-800/50 border border-gray-700/50 rounded-2xl shadow-lg overflow-hidden max-[768px]:p-4 max-[768px]:max-h-[85vh]"
525
- onClick={(e) => e.stopPropagation()}
526
- >
527
- <CloseButton
528
- variant="close-form"
529
- onClick={handleCloseModal}
530
- >
531
- <X className="h-6 w-6 sm:h-8 sm:w-8" />
532
- </CloseButton>
533
- <div className="relative w-full h-[70vh] sm:h-[80vh]">
534
- <Image
535
- src={selectedImage.url}
536
- alt={
537
- selectedImage.title?.trim() &&
538
- !selectedImage.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/)
539
- ? selectedImage.title
540
- : GALLERY_COMPLEX.UI.DEFAULT_IMAGE_ALT
541
- }
542
- fill
543
- className="object-contain rounded-2xl"
544
- quality={85}
545
- />
546
- {(selectedImage.title?.trim() &&
547
- !selectedImage.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) ||
548
- selectedImage.description?.trim()) && (
549
- <div className="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/80 to-transparent p-3 sm:p-4">
550
- {selectedImage.title?.trim() &&
551
- !selectedImage.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) && (
552
- <h3 className="text-lg sm:text-xl md:text-2xl font-bold text-white drop-shadow-lg">
553
- {selectedImage.title}
554
- </h3>
555
- )}
556
- {selectedImage.description?.trim() && (
557
- <p className="text-xs sm:text-sm md:text-base text-gray-200 drop-shadow-md line-clamp-2">
558
- {selectedImage.description}
559
- </p>
560
- )}
561
- </div>
562
- )}
563
- </div>
564
- </div>
565
- </motion.div>
566
- )}
567
-
568
- {isConfirmDeleteOpen && isAdmin && (
569
- <motion.div
570
- variants={modalVariants}
571
- initial="hidden"
572
- animate="visible"
573
- exit="exit"
574
- className="fixed inset-0 bg-black/90 flex items-center justify-center z-[10000] p-4 isolate"
575
- onClick={handleCancelDelete}
576
- role="dialog"
577
- aria-modal="true"
578
- aria-labelledby="modal-title"
579
- >
580
- <div
581
- className="relative max-w-md w-full mx-4 p-6 bg-gray-800/50 border border-gray-700/50 rounded-lg shadow-lg max-[768px]:p-4 max-[768px]:max-h-[85vh]"
582
- onClick={(e) => e.stopPropagation()}
583
- >
584
- <CloseButton
585
- onClick={handleCancelDelete}
586
- >
587
- <X className="h-6 w-6 sm:h-8 sm:w-8" />
588
- </CloseButton>
589
- <h3 id="modal-title" className="text-xl font-bold text-white mb-4">
590
- {GALLERY_COMPLEX.UI.DELETE_MODAL_HEADING}
591
- </h3>
592
- <p className="text-gray-300 text-sm mb-4">
593
- {GALLERY_COMPLEX.UI.DELETE_CONFIRMATION_MESSAGE}
594
- </p>
595
- <div className="flex space-x-3">
596
- <DeleteButton
597
- onClick={handleConfirmDelete}
598
- disabled={isLoading}
599
- >
600
- {isLoading ? GALLERY_COMPLEX.BUTTONS.DELETING_BUTTON : GALLERY_COMPLEX.BUTTONS.DELETE_BUTTON}
601
- </DeleteButton>
602
- <CancelButton
603
- onClick={handleCancelDelete}
604
- />
605
- </div>
606
- </div>
607
- </motion.div>
608
- )}
609
-
610
- {isEditModalOpen && isAdmin && (
611
- <motion.div
612
- variants={modalVariants}
613
- initial="hidden"
614
- animate="visible"
615
- exit="exit"
616
- className="fixed inset-0 bg-black/90 flex items-center justify-center z-[10000] p-4 isolate"
617
- onClick={handleCloseEditModal}
618
- role="dialog"
619
- aria-modal="true"
620
- aria-labelledby="edit-modal-title"
621
- >
622
- <div
623
- className="relative max-w-md w-full mx-4 p-6 bg-gray-800/50 border border-gray-700/50 rounded-lg shadow-lg max-[768px]:p-4 max-[768px]:max-h-[85vh]"
624
- onClick={(e) => e.stopPropagation()}
625
- >
626
- <CloseButton
627
- onClick={handleCloseEditModal}
628
- >
629
- <X className="h-6 w-6 sm:h-8 sm:w-8" />
630
- </CloseButton>
631
- <h3 id="edit-modal-title" className="text-xl font-bold text-white mb-4">
632
- {GALLERY_COMPLEX.UI.EDIT_MODAL_HEADING}
633
- </h3>
634
- <form onSubmit={handleEditImage} className="flex flex-col space-y-4">
635
- <div>
636
- <label htmlFor="edit-image" className="block text-sm font-medium text-gray-300 mb-1">
637
- Replace Image (optional)
638
- </label>
639
- <input
640
- id="edit-image"
641
- type="file"
642
- accept="image/jpeg,image/png,image/gif"
643
- onChange={(e) => setEditForm({ ...editForm, file: e.target.files?.[0] || null })}
644
- className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
645
- disabled={isLoading}
646
- />
647
- {editForm.file && (
648
- <p className="mt-2 text-gray-300 text-sm">Selected: {editForm.file.name}</p>
649
- )}
650
- </div>
651
- <div>
652
- <label htmlFor="edit-title" className="block text-sm font-medium text-gray-300 mb-1">
653
- Image Title (optional)
654
- </label>
655
- <input
656
- id="edit-title"
657
- value={editForm.title}
658
- onChange={(e) => setEditForm({ ...editForm, title: e.target.value })}
659
- placeholder={GALLERY_COMPLEX.UI.TITLE_PLACEHOLDER}
660
- className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
661
- disabled={isLoading}
662
- />
663
- </div>
664
- <div>
665
- <label htmlFor="edit-description" className="block text-sm font-medium text-gray-300 mb-1">
666
- Image Description (optional)
667
- </label>
668
- <textarea
669
- id="edit-description"
670
- value={editForm.description}
671
- onChange={(e) => setEditForm({ ...editForm, description: e.target.value })}
672
- placeholder={GALLERY_COMPLEX.UI.DESCRIPTION_PLACEHOLDER}
673
- className="p-2 bg-gray-700 text-white rounded-lg w-full h-24 focus:outline-none focus:ring-2 focus:ring-blue-500"
674
- disabled={isLoading}
675
- />
676
- </div>
677
- <div>
678
- <label htmlFor="edit-category" className="block text-sm font-medium text-gray-300 mb-1">
679
- Category
680
- </label>
681
- <select
682
- id="edit-category"
683
- value={editForm.category || "none"}
684
- onChange={(e) =>
685
- setEditForm({
686
- ...editForm,
687
- category: e.target.value as Category,
688
- })
689
- }
690
- className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
691
- disabled={isLoading}
692
- >
693
- <option value="none">{GALLERY_COMPLEX.UI.CATEGORY_NONE}</option>
694
- <option value="indoor">{GALLERY_COMPLEX.UI.CATEGORY_INDOOR}</option>
695
- <option value="outdoor">{GALLERY_COMPLEX.UI.CATEGORY_OUTDOOR}</option>
696
- <option value="commercial">{GALLERY_COMPLEX.UI.CATEGORY_COMMERCIAL}</option>
697
- </select>
698
- </div>
699
- <div className="flex space-x-3">
700
- <SubmitButton
701
- type="submit"
702
- disabled={isLoading}
703
- >
704
- {isLoading ? GALLERY_COMPLEX.BUTTONS.SAVING_BUTTON : GALLERY_COMPLEX.BUTTONS.SAVE_BUTTON}
705
- </SubmitButton>
706
- <CancelButton
707
- onClick={handleCloseEditModal}
708
- />
709
- </div>
710
- </form>
711
- </div>
712
- </motion.div>
713
- )}
714
-
715
- {isUploadModalOpen && isAdmin && (
716
- <motion.div
717
- variants={modalVariants}
718
- initial="hidden"
719
- animate="visible"
720
- exit="exit"
721
- className="fixed inset-0 bg-black/90 flex items-center justify-center z-[10000] p-4 isolate"
722
- onClick={handleCloseUploadModal}
723
- role="dialog"
724
- aria-modal="true"
725
- aria-labelledby="upload-modal-title"
726
- >
727
- <div
728
- className="relative max-w-md w-full mx-4 p-6 bg-gray-800/50 border border-gray-700/50 rounded-lg shadow-lg max-[768px]:p-4 max-[768px]:max-h-[85vh]"
729
- onClick={(e) => e.stopPropagation()}
730
- >
731
- <CloseButton
732
- onClick={handleCloseUploadModal}
733
- >
734
- <X className="h-6 w-6 sm:h-8 sm:w-8" />
735
- </CloseButton>
736
- <h3 id="upload-modal-title" className="text-xl font-bold text-white mb-4">
737
- {GALLERY_COMPLEX.UI.UPLOAD_MODAL_HEADING}
738
- </h3>
739
- <form
740
- onSubmit={handleUploadSubmit}
741
- className="flex flex-col space-y-4"
742
- >
743
- <div>
744
- <label htmlFor="image-upload" className="block text-sm font-medium text-gray-300 mb-1">
745
- Choose Image
746
- </label>
747
- <input
748
- type="file"
749
- accept="image/jpeg,image/png,image/gif"
750
- onChange={(e) => {
751
- const file = e.target.files?.[0] || null;
752
- setUploadForm({ ...uploadForm, file });
753
- }}
754
- disabled={isLoading}
755
- className="hidden"
756
- id="image-upload"
757
- />
758
- <label htmlFor="image-upload" className="cursor-pointer">
759
- <div className="flex items-center justify-between bg-gray-700 text-white px-4 py-2 rounded-lg">
760
- <span>{uploadForm.file ? uploadForm.file.name : GALLERY_COMPLEX.UI.CHOOSE_IMAGE_TEXT}</span>
761
- <Upload className="h-4 w-4" />
762
- </div>
763
- </label>
764
- </div>
765
- <div>
766
- <label htmlFor="upload-title" className="block text-sm font-medium text-gray-300 mb-1">
767
- Image Title (optional)
768
- </label>
769
- <input
770
- id="upload-title"
771
- value={uploadForm.title}
772
- onChange={(e) => setUploadForm({ ...uploadForm, title: e.target.value })}
773
- placeholder={GALLERY_COMPLEX.UI.TITLE_PLACEHOLDER}
774
- className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
775
- disabled={isLoading}
776
- />
777
- </div>
778
- <div>
779
- <label htmlFor="upload-description" className="block text-sm font-medium text-gray-300 mb-1">
780
- Image Description (optional)
781
- </label>
782
- <textarea
783
- id="upload-description"
784
- value={uploadForm.description}
785
- onChange={(e) => setUploadForm({ ...uploadForm, description: e.target.value })}
786
- placeholder={GALLERY_COMPLEX.UI.DESCRIPTION_PLACEHOLDER}
787
- className="p-2 bg-gray-700 text-white rounded-lg w-full h-24 focus:outline-none focus:ring-2 focus:ring-blue-500"
788
- disabled={isLoading}
789
- />
790
- </div>
791
- <div>
792
- <label htmlFor="upload-category" className="block text-sm font-medium text-gray-300 mb-1">
793
- Category
794
- </label>
795
- <select
796
- id="upload-category"
797
- value={uploadForm.category || "none"}
798
- onChange={(e) =>
799
- setUploadForm({
800
- ...uploadForm,
801
- category: e.target.value as Category,
802
- })
803
- }
804
- className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
805
- disabled={isLoading}
806
- >
807
- <option value="none">{GALLERY_COMPLEX.UI.CATEGORY_NONE}</option>
808
- <option value="indoor">{GALLERY_COMPLEX.UI.CATEGORY_INDOOR}</option>
809
- <option value="outdoor">{GALLERY_COMPLEX.UI.CATEGORY_OUTDOOR}</option>
810
- <option value="commercial">{GALLERY_COMPLEX.UI.CATEGORY_COMMERCIAL}</option>
811
- </select>
812
- </div>
813
- <div className="flex space-x-3">
814
- <SubmitButton
815
- type="submit"
816
- disabled={isLoading || !uploadForm.file}
817
- >
818
- {isLoading ? GALLERY_COMPLEX.BUTTONS.UPLOADING_BUTTON : GALLERY_COMPLEX.BUTTONS.UPLOAD_BUTTON}
819
- </SubmitButton>
820
- <CancelButton
821
- onClick={handleCloseUploadModal}
822
- />
823
- </div>
824
- </form>
825
- </div>
826
- </motion.div>
827
- )}
828
-
829
- <motion.div
830
- initial={{ opacity: 0, scale: 0.8 }}
831
- animate={{ opacity: 0, scale: 0.8 }}
832
- transition={{ duration: 0.3 }}
833
- className="fixed bottom-6 right-6 z-40 pb-24"
834
- />
835
- </div>
836
- );
1
+ "use client";
2
+
3
+ import { useState, useRef, useEffect } from "react";
4
+ import { Card } from "@/components/other/card";
5
+ import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/other/tabs";
6
+ import { motion, useScroll, useTransform } from "framer-motion";
7
+ import Image from "next/image";
8
+ import { ActionButton, EditIconButton, TrashIconButton, CloseButton, SubmitButton, CancelButton, FilterButton, DeleteButton } from "@/components/other/button";
9
+ import { Upload, X } from "lucide-react";
10
+ import { useUser, useAuth } from "@clerk/nextjs";
11
+ import { useStrapiAuth } from "@/lib/auth-context";
12
+ import { GALLERY_COMPLEX } from "./constants/galleryComplex";
13
+ import { StrapiUser, UploadedImage, EditFormState, Category } from "@/components/types";
14
+
15
+ interface GallerySectionProps {
16
+ user: StrapiUser | null;
17
+ setUser: (user: StrapiUser | null) => void;
18
+ authLoading: boolean;
19
+ uploadedImages: UploadedImage[];
20
+ setUploadedImages: (images: UploadedImage[]) => void;
21
+ error: string | null;
22
+ setError: (error: string | null) => void;
23
+ isLoading: boolean;
24
+ setIsLoading: (isLoading: boolean) => void;
25
+ handleImageUpload: (
26
+ e: React.FormEvent<HTMLFormElement>,
27
+ file: File | null,
28
+ title: string,
29
+ description: string,
30
+ category: Category
31
+ ) => Promise<void>;
32
+ handleDeleteImage: (documentId: string) => Promise<void>;
33
+ }
34
+
35
+ export function GallerySection({
36
+ user,
37
+ setUser,
38
+ authLoading,
39
+ uploadedImages,
40
+ setUploadedImages,
41
+ error,
42
+ setError,
43
+ isLoading,
44
+ setIsLoading,
45
+ handleImageUpload,
46
+ handleDeleteImage,
47
+ }: GallerySectionProps) {
48
+ const { isSignedIn } = useUser();
49
+ const { getToken } = useAuth();
50
+ const { checkSession } = useStrapiAuth();
51
+ const isAdmin = isSignedIn && !!user?.businessAdminId || false;
52
+ const [activeTab, setActiveTab] = useState("photos");
53
+ const [activeSubTab, setActiveSubTab] = useState("all");
54
+ const [selectedImage, setSelectedImage] = useState<UploadedImage | null>(null);
55
+ const [isMobile, setIsMobile] = useState(false);
56
+ const [visiblePhotos, setVisiblePhotos] = useState(12);
57
+ const [isConfirmDeleteOpen, setIsConfirmDeleteOpen] = useState(false);
58
+ const [documentIdToDelete, setDocumentIdToDelete] = useState<string | null>(null);
59
+ const [isEditModalOpen, setIsEditModalOpen] = useState(false);
60
+ const [isUploadModalOpen, setIsUploadModalOpen] = useState(false);
61
+ const [editForm, setEditForm] = useState<EditFormState>({
62
+ id: 0,
63
+ documentId: "",
64
+ title: "",
65
+ description: "",
66
+ category: "none",
67
+ file: null,
68
+ });
69
+ const [uploadForm, setUploadForm] = useState<{
70
+ file: File | null;
71
+ title: string;
72
+ description: string;
73
+ category: Category;
74
+ }>({ file: null, title: "", description: "", category: "none" });
75
+ const containerRef = useRef<HTMLDivElement>(null);
76
+ const { scrollYProgress } = useScroll({
77
+ target: containerRef,
78
+ offset: ["start end", "end start"],
79
+ });
80
+ const parallaxY = useTransform(scrollYProgress, [0, 1], [0, -50]);
81
+
82
+ const filteredImages = activeTab === "photos"
83
+ ? activeSubTab === "all"
84
+ ? uploadedImages
85
+ : uploadedImages.filter((img) => (img.category || "none") === activeSubTab)
86
+ : uploadedImages.filter((img) => (img.category || "none") === activeTab);
87
+
88
+ useEffect(() => {
89
+ const handleLogin = () => checkSession();
90
+ const handleLogout = () => checkSession();
91
+ window.addEventListener("user-login", handleLogin);
92
+ window.removeEventListener("user-logout", handleLogout);
93
+ return () => {
94
+ window.removeEventListener("user-login", handleLogin);
95
+ window.removeEventListener("user-logout", handleLogout);
96
+ };
97
+ }, [checkSession]);
98
+
99
+ useEffect(() => {
100
+ const checkMobile = () => setIsMobile(window.innerWidth < 768);
101
+ checkMobile();
102
+ window.addEventListener("resize", checkMobile);
103
+ return () => window.removeEventListener("resize", checkMobile);
104
+ }, []);
105
+
106
+ useEffect(() => {
107
+ if (selectedImage || isConfirmDeleteOpen || isEditModalOpen || isUploadModalOpen) {
108
+ document.body.classList.add("overflow-hidden");
109
+ } else {
110
+ document.body.classList.remove("overflow-hidden");
111
+ }
112
+ return () => {
113
+ document.body.classList.remove("overflow-hidden");
114
+ };
115
+ }, [selectedImage, isConfirmDeleteOpen, isEditModalOpen, isUploadModalOpen]);
116
+
117
+ useEffect(() => {
118
+ const event = new CustomEvent("modalStateChange", {
119
+ detail: { isOpen: !!selectedImage || isConfirmDeleteOpen || isEditModalOpen || isUploadModalOpen },
120
+ });
121
+ window.dispatchEvent(event);
122
+ }, [selectedImage, isConfirmDeleteOpen, isEditModalOpen, isUploadModalOpen]);
123
+
124
+ useEffect(() => {
125
+ const handleEsc = (e: KeyboardEvent) => {
126
+ if (e.key === "Escape") {
127
+ if (isConfirmDeleteOpen) {
128
+ handleCancelDelete();
129
+ } else if (selectedImage) {
130
+ handleCloseModal();
131
+ } else if (isEditModalOpen) {
132
+ handleCloseEditModal();
133
+ } else if (isUploadModalOpen) {
134
+ handleCloseUploadModal();
135
+ }
136
+ }
137
+ };
138
+ window.addEventListener("keydown", handleEsc);
139
+ return () => window.removeEventListener("keydown", handleEsc);
140
+ }, [isConfirmDeleteOpen, selectedImage, isEditModalOpen, isUploadModalOpen]);
141
+
142
+ const openConfirmDelete = (documentId: string) => {
143
+ if (!isAdmin) {
144
+ setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_DELETE);
145
+ return;
146
+ }
147
+ setDocumentIdToDelete(documentId);
148
+ setIsConfirmDeleteOpen(true);
149
+ };
150
+
151
+ const handleConfirmDelete = async () => {
152
+ if (!isAdmin) {
153
+ setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_DELETE);
154
+ setIsConfirmDeleteOpen(false);
155
+ return;
156
+ }
157
+ if (documentIdToDelete !== null) {
158
+ setIsLoading(true);
159
+ try {
160
+ await handleDeleteImage(documentIdToDelete);
161
+ } finally {
162
+ setIsLoading(false);
163
+ setIsConfirmDeleteOpen(false);
164
+ setDocumentIdToDelete(null);
165
+ }
166
+ }
167
+ };
168
+
169
+ const handleCancelDelete = () => {
170
+ setIsConfirmDeleteOpen(false);
171
+ setDocumentIdToDelete(null);
172
+ };
173
+
174
+ const handleImageClick = (image: UploadedImage) => {
175
+ setSelectedImage(image);
176
+ };
177
+
178
+ const handleCloseModal = () => {
179
+ setSelectedImage(null);
180
+ };
181
+
182
+ const openEditModal = (image: UploadedImage) => {
183
+ if (!isAdmin) {
184
+ setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_EDIT);
185
+ return;
186
+ }
187
+ setEditForm({
188
+ id: image.id,
189
+ documentId: image.documentId,
190
+ title: image.title?.trim() && !image.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) ? image.title : "",
191
+ description: image.description || "",
192
+ category: image.category || "none",
193
+ file: null,
194
+ });
195
+ setIsEditModalOpen(true);
196
+ };
197
+
198
+ const handleCloseEditModal = () => {
199
+ setIsEditModalOpen(false);
200
+ setEditForm({ id: 0, documentId: "", title: "", description: "", category: "none", file: null });
201
+ };
202
+
203
+ const handleCloseUploadModal = () => {
204
+ setIsUploadModalOpen(false);
205
+ setUploadForm({ file: null, title: "", description: "", category: "none" });
206
+ };
207
+
208
+ const handleEditImage = async (e: React.FormEvent<HTMLFormElement>) => {
209
+ e.preventDefault();
210
+ if (!isAdmin) {
211
+ console.error("GallerySection: Unauthorized edit attempt", {
212
+ isSignedIn,
213
+ businessAdminId: user?.businessAdminId,
214
+ });
215
+ setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_EDIT);
216
+ return;
217
+ }
218
+
219
+ try {
220
+ setIsLoading(true);
221
+ const token = await getToken();
222
+ if (!token) {
223
+ console.error("GallerySection: No authentication token available");
224
+ setError(GALLERY_COMPLEX.ERRORS.AUTHENTICATION_ERROR);
225
+ setUser(null);
226
+ return;
227
+ }
228
+
229
+ const formData = new FormData();
230
+ formData.append("documentId", editForm.documentId);
231
+ formData.append("title", editForm.title || `Image ${new Date().toISOString()}`);
232
+ formData.append("description", editForm.description || "");
233
+ formData.append("category", editForm.category || "none");
234
+ if (editForm.file) {
235
+ formData.append("file", editForm.file);
236
+ }
237
+
238
+ const response = await fetch("/api/gallery-data", {
239
+ method: "PUT",
240
+ headers: {
241
+ Authorization: `Bearer ${token}`,
242
+ },
243
+ body: formData,
244
+ });
245
+
246
+ if (!response.ok) {
247
+ const errorData = await response.json();
248
+ console.error("GallerySection: Edit failed", { status: response.status, errorData });
249
+ if (response.status === 401) {
250
+ setError(GALLERY_COMPLEX.ERRORS.AUTHENTICATION_ERROR);
251
+ setUser(null);
252
+ return;
253
+ }
254
+ throw new Error(errorData.error || GALLERY_COMPLEX.ERRORS.EDIT_FAILED_STATUS.replace("${response.status}", response.status.toString()));
255
+ }
256
+
257
+ const { data } = await response.json();
258
+ setUploadedImages(data || []);
259
+ setError(null);
260
+ setIsEditModalOpen(false);
261
+ setEditForm({ id: 0, documentId: "", title: "", description: "", category: "none", file: null });
262
+ } catch (err) {
263
+ console.error("GallerySection: Edit Error", err);
264
+ setError(err instanceof Error ? err.message : GALLERY_COMPLEX.ERRORS.EDIT_FAILED);
265
+ } finally {
266
+ setIsLoading(false);
267
+ }
268
+ };
269
+
270
+ const handleUploadSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
271
+ e.preventDefault();
272
+ if (!isAdmin) {
273
+ console.error("GallerySection: Unauthorized upload attempt", {
274
+ isSignedIn,
275
+ businessAdminId: user?.businessAdminId,
276
+ });
277
+ setError(GALLERY_COMPLEX.ERRORS.UNAUTHORIZED_UPLOAD);
278
+ return;
279
+ }
280
+ setIsLoading(true);
281
+ try {
282
+ await handleImageUpload(
283
+ e,
284
+ uploadForm.file,
285
+ uploadForm.title,
286
+ uploadForm.description,
287
+ uploadForm.category || "none"
288
+ );
289
+ setUploadForm({ file: null, title: "", description: "", category: "none" });
290
+ setIsUploadModalOpen(false);
291
+ } catch (err) {
292
+ console.error("GallerySection: Upload Error", err);
293
+ setError(err instanceof Error ? err.message : GALLERY_COMPLEX.ERRORS.UPLOAD_FAILED);
294
+ } finally {
295
+ setIsLoading(false);
296
+ }
297
+ };
298
+
299
+ const loadMore = () => {
300
+ setVisiblePhotos((prev) => prev + 12);
301
+ };
302
+
303
+ const sectionVariants = {
304
+ hidden: { opacity: 0 },
305
+ visible: {
306
+ opacity: 1,
307
+ transition: { duration: 0.8, ease: [0.16, 1, 0.3, 1], staggerChildren: 0.1 },
308
+ },
309
+ };
310
+
311
+ const cardVariants = {
312
+ hidden: { opacity: 0, y: 30 },
313
+ visible: {
314
+ opacity: 1,
315
+ y: 0,
316
+ transition: { duration: 0.5 },
317
+ },
318
+ };
319
+
320
+ const modalVariants = {
321
+ hidden: { opacity: 0, y: "100vh" },
322
+ visible: { opacity: 1, y: 0, transition: { duration: 0.5, ease: [0.16, 1, 0.3, 1] } },
323
+ exit: { opacity: 0, y: "100vh", transition: { duration: 0.3, ease: "easeIn" } },
324
+ };
325
+
326
+ return (
327
+ <div className="w-full font-inter">
328
+ <motion.div
329
+ variants={sectionVariants}
330
+ initial="hidden"
331
+ whileInView="visible"
332
+ viewport={{ once: true }}
333
+ className="p-4 sm:p-8 lg:p-12"
334
+ ref={containerRef}
335
+ >
336
+ <Tabs defaultValue="photos" className="w-full" onValueChange={(value) => setActiveTab(value)}>
337
+ <TabsList className="grid w-full md:w-3/4 mx-auto grid-cols-2 mb-12 bg-white/10 backdrop-blur-lg border-2 border-transparent shadow-xl rounded-[2rem] p-4 h-24 supports-[not(backdrop-filter:blur(10px))]:bg-white/20">
338
+ {["photos", "videos"].map((tab) => (
339
+ <TabsTrigger
340
+ key={tab}
341
+ value={tab}
342
+ className="rounded-[1.5rem] text-xl sm:text-2xl font-bold text-gray-700 data-[state=active]:text-white data-[state=active]:bg-blue-600 h-full flex items-center justify-center transition-all duration-300"
343
+ >
344
+ {tab === "photos" ? GALLERY_COMPLEX.UI.PHOTOS_TAB : GALLERY_COMPLEX.UI.VIDEOS_TAB}
345
+ </TabsTrigger>
346
+ ))}
347
+ </TabsList>
348
+ <TabsContent value="photos">
349
+ <Tabs defaultValue="all" onValueChange={(value) => setActiveSubTab(value)}>
350
+ {isMobile ? (
351
+ <div className="flex justify-center mb-6 max-w-2xl mx-auto">
352
+ <select
353
+ value={activeSubTab}
354
+ onChange={(e) => setActiveSubTab(e.target.value)}
355
+ className="px-4 py-2 text-base font-medium text-gray-600 bg-white rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 w-full max-w-xs"
356
+ >
357
+ {["all", "indoor", "outdoor", "commercial"].map((subTab) => (
358
+ <option key={subTab} value={subTab}>
359
+ {subTab === "all" ? GALLERY_COMPLEX.UI.ALL_SUB_TAB :
360
+ subTab === "indoor" ? GALLERY_COMPLEX.UI.INDOOR_SUB_TAB :
361
+ subTab === "outdoor" ? GALLERY_COMPLEX.UI.OUTDOOR_SUB_TAB :
362
+ GALLERY_COMPLEX.UI.COMMERCIAL_SUB_TAB}
363
+ </option>
364
+ ))}
365
+ </select>
366
+ </div>
367
+ ) : (
368
+ <div className="flex justify-center gap-4 mb-12 max-w-2xl mx-auto">
369
+ {["all", "indoor", "outdoor", "commercial"].map((subTab) => (
370
+ <FilterButton
371
+ key={subTab}
372
+ isActive={activeSubTab === subTab}
373
+ useBlueActive={true}
374
+ onClick={() => setActiveSubTab(subTab)}
375
+ >
376
+ {subTab === "all" ? GALLERY_COMPLEX.UI.ALL_SUB_TAB :
377
+ subTab === "indoor" ? GALLERY_COMPLEX.UI.INDOOR_SUB_TAB :
378
+ subTab === "outdoor" ? GALLERY_COMPLEX.UI.OUTDOOR_SUB_TAB :
379
+ GALLERY_COMPLEX.UI.COMMERCIAL_SUB_TAB}
380
+ </FilterButton>
381
+ ))}
382
+ </div>
383
+ )}
384
+
385
+ {["all", "indoor", "outdoor", "commercial"].map((subTab) => (
386
+ <TabsContent key={subTab} value={subTab}>
387
+ <div className="space-y-6">
388
+ {error && (
389
+ <p className="text-red-400 text-base sm:text-lg md:text-xl text-center">{error}</p>
390
+ )}
391
+ {isAdmin && (
392
+ <div className="flex justify-center pb-12">
393
+ <ActionButton
394
+ onClick={() => setIsUploadModalOpen(true)}
395
+ className="flex items-center gap-2"
396
+ disabled={isLoading}
397
+ >
398
+ <Upload className="h-4 w-4 sm:h-5 sm:w-5" />
399
+ {GALLERY_COMPLEX.BUTTONS.UPLOAD_IMAGE_BUTTON}
400
+ </ActionButton>
401
+ </div>
402
+ )}
403
+ {filteredImages.length > 0 ? (
404
+ <>
405
+ <motion.div
406
+ className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2 sm:gap-8"
407
+ style={{ y: isMobile ? 0 : parallaxY }}
408
+ >
409
+ {filteredImages.slice(0, visiblePhotos).map((image, index) => (
410
+ <motion.div
411
+ key={image.documentId}
412
+ variants={cardVariants}
413
+ initial="hidden"
414
+ whileInView="visible"
415
+ viewport={{ once: true, amount: 0.2 }}
416
+ onClick={() => handleImageClick(image)}
417
+ className="cursor-pointer will-change-transform will-change-opacity"
418
+ >
419
+ <Card className="overflow-hidden bg-white/10 backdrop-blur-lg border-2 border-transparent shadow-xl rounded-[1.5rem] p-2 sm:p-4 relative supports-[not(backdrop-filter:blur(10px))]:bg-white/20">
420
+ <div className="relative w-full aspect-[3/2]">
421
+ <Image
422
+ src={image.url}
423
+ alt={
424
+ image.title?.trim() &&
425
+ !image.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/)
426
+ ? image.title
427
+ : GALLERY_COMPLEX.UI.DEFAULT_IMAGE_ALT
428
+ }
429
+ fill
430
+ className="object-cover object-center rounded-[1rem] transition-all duration-300"
431
+ priority={index === 0}
432
+ loading={index === 0 ? "eager" : "lazy"}
433
+ quality={85}
434
+ />
435
+ </div>
436
+ {isAdmin && (
437
+ <div className="absolute top-2 right-2 flex space-x-2">
438
+ <EditIconButton
439
+ onClick={(e) => {
440
+ e.stopPropagation();
441
+ openEditModal(image);
442
+ }}
443
+ />
444
+ <TrashIconButton
445
+ onClick={(e) => {
446
+ e.stopPropagation();
447
+ openConfirmDelete(image.documentId);
448
+ }}
449
+ />
450
+ </div>
451
+ )}
452
+ {(image.title?.trim() &&
453
+ !image.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) ||
454
+ image.description?.trim()) && (
455
+ <div className="p-4">
456
+ {image.title?.trim() &&
457
+ !image.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) && (
458
+ <h3 className="text-lg font-semibold text-gray-700">{image.title}</h3>
459
+ )}
460
+ {image.description?.trim() && (
461
+ <p className="text-sm text-gray-600 line-clamp-2">{image.description}</p>
462
+ )}
463
+ </div>
464
+ )}
465
+ </Card>
466
+ </motion.div>
467
+ ))}
468
+ </motion.div>
469
+ {visiblePhotos < filteredImages.length && (
470
+ <div className="mt-8 text-center">
471
+ <ActionButton
472
+ onClick={loadMore}
473
+ className="flex items-center gap-2"
474
+ >
475
+ {GALLERY_COMPLEX.BUTTONS.LOAD_MORE_BUTTON}
476
+ </ActionButton>
477
+ </div>
478
+ )}
479
+ </>
480
+ ) : (
481
+ <p className="text-center text-gray-700 font-bold text-base sm:text-lg md:text-xl">
482
+ {GALLERY_COMPLEX.UI.NO_IMAGES_MESSAGE}
483
+ </p>
484
+ )}
485
+ </div>
486
+ </TabsContent>
487
+ ))}
488
+ </Tabs>
489
+ </TabsContent>
490
+
491
+ <TabsContent value="videos">
492
+ <div className="space-y-6">
493
+ <p className="text-center text-gray-700 font-bold text-base sm:text-lg md:text-xl">
494
+ {GALLERY_COMPLEX.UI.NO_VIDEOS_MESSAGE || "No videos are available"}
495
+ </p>
496
+ </div>
497
+ </TabsContent>
498
+ </Tabs>
499
+ <div className="mt-4 text-center">
500
+ {authLoading || isLoading ? (
501
+ <p className="text-gray-400 text-sm font-medium">{GALLERY_COMPLEX.UI.LOADING_MESSAGE}</p>
502
+ ) : isAdmin ? (
503
+ <p className="text-gray-400 text-sm font-medium">{GALLERY_COMPLEX.UI.ADMIN_LOGGED_IN_MESSAGE}</p>
504
+ ) : user ? (
505
+ <p className="text-gray-400 text-sm font-medium"></p>
506
+ ) : (
507
+ <p className="text-gray-400 text-sm font-medium"></p>
508
+ )}
509
+ </div>
510
+ </motion.div>
511
+ {selectedImage && (
512
+ <motion.div
513
+ variants={modalVariants}
514
+ initial="hidden"
515
+ animate="visible"
516
+ exit="exit"
517
+ className="fixed inset-0 bg-black/90 flex items-center justify-center z-[10000] p-2 sm:p-4 isolate"
518
+ onClick={handleCloseModal}
519
+ role="dialog"
520
+ aria-modal="true"
521
+ aria-labelledby="modal-image"
522
+ >
523
+ <div
524
+ className="relative max-w-5xl w-full mx-2 sm:mx-4 max-h-[90vh] bg-gray-800/50 border border-gray-700/50 rounded-2xl shadow-lg overflow-hidden max-[768px]:p-4 max-[768px]:max-h-[85vh]"
525
+ onClick={(e) => e.stopPropagation()}
526
+ >
527
+ <CloseButton
528
+ variant="close-form"
529
+ onClick={handleCloseModal}
530
+ >
531
+ <X className="h-6 w-6 sm:h-8 sm:w-8" />
532
+ </CloseButton>
533
+ <div className="relative w-full h-[70vh] sm:h-[80vh]">
534
+ <Image
535
+ src={selectedImage.url}
536
+ alt={
537
+ selectedImage.title?.trim() &&
538
+ !selectedImage.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/)
539
+ ? selectedImage.title
540
+ : GALLERY_COMPLEX.UI.DEFAULT_IMAGE_ALT
541
+ }
542
+ fill
543
+ className="object-contain rounded-2xl"
544
+ quality={85}
545
+ />
546
+ {(selectedImage.title?.trim() &&
547
+ !selectedImage.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) ||
548
+ selectedImage.description?.trim()) && (
549
+ <div className="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/80 to-transparent p-3 sm:p-4">
550
+ {selectedImage.title?.trim() &&
551
+ !selectedImage.title.match(/Image \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/) && (
552
+ <h3 className="text-lg sm:text-xl md:text-2xl font-bold text-white drop-shadow-lg">
553
+ {selectedImage.title}
554
+ </h3>
555
+ )}
556
+ {selectedImage.description?.trim() && (
557
+ <p className="text-xs sm:text-sm md:text-base text-gray-200 drop-shadow-md line-clamp-2">
558
+ {selectedImage.description}
559
+ </p>
560
+ )}
561
+ </div>
562
+ )}
563
+ </div>
564
+ </div>
565
+ </motion.div>
566
+ )}
567
+
568
+ {isConfirmDeleteOpen && isAdmin && (
569
+ <motion.div
570
+ variants={modalVariants}
571
+ initial="hidden"
572
+ animate="visible"
573
+ exit="exit"
574
+ className="fixed inset-0 bg-black/90 flex items-center justify-center z-[10000] p-4 isolate"
575
+ onClick={handleCancelDelete}
576
+ role="dialog"
577
+ aria-modal="true"
578
+ aria-labelledby="modal-title"
579
+ >
580
+ <div
581
+ className="relative max-w-md w-full mx-4 p-6 bg-gray-800/50 border border-gray-700/50 rounded-lg shadow-lg max-[768px]:p-4 max-[768px]:max-h-[85vh]"
582
+ onClick={(e) => e.stopPropagation()}
583
+ >
584
+ <CloseButton
585
+ onClick={handleCancelDelete}
586
+ >
587
+ <X className="h-6 w-6 sm:h-8 sm:w-8" />
588
+ </CloseButton>
589
+ <h3 id="modal-title" className="text-xl font-bold text-white mb-4">
590
+ {GALLERY_COMPLEX.UI.DELETE_MODAL_HEADING}
591
+ </h3>
592
+ <p className="text-gray-300 text-sm mb-4">
593
+ {GALLERY_COMPLEX.UI.DELETE_CONFIRMATION_MESSAGE}
594
+ </p>
595
+ <div className="flex space-x-3">
596
+ <DeleteButton
597
+ onClick={handleConfirmDelete}
598
+ disabled={isLoading}
599
+ >
600
+ {isLoading ? GALLERY_COMPLEX.BUTTONS.DELETING_BUTTON : GALLERY_COMPLEX.BUTTONS.DELETE_BUTTON}
601
+ </DeleteButton>
602
+ <CancelButton
603
+ onClick={handleCancelDelete}
604
+ />
605
+ </div>
606
+ </div>
607
+ </motion.div>
608
+ )}
609
+
610
+ {isEditModalOpen && isAdmin && (
611
+ <motion.div
612
+ variants={modalVariants}
613
+ initial="hidden"
614
+ animate="visible"
615
+ exit="exit"
616
+ className="fixed inset-0 bg-black/90 flex items-center justify-center z-[10000] p-4 isolate"
617
+ onClick={handleCloseEditModal}
618
+ role="dialog"
619
+ aria-modal="true"
620
+ aria-labelledby="edit-modal-title"
621
+ >
622
+ <div
623
+ className="relative max-w-md w-full mx-4 p-6 bg-gray-800/50 border border-gray-700/50 rounded-lg shadow-lg max-[768px]:p-4 max-[768px]:max-h-[85vh]"
624
+ onClick={(e) => e.stopPropagation()}
625
+ >
626
+ <CloseButton
627
+ onClick={handleCloseEditModal}
628
+ >
629
+ <X className="h-6 w-6 sm:h-8 sm:w-8" />
630
+ </CloseButton>
631
+ <h3 id="edit-modal-title" className="text-xl font-bold text-white mb-4">
632
+ {GALLERY_COMPLEX.UI.EDIT_MODAL_HEADING}
633
+ </h3>
634
+ <form onSubmit={handleEditImage} className="flex flex-col space-y-4">
635
+ <div>
636
+ <label htmlFor="edit-image" className="block text-sm font-medium text-gray-300 mb-1">
637
+ Replace Image (optional)
638
+ </label>
639
+ <input
640
+ id="edit-image"
641
+ type="file"
642
+ accept="image/jpeg,image/png,image/gif"
643
+ onChange={(e) => setEditForm({ ...editForm, file: e.target.files?.[0] || null })}
644
+ className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
645
+ disabled={isLoading}
646
+ />
647
+ {editForm.file && (
648
+ <p className="mt-2 text-gray-300 text-sm">Selected: {editForm.file.name}</p>
649
+ )}
650
+ </div>
651
+ <div>
652
+ <label htmlFor="edit-title" className="block text-sm font-medium text-gray-300 mb-1">
653
+ Image Title (optional)
654
+ </label>
655
+ <input
656
+ id="edit-title"
657
+ value={editForm.title}
658
+ onChange={(e) => setEditForm({ ...editForm, title: e.target.value })}
659
+ placeholder={GALLERY_COMPLEX.UI.TITLE_PLACEHOLDER}
660
+ className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
661
+ disabled={isLoading}
662
+ />
663
+ </div>
664
+ <div>
665
+ <label htmlFor="edit-description" className="block text-sm font-medium text-gray-300 mb-1">
666
+ Image Description (optional)
667
+ </label>
668
+ <textarea
669
+ id="edit-description"
670
+ value={editForm.description}
671
+ onChange={(e) => setEditForm({ ...editForm, description: e.target.value })}
672
+ placeholder={GALLERY_COMPLEX.UI.DESCRIPTION_PLACEHOLDER}
673
+ className="p-2 bg-gray-700 text-white rounded-lg w-full h-24 focus:outline-none focus:ring-2 focus:ring-blue-500"
674
+ disabled={isLoading}
675
+ />
676
+ </div>
677
+ <div>
678
+ <label htmlFor="edit-category" className="block text-sm font-medium text-gray-300 mb-1">
679
+ Category
680
+ </label>
681
+ <select
682
+ id="edit-category"
683
+ value={editForm.category || "none"}
684
+ onChange={(e) =>
685
+ setEditForm({
686
+ ...editForm,
687
+ category: e.target.value as Category,
688
+ })
689
+ }
690
+ className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
691
+ disabled={isLoading}
692
+ >
693
+ <option value="none">{GALLERY_COMPLEX.UI.CATEGORY_NONE}</option>
694
+ <option value="indoor">{GALLERY_COMPLEX.UI.CATEGORY_INDOOR}</option>
695
+ <option value="outdoor">{GALLERY_COMPLEX.UI.CATEGORY_OUTDOOR}</option>
696
+ <option value="commercial">{GALLERY_COMPLEX.UI.CATEGORY_COMMERCIAL}</option>
697
+ </select>
698
+ </div>
699
+ <div className="flex space-x-3">
700
+ <SubmitButton
701
+ type="submit"
702
+ disabled={isLoading}
703
+ >
704
+ {isLoading ? GALLERY_COMPLEX.BUTTONS.SAVING_BUTTON : GALLERY_COMPLEX.BUTTONS.SAVE_BUTTON}
705
+ </SubmitButton>
706
+ <CancelButton
707
+ onClick={handleCloseEditModal}
708
+ />
709
+ </div>
710
+ </form>
711
+ </div>
712
+ </motion.div>
713
+ )}
714
+
715
+ {isUploadModalOpen && isAdmin && (
716
+ <motion.div
717
+ variants={modalVariants}
718
+ initial="hidden"
719
+ animate="visible"
720
+ exit="exit"
721
+ className="fixed inset-0 bg-black/90 flex items-center justify-center z-[10000] p-4 isolate"
722
+ onClick={handleCloseUploadModal}
723
+ role="dialog"
724
+ aria-modal="true"
725
+ aria-labelledby="upload-modal-title"
726
+ >
727
+ <div
728
+ className="relative max-w-md w-full mx-4 p-6 bg-gray-800/50 border border-gray-700/50 rounded-lg shadow-lg max-[768px]:p-4 max-[768px]:max-h-[85vh]"
729
+ onClick={(e) => e.stopPropagation()}
730
+ >
731
+ <CloseButton
732
+ onClick={handleCloseUploadModal}
733
+ >
734
+ <X className="h-6 w-6 sm:h-8 sm:w-8" />
735
+ </CloseButton>
736
+ <h3 id="upload-modal-title" className="text-xl font-bold text-white mb-4">
737
+ {GALLERY_COMPLEX.UI.UPLOAD_MODAL_HEADING}
738
+ </h3>
739
+ <form
740
+ onSubmit={handleUploadSubmit}
741
+ className="flex flex-col space-y-4"
742
+ >
743
+ <div>
744
+ <label htmlFor="image-upload" className="block text-sm font-medium text-gray-300 mb-1">
745
+ Choose Image
746
+ </label>
747
+ <input
748
+ type="file"
749
+ accept="image/jpeg,image/png,image/gif"
750
+ onChange={(e) => {
751
+ const file = e.target.files?.[0] || null;
752
+ setUploadForm({ ...uploadForm, file });
753
+ }}
754
+ disabled={isLoading}
755
+ className="hidden"
756
+ id="image-upload"
757
+ />
758
+ <label htmlFor="image-upload" className="cursor-pointer">
759
+ <div className="flex items-center justify-between bg-gray-700 text-white px-4 py-2 rounded-lg">
760
+ <span>{uploadForm.file ? uploadForm.file.name : GALLERY_COMPLEX.UI.CHOOSE_IMAGE_TEXT}</span>
761
+ <Upload className="h-4 w-4" />
762
+ </div>
763
+ </label>
764
+ </div>
765
+ <div>
766
+ <label htmlFor="upload-title" className="block text-sm font-medium text-gray-300 mb-1">
767
+ Image Title (optional)
768
+ </label>
769
+ <input
770
+ id="upload-title"
771
+ value={uploadForm.title}
772
+ onChange={(e) => setUploadForm({ ...uploadForm, title: e.target.value })}
773
+ placeholder={GALLERY_COMPLEX.UI.TITLE_PLACEHOLDER}
774
+ className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
775
+ disabled={isLoading}
776
+ />
777
+ </div>
778
+ <div>
779
+ <label htmlFor="upload-description" className="block text-sm font-medium text-gray-300 mb-1">
780
+ Image Description (optional)
781
+ </label>
782
+ <textarea
783
+ id="upload-description"
784
+ value={uploadForm.description}
785
+ onChange={(e) => setUploadForm({ ...uploadForm, description: e.target.value })}
786
+ placeholder={GALLERY_COMPLEX.UI.DESCRIPTION_PLACEHOLDER}
787
+ className="p-2 bg-gray-700 text-white rounded-lg w-full h-24 focus:outline-none focus:ring-2 focus:ring-blue-500"
788
+ disabled={isLoading}
789
+ />
790
+ </div>
791
+ <div>
792
+ <label htmlFor="upload-category" className="block text-sm font-medium text-gray-300 mb-1">
793
+ Category
794
+ </label>
795
+ <select
796
+ id="upload-category"
797
+ value={uploadForm.category || "none"}
798
+ onChange={(e) =>
799
+ setUploadForm({
800
+ ...uploadForm,
801
+ category: e.target.value as Category,
802
+ })
803
+ }
804
+ className="p-2 bg-gray-700 text-white rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500"
805
+ disabled={isLoading}
806
+ >
807
+ <option value="none">{GALLERY_COMPLEX.UI.CATEGORY_NONE}</option>
808
+ <option value="indoor">{GALLERY_COMPLEX.UI.CATEGORY_INDOOR}</option>
809
+ <option value="outdoor">{GALLERY_COMPLEX.UI.CATEGORY_OUTDOOR}</option>
810
+ <option value="commercial">{GALLERY_COMPLEX.UI.CATEGORY_COMMERCIAL}</option>
811
+ </select>
812
+ </div>
813
+ <div className="flex space-x-3">
814
+ <SubmitButton
815
+ type="submit"
816
+ disabled={isLoading || !uploadForm.file}
817
+ >
818
+ {isLoading ? GALLERY_COMPLEX.BUTTONS.UPLOADING_BUTTON : GALLERY_COMPLEX.BUTTONS.UPLOAD_BUTTON}
819
+ </SubmitButton>
820
+ <CancelButton
821
+ onClick={handleCloseUploadModal}
822
+ />
823
+ </div>
824
+ </form>
825
+ </div>
826
+ </motion.div>
827
+ )}
828
+
829
+ <motion.div
830
+ initial={{ opacity: 0, scale: 0.8 }}
831
+ animate={{ opacity: 0, scale: 0.8 }}
832
+ transition={{ duration: 0.3 }}
833
+ className="fixed bottom-6 right-6 z-40 pb-24"
834
+ />
835
+ </div>
836
+ );
837
837
  }