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,124 @@
|
|
|
1
|
+
import React, { useRef, useState } from 'react'
|
|
2
|
+
import getString from 'nextjs-cms/translations'
|
|
3
|
+
import FormInputElement from '@/components/form/FormInputElement'
|
|
4
|
+
import ProtectedDocument from '@/components/ProtectedDocument'
|
|
5
|
+
import { DocumentFieldClientConfig } from 'nextjs-cms/core/fields'
|
|
6
|
+
import { ChevronRight, X } from 'lucide-react'
|
|
7
|
+
import { useController, useFormContext } from 'react-hook-form'
|
|
8
|
+
|
|
9
|
+
export default function DocumentFormInput({
|
|
10
|
+
input,
|
|
11
|
+
sectionName,
|
|
12
|
+
}: {
|
|
13
|
+
input: DocumentFieldClientConfig
|
|
14
|
+
sectionName: string
|
|
15
|
+
}) {
|
|
16
|
+
const { control } = useFormContext()
|
|
17
|
+
const {
|
|
18
|
+
field,
|
|
19
|
+
fieldState: { invalid, isTouched, isDirty, error },
|
|
20
|
+
} = useController({
|
|
21
|
+
name: input.name,
|
|
22
|
+
control,
|
|
23
|
+
defaultValue: input.value ?? '',
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const [fileName, setFileName] = useState(getString('no_file_selected'))
|
|
27
|
+
const fileInputContainerRef = useRef<HTMLInputElement>(null)
|
|
28
|
+
const [image, setImage] = useState<string | null>(null)
|
|
29
|
+
|
|
30
|
+
const onImageChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
31
|
+
if (event.target.files && event.target.files[0]) {
|
|
32
|
+
setFileName(event.target.files?.[0].name || getString('no_file_selected'))
|
|
33
|
+
setImage(URL.createObjectURL(event.target.files[0]))
|
|
34
|
+
} else {
|
|
35
|
+
setFileName(getString('no_file_selected'))
|
|
36
|
+
setImage(null)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const document = (
|
|
41
|
+
<ProtectedDocument
|
|
42
|
+
section={sectionName}
|
|
43
|
+
fieldName={input.name}
|
|
44
|
+
file={input.value}
|
|
45
|
+
width={450}
|
|
46
|
+
height={620}
|
|
47
|
+
className='mb-4 rounded p-1 ring ring-gray-400'
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<FormInputElement
|
|
53
|
+
validationError={error}
|
|
54
|
+
value={document}
|
|
55
|
+
readonly={input.readonly}
|
|
56
|
+
label={input.label}
|
|
57
|
+
required={input.required}
|
|
58
|
+
>
|
|
59
|
+
<div className='flex flex-row gap-2'>
|
|
60
|
+
{input.value ? document : null}
|
|
61
|
+
{image && (
|
|
62
|
+
<div className='relative flex items-center'>
|
|
63
|
+
<ChevronRight fontSize='large' />
|
|
64
|
+
<div className='relative'>
|
|
65
|
+
<X
|
|
66
|
+
className='absolute -right-3 -top-3 cursor-pointer rounded-full border-2 border-gray-500 bg-white p-1'
|
|
67
|
+
onClick={() => {
|
|
68
|
+
setImage(null)
|
|
69
|
+
setFileName(getString('no_file_selected'))
|
|
70
|
+
field.onChange(undefined)
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Clear the child input value
|
|
74
|
+
*/
|
|
75
|
+
if (fileInputContainerRef.current?.firstChild) {
|
|
76
|
+
;(fileInputContainerRef.current.firstChild as HTMLInputElement).value = ''
|
|
77
|
+
}
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
<embed
|
|
81
|
+
src={image}
|
|
82
|
+
className='mb-4 max-w-full rounded p-1 ring ring-green-600'
|
|
83
|
+
width={350}
|
|
84
|
+
height={520}
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
)}
|
|
89
|
+
</div>
|
|
90
|
+
<div ref={fileInputContainerRef}>
|
|
91
|
+
<input
|
|
92
|
+
type='file'
|
|
93
|
+
className='hidden'
|
|
94
|
+
name={field.name}
|
|
95
|
+
ref={field.ref}
|
|
96
|
+
onChange={(e) => {
|
|
97
|
+
onImageChange(e)
|
|
98
|
+
if (!input.value) {
|
|
99
|
+
field.onChange(e.target?.files?.length ? e.target.files[0] : undefined)
|
|
100
|
+
}
|
|
101
|
+
}}
|
|
102
|
+
/>
|
|
103
|
+
</div>
|
|
104
|
+
<div className='flex flex-col items-center gap-2 md:flex-row'>
|
|
105
|
+
<div className='w-full flex-1 md:flex-[0.5]'>
|
|
106
|
+
<button
|
|
107
|
+
type='button'
|
|
108
|
+
className='w-full rounded border bg-gradient-to-r from-blue-700 to-sky-500 p-2 text-center text-sm font-bold uppercase text-white drop-shadow'
|
|
109
|
+
onClick={() => {
|
|
110
|
+
if (fileInputContainerRef.current?.firstChild) {
|
|
111
|
+
;(fileInputContainerRef.current.firstChild as HTMLInputElement).click()
|
|
112
|
+
}
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
Upload
|
|
116
|
+
</button>
|
|
117
|
+
</div>
|
|
118
|
+
<div className='w-full flex-1'>
|
|
119
|
+
<span>{fileName}</span>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
</FormInputElement>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
|
+
import { APIProvider, Map, Marker } from '@vis.gl/react-google-maps'
|
|
3
|
+
import ContainerBox from '@/components/ContainerBox'
|
|
4
|
+
import { Button } from '@/components/ui/button'
|
|
5
|
+
import TooltipComponent from '@/components/TooltipComponent'
|
|
6
|
+
import getString from 'nextjs-cms/translations'
|
|
7
|
+
import { MapFieldClientConfig } from 'nextjs-cms/core/fields'
|
|
8
|
+
import { useController, useFormContext } from 'react-hook-form'
|
|
9
|
+
import FormInputElement from '@/components/form/FormInputElement'
|
|
10
|
+
|
|
11
|
+
export default function MapFormInput({ input }: { input: MapFieldClientConfig }) {
|
|
12
|
+
const { control } = useFormContext()
|
|
13
|
+
const {
|
|
14
|
+
field,
|
|
15
|
+
fieldState: { invalid, isTouched, isDirty, error },
|
|
16
|
+
} = useController({
|
|
17
|
+
name: input.name,
|
|
18
|
+
control,
|
|
19
|
+
defaultValue: input.value ?? undefined,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const [coords, setCoords] = React.useState<
|
|
23
|
+
| {
|
|
24
|
+
lat: number
|
|
25
|
+
lng: number
|
|
26
|
+
}
|
|
27
|
+
| undefined
|
|
28
|
+
>(() => {
|
|
29
|
+
if (input.value?.lat && input.value?.lng) {
|
|
30
|
+
return {
|
|
31
|
+
lat: input.value.lat,
|
|
32
|
+
lng: input.value.lng,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
field.onChange(coords ? `${coords.lat},${coords.lng}` : undefined)
|
|
39
|
+
}, [coords])
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<FormInputElement
|
|
43
|
+
validationError={error}
|
|
44
|
+
value={
|
|
45
|
+
<span>
|
|
46
|
+
{input.value?.lat}, {input.value?.lng}
|
|
47
|
+
</span>
|
|
48
|
+
}
|
|
49
|
+
readonly={input.readonly}
|
|
50
|
+
label={input.label}
|
|
51
|
+
required={input.required}
|
|
52
|
+
>
|
|
53
|
+
<ContainerBox>
|
|
54
|
+
<div className='relative h-[500px] w-full overflow-hidden rounded-xl outline-0'>
|
|
55
|
+
<input
|
|
56
|
+
type='hidden'
|
|
57
|
+
value={coords ? `${coords.lat},${coords.lng}` : ''}
|
|
58
|
+
disabled={field.disabled}
|
|
59
|
+
name={field.name}
|
|
60
|
+
onChange={field.onChange}
|
|
61
|
+
onBlur={field.onBlur}
|
|
62
|
+
ref={field.ref}
|
|
63
|
+
/>
|
|
64
|
+
<APIProvider apiKey={process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? ''}>
|
|
65
|
+
<Map
|
|
66
|
+
clickableIcons={false}
|
|
67
|
+
zoomControl={true}
|
|
68
|
+
onClick={(e) => {
|
|
69
|
+
e.stop()
|
|
70
|
+
setCoords(() => {
|
|
71
|
+
if (e.detail.latLng) {
|
|
72
|
+
return {
|
|
73
|
+
lat: e.detail.latLng.lat,
|
|
74
|
+
lng: e.detail.latLng.lng,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}}
|
|
79
|
+
zoom={input.zoom}
|
|
80
|
+
minZoom={input.minZoom}
|
|
81
|
+
restriction={{
|
|
82
|
+
latLngBounds: input.latLngBounds,
|
|
83
|
+
strictBounds: true,
|
|
84
|
+
}}
|
|
85
|
+
center={input.value ? { lat: input.value.lat, lng: input.value.lng } : input.center}
|
|
86
|
+
gestureHandling={'greedy'}
|
|
87
|
+
disableDefaultUI={true}
|
|
88
|
+
>
|
|
89
|
+
{coords?.lat && coords?.lng ? (
|
|
90
|
+
<Marker position={{ lat: coords.lat, lng: coords.lng }} />
|
|
91
|
+
) : null}
|
|
92
|
+
</Map>
|
|
93
|
+
</APIProvider>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
<div className='my-2 flex flex-wrap gap-2'>
|
|
97
|
+
<Button
|
|
98
|
+
type='button'
|
|
99
|
+
size={'sm'}
|
|
100
|
+
disabled={!coords?.lat || !coords?.lng}
|
|
101
|
+
variant='default'
|
|
102
|
+
onClick={(e) => {
|
|
103
|
+
e.preventDefault()
|
|
104
|
+
e.stopPropagation()
|
|
105
|
+
setCoords(undefined)
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
{getString('removeMarker')}
|
|
109
|
+
</Button>
|
|
110
|
+
<TooltipComponent
|
|
111
|
+
delayDuration={100}
|
|
112
|
+
content={!(input.value?.lat && input.value?.lng) ? getString('restoreMarkerTooltip') : null}
|
|
113
|
+
>
|
|
114
|
+
<Button
|
|
115
|
+
type='button'
|
|
116
|
+
size={'sm'}
|
|
117
|
+
disabled={!(input.value?.lat && input.value?.lng)}
|
|
118
|
+
variant='default'
|
|
119
|
+
onClick={(e) => {
|
|
120
|
+
e.preventDefault()
|
|
121
|
+
e.stopPropagation()
|
|
122
|
+
setCoords(() => {
|
|
123
|
+
if (input.value?.lat && input.value?.lng) {
|
|
124
|
+
return {
|
|
125
|
+
lat: input.value.lat,
|
|
126
|
+
lng: input.value.lng,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
{getString('restoreMarker')}
|
|
133
|
+
</Button>
|
|
134
|
+
</TooltipComponent>
|
|
135
|
+
</div>
|
|
136
|
+
</ContainerBox>
|
|
137
|
+
</FormInputElement>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import FormInputElement from '@/components/form/FormInputElement'
|
|
2
|
+
import { Autocomplete, Checkbox, Chip, TextField } from '@mui/material'
|
|
3
|
+
import { useEffect, useState } from 'react'
|
|
4
|
+
import * as React from 'react'
|
|
5
|
+
import { useTheme } from 'next-themes'
|
|
6
|
+
|
|
7
|
+
import { styled } from '@mui/material/styles'
|
|
8
|
+
import { SelectMultipleFieldClientConfig, SelectOption } from 'nextjs-cms/core/fields'
|
|
9
|
+
import { Square, CheckSquare2 } from 'lucide-react'
|
|
10
|
+
import { useController, useFormContext } from 'react-hook-form'
|
|
11
|
+
|
|
12
|
+
const icon = <Square fontSize='small' />
|
|
13
|
+
const checkedIcon = <CheckSquare2 fontSize='small' />
|
|
14
|
+
export default function MultipleSelectFormInput({ input }: { input: SelectMultipleFieldClientConfig }) {
|
|
15
|
+
const { control } = useFormContext()
|
|
16
|
+
const {
|
|
17
|
+
field,
|
|
18
|
+
fieldState: { invalid, isTouched, isDirty, error },
|
|
19
|
+
} = useController({
|
|
20
|
+
name: input.name,
|
|
21
|
+
control,
|
|
22
|
+
defaultValue: input.value,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const [value, setValue] = useState<SelectOption[] | undefined>([])
|
|
26
|
+
const { theme } = useTheme()
|
|
27
|
+
|
|
28
|
+
const borderColor = theme === 'dark' ? 'rgba(66,72,79,0.46)' : 'rgb(204,204,204)'
|
|
29
|
+
const darkColor = 'rgba(66,72,79,0.46)' // Replace with the actual color from your screenshot
|
|
30
|
+
const lightColor = '#f8f9fa' // Replace with the actual color from your screenshot
|
|
31
|
+
const textColor = theme === 'dark' ? '#f8f9fa' : '#111111'
|
|
32
|
+
const placeholderColor = theme === 'dark' ? '#bdbdbd' : '#a1a1a1'
|
|
33
|
+
|
|
34
|
+
// Custom styled TextField for Autocomplete
|
|
35
|
+
const CustomTextField = styled(TextField)({
|
|
36
|
+
'& .MuiFormLabel-root': {
|
|
37
|
+
color: placeholderColor,
|
|
38
|
+
},
|
|
39
|
+
'& label.Mui-focused': {
|
|
40
|
+
color: placeholderColor,
|
|
41
|
+
},
|
|
42
|
+
'& .MuiInput-underline:after': {
|
|
43
|
+
borderBottomColor: theme === 'dark' ? lightColor : darkColor,
|
|
44
|
+
},
|
|
45
|
+
'& .MuiOutlinedInput-root': {
|
|
46
|
+
'& fieldset': {
|
|
47
|
+
borderColor: borderColor,
|
|
48
|
+
borderWidth: 2,
|
|
49
|
+
borderRadius: 8,
|
|
50
|
+
},
|
|
51
|
+
'&:hover fieldset': {
|
|
52
|
+
borderColor: theme === 'dark' ? lightColor : darkColor,
|
|
53
|
+
},
|
|
54
|
+
'&.Mui-focused fieldset': {
|
|
55
|
+
borderColor: '#5572fa',
|
|
56
|
+
},
|
|
57
|
+
'& input': {
|
|
58
|
+
color: textColor,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (input.value && input.value?.length > 0) {
|
|
65
|
+
setValue(input.value)
|
|
66
|
+
}
|
|
67
|
+
}, [input.value])
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<FormInputElement validationError={error} label={input.label} required={input.required}>
|
|
71
|
+
<input
|
|
72
|
+
type='hidden'
|
|
73
|
+
className='hidden'
|
|
74
|
+
disabled={field.disabled}
|
|
75
|
+
name={field.name}
|
|
76
|
+
onBlur={field.onBlur}
|
|
77
|
+
ref={field.ref}
|
|
78
|
+
value={JSON.stringify(field.value)}
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
<Autocomplete
|
|
82
|
+
className=''
|
|
83
|
+
multiple
|
|
84
|
+
options={input.options ? input.options : []}
|
|
85
|
+
disableCloseOnSelect
|
|
86
|
+
getOptionLabel={(option) => option.label.toString()}
|
|
87
|
+
renderOption={(props, option, { selected }) => (
|
|
88
|
+
<li {...props}>
|
|
89
|
+
<Checkbox icon={icon} checkedIcon={checkedIcon} style={{ marginRight: 8 }} checked={selected} />
|
|
90
|
+
{option.label}
|
|
91
|
+
</li>
|
|
92
|
+
)}
|
|
93
|
+
sx={{
|
|
94
|
+
'& .MuiAutocomplete-inputRoot': {
|
|
95
|
+
color: lightColor, // text color
|
|
96
|
+
'& .MuiAutocomplete-endAdornment': {
|
|
97
|
+
color: lightColor,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
'& .MuiAutocomplete-popupIndicator': {
|
|
101
|
+
color: lightColor,
|
|
102
|
+
},
|
|
103
|
+
'& .MuiAutocomplete-clearIndicator': {
|
|
104
|
+
color: lightColor,
|
|
105
|
+
},
|
|
106
|
+
'& .MuiPaper-root': {
|
|
107
|
+
bgcolor: darkColor, // dropdown background color
|
|
108
|
+
color: lightColor, // option text color
|
|
109
|
+
'& .MuiAutocomplete-option': {
|
|
110
|
+
'&:hover': {
|
|
111
|
+
bgcolor: lightColor, // option hover color
|
|
112
|
+
color: darkColor,
|
|
113
|
+
},
|
|
114
|
+
'&[aria-selected="true"]': {
|
|
115
|
+
bgcolor: lightColor, // option selected color
|
|
116
|
+
color: darkColor,
|
|
117
|
+
},
|
|
118
|
+
'&[data-focus="true"]': {
|
|
119
|
+
bgcolor: lightColor, // option focused color
|
|
120
|
+
color: darkColor,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
}}
|
|
125
|
+
defaultValue={input.value ? input.value : []}
|
|
126
|
+
renderInput={(params) => (
|
|
127
|
+
<CustomTextField
|
|
128
|
+
className='w-full bg-input text-foreground'
|
|
129
|
+
{...params}
|
|
130
|
+
label={input.label}
|
|
131
|
+
placeholder={input.label}
|
|
132
|
+
/>
|
|
133
|
+
)}
|
|
134
|
+
isOptionEqualToValue={(option, value) => option.value.toString() === value.value.toString()}
|
|
135
|
+
onChange={(event, newInputValue) => {
|
|
136
|
+
if (newInputValue) {
|
|
137
|
+
field.onChange(newInputValue)
|
|
138
|
+
setValue(newInputValue)
|
|
139
|
+
}
|
|
140
|
+
}}
|
|
141
|
+
disableClearable={true}
|
|
142
|
+
renderTags={(tagValue, getTagProps) => {
|
|
143
|
+
return tagValue.map((option, index) => (
|
|
144
|
+
<Chip color='primary' {...getTagProps({ index })} key={option.value} label={option.label} />
|
|
145
|
+
))
|
|
146
|
+
}}
|
|
147
|
+
/>
|
|
148
|
+
</FormInputElement>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import FormInputElement from '@/components/form/FormInputElement'
|
|
3
|
+
import type { NumberFieldClientConfig } from 'nextjs-cms/core/fields'
|
|
4
|
+
import { useController, useFormContext } from 'react-hook-form'
|
|
5
|
+
import { isNumber, toNumber } from 'lodash-es'
|
|
6
|
+
|
|
7
|
+
export default function NumberFormInput({ input }: { input: NumberFieldClientConfig }) {
|
|
8
|
+
const { control } = useFormContext()
|
|
9
|
+
const {
|
|
10
|
+
field,
|
|
11
|
+
fieldState: { invalid, isTouched, isDirty, error },
|
|
12
|
+
} = useController({
|
|
13
|
+
name: input.name,
|
|
14
|
+
control,
|
|
15
|
+
defaultValue: isNumber(input.value) ? input.value : undefined,
|
|
16
|
+
disabled: input.readonly,
|
|
17
|
+
})
|
|
18
|
+
return (
|
|
19
|
+
<FormInputElement
|
|
20
|
+
validationError={error}
|
|
21
|
+
value={input.value}
|
|
22
|
+
label={input.label}
|
|
23
|
+
required={input.required}
|
|
24
|
+
readonly={input.readonly}
|
|
25
|
+
>
|
|
26
|
+
<input
|
|
27
|
+
type='number'
|
|
28
|
+
placeholder={input.label}
|
|
29
|
+
readOnly={field.disabled}
|
|
30
|
+
disabled={field.disabled}
|
|
31
|
+
name={field.name}
|
|
32
|
+
onChange={(event) =>
|
|
33
|
+
event.target.value ? field.onChange(toNumber(event.target.value)) : field.onChange(NaN)
|
|
34
|
+
}
|
|
35
|
+
onBlur={field.onBlur}
|
|
36
|
+
value={field.value}
|
|
37
|
+
ref={field.ref}
|
|
38
|
+
className='w-full rounded bg-input p-3 text-foreground shadow-sm outline-0 ring-2 ring-gray-300 hover:ring-gray-400 focus:ring-blue-500'
|
|
39
|
+
/>
|
|
40
|
+
</FormInputElement>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import FormInputElement from '@/components/form/FormInputElement'
|
|
3
|
+
import { PasswordFieldClientConfig } from 'nextjs-cms/core/fields'
|
|
4
|
+
import { useController, useFormContext } from 'react-hook-form'
|
|
5
|
+
|
|
6
|
+
export default function PasswordFormInput({
|
|
7
|
+
input,
|
|
8
|
+
defaultValue,
|
|
9
|
+
direction,
|
|
10
|
+
}: {
|
|
11
|
+
input: PasswordFieldClientConfig
|
|
12
|
+
defaultValue?: string | null
|
|
13
|
+
direction?: 'row' | 'col'
|
|
14
|
+
}) {
|
|
15
|
+
const { control } = useFormContext()
|
|
16
|
+
const {
|
|
17
|
+
field,
|
|
18
|
+
fieldState: { invalid, isTouched, isDirty, error },
|
|
19
|
+
} = useController({
|
|
20
|
+
name: input.name,
|
|
21
|
+
control,
|
|
22
|
+
defaultValue: defaultValue ?? input.value ?? undefined,
|
|
23
|
+
disabled: input.readonly,
|
|
24
|
+
})
|
|
25
|
+
return (
|
|
26
|
+
<FormInputElement
|
|
27
|
+
validationError={error}
|
|
28
|
+
value={'********'}
|
|
29
|
+
readonly={input.readonly}
|
|
30
|
+
label={input.label}
|
|
31
|
+
required={input.required}
|
|
32
|
+
>
|
|
33
|
+
<input
|
|
34
|
+
placeholder={input.placeholder ? input.placeholder : input.label}
|
|
35
|
+
type='password'
|
|
36
|
+
readOnly={input.readonly}
|
|
37
|
+
disabled={field.disabled}
|
|
38
|
+
name={field.name}
|
|
39
|
+
onChange={field.onChange}
|
|
40
|
+
onBlur={field.onBlur}
|
|
41
|
+
value={field.value}
|
|
42
|
+
ref={field.ref}
|
|
43
|
+
className='w-full rounded bg-input p-3 text-foreground shadow-sm outline-0 ring-2 ring-gray-300 hover:ring-gray-400 focus:ring-blue-500'
|
|
44
|
+
/>
|
|
45
|
+
</FormInputElement>
|
|
46
|
+
)
|
|
47
|
+
}
|