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.
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +395 -0
- package/dist/lib/utils.d.ts +11 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +48 -0
- package/package.json +44 -0
- package/templates/default/.env +24 -0
- package/templates/default/.env.development +8 -0
- package/templates/default/.eslintrc.json +5 -0
- package/templates/default/.prettierignore +7 -0
- package/templates/default/.prettierrc.json +19 -0
- package/templates/default/CHANGELOG.md +77 -0
- package/templates/default/README.md +45 -0
- package/templates/default/app/(auth)/auth/login/LoginPage.tsx +175 -0
- package/templates/default/app/(auth)/auth/login/page.tsx +12 -0
- package/templates/default/app/(rootLayout)/admins/page.tsx +5 -0
- package/templates/default/app/(rootLayout)/advanced/page.tsx +5 -0
- package/templates/default/app/(rootLayout)/analytics/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/browse/[section]/[page]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/categorized/[section]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/dashboard/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/edit/[section]/[itemId]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/emails/page.tsx +6 -0
- package/templates/default/app/(rootLayout)/layout.tsx +5 -0
- package/templates/default/app/(rootLayout)/loading.tsx +10 -0
- package/templates/default/app/(rootLayout)/log/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/new/[section]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/page.tsx +9 -0
- package/templates/default/app/(rootLayout)/section/[section]/page.tsx +7 -0
- package/templates/default/app/(rootLayout)/settings/page.tsx +7 -0
- package/templates/default/app/_trpc/client.ts +4 -0
- package/templates/default/app/api/auth/csrf/route.ts +25 -0
- package/templates/default/app/api/auth/refresh/route.ts +10 -0
- package/templates/default/app/api/auth/route.ts +23 -0
- package/templates/default/app/api/auth/session/route.ts +20 -0
- package/templates/default/app/api/editor/photo/route.ts +42 -0
- package/templates/default/app/api/photo/route.ts +27 -0
- package/templates/default/app/api/placeholder/route.ts +7 -0
- package/templates/default/app/api/submit/section/item/[slug]/route.ts +63 -0
- package/templates/default/app/api/submit/section/item/route.ts +53 -0
- package/templates/default/app/api/submit/section/simple/route.ts +54 -0
- package/templates/default/app/api/trpc/[trpc]/route.ts +33 -0
- package/templates/default/app/api/video/route.ts +174 -0
- package/templates/default/app/dictionaries.ts +14 -0
- package/templates/default/app/layout.tsx +28 -0
- package/templates/default/app/providers.tsx +151 -0
- package/templates/default/cli.ts +4 -0
- package/templates/default/components/AdminCard.tsx +163 -0
- package/templates/default/components/AdminEditPage.tsx +123 -0
- package/templates/default/components/AdminPrivilegeCard.tsx +184 -0
- package/templates/default/components/AdminsPage.tsx +43 -0
- package/templates/default/components/AdvancedSettingsPage.tsx +167 -0
- package/templates/default/components/AnalyticsPage.tsx +127 -0
- package/templates/default/components/BarChartBox.tsx +43 -0
- package/templates/default/components/BrowsePage.tsx +119 -0
- package/templates/default/components/CategorizedSectionPage.tsx +36 -0
- package/templates/default/components/CategoryDeleteConfirmPage.tsx +129 -0
- package/templates/default/components/CategorySectionSelectInput.tsx +139 -0
- package/templates/default/components/ConditionalFields.tsx +49 -0
- package/templates/default/components/ContainerBox.tsx +24 -0
- package/templates/default/components/DashboardPage.tsx +187 -0
- package/templates/default/components/DashboardPageAlt.tsx +43 -0
- package/templates/default/components/DefaultNavItems.tsx +3 -0
- package/templates/default/components/Dropzone.tsx +153 -0
- package/templates/default/components/EmailCard.tsx +137 -0
- package/templates/default/components/EmailPasswordForm.tsx +84 -0
- package/templates/default/components/EmailQuotaForm.tsx +72 -0
- package/templates/default/components/EmailsPage.tsx +48 -0
- package/templates/default/components/GalleryPhoto.tsx +93 -0
- package/templates/default/components/InfoCard.tsx +94 -0
- package/templates/default/components/ItemEditPage.tsx +217 -0
- package/templates/default/components/Layout.tsx +70 -0
- package/templates/default/components/LoadingSpinners.tsx +67 -0
- package/templates/default/components/LogPage.tsx +17 -0
- package/templates/default/components/Modal.tsx +99 -0
- package/templates/default/components/Navbar.tsx +29 -0
- package/templates/default/components/NavbarAlt.tsx +182 -0
- package/templates/default/components/NewAdminForm.tsx +172 -0
- package/templates/default/components/NewEmailForm.tsx +131 -0
- package/templates/default/components/NewPage.tsx +206 -0
- package/templates/default/components/NewVariantComponent.tsx +228 -0
- package/templates/default/components/PhotoGallery.tsx +35 -0
- package/templates/default/components/PieChartBox.tsx +101 -0
- package/templates/default/components/ProgressBar.tsx +24 -0
- package/templates/default/components/ProtectedDocument.tsx +78 -0
- package/templates/default/components/ProtectedImage.tsx +143 -0
- package/templates/default/components/ProtectedVideo.tsx +76 -0
- package/templates/default/components/SectionItemCard.tsx +143 -0
- package/templates/default/components/SectionItemStatusBadge.tsx +16 -0
- package/templates/default/components/SectionPage.tsx +124 -0
- package/templates/default/components/SelectBox.tsx +99 -0
- package/templates/default/components/SelectInputButtons.tsx +124 -0
- package/templates/default/components/SettingsPage.tsx +238 -0
- package/templates/default/components/Sidebar.tsx +209 -0
- package/templates/default/components/SidebarDropdownItem.tsx +74 -0
- package/templates/default/components/SidebarItem.tsx +19 -0
- package/templates/default/components/TempPage.tsx +12 -0
- package/templates/default/components/ThemeProvider.tsx +8 -0
- package/templates/default/components/TooltipComponent.tsx +27 -0
- package/templates/default/components/VariantCard.tsx +123 -0
- package/templates/default/components/VariantEditPage.tsx +229 -0
- package/templates/default/components/analytics/BounceRate.tsx +69 -0
- package/templates/default/components/analytics/LivePageViews.tsx +54 -0
- package/templates/default/components/analytics/LiveUsersCount.tsx +32 -0
- package/templates/default/components/analytics/MonthlyPageViews.tsx +41 -0
- package/templates/default/components/analytics/TopCountries.tsx +51 -0
- package/templates/default/components/analytics/TopDevices.tsx +45 -0
- package/templates/default/components/analytics/TopMediums.tsx +57 -0
- package/templates/default/components/analytics/TopSources.tsx +44 -0
- package/templates/default/components/analytics/TotalPageViews.tsx +40 -0
- package/templates/default/components/analytics/TotalSessions.tsx +40 -0
- package/templates/default/components/analytics/TotalUniqueUsers.tsx +40 -0
- package/templates/default/components/custom/RightHomeRoomVariantCard.tsx +137 -0
- package/templates/default/components/dndKit/Draggable.tsx +21 -0
- package/templates/default/components/dndKit/Droppable.tsx +20 -0
- package/templates/default/components/dndKit/SortableItem.tsx +18 -0
- package/templates/default/components/form/DateRangeFormInput.tsx +55 -0
- package/templates/default/components/form/Form.tsx +298 -0
- package/templates/default/components/form/FormInputElement.tsx +68 -0
- package/templates/default/components/form/FormInputs.tsx +108 -0
- package/templates/default/components/form/helpers/util.ts +20 -0
- package/templates/default/components/form/inputs/CheckboxFormInput.tsx +33 -0
- package/templates/default/components/form/inputs/ColorFormInput.tsx +44 -0
- package/templates/default/components/form/inputs/DateFormInput.tsx +107 -0
- package/templates/default/components/form/inputs/DocumentFormInput.tsx +124 -0
- package/templates/default/components/form/inputs/MapFormInput.tsx +139 -0
- package/templates/default/components/form/inputs/MultipleSelectFormInput.tsx +150 -0
- package/templates/default/components/form/inputs/NumberFormInput.tsx +42 -0
- package/templates/default/components/form/inputs/PasswordFormInput.tsx +47 -0
- package/templates/default/components/form/inputs/PhotoFormInput.tsx +218 -0
- package/templates/default/components/form/inputs/RichTextFormInput.tsx +133 -0
- package/templates/default/components/form/inputs/SelectFormInput.tsx +164 -0
- package/templates/default/components/form/inputs/TagsFormInput.tsx +63 -0
- package/templates/default/components/form/inputs/TextFormInput.tsx +48 -0
- package/templates/default/components/form/inputs/TextareaFormInput.tsx +47 -0
- package/templates/default/components/form/inputs/VideoFormInput.tsx +117 -0
- package/templates/default/components/pagination/Pagination.tsx +36 -0
- package/templates/default/components/pagination/PaginationButtons.tsx +145 -0
- package/templates/default/components/ui/accordion.tsx +57 -0
- package/templates/default/components/ui/alert.tsx +46 -0
- package/templates/default/components/ui/badge.tsx +33 -0
- package/templates/default/components/ui/button.tsx +57 -0
- package/templates/default/components/ui/calendar.tsx +68 -0
- package/templates/default/components/ui/card.tsx +76 -0
- package/templates/default/components/ui/checkbox.tsx +29 -0
- package/templates/default/components/ui/dropdown-menu.tsx +205 -0
- package/templates/default/components/ui/input.tsx +25 -0
- package/templates/default/components/ui/label.tsx +26 -0
- package/templates/default/components/ui/popover.tsx +31 -0
- package/templates/default/components/ui/scroll-area.tsx +42 -0
- package/templates/default/components/ui/select.tsx +164 -0
- package/templates/default/components/ui/sheet.tsx +107 -0
- package/templates/default/components/ui/switch.tsx +29 -0
- package/templates/default/components/ui/table.tsx +120 -0
- package/templates/default/components/ui/tabs.tsx +55 -0
- package/templates/default/components/ui/toast.tsx +113 -0
- package/templates/default/components/ui/toaster.tsx +35 -0
- package/templates/default/components/ui/tooltip.tsx +30 -0
- package/templates/default/components/ui/use-toast.ts +188 -0
- package/templates/default/components.json +16 -0
- package/templates/default/context/ModalProvider.tsx +53 -0
- package/templates/default/drizzle.config.ts +4 -0
- package/templates/default/dynamic-schemas/schema.ts +373 -0
- package/templates/default/env/env.js +130 -0
- package/templates/default/envConfig.ts +4 -0
- package/templates/default/hooks/useModal.ts +8 -0
- package/templates/default/lib/apiHelpers.ts +106 -0
- package/templates/default/lz.config.ts +40 -0
- package/templates/default/middleware.ts +33 -0
- package/templates/default/next.config.ts +46 -0
- package/templates/default/package.json +134 -0
- package/templates/default/postcss.config.js +6 -0
- package/templates/default/postinstall.js +14 -0
- package/templates/default/public/blank_avatar.png +0 -0
- package/templates/default/public/favicon.ico +0 -0
- package/templates/default/public/img/placeholder.svg +1 -0
- package/templates/default/public/lazemni_logo.png +0 -0
- package/templates/default/public/next.svg +1 -0
- package/templates/default/public/vercel.svg +1 -0
- package/templates/default/section-tests.ts +92 -0
- package/templates/default/styles/globals.css +88 -0
- package/templates/default/tailwind.config.js +95 -0
- package/templates/default/test.ts +77 -0
- package/templates/default/tsconfig.json +44 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React, { useEffect, useState } from 'react'
|
|
4
|
+
import getString from 'nextjs-cms/translations'
|
|
5
|
+
import useModal from '@/hooks/useModal'
|
|
6
|
+
import InfoCard from '@/components/InfoCard'
|
|
7
|
+
import LoadingSpinners from '@/components/LoadingSpinners'
|
|
8
|
+
import { Alert, AlertDescription } from '@/components/ui/alert'
|
|
9
|
+
import { useToast } from '@/components/ui/use-toast'
|
|
10
|
+
import { trpc } from '@/app/_trpc/client'
|
|
11
|
+
import Form from '@/components/form/Form'
|
|
12
|
+
|
|
13
|
+
export default function AdvancedSettingsPage() {
|
|
14
|
+
const [progress, setProgress] = useState(0)
|
|
15
|
+
const [progressVariant, setProgressVariant] = useState<'determinate' | 'query'>('determinate')
|
|
16
|
+
const [isSubmitting, setIsSubmitting] = useState(false)
|
|
17
|
+
const { setModal } = useModal()
|
|
18
|
+
|
|
19
|
+
const { toast } = useToast()
|
|
20
|
+
|
|
21
|
+
const { isLoading, data, refetch } = trpc.cmsSettings.get.useQuery()
|
|
22
|
+
const saveMutation = trpc.cmsSettings.save.useMutation({
|
|
23
|
+
onSuccess: async (data) => {
|
|
24
|
+
setIsSubmitting(false)
|
|
25
|
+
setProgress(0)
|
|
26
|
+
setProgressVariant('determinate')
|
|
27
|
+
if (data === true) {
|
|
28
|
+
// Refetch the page
|
|
29
|
+
await refetch()
|
|
30
|
+
|
|
31
|
+
toast({
|
|
32
|
+
title: getString('success'),
|
|
33
|
+
description: getString('success'),
|
|
34
|
+
duration: 2000,
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
onError: (error) => {
|
|
39
|
+
setIsSubmitting(false)
|
|
40
|
+
setProgress(0)
|
|
41
|
+
setProgressVariant('determinate')
|
|
42
|
+
if (error) {
|
|
43
|
+
setModal({
|
|
44
|
+
title: getString('delete_admin'),
|
|
45
|
+
body: <InfoCard result={{ key: 'danger', title: error.message, status: false }} />,
|
|
46
|
+
headerColor: 'bg-red-700',
|
|
47
|
+
titleColor: 'text-white',
|
|
48
|
+
lang: 'en',
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const handleSubmit = async (formData: FormData) => {
|
|
55
|
+
setIsSubmitting(true)
|
|
56
|
+
if (isSubmitting) return
|
|
57
|
+
saveMutation.mutate({
|
|
58
|
+
googleTagId: formData.get('ga_tag_id') as string,
|
|
59
|
+
googlePropertyId: formData.get('ga_property_id') as string,
|
|
60
|
+
googleServiceAccountCredentials: formData.get('ga_code') as string,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function cancelSubmit() {
|
|
65
|
+
setIsSubmitting(false)
|
|
66
|
+
setProgress(0)
|
|
67
|
+
setProgressVariant('determinate')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
return () => {
|
|
72
|
+
cancelSubmit()
|
|
73
|
+
}
|
|
74
|
+
}, [])
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div>
|
|
78
|
+
<div className='w-full overflow-hidden bg-background'>
|
|
79
|
+
<div className='bg-gradient-to-r from-rose-200 via-rose-400 to-sky-400 p-8 font-extrabold text-black'>
|
|
80
|
+
<h1 className='text-3xl'>{getString('advancedSettings')}</h1>
|
|
81
|
+
</div>
|
|
82
|
+
<div className='flex w-full flex-col'>
|
|
83
|
+
<div className='flex w-full flex-col gap-2 p-4'>
|
|
84
|
+
<Alert variant='destructive' className='bg-destructive text-destructive-foreground'>
|
|
85
|
+
<AlertDescription className='font-bold'>
|
|
86
|
+
{getString('advancedSettingsWarning')}
|
|
87
|
+
</AlertDescription>
|
|
88
|
+
</Alert>
|
|
89
|
+
<Alert variant='default' className='bg-primary text-primary-foreground'>
|
|
90
|
+
<AlertDescription className='font-bold'>
|
|
91
|
+
<div>{getString('googleAnalyticsChangeText')}</div>
|
|
92
|
+
<div>
|
|
93
|
+
{getString('googleAnalyticsChangeSubText')}{' '}
|
|
94
|
+
<a
|
|
95
|
+
className='text-sky-500'
|
|
96
|
+
target='_blank'
|
|
97
|
+
href='https://analytics.google.com/analytics/web/'
|
|
98
|
+
>
|
|
99
|
+
{getString('here')}
|
|
100
|
+
</a>
|
|
101
|
+
</div>
|
|
102
|
+
</AlertDescription>
|
|
103
|
+
</Alert>
|
|
104
|
+
</div>
|
|
105
|
+
{isLoading ? (
|
|
106
|
+
<div>
|
|
107
|
+
<LoadingSpinners />
|
|
108
|
+
</div>
|
|
109
|
+
) : (
|
|
110
|
+
<Form
|
|
111
|
+
buttonType='small'
|
|
112
|
+
data={{
|
|
113
|
+
section: {
|
|
114
|
+
name: 'advanced_settings',
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
inputGroups: [
|
|
118
|
+
{
|
|
119
|
+
groupId: 1,
|
|
120
|
+
groupTitle: getString('advancedSettings'),
|
|
121
|
+
groupOrder: 1,
|
|
122
|
+
inputs: [
|
|
123
|
+
{
|
|
124
|
+
type: 'text',
|
|
125
|
+
required: false,
|
|
126
|
+
label: 'Measurement ID (Google Tag ID)',
|
|
127
|
+
name: 'ga_tag_id',
|
|
128
|
+
placeholder: 'G-XXXXXXXXXX',
|
|
129
|
+
value: data?.googleTagId,
|
|
130
|
+
readonly: false,
|
|
131
|
+
conditionalFields: [],
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
type: 'text',
|
|
135
|
+
required: false,
|
|
136
|
+
label: 'Property ID',
|
|
137
|
+
name: 'ga_property_id',
|
|
138
|
+
placeholder: 'XXXXXXXXXX',
|
|
139
|
+
value: data?.googlePropertyId,
|
|
140
|
+
readonly: false,
|
|
141
|
+
conditionalFields: [],
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: 'textarea',
|
|
145
|
+
required: false,
|
|
146
|
+
label: 'Service Account Credentials',
|
|
147
|
+
name: 'ga_code',
|
|
148
|
+
placeholder: 'Paste your service account credentials here',
|
|
149
|
+
value: data?.googleServiceAccountCredentials,
|
|
150
|
+
readonly: false,
|
|
151
|
+
conditionalFields: [],
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
}}
|
|
157
|
+
progressVariant={progressVariant}
|
|
158
|
+
progress={progress}
|
|
159
|
+
handleSubmit={handleSubmit}
|
|
160
|
+
isSubmitting={isSubmitting}
|
|
161
|
+
/>
|
|
162
|
+
)}
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
)
|
|
167
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
|
3
|
+
import React, { useEffect, useRef } from 'react'
|
|
4
|
+
import getString from 'nextjs-cms/translations'
|
|
5
|
+
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js'
|
|
6
|
+
import { DatePickerWithRange } from '@/components/form/DateRangeFormInput'
|
|
7
|
+
import { MonthlyPageViews } from '@/components/analytics/MonthlyPageViews'
|
|
8
|
+
import { TopSources } from '@/components/analytics/TopSources'
|
|
9
|
+
import { TopMediums } from '@/components/analytics/TopMediums'
|
|
10
|
+
import { LiveUsersCount } from '@/components/analytics/LiveUsersCount'
|
|
11
|
+
import { TotalPageViews } from '@/components/analytics/TotalPageViews'
|
|
12
|
+
import { TotalSessions } from '@/components/analytics/TotalSessions'
|
|
13
|
+
import { TotalUniqueUsers } from '@/components/analytics/TotalUniqueUsers'
|
|
14
|
+
import { BounceRate } from '@/components/analytics/BounceRate'
|
|
15
|
+
import { LivePageViews } from '@/components/analytics/LivePageViews'
|
|
16
|
+
import { TopCountries } from '@/components/analytics/TopCountries'
|
|
17
|
+
import { TopDevices } from '@/components/analytics/TopDevices'
|
|
18
|
+
import { trpc } from '@/app/_trpc/client'
|
|
19
|
+
ChartJS.register(ArcElement, Tooltip, Legend)
|
|
20
|
+
|
|
21
|
+
const AnalyticsPage = () => {
|
|
22
|
+
const controller = new AbortController()
|
|
23
|
+
const datePickerRangeRef = useRef<HTMLDivElement>(null)
|
|
24
|
+
const [fromDate, setFromDate] = React.useState<Date | string>('30daysAgo')
|
|
25
|
+
const [toDate, setToDate] = React.useState<Date | string>('today')
|
|
26
|
+
|
|
27
|
+
const { data, isError } = trpc.googleAnalytics.test.useQuery()
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
return () => {
|
|
31
|
+
controller.abort()
|
|
32
|
+
}
|
|
33
|
+
}, [])
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div className='w-full'>
|
|
37
|
+
<div className='bg-gradient-to-r from-sky-200 via-emerald-300 to-blue-600 p-8 font-extrabold text-foreground dark:from-blue-800 dark:via-amber-700 dark:to-rose-900'>
|
|
38
|
+
<h1 className='text-3xl'>{getString('analytics')}</h1>
|
|
39
|
+
</div>
|
|
40
|
+
<div className='p-4'>
|
|
41
|
+
<div className='flex gap-2'>
|
|
42
|
+
<Tabs
|
|
43
|
+
defaultValue='account'
|
|
44
|
+
onValueChange={(value) => {
|
|
45
|
+
if (value === 'custom') {
|
|
46
|
+
// Remove hidden class from date picker range
|
|
47
|
+
datePickerRangeRef.current?.classList.remove('hidden')
|
|
48
|
+
} else {
|
|
49
|
+
// Add hidden class to date picker range
|
|
50
|
+
datePickerRangeRef.current?.classList.add('hidden')
|
|
51
|
+
}
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<Tabs
|
|
55
|
+
defaultValue='lastMonth'
|
|
56
|
+
onValueChange={(value) => {
|
|
57
|
+
if (value === 'custom') {
|
|
58
|
+
// Remove hidden class from date picker range
|
|
59
|
+
datePickerRangeRef.current?.classList.remove('hidden')
|
|
60
|
+
} else {
|
|
61
|
+
switch (value) {
|
|
62
|
+
case 'today':
|
|
63
|
+
setFromDate('yesterday')
|
|
64
|
+
setToDate('today')
|
|
65
|
+
break
|
|
66
|
+
case 'lastWeek':
|
|
67
|
+
setFromDate('10daysAgo')
|
|
68
|
+
setToDate('today')
|
|
69
|
+
break
|
|
70
|
+
case 'lastMonth':
|
|
71
|
+
setFromDate('30daysAgo')
|
|
72
|
+
setToDate('today')
|
|
73
|
+
break
|
|
74
|
+
case 'lastYear':
|
|
75
|
+
setFromDate('365daysAgo')
|
|
76
|
+
setToDate('today')
|
|
77
|
+
break
|
|
78
|
+
}
|
|
79
|
+
// Add hidden class to date picker range
|
|
80
|
+
datePickerRangeRef.current?.classList.add('hidden')
|
|
81
|
+
}
|
|
82
|
+
}}
|
|
83
|
+
>
|
|
84
|
+
<TabsList>
|
|
85
|
+
<TabsTrigger value='today'>Today</TabsTrigger>
|
|
86
|
+
<TabsTrigger value='lastWeek'>Last 7 Days</TabsTrigger>
|
|
87
|
+
<TabsTrigger value='lastMonth'>Last 30 Days</TabsTrigger>
|
|
88
|
+
<TabsTrigger value='lastYear'>Last 365 Days</TabsTrigger>
|
|
89
|
+
<TabsTrigger value='custom'>Custom</TabsTrigger>
|
|
90
|
+
</TabsList>
|
|
91
|
+
</Tabs>
|
|
92
|
+
</Tabs>
|
|
93
|
+
<div ref={datePickerRangeRef} className='hidden'>
|
|
94
|
+
<DatePickerWithRange />
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
<div className='my-2 grid grid-cols-2 gap-4 sm-sidebar:grid-cols-2 md-sidebar:grid-cols-2 lg-sidebar:grid-cols-4'>
|
|
98
|
+
<LiveUsersCount />
|
|
99
|
+
<TotalPageViews fromDate={fromDate} toDate={toDate} />
|
|
100
|
+
<TotalSessions fromDate={fromDate} toDate={toDate} />
|
|
101
|
+
<TotalUniqueUsers fromDate={fromDate} toDate={toDate} />
|
|
102
|
+
</div>
|
|
103
|
+
<div className='my-4 grid grid-cols-1 gap-4 sm-sidebar:grid-cols-1 md-sidebar:grid-cols-2 lg-sidebar:grid-cols-4'>
|
|
104
|
+
<div className='col-span-2'>
|
|
105
|
+
<MonthlyPageViews fromDate={fromDate} toDate={toDate} />
|
|
106
|
+
</div>
|
|
107
|
+
<div className='col-span-2 grid grid-cols-1 gap-4 sm-sidebar:grid-cols-1 md-sidebar:grid-cols-2'>
|
|
108
|
+
<TopCountries fromDate={fromDate} toDate={toDate} />
|
|
109
|
+
<BounceRate fromDate={fromDate} toDate={toDate} />
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
<div className='my-4 grid grid-cols-1 gap-4 sm-sidebar:grid-cols-1 md-sidebar:grid-cols-2 lg-sidebar:grid-cols-4'>
|
|
113
|
+
<div className='col-span-2'>
|
|
114
|
+
<TopSources fromDate={fromDate} toDate={toDate} />
|
|
115
|
+
</div>
|
|
116
|
+
<TopMediums fromDate={fromDate} toDate={toDate} />
|
|
117
|
+
<TopDevices fromDate={fromDate} toDate={toDate} />
|
|
118
|
+
</div>
|
|
119
|
+
<div className='my-2'>
|
|
120
|
+
<LivePageViews />
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default AnalyticsPage
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import ContainerBox from '@/components/ContainerBox'
|
|
3
|
+
import { BarChart, Bar, Rectangle, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'
|
|
4
|
+
import { BarChartDataItem } from 'nextjs-cms/core/types'
|
|
5
|
+
import LoadingSpinners from '@/components/LoadingSpinners'
|
|
6
|
+
|
|
7
|
+
export default function BarChartBox({
|
|
8
|
+
chartData,
|
|
9
|
+
title,
|
|
10
|
+
fill = '#adfa1d',
|
|
11
|
+
isLoading,
|
|
12
|
+
}: {
|
|
13
|
+
chartData: BarChartDataItem[]
|
|
14
|
+
title: string
|
|
15
|
+
fill?: string
|
|
16
|
+
isLoading?: boolean
|
|
17
|
+
}) {
|
|
18
|
+
return (
|
|
19
|
+
<ContainerBox title={title}>
|
|
20
|
+
<div>
|
|
21
|
+
<div style={{ width: '100%', height: 300 }}>
|
|
22
|
+
{isLoading ? (
|
|
23
|
+
<LoadingSpinners single={true} />
|
|
24
|
+
) : (
|
|
25
|
+
<ResponsiveContainer width='100%' height='100%'>
|
|
26
|
+
<BarChart data={chartData}>
|
|
27
|
+
<XAxis
|
|
28
|
+
dataKey='name'
|
|
29
|
+
stroke='#888888'
|
|
30
|
+
fontSize={12}
|
|
31
|
+
tickLine={false}
|
|
32
|
+
axisLine={false}
|
|
33
|
+
/>
|
|
34
|
+
<YAxis stroke='#888888' fontSize={12} tickLine={false} axisLine={true} />
|
|
35
|
+
<Bar dataKey='value' fill={fill} radius={[4, 4, 0, 0]} />
|
|
36
|
+
</BarChart>
|
|
37
|
+
</ResponsiveContainer>
|
|
38
|
+
)}
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</ContainerBox>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React, { useEffect, useRef } from 'react'
|
|
4
|
+
import getString from 'nextjs-cms/translations'
|
|
5
|
+
import SectionItemCard from '@/components/SectionItemCard'
|
|
6
|
+
import LoadingSpinners from '@/components/LoadingSpinners'
|
|
7
|
+
import ContainerBox from '@/components/ContainerBox'
|
|
8
|
+
import Pagination from '@/components/pagination/Pagination'
|
|
9
|
+
import { Alert, AlertDescription } from '@/components/ui/alert'
|
|
10
|
+
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from './ui/card'
|
|
11
|
+
import { Input } from './ui/input'
|
|
12
|
+
import { Button } from './ui/button'
|
|
13
|
+
import { useRouter, useSearchParams } from 'next/navigation'
|
|
14
|
+
import { trpc } from '@/app/_trpc/client'
|
|
15
|
+
import { ExclamationTriangleIcon } from '@radix-ui/react-icons'
|
|
16
|
+
import { capitalizeWords } from 'nextjs-cms/utils'
|
|
17
|
+
|
|
18
|
+
export default function BrowsePage({ section, page }: { section: string; page: string }) {
|
|
19
|
+
const pageInt = parseInt(page) ?? 1
|
|
20
|
+
const params = useSearchParams()
|
|
21
|
+
const router = useRouter()
|
|
22
|
+
const q = params.get('q') ?? ''
|
|
23
|
+
const searchInputRef = useRef<HTMLInputElement>(null)
|
|
24
|
+
const { isLoading, isError, data, error, refetch } = trpc.hasItemsSections.listItems.useQuery({
|
|
25
|
+
sectionName: section,
|
|
26
|
+
page: pageInt,
|
|
27
|
+
q,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
useEffect(() => {}, [])
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div>
|
|
34
|
+
<div className='relative z-[1] border-b-2 p-8 pt-12 font-extrabold text-foreground'>
|
|
35
|
+
<div className='absolute left-0 top-0 z-[2] h-4 w-full bg-gradient-to-r from-sky-300 via-gray-300 to-blue-400'></div>
|
|
36
|
+
<h1 className='text-3xl'>{data?.section?.title}</h1>
|
|
37
|
+
</div>
|
|
38
|
+
<div className='p-4'>
|
|
39
|
+
{data?.section?.hasSearch ? (
|
|
40
|
+
<Card className='mb-4 border border-accent-foreground'>
|
|
41
|
+
<form
|
|
42
|
+
onSubmit={(event) => {
|
|
43
|
+
event.preventDefault()
|
|
44
|
+
event.stopPropagation()
|
|
45
|
+
|
|
46
|
+
router.push(
|
|
47
|
+
decodeURIComponent(`/browse/${section}?q=${searchInputRef.current?.value || ''}`),
|
|
48
|
+
)
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
<CardHeader>
|
|
52
|
+
<CardTitle>Search {data?.section?.title}</CardTitle>
|
|
53
|
+
{/*<CardDescription>Search by title</CardDescription>*/}
|
|
54
|
+
</CardHeader>
|
|
55
|
+
<CardContent>
|
|
56
|
+
<Input
|
|
57
|
+
className='border-accent-foreground bg-input'
|
|
58
|
+
ref={searchInputRef}
|
|
59
|
+
placeholder={`${capitalizeWords(getString('search'))}...`}
|
|
60
|
+
defaultValue={q || ''}
|
|
61
|
+
/>
|
|
62
|
+
</CardContent>
|
|
63
|
+
<CardFooter className='border-t px-6 py-4'>
|
|
64
|
+
<Button>{capitalizeWords(getString('search'))}</Button>
|
|
65
|
+
</CardFooter>
|
|
66
|
+
</form>
|
|
67
|
+
</Card>
|
|
68
|
+
) : null}
|
|
69
|
+
<ContainerBox title={getString('browse')}>
|
|
70
|
+
{isLoading ? (
|
|
71
|
+
<div>
|
|
72
|
+
<LoadingSpinners />
|
|
73
|
+
</div>
|
|
74
|
+
) : null}
|
|
75
|
+
|
|
76
|
+
{data ? (
|
|
77
|
+
<>
|
|
78
|
+
{data.error ? (
|
|
79
|
+
<Alert variant='destructive' className='my-8'>
|
|
80
|
+
<AlertDescription className='text-md font-bold'>
|
|
81
|
+
<div className='flex items-center gap-1.5'>
|
|
82
|
+
<ExclamationTriangleIcon className='h-5 w-5' /> {data.error.message}
|
|
83
|
+
</div>
|
|
84
|
+
</AlertDescription>
|
|
85
|
+
</Alert>
|
|
86
|
+
) : data.items && data.items.length > 0 ? (
|
|
87
|
+
<div className='mt-2 grid w-full grid-cols-1 gap-8 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4'>
|
|
88
|
+
{data.items.map((item, index: number) => (
|
|
89
|
+
<SectionItemCard
|
|
90
|
+
key={`${data.section.name}-${item.id}-${index}`}
|
|
91
|
+
item={item}
|
|
92
|
+
sectionName={data.section.name}
|
|
93
|
+
action={() => refetch()}
|
|
94
|
+
/>
|
|
95
|
+
))}
|
|
96
|
+
</div>
|
|
97
|
+
) : (
|
|
98
|
+
<Alert variant='default' className='my-8 bg-primary text-primary-foreground'>
|
|
99
|
+
<AlertDescription className='font-bold'>{getString('noItems')}</AlertDescription>
|
|
100
|
+
</Alert>
|
|
101
|
+
)}
|
|
102
|
+
</>
|
|
103
|
+
) : null}
|
|
104
|
+
</ContainerBox>
|
|
105
|
+
{data?.totalCount && data?.totalCount > 0 ? (
|
|
106
|
+
<Pagination
|
|
107
|
+
page={pageInt}
|
|
108
|
+
totalCount={data?.totalCount}
|
|
109
|
+
limit={12}
|
|
110
|
+
route={`browse/${section}`}
|
|
111
|
+
lang='en'
|
|
112
|
+
paginationLinksToShow={4}
|
|
113
|
+
searchParams={q ? `q=${q}` : null}
|
|
114
|
+
/>
|
|
115
|
+
) : null}
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React, { useEffect } from 'react'
|
|
4
|
+
import LoadingSpinners from '@/components/LoadingSpinners'
|
|
5
|
+
import { trpc } from '@/app/_trpc/client'
|
|
6
|
+
import CategorySectionSelectInput from '@/components/CategorySectionSelectInput'
|
|
7
|
+
|
|
8
|
+
export default function CategorizedSectionPage({ section }: { section: string }) {
|
|
9
|
+
const { isLoading, isError, data, error, refetch } = trpc.categorySections.get.useQuery({
|
|
10
|
+
sectionName: section,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
useEffect(() => {}, [])
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<div className='w-full'>
|
|
18
|
+
<div className='relative z-[1] border-b-2 p-8 pt-12 font-extrabold text-foreground'>
|
|
19
|
+
<div className='absolute left-0 top-0 z-[2] h-4 w-full bg-gradient-to-r from-rose-200 via-rose-400 to-sky-400'></div>{' '}
|
|
20
|
+
{data && data.section && <h1 className='text-3xl'>{data?.section?.title.section}</h1>}
|
|
21
|
+
</div>
|
|
22
|
+
<div className='flex w-full flex-col'>
|
|
23
|
+
<div className='rounded-xl p-4 shadow'>
|
|
24
|
+
{isLoading && (
|
|
25
|
+
<div>
|
|
26
|
+
<LoadingSpinners />
|
|
27
|
+
</div>
|
|
28
|
+
)}
|
|
29
|
+
|
|
30
|
+
{data && data.data ? <CategorySectionSelectInput refetch={refetch} input={data.data} /> : null}
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import LoadingSpinners from '@/components/LoadingSpinners'
|
|
2
|
+
import InfoCard from '@/components/InfoCard'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import getString from 'nextjs-cms/translations'
|
|
5
|
+
import { Button } from '@/components/ui/button'
|
|
6
|
+
import useModal from '@/hooks/useModal'
|
|
7
|
+
import { useToast } from '@/components/ui/use-toast'
|
|
8
|
+
import { trpc } from '@/app/_trpc/client'
|
|
9
|
+
import { Switch } from './ui/switch'
|
|
10
|
+
import { Label } from '@/components/ui/label'
|
|
11
|
+
|
|
12
|
+
export default function CategoryDeleteConfirmPage({
|
|
13
|
+
section,
|
|
14
|
+
sectionTitle,
|
|
15
|
+
id,
|
|
16
|
+
action,
|
|
17
|
+
allowRecursiveDelete,
|
|
18
|
+
}: {
|
|
19
|
+
section: string
|
|
20
|
+
sectionTitle: string
|
|
21
|
+
id: string
|
|
22
|
+
action: any
|
|
23
|
+
allowRecursiveDelete: boolean
|
|
24
|
+
}) {
|
|
25
|
+
const { setModal } = useModal()
|
|
26
|
+
const { toast } = useToast()
|
|
27
|
+
|
|
28
|
+
// TODO: implement this? Basically we're getting the associated items with the category,
|
|
29
|
+
// and displaying their count to notify the admin,
|
|
30
|
+
// for now we will not delete the items, only the category
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
const { isLoading, isError, data, error, refetch } = useQuery({
|
|
34
|
+
queryKey: ['confirmCategoryDeletion', section, id],
|
|
35
|
+
queryFn: () => confirmCategoryDeletion(section, id, axiosPrivate, controller),
|
|
36
|
+
})
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
const deleteMutation = trpc.hasItemsSections.deleteItem.useMutation({
|
|
40
|
+
onError: (error) => {
|
|
41
|
+
setModal({
|
|
42
|
+
title: getString('delete'),
|
|
43
|
+
body: (
|
|
44
|
+
<div className='rounded border-2 border-dashed border-red-500 bg-red-100 p-2 text-red-800'>
|
|
45
|
+
{error.message}
|
|
46
|
+
</div>
|
|
47
|
+
),
|
|
48
|
+
headerColor: 'bg-red-700',
|
|
49
|
+
titleColor: 'text-white',
|
|
50
|
+
lang: 'en',
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
onSuccess: async (data) => {
|
|
55
|
+
await action()
|
|
56
|
+
setModal(null)
|
|
57
|
+
toast({
|
|
58
|
+
title: getString('delete'),
|
|
59
|
+
description: getString('itemDeletedSuccessfully'),
|
|
60
|
+
variant: 'success',
|
|
61
|
+
})
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
const handleDelete = async () => {
|
|
65
|
+
deleteMutation.mutate({
|
|
66
|
+
sectionName: section,
|
|
67
|
+
sectionItemId: id,
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div className='flex flex-col'>
|
|
73
|
+
<div className='flex flex-col gap-3'>
|
|
74
|
+
<div className='relative z-[1] border-b-2 p-8 pt-12 font-extrabold text-foreground'>
|
|
75
|
+
<div className='absolute left-0 top-0 z-[2] h-4 w-full bg-gradient-to-r from-red-300 via-rose-500 to-pink-400'></div>
|
|
76
|
+
<h1 className='pb-4 text-3xl'>{sectionTitle}</h1>
|
|
77
|
+
<span>/{getString('delete')}</span>
|
|
78
|
+
</div>
|
|
79
|
+
<div className='flex flex-col gap-2 px-8 py-4'>
|
|
80
|
+
<div className='mb-4 text-2xl'>{getString('catDeleteTextLight')}</div>
|
|
81
|
+
{deleteMutation.isPending ? (
|
|
82
|
+
<div className='flex w-full items-center justify-center text-center'>
|
|
83
|
+
<LoadingSpinners />
|
|
84
|
+
</div>
|
|
85
|
+
) : null}
|
|
86
|
+
<div className='flex flex-col gap-3 rounded p-2 ring ring-sky-300'>
|
|
87
|
+
<InfoCard
|
|
88
|
+
result={{
|
|
89
|
+
key: 'info',
|
|
90
|
+
title: `${getString('catDeleteWarningLight')}`,
|
|
91
|
+
status: false,
|
|
92
|
+
}}
|
|
93
|
+
/>
|
|
94
|
+
</div>
|
|
95
|
+
{allowRecursiveDelete ? (
|
|
96
|
+
<div className='flex flex-col gap-3 rounded p-2 ring ring-sky-300'>
|
|
97
|
+
<InfoCard
|
|
98
|
+
result={{
|
|
99
|
+
key: 'info',
|
|
100
|
+
title: `${getString('recursiveCategoryDeleteWarning')}`,
|
|
101
|
+
status: false,
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
<div className='flex items-center space-x-2'>
|
|
105
|
+
<Switch id='recursive-category-delete' />
|
|
106
|
+
<Label htmlFor='airplane-mode'>{getString('recursiveCategoryDelete')}</Label>
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
) : null}
|
|
110
|
+
|
|
111
|
+
<div className='mt-2 flex flex-wrap gap-2'>
|
|
112
|
+
<Button variant='destructive' onClick={handleDelete}>
|
|
113
|
+
{getString('delete')}
|
|
114
|
+
</Button>
|
|
115
|
+
|
|
116
|
+
<Button
|
|
117
|
+
variant='outline'
|
|
118
|
+
onClick={() => {
|
|
119
|
+
setModal(null)
|
|
120
|
+
}}
|
|
121
|
+
>
|
|
122
|
+
{getString('cancel')}
|
|
123
|
+
</Button>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
)
|
|
129
|
+
}
|