create-nextjs-cms 0.5.8

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 (187) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +395 -0
  6. package/dist/lib/utils.d.ts +11 -0
  7. package/dist/lib/utils.d.ts.map +1 -0
  8. package/dist/lib/utils.js +48 -0
  9. package/package.json +44 -0
  10. package/templates/default/.env +24 -0
  11. package/templates/default/.env.development +8 -0
  12. package/templates/default/.eslintrc.json +5 -0
  13. package/templates/default/.prettierignore +7 -0
  14. package/templates/default/.prettierrc.json +19 -0
  15. package/templates/default/CHANGELOG.md +77 -0
  16. package/templates/default/README.md +45 -0
  17. package/templates/default/app/(auth)/auth/login/LoginPage.tsx +175 -0
  18. package/templates/default/app/(auth)/auth/login/page.tsx +12 -0
  19. package/templates/default/app/(rootLayout)/admins/page.tsx +5 -0
  20. package/templates/default/app/(rootLayout)/advanced/page.tsx +5 -0
  21. package/templates/default/app/(rootLayout)/analytics/page.tsx +7 -0
  22. package/templates/default/app/(rootLayout)/browse/[section]/[page]/page.tsx +7 -0
  23. package/templates/default/app/(rootLayout)/categorized/[section]/page.tsx +7 -0
  24. package/templates/default/app/(rootLayout)/dashboard/page.tsx +7 -0
  25. package/templates/default/app/(rootLayout)/edit/[section]/[itemId]/page.tsx +7 -0
  26. package/templates/default/app/(rootLayout)/emails/page.tsx +6 -0
  27. package/templates/default/app/(rootLayout)/layout.tsx +5 -0
  28. package/templates/default/app/(rootLayout)/loading.tsx +10 -0
  29. package/templates/default/app/(rootLayout)/log/page.tsx +7 -0
  30. package/templates/default/app/(rootLayout)/new/[section]/page.tsx +7 -0
  31. package/templates/default/app/(rootLayout)/page.tsx +9 -0
  32. package/templates/default/app/(rootLayout)/section/[section]/page.tsx +7 -0
  33. package/templates/default/app/(rootLayout)/settings/page.tsx +7 -0
  34. package/templates/default/app/_trpc/client.ts +4 -0
  35. package/templates/default/app/api/auth/csrf/route.ts +25 -0
  36. package/templates/default/app/api/auth/refresh/route.ts +10 -0
  37. package/templates/default/app/api/auth/route.ts +23 -0
  38. package/templates/default/app/api/auth/session/route.ts +20 -0
  39. package/templates/default/app/api/editor/photo/route.ts +42 -0
  40. package/templates/default/app/api/photo/route.ts +27 -0
  41. package/templates/default/app/api/placeholder/route.ts +7 -0
  42. package/templates/default/app/api/submit/section/item/[slug]/route.ts +63 -0
  43. package/templates/default/app/api/submit/section/item/route.ts +53 -0
  44. package/templates/default/app/api/submit/section/simple/route.ts +54 -0
  45. package/templates/default/app/api/trpc/[trpc]/route.ts +33 -0
  46. package/templates/default/app/api/video/route.ts +174 -0
  47. package/templates/default/app/dictionaries.ts +14 -0
  48. package/templates/default/app/layout.tsx +28 -0
  49. package/templates/default/app/providers.tsx +151 -0
  50. package/templates/default/cli.ts +4 -0
  51. package/templates/default/components/AdminCard.tsx +163 -0
  52. package/templates/default/components/AdminEditPage.tsx +123 -0
  53. package/templates/default/components/AdminPrivilegeCard.tsx +184 -0
  54. package/templates/default/components/AdminsPage.tsx +43 -0
  55. package/templates/default/components/AdvancedSettingsPage.tsx +167 -0
  56. package/templates/default/components/AnalyticsPage.tsx +127 -0
  57. package/templates/default/components/BarChartBox.tsx +43 -0
  58. package/templates/default/components/BrowsePage.tsx +119 -0
  59. package/templates/default/components/CategorizedSectionPage.tsx +36 -0
  60. package/templates/default/components/CategoryDeleteConfirmPage.tsx +129 -0
  61. package/templates/default/components/CategorySectionSelectInput.tsx +139 -0
  62. package/templates/default/components/ConditionalFields.tsx +49 -0
  63. package/templates/default/components/ContainerBox.tsx +24 -0
  64. package/templates/default/components/DashboardPage.tsx +187 -0
  65. package/templates/default/components/DashboardPageAlt.tsx +43 -0
  66. package/templates/default/components/DefaultNavItems.tsx +3 -0
  67. package/templates/default/components/Dropzone.tsx +153 -0
  68. package/templates/default/components/EmailCard.tsx +137 -0
  69. package/templates/default/components/EmailPasswordForm.tsx +84 -0
  70. package/templates/default/components/EmailQuotaForm.tsx +72 -0
  71. package/templates/default/components/EmailsPage.tsx +48 -0
  72. package/templates/default/components/GalleryPhoto.tsx +93 -0
  73. package/templates/default/components/InfoCard.tsx +94 -0
  74. package/templates/default/components/ItemEditPage.tsx +217 -0
  75. package/templates/default/components/Layout.tsx +70 -0
  76. package/templates/default/components/LoadingSpinners.tsx +67 -0
  77. package/templates/default/components/LogPage.tsx +17 -0
  78. package/templates/default/components/Modal.tsx +99 -0
  79. package/templates/default/components/Navbar.tsx +29 -0
  80. package/templates/default/components/NavbarAlt.tsx +182 -0
  81. package/templates/default/components/NewAdminForm.tsx +172 -0
  82. package/templates/default/components/NewEmailForm.tsx +131 -0
  83. package/templates/default/components/NewPage.tsx +206 -0
  84. package/templates/default/components/NewVariantComponent.tsx +228 -0
  85. package/templates/default/components/PhotoGallery.tsx +35 -0
  86. package/templates/default/components/PieChartBox.tsx +101 -0
  87. package/templates/default/components/ProgressBar.tsx +24 -0
  88. package/templates/default/components/ProtectedDocument.tsx +78 -0
  89. package/templates/default/components/ProtectedImage.tsx +143 -0
  90. package/templates/default/components/ProtectedVideo.tsx +76 -0
  91. package/templates/default/components/SectionItemCard.tsx +143 -0
  92. package/templates/default/components/SectionItemStatusBadge.tsx +16 -0
  93. package/templates/default/components/SectionPage.tsx +124 -0
  94. package/templates/default/components/SelectBox.tsx +99 -0
  95. package/templates/default/components/SelectInputButtons.tsx +124 -0
  96. package/templates/default/components/SettingsPage.tsx +238 -0
  97. package/templates/default/components/Sidebar.tsx +209 -0
  98. package/templates/default/components/SidebarDropdownItem.tsx +74 -0
  99. package/templates/default/components/SidebarItem.tsx +19 -0
  100. package/templates/default/components/TempPage.tsx +12 -0
  101. package/templates/default/components/ThemeProvider.tsx +8 -0
  102. package/templates/default/components/TooltipComponent.tsx +27 -0
  103. package/templates/default/components/VariantCard.tsx +123 -0
  104. package/templates/default/components/VariantEditPage.tsx +229 -0
  105. package/templates/default/components/analytics/BounceRate.tsx +69 -0
  106. package/templates/default/components/analytics/LivePageViews.tsx +54 -0
  107. package/templates/default/components/analytics/LiveUsersCount.tsx +32 -0
  108. package/templates/default/components/analytics/MonthlyPageViews.tsx +41 -0
  109. package/templates/default/components/analytics/TopCountries.tsx +51 -0
  110. package/templates/default/components/analytics/TopDevices.tsx +45 -0
  111. package/templates/default/components/analytics/TopMediums.tsx +57 -0
  112. package/templates/default/components/analytics/TopSources.tsx +44 -0
  113. package/templates/default/components/analytics/TotalPageViews.tsx +40 -0
  114. package/templates/default/components/analytics/TotalSessions.tsx +40 -0
  115. package/templates/default/components/analytics/TotalUniqueUsers.tsx +40 -0
  116. package/templates/default/components/custom/RightHomeRoomVariantCard.tsx +137 -0
  117. package/templates/default/components/dndKit/Draggable.tsx +21 -0
  118. package/templates/default/components/dndKit/Droppable.tsx +20 -0
  119. package/templates/default/components/dndKit/SortableItem.tsx +18 -0
  120. package/templates/default/components/form/DateRangeFormInput.tsx +55 -0
  121. package/templates/default/components/form/Form.tsx +298 -0
  122. package/templates/default/components/form/FormInputElement.tsx +68 -0
  123. package/templates/default/components/form/FormInputs.tsx +108 -0
  124. package/templates/default/components/form/helpers/util.ts +20 -0
  125. package/templates/default/components/form/inputs/CheckboxFormInput.tsx +33 -0
  126. package/templates/default/components/form/inputs/ColorFormInput.tsx +44 -0
  127. package/templates/default/components/form/inputs/DateFormInput.tsx +107 -0
  128. package/templates/default/components/form/inputs/DocumentFormInput.tsx +124 -0
  129. package/templates/default/components/form/inputs/MapFormInput.tsx +139 -0
  130. package/templates/default/components/form/inputs/MultipleSelectFormInput.tsx +150 -0
  131. package/templates/default/components/form/inputs/NumberFormInput.tsx +42 -0
  132. package/templates/default/components/form/inputs/PasswordFormInput.tsx +47 -0
  133. package/templates/default/components/form/inputs/PhotoFormInput.tsx +218 -0
  134. package/templates/default/components/form/inputs/RichTextFormInput.tsx +133 -0
  135. package/templates/default/components/form/inputs/SelectFormInput.tsx +164 -0
  136. package/templates/default/components/form/inputs/TagsFormInput.tsx +63 -0
  137. package/templates/default/components/form/inputs/TextFormInput.tsx +48 -0
  138. package/templates/default/components/form/inputs/TextareaFormInput.tsx +47 -0
  139. package/templates/default/components/form/inputs/VideoFormInput.tsx +117 -0
  140. package/templates/default/components/pagination/Pagination.tsx +36 -0
  141. package/templates/default/components/pagination/PaginationButtons.tsx +145 -0
  142. package/templates/default/components/ui/accordion.tsx +57 -0
  143. package/templates/default/components/ui/alert.tsx +46 -0
  144. package/templates/default/components/ui/badge.tsx +33 -0
  145. package/templates/default/components/ui/button.tsx +57 -0
  146. package/templates/default/components/ui/calendar.tsx +68 -0
  147. package/templates/default/components/ui/card.tsx +76 -0
  148. package/templates/default/components/ui/checkbox.tsx +29 -0
  149. package/templates/default/components/ui/dropdown-menu.tsx +205 -0
  150. package/templates/default/components/ui/input.tsx +25 -0
  151. package/templates/default/components/ui/label.tsx +26 -0
  152. package/templates/default/components/ui/popover.tsx +31 -0
  153. package/templates/default/components/ui/scroll-area.tsx +42 -0
  154. package/templates/default/components/ui/select.tsx +164 -0
  155. package/templates/default/components/ui/sheet.tsx +107 -0
  156. package/templates/default/components/ui/switch.tsx +29 -0
  157. package/templates/default/components/ui/table.tsx +120 -0
  158. package/templates/default/components/ui/tabs.tsx +55 -0
  159. package/templates/default/components/ui/toast.tsx +113 -0
  160. package/templates/default/components/ui/toaster.tsx +35 -0
  161. package/templates/default/components/ui/tooltip.tsx +30 -0
  162. package/templates/default/components/ui/use-toast.ts +188 -0
  163. package/templates/default/components.json +16 -0
  164. package/templates/default/context/ModalProvider.tsx +53 -0
  165. package/templates/default/drizzle.config.ts +4 -0
  166. package/templates/default/dynamic-schemas/schema.ts +373 -0
  167. package/templates/default/env/env.js +130 -0
  168. package/templates/default/envConfig.ts +4 -0
  169. package/templates/default/hooks/useModal.ts +8 -0
  170. package/templates/default/lib/apiHelpers.ts +106 -0
  171. package/templates/default/lz.config.ts +40 -0
  172. package/templates/default/middleware.ts +33 -0
  173. package/templates/default/next.config.ts +46 -0
  174. package/templates/default/package.json +134 -0
  175. package/templates/default/postcss.config.js +6 -0
  176. package/templates/default/postinstall.js +14 -0
  177. package/templates/default/public/blank_avatar.png +0 -0
  178. package/templates/default/public/favicon.ico +0 -0
  179. package/templates/default/public/img/placeholder.svg +1 -0
  180. package/templates/default/public/lazemni_logo.png +0 -0
  181. package/templates/default/public/next.svg +1 -0
  182. package/templates/default/public/vercel.svg +1 -0
  183. package/templates/default/section-tests.ts +92 -0
  184. package/templates/default/styles/globals.css +88 -0
  185. package/templates/default/tailwind.config.js +95 -0
  186. package/templates/default/test.ts +77 -0
  187. package/templates/default/tsconfig.json +44 -0
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { ThemeProvider as NextThemesProvider } from 'next-themes'
5
+
6
+ export function ThemeProvider({ children, ...props }: React.ComponentProps<typeof NextThemesProvider>) {
7
+ return <NextThemesProvider {...props}>{children}</NextThemesProvider>
8
+ }
@@ -0,0 +1,27 @@
1
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
2
+ export default function TooltipComponent({
3
+ children,
4
+ content,
5
+ delayDuration = 200,
6
+ }: {
7
+ children: React.ReactNode
8
+ content: React.ReactNode
9
+ delayDuration?: number
10
+ }) {
11
+ if (!content) return children
12
+ return (
13
+ <TooltipProvider delayDuration={delayDuration}>
14
+ <Tooltip>
15
+ <TooltipTrigger
16
+ onClick={(e) => {
17
+ e.preventDefault()
18
+ e.stopPropagation()
19
+ }}
20
+ >
21
+ {children}
22
+ </TooltipTrigger>
23
+ <TooltipContent>{content}</TooltipContent>
24
+ </Tooltip>
25
+ </TooltipProvider>
26
+ )
27
+ }
@@ -0,0 +1,123 @@
1
+ import getString from 'nextjs-cms/translations'
2
+ import ContainerBox from '@/components/ContainerBox'
3
+ import React from 'react'
4
+ import { Variant } from 'nextjs-cms/core/types'
5
+ import useModal from '@/hooks/useModal'
6
+ import { useAxiosPrivate } from 'nextjs-cms/auth/hooks'
7
+ import { handleVariantDeletion } from '@/lib/apiHelpers'
8
+ import { useToast } from '@/components/ui/use-toast'
9
+ import { Button } from '@/components/ui/button'
10
+ import VariantEditPage from '@/components/VariantEditPage'
11
+
12
+ const VariantCard = ({
13
+ variant,
14
+ variantItem,
15
+ sectionItemId,
16
+ action,
17
+ }: {
18
+ variant: Variant
19
+ variantItem: any
20
+ sectionItemId: string
21
+ action: any
22
+ }) => {
23
+ const { setModal, modal, modalResponse, setModalResponse } = useModal()
24
+ const axiosPrivate = useAxiosPrivate()
25
+ const controller = new AbortController()
26
+ const { toast } = useToast()
27
+
28
+ const handleDelete = async () => {
29
+ const response = await handleVariantDeletion(variant.variant_name, variantItem.id, axiosPrivate, controller)
30
+ if (response.error) {
31
+ toast({
32
+ variant: 'destructive',
33
+ title: getString('delete_admin'),
34
+ description: response.error.message,
35
+ })
36
+ } else if (response.code === 200) {
37
+ action ? action() : null
38
+ setModal(null)
39
+ setModalResponse(null)
40
+ toast({
41
+ variant: 'success',
42
+ title: getString('itemDeletedSuccessfully'),
43
+ description: response.message,
44
+ })
45
+ }
46
+ }
47
+ return (
48
+ <ContainerBox title={variantItem.display_name} key={variantItem.id}>
49
+ <div className='flex flex-col gap-4'>
50
+ <div className='flex flex-row gap-2'>
51
+ <Button
52
+ size='sm'
53
+ type='button'
54
+ variant='default'
55
+ onClick={() => {
56
+ setModal({
57
+ size: 'lg',
58
+ title: getString('edit'),
59
+ body: (
60
+ <div className='p-4'>
61
+ <VariantEditPage
62
+ section={variant.section_name}
63
+ variant={variant.variant_name}
64
+ sectionItemId={sectionItemId}
65
+ itemId={variantItem.id}
66
+ action={action}
67
+ />
68
+ </div>
69
+ ),
70
+ headerColor: 'bg-sky-700',
71
+ titleColor: 'text-white',
72
+ lang: 'en',
73
+ })
74
+ }}
75
+ >
76
+ {getString('edit')}
77
+ </Button>
78
+ {/* Delete Button */}
79
+ <Button
80
+ size='sm'
81
+ type='button'
82
+ variant='destructive'
83
+ onClick={() => {
84
+ setModal({
85
+ title: getString('delete'),
86
+ body: (
87
+ <div className='p-4'>
88
+ <div className='flex flex-col gap-4'>
89
+ <div>{getString('deleteItemText')}</div>
90
+ <div className='flex gap-2'>
91
+ <button
92
+ className='rounded bg-green-600 px-2 py-1 text-white'
93
+ onClick={handleDelete}
94
+ >
95
+ Yes
96
+ </button>
97
+ <button
98
+ className='rounded bg-red-800 px-2 py-1 text-white'
99
+ onClick={() => {
100
+ setModal(null)
101
+ }}
102
+ >
103
+ No
104
+ </button>
105
+ </div>
106
+ </div>
107
+ </div>
108
+ ),
109
+ headerColor: 'bg-red-700',
110
+ titleColor: 'text-white',
111
+ lang: 'en',
112
+ })
113
+ }}
114
+ >
115
+ {getString('delete')}
116
+ </Button>
117
+ </div>
118
+ </div>
119
+ </ContainerBox>
120
+ )
121
+ }
122
+
123
+ export default VariantCard
@@ -0,0 +1,229 @@
1
+ 'use client'
2
+
3
+ import { useAxiosPrivate } from 'nextjs-cms/auth/hooks'
4
+ import { getVariantPage } from '@/lib/apiHelpers'
5
+ import React, { RefObject, useEffect, useRef, useState } from 'react'
6
+ import { useQuery } from '@tanstack/react-query'
7
+ import { InputGroup } from 'nextjs-cms/core/types'
8
+ import getString from 'nextjs-cms/translations'
9
+ import useModal from '@/hooks/useModal'
10
+ import { AxiosError } from 'axios'
11
+ import InfoCard from '@/components/InfoCard'
12
+ import { useRouter } from 'next/navigation'
13
+ import ProgressBar from '@/components/ProgressBar'
14
+ import classNames from 'classnames'
15
+ import LoadingSpinners from '@/components/LoadingSpinners'
16
+ import { useToast } from '@/components/ui/use-toast'
17
+ import ContainerBox from '@/components/ContainerBox'
18
+ import FormInputs from '@/components/form/FormInputs'
19
+ import Dropzone, { DropzoneHandles } from '@/components/Dropzone'
20
+ import PhotoGallery from '@/components/PhotoGallery'
21
+
22
+ export default function VariantEditPage({
23
+ section,
24
+ variant,
25
+ sectionItemId,
26
+ itemId,
27
+ hiddenInputs,
28
+ action,
29
+ }: {
30
+ section: string
31
+ variant: string
32
+ sectionItemId: string
33
+ itemId: string
34
+ hiddenInputs?: {
35
+ name: string
36
+ value: string
37
+ }[]
38
+ action?: any
39
+ }) {
40
+ const [response, setResponse] = useState<any>(null)
41
+ const [progress, setProgress] = useState(0)
42
+ const [progressVariant, setProgressVariant] = useState<'determinate' | 'query'>('determinate')
43
+ const [isSubmitting, setIsSubmitting] = useState(false)
44
+ const { setModal, modal, modalResponse, setModalResponse } = useModal()
45
+ const axiosPrivate = useAxiosPrivate()
46
+ const controller = new AbortController()
47
+ const { toast } = useToast()
48
+ const router = useRouter()
49
+ const dropzoneRef: RefObject<DropzoneHandles | null> = useRef(null)
50
+
51
+ const { isLoading, isError, data, error, refetch } = useQuery({
52
+ queryKey: ['edit', variant, itemId],
53
+ queryFn: () => getVariantPage(section, variant, sectionItemId, itemId, axiosPrivate, controller),
54
+ })
55
+
56
+ const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
57
+ setIsSubmitting(true)
58
+ e.preventDefault()
59
+ e.stopPropagation()
60
+ if (isSubmitting) return
61
+ setResponse(null)
62
+ const formData = new FormData(e.currentTarget)
63
+
64
+ formData.append('section', section)
65
+ formData.append('variant', variant)
66
+ formData.append('form_type', 'edit')
67
+
68
+ // Retrieve the files from the Dropzone's state
69
+ if (dropzoneRef.current) {
70
+ const files: File[] = dropzoneRef.current.getFiles()
71
+ // Add files to the body
72
+ files.forEach((file, index) => {
73
+ formData.append(`dropzoneFiles[${index}]`, file)
74
+ })
75
+ }
76
+
77
+ // Check if there are any hidden inputs passed to the component
78
+ if (hiddenInputs) {
79
+ // Add hidden inputs to the body
80
+ hiddenInputs.forEach((input) => {
81
+ formData.append(input.name, input.value)
82
+ })
83
+ }
84
+
85
+ const body = Object.fromEntries(formData.entries())
86
+ try {
87
+ const res = await axiosPrivate.post(`/api-submit`, body, {
88
+ signal: controller.signal,
89
+ onUploadProgress: (progressEvent) => {
90
+ if (!progressEvent.total) return
91
+ const progress = Math.round((progressEvent.loaded / progressEvent.total) * 100)
92
+ // Update progress bar value here
93
+ setProgress(progress)
94
+
95
+ if (progress === 100) {
96
+ setProgressVariant('query')
97
+ }
98
+ },
99
+ headers: {
100
+ 'Content-Type': 'multipart/form-data',
101
+ },
102
+ })
103
+
104
+ if (res) {
105
+ setIsSubmitting(false)
106
+ setProgress(0)
107
+ setProgressVariant('determinate')
108
+ if (res.data.code === 200) {
109
+ // Refetch the page
110
+ // Clear Dropzone
111
+ if (dropzoneRef.current) {
112
+ dropzoneRef.current.removeFiles()
113
+ }
114
+ action ? action() : null
115
+ setModal(null)
116
+ setModalResponse(null)
117
+ setResponse(null)
118
+ toast({
119
+ variant: 'success',
120
+ description: getString('itemUpdatedSuccessfully'),
121
+ })
122
+
123
+ // Redirect to the edit page
124
+ // router.push(`/edit/${section}/${res.data.identifier}`)
125
+ // Or redirect to the browse page
126
+ }
127
+ }
128
+ } catch (error: AxiosError | any) {
129
+ setIsSubmitting(false)
130
+ setProgress(0)
131
+ setProgressVariant('determinate')
132
+ if (error?.response?.data) {
133
+ setResponse(
134
+ <InfoCard result={{ key: 'danger', title: error.response.data.error.message, status: false }} />,
135
+ )
136
+ }
137
+ }
138
+ }
139
+
140
+ function cancelSubmit() {
141
+ controller.abort()
142
+ setIsSubmitting(false)
143
+ setProgress(0)
144
+ setProgressVariant('determinate')
145
+ }
146
+
147
+ useEffect(() => {
148
+ return () => {
149
+ cancelSubmit()
150
+ }
151
+ }, [])
152
+
153
+ return (
154
+ <div>
155
+ <div className='w-full overflow-hidden'>
156
+ <form onSubmit={handleSubmit}>
157
+ <div className='bg-gradient-to-r from-sky-200 via-emerald-300 to-blue-600 p-8 font-extrabold text-black'>
158
+ {data && data.variant && (
159
+ <>
160
+ <h1 className='pb-4 text-4xl'>{data?.variant?.variant_html_name_en}</h1>
161
+ <span>
162
+ /{getString('edit')} {data?.variant?.variant_single_item_name_en}
163
+ </span>
164
+ </>
165
+ )}
166
+ </div>
167
+ <div className='p-8'>
168
+ <div className=''>
169
+ {isLoading && (
170
+ <div>
171
+ <LoadingSpinners />
172
+ </div>
173
+ )}
174
+ {data?.error && <InfoCard result={{ icon: true, key: 'danger', title: data.error }} />}
175
+ {data && data.inputGroups && (
176
+ <div className='flex flex-col gap-4'>
177
+ <input type='hidden' name={data?.variant?.variant_item_identifier} value={itemId} />
178
+ <input type='hidden' name='parentId' value={sectionItemId} />
179
+ {data?.inputGroups?.length > 0 &&
180
+ data?.inputGroups?.map((inputGroup: InputGroup, index: number) => {
181
+ return (
182
+ <ContainerBox title={inputGroup.groupTitle} key={index}>
183
+ <FormInputs inputs={[]} sectionName={variant} />
184
+ </ContainerBox>
185
+ )
186
+ })}
187
+
188
+ {data.variant.variant_item_has_gallery === 'true' ? (
189
+ <>
190
+ <div className='w-full'>
191
+ <PhotoGallery sectionName={variant} gallery={data.photo_gallery} />
192
+ </div>
193
+ <div className='w-full'>
194
+ <Dropzone ref={dropzoneRef} />
195
+ </div>
196
+ </>
197
+ ) : null}
198
+
199
+ <div className='my-4 flex flex-col gap-3 p-4'>
200
+ <div className='mt-5'>
201
+ <button
202
+ className={classNames({
203
+ 'w-full rounded bg-gradient-to-r p-2 font-bold text-white drop-shadow':
204
+ true,
205
+ 'from-emerald-700 via-green-700 to-green-500': !isSubmitting,
206
+ 'from-gray-600 via-gray-500 to-gray-400': isSubmitting,
207
+ })}
208
+ type='submit'
209
+ disabled={isSubmitting}
210
+ >
211
+ {isSubmitting ? getString('loading') : getString('save')}
212
+ </button>
213
+ {isSubmitting && (
214
+ <div className='mt-0.5'>
215
+ <ProgressBar variant={progressVariant} value={progress} />
216
+ </div>
217
+ )}
218
+ </div>
219
+ {response && <div className='w-full'>{response}</div>}
220
+ </div>
221
+ </div>
222
+ )}
223
+ </div>
224
+ </div>
225
+ </form>
226
+ </div>
227
+ </div>
228
+ )
229
+ }
@@ -0,0 +1,69 @@
1
+ import getString from 'nextjs-cms/translations'
2
+ import { formatNumber } from 'nextjs-cms/utils'
3
+ import PieChartBox from '@/components/PieChartBox'
4
+ import React, { useEffect } from 'react'
5
+ import { useQuery } from '@tanstack/react-query'
6
+ import { getAnalytics } from '@/lib/apiHelpers'
7
+ import { PieChartDataItem } from 'nextjs-cms/core/types'
8
+ import { useAxiosPrivate } from 'nextjs-cms/auth/hooks'
9
+ import { useTheme } from 'next-themes'
10
+
11
+ export const BounceRate = ({ fromDate, toDate }: { fromDate: Date | string | null; toDate: Date | string | null }) => {
12
+ const axiosPrivate = useAxiosPrivate()
13
+ let controller = new AbortController()
14
+ const { theme } = useTheme()
15
+
16
+ const { isLoading, isError, data, error } = useQuery({
17
+ queryKey: ['analyticsPage', 'statistics', fromDate, toDate],
18
+ queryFn: () => {
19
+ // Abort the previous request
20
+ controller.abort()
21
+
22
+ // Create a new AbortController for the new request
23
+ controller = new AbortController()
24
+
25
+ return getAnalytics({
26
+ requestType: 'statistics',
27
+ axiosPrivate,
28
+ controller,
29
+ fromDate,
30
+ toDate,
31
+ })
32
+ },
33
+ })
34
+
35
+ const bounceRateData: PieChartDataItem[] = [
36
+ {
37
+ name: getString('total_disk_space'),
38
+ value: 100 - parseInt(data?.bounceRate),
39
+ fill: 'transparent',
40
+ },
41
+ {
42
+ name: getString('used_disk_space'),
43
+ value: parseInt(data?.bounceRate),
44
+ fill: theme === 'dark' ? '#adfa1d' : '#E1315B',
45
+ },
46
+ ]
47
+
48
+ useEffect(() => {
49
+ return () => {
50
+ controller.abort()
51
+ }
52
+ }, [])
53
+
54
+ return (
55
+ <PieChartBox
56
+ height={250}
57
+ legend={false}
58
+ chartData={bounceRateData}
59
+ isLoading={isLoading}
60
+ chartBoxTitles={{
61
+ mainTitle: getString('bounceRate'),
62
+ totalUnitSubtitle: {
63
+ key: getString('sessionsPerUser'),
64
+ value: formatNumber(data?.sessionsPerUser),
65
+ },
66
+ }}
67
+ />
68
+ )
69
+ }
@@ -0,0 +1,54 @@
1
+ import getString from 'nextjs-cms/translations'
2
+ import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
3
+ import ContainerBox from '@/components/ContainerBox'
4
+ import React, { useEffect } from 'react'
5
+ import { useAxiosPrivate } from 'nextjs-cms/auth/hooks'
6
+ import { useQuery } from '@tanstack/react-query'
7
+ import { getAnalytics } from '@/lib/apiHelpers'
8
+
9
+ export const LivePageViews = () => {
10
+ const axiosPrivate = useAxiosPrivate()
11
+ const controller = new AbortController()
12
+
13
+ const { isLoading, isError, data, error } = useQuery({
14
+ queryKey: ['analyticsPage', 'livePageViews'],
15
+ queryFn: () =>
16
+ getAnalytics({
17
+ requestType: 'livePageViews',
18
+ axiosPrivate,
19
+ controller,
20
+ }),
21
+ })
22
+
23
+ return (
24
+ <ContainerBox title={getString('liveUsersAreViewing')}>
25
+ <Table>
26
+ <TableCaption>{getString('liveUsersSubtitle')}</TableCaption>
27
+ <TableHeader>
28
+ <TableRow>
29
+ <TableHead>{getString('country')}</TableHead>
30
+ <TableHead>{getString('device')}</TableHead>
31
+ <TableHead>{getString('page')}</TableHead>
32
+ </TableRow>
33
+ </TableHeader>
34
+ <TableBody>
35
+ {data?.livePageViews?.locations?.length > 0 ? (
36
+ data.livePageViews.locations.map((location: any, index: number) => (
37
+ <TableRow key={index}>
38
+ <TableCell>{location.country}</TableCell>
39
+ <TableCell>{location.device}</TableCell>
40
+ <TableCell>{location.page}</TableCell>
41
+ </TableRow>
42
+ ))
43
+ ) : (
44
+ <TableRow>
45
+ <TableCell colSpan={3} className='text-center'>
46
+ {getString('noLiveUsers')}
47
+ </TableCell>
48
+ </TableRow>
49
+ )}
50
+ </TableBody>
51
+ </Table>
52
+ </ContainerBox>
53
+ )
54
+ }
@@ -0,0 +1,32 @@
1
+ import getString from 'nextjs-cms/translations'
2
+ import { formatNumber } from 'nextjs-cms/utils'
3
+ import ContainerBox from '@/components/ContainerBox'
4
+ import React from 'react'
5
+ import { useAxiosPrivate } from 'nextjs-cms/auth/hooks'
6
+ import { useQuery } from '@tanstack/react-query'
7
+ import { getAnalytics } from '@/lib/apiHelpers'
8
+ import LoadingSpinners from '@/components/LoadingSpinners'
9
+
10
+ export const LiveUsersCount = () => {
11
+ const axiosPrivate = useAxiosPrivate()
12
+ const controller = new AbortController()
13
+
14
+ const { isLoading, isError, data, error } = useQuery({
15
+ queryKey: ['analyticsPage', 'liveUsersCount'],
16
+ queryFn: () =>
17
+ getAnalytics({
18
+ requestType: 'liveUsersCount',
19
+ axiosPrivate,
20
+ controller,
21
+ }),
22
+ })
23
+ return (
24
+ <ContainerBox title={getString('liveUsers')}>
25
+ {isLoading ? (
26
+ <LoadingSpinners single={true} />
27
+ ) : (
28
+ <div className='text-4xl'>{formatNumber(data?.liveUsers?.count)}</div>
29
+ )}
30
+ </ContainerBox>
31
+ )
32
+ }
@@ -0,0 +1,41 @@
1
+ import getString from 'nextjs-cms/translations'
2
+ import BarChartBox from '@/components/BarChartBox'
3
+ import React from 'react'
4
+ import { useTheme } from 'next-themes'
5
+ import { useQuery } from '@tanstack/react-query'
6
+ import { getAnalytics } from '@/lib/apiHelpers'
7
+ import { useAxiosPrivate } from 'nextjs-cms/auth/hooks'
8
+
9
+ export const MonthlyPageViews = ({
10
+ fromDate,
11
+ toDate,
12
+ }: {
13
+ fromDate: Date | string | null
14
+ toDate: Date | string | null
15
+ }) => {
16
+ const axiosPrivate = useAxiosPrivate()
17
+ const controller = new AbortController()
18
+ const { theme } = useTheme()
19
+
20
+ const { isLoading, isError, data, error } = useQuery({
21
+ queryKey: ['analyticsPage', 'monthlyPageViews', fromDate, toDate],
22
+ queryFn: () =>
23
+ getAnalytics({
24
+ requestType: 'monthlyPageViews',
25
+ axiosPrivate,
26
+ controller,
27
+ fromDate,
28
+ toDate,
29
+ }),
30
+ })
31
+ return (
32
+ <>
33
+ <BarChartBox
34
+ isLoading={isLoading}
35
+ chartData={data?.monthlyPageViews}
36
+ title={getString('monthlyPageViews')}
37
+ fill={theme === 'dark' ? '#adfa1d' : '#ff6688'}
38
+ />
39
+ </>
40
+ )
41
+ }
@@ -0,0 +1,51 @@
1
+ import getString from 'nextjs-cms/translations'
2
+ import { BarChartDataItem } from 'nextjs-cms/core/types'
3
+ import { Badge } from '@/components/ui/badge'
4
+ import { formatNumber } from 'nextjs-cms/utils'
5
+ import ContainerBox from '@/components/ContainerBox'
6
+ import React from 'react'
7
+ import { useAxiosPrivate } from 'nextjs-cms/auth/hooks'
8
+ import { useQuery } from '@tanstack/react-query'
9
+ import { getAnalytics } from '@/lib/apiHelpers'
10
+ import LoadingSpinners from '@/components/LoadingSpinners'
11
+
12
+ export const TopCountries = ({
13
+ fromDate,
14
+ toDate,
15
+ }: {
16
+ fromDate: Date | string | null
17
+ toDate: Date | string | null
18
+ }) => {
19
+ const axiosPrivate = useAxiosPrivate()
20
+ const controller = new AbortController()
21
+
22
+ const { isLoading, isError, data, error } = useQuery({
23
+ queryKey: ['analyticsPage', 'topCountries', fromDate, toDate],
24
+ queryFn: () =>
25
+ getAnalytics({
26
+ requestType: 'topCountries',
27
+ axiosPrivate,
28
+ controller,
29
+ fromDate,
30
+ toDate,
31
+ }),
32
+ })
33
+
34
+ return (
35
+ <ContainerBox title={getString('countries')}>
36
+ <div className='w-full mb-6'>
37
+ <h1 className='font-bold border-b pb-1 my-1'>{getString('topCountries')}</h1>
38
+ {isLoading && <LoadingSpinners single={true} />}
39
+ {data?.topCountries?.length > 0 &&
40
+ data.topCountries.map((country: BarChartDataItem, index: number) => (
41
+ <div key={`${index}-${country.name}`} className='w-full text-sm flex justify-between'>
42
+ <span className='font-bold text-foreground'>{country.name}:</span>
43
+ <Badge variant='outline' className='ms-2'>
44
+ {formatNumber(country.value)}
45
+ </Badge>
46
+ </div>
47
+ ))}
48
+ </div>
49
+ </ContainerBox>
50
+ )
51
+ }