create-nextjs-cms 0.9.22 → 0.9.24

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