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,217 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useAxiosPrivate } from 'nextjs-cms/auth/hooks'
|
|
4
|
+
import React, { RefObject, useEffect, useRef, useState } from 'react'
|
|
5
|
+
import { SectionType } from 'nextjs-cms/core/types'
|
|
6
|
+
import getString from 'nextjs-cms/translations'
|
|
7
|
+
import useModal from '@/hooks/useModal'
|
|
8
|
+
import { AxiosError } from 'axios'
|
|
9
|
+
import InfoCard from '@/components/InfoCard'
|
|
10
|
+
import { useRouter } from 'next/navigation'
|
|
11
|
+
import LoadingSpinners from '@/components/LoadingSpinners'
|
|
12
|
+
import { useToast } from '@/components/ui/use-toast'
|
|
13
|
+
import { DropzoneHandles } from '@/components/Dropzone'
|
|
14
|
+
import { VariantHandles } from '@/components/NewVariantComponent'
|
|
15
|
+
import { trpc } from '@/app/_trpc/client'
|
|
16
|
+
import Form from '@/components/form/Form'
|
|
17
|
+
|
|
18
|
+
export default function ItemEditPage({
|
|
19
|
+
section,
|
|
20
|
+
sectionType,
|
|
21
|
+
itemId,
|
|
22
|
+
hiddenInputs,
|
|
23
|
+
action,
|
|
24
|
+
}: {
|
|
25
|
+
section: string
|
|
26
|
+
sectionType: SectionType
|
|
27
|
+
itemId: string
|
|
28
|
+
hiddenInputs?: {
|
|
29
|
+
name: string
|
|
30
|
+
value: any
|
|
31
|
+
}[]
|
|
32
|
+
action?: any
|
|
33
|
+
}) {
|
|
34
|
+
const [response, setResponse] = useState<any>(null)
|
|
35
|
+
const [progress, setProgress] = useState(0)
|
|
36
|
+
const [progressVariant, setProgressVariant] = useState<'determinate' | 'query'>('determinate')
|
|
37
|
+
const [isSubmitting, setIsSubmitting] = useState(false)
|
|
38
|
+
const { setModal } = useModal()
|
|
39
|
+
const axiosPrivate = useAxiosPrivate()
|
|
40
|
+
const controller = new AbortController()
|
|
41
|
+
const { toast } = useToast()
|
|
42
|
+
const router = useRouter()
|
|
43
|
+
const dropzoneRef: RefObject<DropzoneHandles | null> = useRef(null)
|
|
44
|
+
const variantRef: RefObject<VariantHandles[]> = useRef([])
|
|
45
|
+
const { isLoading, isError, data, error, refetch } = trpc.hasItemsSections.editItem.useQuery({
|
|
46
|
+
sectionName: section,
|
|
47
|
+
sectionItemId: itemId,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const handleSubmit = async (formData: FormData) => {
|
|
51
|
+
setIsSubmitting(true)
|
|
52
|
+
if (isSubmitting) return
|
|
53
|
+
setResponse(null)
|
|
54
|
+
|
|
55
|
+
formData.append('sectionName', section)
|
|
56
|
+
formData.append('formType', 'edit')
|
|
57
|
+
formData.append('sectionType', sectionType)
|
|
58
|
+
|
|
59
|
+
// Retrieve the files from the Dropzone's state
|
|
60
|
+
if (dropzoneRef.current) {
|
|
61
|
+
const files: File[] = dropzoneRef.current.getFiles()
|
|
62
|
+
// Add files to the body
|
|
63
|
+
files.forEach((file, index) => {
|
|
64
|
+
formData.append(`dropzoneFiles`, file)
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Retrieve the variants from the variants component
|
|
69
|
+
// For now, only one variant is allowed
|
|
70
|
+
const variantsObject: any[] = []
|
|
71
|
+
if (variantRef.current && data?.section?.variants?.length && data?.section?.variants[0]) {
|
|
72
|
+
// Add variants to the body
|
|
73
|
+
variantRef.current.map((ref, index) => {
|
|
74
|
+
variantsObject.push({
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
variant: data.section.variants[index],
|
|
77
|
+
items: ref.getVariants(),
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
formData.append(`variantItems`, JSON.stringify(variantsObject))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Check if there are any hidden inputs passed to the component
|
|
85
|
+
if (hiddenInputs) {
|
|
86
|
+
// Add hidden inputs to the body
|
|
87
|
+
hiddenInputs.forEach((input) => {
|
|
88
|
+
if (!input.value) return
|
|
89
|
+
formData.append(input.name, input.value)
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// const body = Object.fromEntries(formData.entries())
|
|
94
|
+
try {
|
|
95
|
+
const res = await axiosPrivate.put(`/submit/section/item/${itemId}`, formData, {
|
|
96
|
+
signal: controller.signal,
|
|
97
|
+
onUploadProgress: (progressEvent) => {
|
|
98
|
+
if (!progressEvent.total) return
|
|
99
|
+
const progress = Math.round((progressEvent.loaded / progressEvent.total) * 100)
|
|
100
|
+
// Update progress bar value here
|
|
101
|
+
setProgress(progress)
|
|
102
|
+
|
|
103
|
+
if (progress === 100) {
|
|
104
|
+
setProgressVariant('query')
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
headers: {
|
|
108
|
+
'Content-Type': 'multipart/form-data',
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
if (res) {
|
|
113
|
+
setIsSubmitting(false)
|
|
114
|
+
setProgress(0)
|
|
115
|
+
setProgressVariant('determinate')
|
|
116
|
+
if (res.status === 200) {
|
|
117
|
+
// Refetch the page
|
|
118
|
+
// Clear Dropzone
|
|
119
|
+
if (dropzoneRef.current) {
|
|
120
|
+
dropzoneRef.current.removeFiles()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Clear Variants
|
|
124
|
+
if (variantRef.current) {
|
|
125
|
+
variantRef.current.map((ref) => {
|
|
126
|
+
ref.removeVariants()
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
await refetch()
|
|
130
|
+
switch (sectionType) {
|
|
131
|
+
case 'categorized':
|
|
132
|
+
// Just close the modal and refetch the page
|
|
133
|
+
setModal(null)
|
|
134
|
+
toast({
|
|
135
|
+
variant: 'success',
|
|
136
|
+
description: getString('itemUpdatedSuccessfully'),
|
|
137
|
+
})
|
|
138
|
+
if (action) {
|
|
139
|
+
await action().then(() => {
|
|
140
|
+
setModal(null)
|
|
141
|
+
router.refresh()
|
|
142
|
+
})
|
|
143
|
+
} else {
|
|
144
|
+
setModal(null)
|
|
145
|
+
}
|
|
146
|
+
break
|
|
147
|
+
|
|
148
|
+
case 'has_items':
|
|
149
|
+
setResponse(null)
|
|
150
|
+
toast({
|
|
151
|
+
variant: 'success',
|
|
152
|
+
description: getString('itemUpdatedSuccessfully'),
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
// Redirect to the edit page
|
|
156
|
+
// router.push(`/edit/${section}/${res.data.identifier}`)
|
|
157
|
+
// Or redirect to the browse page
|
|
158
|
+
break
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} catch (error: AxiosError | any) {
|
|
163
|
+
setIsSubmitting(false)
|
|
164
|
+
setProgress(0)
|
|
165
|
+
setProgressVariant('determinate')
|
|
166
|
+
if (error?.response?.data) {
|
|
167
|
+
setResponse(<InfoCard result={{ key: 'danger', title: error.response.data.error, status: false }} />)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function cancelSubmit() {
|
|
173
|
+
controller.abort()
|
|
174
|
+
setIsSubmitting(false)
|
|
175
|
+
setProgress(0)
|
|
176
|
+
setProgressVariant('determinate')
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
return () => {
|
|
181
|
+
cancelSubmit()
|
|
182
|
+
}
|
|
183
|
+
}, [])
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<div className='flex w-full flex-col overflow-hidden'>
|
|
187
|
+
{isLoading ? (
|
|
188
|
+
<div>
|
|
189
|
+
<LoadingSpinners />
|
|
190
|
+
</div>
|
|
191
|
+
) : null}
|
|
192
|
+
{isError ? <div>{error?.message}</div> : null}
|
|
193
|
+
{data ? (
|
|
194
|
+
<div className='flex w-full flex-col'>
|
|
195
|
+
<div className='relative z-[1] border-b-2 p-8 pt-12 font-extrabold text-foreground'>
|
|
196
|
+
<div className='absolute left-0 top-0 z-[2] h-4 w-full bg-gradient-to-r from-emerald-800 via-emerald-400 to-sky-600'></div>
|
|
197
|
+
<h1 className='pb-4 text-4xl'>{data.section?.title.section}</h1>
|
|
198
|
+
<span>
|
|
199
|
+
/{getString('edit')} {data.section?.title.singular}
|
|
200
|
+
</span>
|
|
201
|
+
</div>
|
|
202
|
+
<Form
|
|
203
|
+
formType='edit'
|
|
204
|
+
progressVariant={progressVariant}
|
|
205
|
+
response={response}
|
|
206
|
+
progress={progress}
|
|
207
|
+
data={data}
|
|
208
|
+
dropzoneRef={dropzoneRef}
|
|
209
|
+
variantRef={variantRef}
|
|
210
|
+
handleSubmit={handleSubmit}
|
|
211
|
+
isSubmitting={isSubmitting}
|
|
212
|
+
/>
|
|
213
|
+
</div>
|
|
214
|
+
) : null}
|
|
215
|
+
</div>
|
|
216
|
+
)
|
|
217
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames'
|
|
4
|
+
import React, { useState } from 'react'
|
|
5
|
+
import Navbar from '@/components/NavbarAlt'
|
|
6
|
+
import Sidebar from '@/components/Sidebar'
|
|
7
|
+
import Modal from '@/components/Modal'
|
|
8
|
+
import { Toaster } from '@/components/ui/toaster'
|
|
9
|
+
import { useSession } from 'nextjs-cms/auth/react'
|
|
10
|
+
import LoadingSpinners from '@/components/LoadingSpinners'
|
|
11
|
+
|
|
12
|
+
function Layout({ children }: { children: React.ReactNode }) {
|
|
13
|
+
const [showMobileSidebar, setShowMobileSidebar] = useState(false)
|
|
14
|
+
const session = useSession({
|
|
15
|
+
required: true,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div
|
|
20
|
+
className={classNames({
|
|
21
|
+
'flex min-h-screen flex-col bg-background text-foreground': true,
|
|
22
|
+
'overflow-hidden': true,
|
|
23
|
+
})}
|
|
24
|
+
>
|
|
25
|
+
<div>
|
|
26
|
+
{session.status === 'loading' ? (
|
|
27
|
+
<div className='align-center flex w-full flex-row items-center justify-center p-2'>
|
|
28
|
+
<LoadingSpinners />
|
|
29
|
+
</div>
|
|
30
|
+
) : (
|
|
31
|
+
<>
|
|
32
|
+
<Sidebar
|
|
33
|
+
closeSideBar={() => {
|
|
34
|
+
setShowMobileSidebar(false)
|
|
35
|
+
}}
|
|
36
|
+
mobileSidebar={showMobileSidebar}
|
|
37
|
+
/>
|
|
38
|
+
{showMobileSidebar && (
|
|
39
|
+
// Display a black transparent div to close the sidebar when clicked outside
|
|
40
|
+
<div
|
|
41
|
+
className='fixed left-0 top-0 z-[15] h-full w-full bg-black/80 md:hidden'
|
|
42
|
+
onClick={() => setShowMobileSidebar(false)}
|
|
43
|
+
></div>
|
|
44
|
+
)}
|
|
45
|
+
<div
|
|
46
|
+
className={classNames({
|
|
47
|
+
'transition-all duration-100 ease-in-out': true,
|
|
48
|
+
'float-right': true,
|
|
49
|
+
'w-full md:w-[calc(100%-275px)]': true,
|
|
50
|
+
})}
|
|
51
|
+
>
|
|
52
|
+
<Navbar onMenuButtonClick={() => setShowMobileSidebar((prev) => !prev)} />
|
|
53
|
+
<div
|
|
54
|
+
className={classNames({
|
|
55
|
+
'h-full w-full': true,
|
|
56
|
+
})}
|
|
57
|
+
>
|
|
58
|
+
{children}
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
<Modal />
|
|
62
|
+
<Toaster />
|
|
63
|
+
</>
|
|
64
|
+
)}
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default Layout
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const LoadingSpinners = ({ single = false }: { single?: boolean }) => {
|
|
2
|
+
return (
|
|
3
|
+
<div className='flex justify-center'>
|
|
4
|
+
<div role='status'>
|
|
5
|
+
<svg
|
|
6
|
+
aria-hidden='true'
|
|
7
|
+
className='mr-2 inline h-8 w-8 animate-spin fill-blue-600 text-gray-200 dark:text-gray-600'
|
|
8
|
+
viewBox='0 0 100 101'
|
|
9
|
+
fill='none'
|
|
10
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
11
|
+
>
|
|
12
|
+
<path
|
|
13
|
+
d='M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z'
|
|
14
|
+
fill='currentColor'
|
|
15
|
+
/>
|
|
16
|
+
<path
|
|
17
|
+
d='M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z'
|
|
18
|
+
fill='currentFill'
|
|
19
|
+
/>
|
|
20
|
+
</svg>
|
|
21
|
+
</div>
|
|
22
|
+
{!single && (
|
|
23
|
+
<>
|
|
24
|
+
<div role='status'>
|
|
25
|
+
<svg
|
|
26
|
+
aria-hidden='true'
|
|
27
|
+
className='mr-2 inline h-8 w-8 animate-spin fill-red-600 text-gray-200 dark:fill-gray-300 dark:text-gray-600'
|
|
28
|
+
viewBox='0 0 100 101'
|
|
29
|
+
fill='none'
|
|
30
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
31
|
+
>
|
|
32
|
+
<path
|
|
33
|
+
d='M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z'
|
|
34
|
+
fill='currentColor'
|
|
35
|
+
/>
|
|
36
|
+
<path
|
|
37
|
+
d='M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z'
|
|
38
|
+
fill='currentFill'
|
|
39
|
+
/>
|
|
40
|
+
</svg>
|
|
41
|
+
</div>
|
|
42
|
+
<div role='status'>
|
|
43
|
+
<svg
|
|
44
|
+
aria-hidden='true'
|
|
45
|
+
className='mr-2 inline h-8 w-8 animate-spin fill-green-500 text-gray-200 dark:text-gray-600'
|
|
46
|
+
viewBox='0 0 100 101'
|
|
47
|
+
fill='none'
|
|
48
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
49
|
+
>
|
|
50
|
+
<path
|
|
51
|
+
d='M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z'
|
|
52
|
+
fill='currentColor'
|
|
53
|
+
/>
|
|
54
|
+
<path
|
|
55
|
+
d='M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z'
|
|
56
|
+
fill='currentFill'
|
|
57
|
+
/>
|
|
58
|
+
</svg>
|
|
59
|
+
</div>
|
|
60
|
+
</>
|
|
61
|
+
)}
|
|
62
|
+
<span className='sr-only'>Loading...</span>
|
|
63
|
+
</div>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default LoadingSpinners
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import getString from 'nextjs-cms/translations'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
export default function LogPage() {
|
|
7
|
+
return (
|
|
8
|
+
<div className='w-full'>
|
|
9
|
+
<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'>
|
|
10
|
+
<h1 className='text-3xl'>{getString('logs')}</h1>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<div className='flex flex-col gap-2 p-4'>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React, { Fragment, useEffect, useRef } from 'react'
|
|
4
|
+
import { Dialog, Transition } from '@headlessui/react'
|
|
5
|
+
import useModal from '@/hooks/useModal'
|
|
6
|
+
import classNames from 'classnames'
|
|
7
|
+
import { X } from 'lucide-react'
|
|
8
|
+
|
|
9
|
+
function Modal() {
|
|
10
|
+
const { setModal, modal, modalResponse, setModalResponse } = useModal()
|
|
11
|
+
|
|
12
|
+
const handleClose = () => {
|
|
13
|
+
setModal(null)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const cancelButtonRef = useRef(null)
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!modal) {
|
|
20
|
+
setModalResponse(null)
|
|
21
|
+
}
|
|
22
|
+
}, [modal])
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Transition.Root show={modal !== null} as={Fragment}>
|
|
26
|
+
<Dialog as='div' className='relative z-50' initialFocus={cancelButtonRef} onClose={handleClose}>
|
|
27
|
+
<Transition.Child
|
|
28
|
+
as={Fragment}
|
|
29
|
+
enter='ease-out duration-300'
|
|
30
|
+
enterFrom='opacity-0'
|
|
31
|
+
enterTo='opacity-100'
|
|
32
|
+
leave='ease-in duration-200'
|
|
33
|
+
leaveFrom='opacity-100'
|
|
34
|
+
leaveTo='opacity-0'
|
|
35
|
+
>
|
|
36
|
+
<div className='fixed inset-0 bg-gray-500/50 backdrop-blur-md transition-opacity' />
|
|
37
|
+
</Transition.Child>
|
|
38
|
+
|
|
39
|
+
<div className='fixed inset-0 z-10 overflow-y-auto'>
|
|
40
|
+
<div className='flex min-h-full items-end justify-center p-4 text-start sm:items-start sm:p-0'>
|
|
41
|
+
<Transition.Child
|
|
42
|
+
as={Fragment}
|
|
43
|
+
enter='ease-out duration-300'
|
|
44
|
+
enterFrom='opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95'
|
|
45
|
+
enterTo='opacity-100 translate-y-0 sm:scale-100'
|
|
46
|
+
leave='ease-in duration-200'
|
|
47
|
+
leaveFrom='opacity-100 translate-y-0 sm:scale-100'
|
|
48
|
+
leaveTo='opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95'
|
|
49
|
+
>
|
|
50
|
+
<Dialog.Panel
|
|
51
|
+
className={classNames({
|
|
52
|
+
'relative w-full rounded-lg bg-background text-start shadow-xl transition-all sm:my-8':
|
|
53
|
+
true,
|
|
54
|
+
'max-w-lg': modal?.size === 'sm' || modal?.size === undefined,
|
|
55
|
+
'max-w-2xl': modal?.size === 'md',
|
|
56
|
+
'max-w-4xl': modal?.size === 'lg',
|
|
57
|
+
'max-w-6xl': modal?.size === 'xl',
|
|
58
|
+
})}
|
|
59
|
+
>
|
|
60
|
+
<div className='rounded-lg bg-background'>
|
|
61
|
+
{modal && (
|
|
62
|
+
<div className='flex flex-col gap-1'>
|
|
63
|
+
<div className='w-full overflow-hidden rounded'>
|
|
64
|
+
<div
|
|
65
|
+
className={`flex items-center rounded-t-lg text-xl font-semibold leading-6 ${modal.titleColor} p-6 pb-4 pt-5 md:pe-20 ${modal.headerColor}`}
|
|
66
|
+
>
|
|
67
|
+
<Dialog.Title as='h3' className='pe-5'>
|
|
68
|
+
{modal.title}
|
|
69
|
+
</Dialog.Title>
|
|
70
|
+
<X
|
|
71
|
+
className={`absolute ${
|
|
72
|
+
modal.lang === 'ar' ? 'left-5' : 'right-5'
|
|
73
|
+
} hidden h-7 w-7 cursor-pointer rounded bg-white text-gray-500 hover:opacity-90 md:block`}
|
|
74
|
+
onClick={handleClose}
|
|
75
|
+
ref={cancelButtonRef}
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
<div className='flex w-full flex-col font-semibold'>
|
|
79
|
+
<div className='w-full text-foreground'>{modal.body}</div>
|
|
80
|
+
<div className='w-full'>
|
|
81
|
+
{modalResponse && (
|
|
82
|
+
<div className={`w-full p-3`}>{modalResponse.message}</div>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
)}
|
|
89
|
+
</div>
|
|
90
|
+
</Dialog.Panel>
|
|
91
|
+
</Transition.Child>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
</Dialog>
|
|
95
|
+
</Transition.Root>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default Modal
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import classNames from 'classnames'
|
|
3
|
+
import { HamburgerMenuIcon } from '@radix-ui/react-icons'
|
|
4
|
+
type Props = {
|
|
5
|
+
/**
|
|
6
|
+
* Allows the parent component to modify the state when the
|
|
7
|
+
* menu button is clicked.
|
|
8
|
+
*/
|
|
9
|
+
onMenuButtonClick(): void
|
|
10
|
+
}
|
|
11
|
+
const Navbar = (props: Props) => {
|
|
12
|
+
return (
|
|
13
|
+
<nav
|
|
14
|
+
className={classNames({
|
|
15
|
+
'bg-white text-zinc-500': true, // colors
|
|
16
|
+
'flex items-center': true, // layout
|
|
17
|
+
'w-full md:w-full sticky z-10 px-4 shadow-sm h-[73px] top-0 ': true, //positioning & styling
|
|
18
|
+
})}
|
|
19
|
+
>
|
|
20
|
+
<div className='font-bold text-lg'>Admin Panel</div>
|
|
21
|
+
<div className='flex-grow'></div>
|
|
22
|
+
<button className='md:hidden' onClick={props.onMenuButtonClick}>
|
|
23
|
+
<HamburgerMenuIcon className='h-6 w-6' />
|
|
24
|
+
</button>
|
|
25
|
+
</nav>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default Navbar
|