create-nextjs-cms 0.9.29 → 0.9.30
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 -21
- package/README.md +71 -71
- package/dist/helpers/utils.js +16 -16
- package/dist/lib/section-creators.js +166 -166
- package/package.json +3 -3
- package/templates/default/.eslintrc.json +5 -5
- package/templates/default/.prettierignore +7 -7
- package/templates/default/.prettierrc.json +27 -27
- package/templates/default/CHANGELOG.md +140 -140
- package/templates/default/_gitignore +57 -57
- package/templates/default/app/(auth)/auth/login/LoginPage.tsx +192 -192
- package/templates/default/app/(auth)/auth/login/page.tsx +11 -11
- package/templates/default/app/(auth)/auth-language-provider.tsx +34 -34
- package/templates/default/app/(auth)/layout.tsx +81 -81
- package/templates/default/app/(rootLayout)/admins/page.tsx +10 -10
- package/templates/default/app/(rootLayout)/browse/[section]/[page]/page.tsx +22 -22
- package/templates/default/app/(rootLayout)/categorized/[section]/page.tsx +15 -15
- package/templates/default/app/(rootLayout)/dashboard/page.tsx +70 -70
- package/templates/default/app/(rootLayout)/edit/[section]/[itemId]/page.tsx +20 -20
- package/templates/default/app/(rootLayout)/layout.tsx +81 -81
- package/templates/default/app/(rootLayout)/loading.tsx +10 -10
- package/templates/default/app/(rootLayout)/log/page.tsx +7 -7
- package/templates/default/app/(rootLayout)/new/[section]/page.tsx +15 -15
- package/templates/default/app/(rootLayout)/section/[section]/page.tsx +19 -19
- package/templates/default/app/(rootLayout)/settings/page.tsx +13 -13
- package/templates/default/app/api/auth/csrf/route.ts +25 -25
- package/templates/default/app/api/auth/refresh/route.ts +10 -10
- package/templates/default/app/api/auth/route.ts +49 -49
- package/templates/default/app/api/auth/session/route.ts +20 -20
- package/templates/default/app/api/document/route.ts +165 -165
- package/templates/default/app/api/editor/photo/route.ts +49 -49
- package/templates/default/app/api/photo/route.ts +27 -27
- package/templates/default/app/api/submit/section/item/[slug]/route.ts +95 -95
- package/templates/default/app/api/submit/section/item/route.ts +56 -56
- package/templates/default/app/api/submit/section/simple/route.ts +86 -86
- package/templates/default/app/api/video/route.ts +174 -174
- package/templates/default/app/globals.css +236 -236
- package/templates/default/cms.config.ts +56 -56
- package/templates/default/components/admin/admin-card.tsx +165 -165
- package/templates/default/components/admin/admin-edit-page.tsx +124 -124
- package/templates/default/components/admin/admin-privilege-card.tsx +184 -184
- package/templates/default/components/admin/new-admin-form.tsx +172 -172
- package/templates/default/components/container-box.tsx +24 -24
- package/templates/default/components/dnd-kit/draggable.tsx +21 -21
- package/templates/default/components/dnd-kit/droppable.tsx +20 -20
- package/templates/default/components/dnd-kit/sortable-item.tsx +18 -18
- package/templates/default/components/feedback/error-component.tsx +16 -16
- package/templates/default/components/feedback/info-card.tsx +93 -93
- package/templates/default/components/feedback/loading-spinners.tsx +67 -67
- package/templates/default/components/feedback/modal.tsx +166 -166
- package/templates/default/components/feedback/progress-bar.tsx +48 -48
- package/templates/default/components/feedback/tooltip-component.tsx +27 -27
- package/templates/default/components/form/form-input-element.tsx +70 -70
- package/templates/default/components/form/helpers/_section-hot-reload.js +1 -1
- package/templates/default/components/form/helpers/util.ts +17 -17
- package/templates/default/components/form/inputs/checkbox-form-input.tsx +46 -46
- package/templates/default/components/form/inputs/color-form-input.tsx +44 -44
- package/templates/default/components/form/inputs/date-form-input.tsx +93 -93
- package/templates/default/components/form/inputs/map-form-input.tsx +141 -141
- package/templates/default/components/form/inputs/multiple-select-form-input.tsx +85 -85
- package/templates/default/components/form/inputs/number-form-input.tsx +43 -43
- package/templates/default/components/form/inputs/password-form-input.tsx +47 -47
- package/templates/default/components/form/inputs/photo-form-input.tsx +279 -279
- package/templates/default/components/form/inputs/rich-text-form-input.tsx +148 -148
- package/templates/default/components/form/inputs/select-form-input.tsx +159 -159
- package/templates/default/components/form/inputs/slug-form-input.tsx +131 -131
- package/templates/default/components/form/inputs/tags-form-input.tsx +255 -255
- package/templates/default/components/form/inputs/text-form-input.tsx +61 -61
- package/templates/default/components/form/inputs/textarea-form-input.tsx +61 -61
- package/templates/default/components/layout/default-nav-items.tsx +3 -3
- package/templates/default/components/layout/layout.tsx +84 -84
- package/templates/default/components/layout/navbar.tsx +258 -258
- package/templates/default/components/layout/sidebar-dropdown-item.tsx +83 -83
- package/templates/default/components/layout/sidebar-item.tsx +24 -24
- package/templates/default/components/layout/sidebar.tsx +229 -229
- package/templates/default/components/layout/theme-provider.tsx +8 -8
- package/templates/default/components/layout/theme-toggle.tsx +39 -39
- package/templates/default/components/locale/locale-switcher.tsx +98 -98
- package/templates/default/components/media/dropzone.tsx +154 -154
- package/templates/default/components/media/protected-document.tsx +44 -44
- package/templates/default/components/media/protected-image.tsx +143 -143
- package/templates/default/components/media/protected-video.tsx +76 -76
- package/templates/default/components/multi-select.tsx +1150 -1150
- package/templates/default/components/pages/admins-page.tsx +43 -43
- package/templates/default/components/pages/browse-page.tsx +106 -106
- package/templates/default/components/pages/categorized-section-page.tsx +31 -31
- package/templates/default/components/pages/dashboard-page-alt.tsx +45 -45
- package/templates/default/components/pages/item-edit-page.tsx +267 -267
- package/templates/default/components/pages/log-page.tsx +107 -107
- package/templates/default/components/pages/new-page.tsx +183 -183
- package/templates/default/components/pages/section-page.tsx +203 -203
- package/templates/default/components/pages/settings-page.tsx +232 -232
- package/templates/default/components/pagination/pagination-buttons.tsx +147 -147
- package/templates/default/components/pagination/pagination.tsx +36 -36
- package/templates/default/components/sections/category-delete-confirm-page.tsx +130 -130
- package/templates/default/components/sections/category-section-select-input.tsx +139 -139
- package/templates/default/components/sections/conditional-fields.tsx +49 -49
- package/templates/default/components/sections/section-icon.tsx +8 -8
- package/templates/default/components/sections/section-item-card.tsx +143 -143
- package/templates/default/components/sections/section-item-status-badge.tsx +17 -17
- package/templates/default/components/sections/select-input-buttons.tsx +125 -125
- package/templates/default/components/select-box.tsx +98 -98
- package/templates/default/components/ui/accordion.tsx +53 -53
- package/templates/default/components/ui/alert-dialog.tsx +113 -113
- package/templates/default/components/ui/alert.tsx +47 -47
- package/templates/default/components/ui/badge.tsx +38 -38
- package/templates/default/components/ui/card.tsx +43 -43
- package/templates/default/components/ui/command.tsx +137 -137
- package/templates/default/components/ui/custom-alert-dialog.tsx +113 -113
- package/templates/default/components/ui/custom-dialog.tsx +123 -123
- package/templates/default/components/ui/dialog.tsx +123 -123
- package/templates/default/components/ui/direction.tsx +22 -22
- package/templates/default/components/ui/dropdown-menu.tsx +182 -182
- package/templates/default/components/ui/input-group.tsx +54 -54
- package/templates/default/components/ui/input.tsx +22 -22
- package/templates/default/components/ui/label.tsx +19 -19
- package/templates/default/components/ui/popover.tsx +42 -42
- package/templates/default/components/ui/progress.tsx +31 -31
- package/templates/default/components/ui/scroll-area.tsx +42 -42
- package/templates/default/components/ui/select.tsx +165 -165
- package/templates/default/components/ui/separator.tsx +28 -28
- package/templates/default/components/ui/sheet.tsx +103 -103
- package/templates/default/components/ui/spinner.tsx +16 -16
- package/templates/default/components/ui/switch.tsx +29 -29
- package/templates/default/components/ui/table.tsx +83 -83
- package/templates/default/components/ui/tabs.tsx +55 -55
- package/templates/default/components/ui/toast.tsx +113 -113
- package/templates/default/components/ui/toaster.tsx +35 -35
- package/templates/default/components/ui/tooltip.tsx +30 -30
- package/templates/default/components/ui/use-toast.ts +187 -187
- package/templates/default/drizzle.config.ts +4 -4
- package/templates/default/dynamic-schemas/schema.ts +75 -225
- package/templates/default/env/env.ts +46 -46
- package/templates/default/envConfig.ts +4 -4
- package/templates/default/lib/postinstall.js +14 -14
- package/templates/default/lib/utils.ts +6 -6
- package/templates/default/next-env.d.ts +6 -6
- package/templates/default/next.config.ts +24 -24
- package/templates/default/package.json +1 -1
- package/templates/default/postcss.config.mjs +6 -6
- package/templates/default/proxy.ts +32 -32
- package/templates/default/tsconfig.json +48 -48
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import React, { useEffect } from 'react'
|
|
2
|
-
import { APIProvider, Map, Marker } from '@vis.gl/react-google-maps'
|
|
3
|
-
import ContainerBox from '@/components/container-box'
|
|
4
|
-
import { Button } from '@/components/ui/button'
|
|
5
|
-
import TooltipComponent from '@/components/feedback/tooltip-component'
|
|
6
|
-
import { useI18n } from 'nextjs-cms/translations/client'
|
|
7
|
-
import { MapFieldClientConfig } from 'nextjs-cms/core/fields'
|
|
8
|
-
import { useController, useFormContext } from 'react-hook-form'
|
|
9
|
-
import FormInputElement from '@/components/form/form-input-element'
|
|
10
|
-
import { env } from '@/env/env'
|
|
11
|
-
|
|
12
|
-
export default function MapFormInput({ input }: { input: MapFieldClientConfig }) {
|
|
13
|
-
const t = useI18n()
|
|
14
|
-
const { control } = useFormContext()
|
|
15
|
-
const {
|
|
16
|
-
field,
|
|
17
|
-
fieldState: { invalid, isTouched, isDirty, error },
|
|
18
|
-
} = useController({
|
|
19
|
-
name: input.name,
|
|
20
|
-
control,
|
|
21
|
-
defaultValue: input.value ?? undefined,
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const [coords, setCoords] = React.useState<
|
|
25
|
-
| {
|
|
26
|
-
lat: number
|
|
27
|
-
lng: number
|
|
28
|
-
}
|
|
29
|
-
| undefined
|
|
30
|
-
>(() => {
|
|
31
|
-
if (input.value?.lat && input.value?.lng) {
|
|
32
|
-
return {
|
|
33
|
-
lat: input.value.lat,
|
|
34
|
-
lng: input.value.lng,
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
field.onChange(coords ? `${coords.lat},${coords.lng}` : undefined)
|
|
41
|
-
}, [coords])
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<FormInputElement
|
|
45
|
-
validationError={error}
|
|
46
|
-
value={
|
|
47
|
-
<span>
|
|
48
|
-
{input.value?.lat}, {input.value?.lng}
|
|
49
|
-
</span>
|
|
50
|
-
}
|
|
51
|
-
readonly={input.readonly}
|
|
52
|
-
label={input.label}
|
|
53
|
-
required={input.required}
|
|
54
|
-
>
|
|
55
|
-
<ContainerBox>
|
|
56
|
-
<div className='relative h-[500px] w-full overflow-hidden rounded-xl outline-0'>
|
|
57
|
-
<input
|
|
58
|
-
type='hidden'
|
|
59
|
-
value={coords ? `${coords.lat},${coords.lng}` : ''}
|
|
60
|
-
disabled={field.disabled}
|
|
61
|
-
name={field.name}
|
|
62
|
-
onChange={field.onChange}
|
|
63
|
-
onBlur={field.onBlur}
|
|
64
|
-
ref={field.ref}
|
|
65
|
-
/>
|
|
66
|
-
<APIProvider apiKey={env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? ''}>
|
|
67
|
-
<Map
|
|
68
|
-
clickableIcons={false}
|
|
69
|
-
zoomControl={true}
|
|
70
|
-
onClick={(e) => {
|
|
71
|
-
e.stop()
|
|
72
|
-
setCoords(() => {
|
|
73
|
-
if (e.detail.latLng) {
|
|
74
|
-
return {
|
|
75
|
-
lat: e.detail.latLng.lat,
|
|
76
|
-
lng: e.detail.latLng.lng,
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
}}
|
|
81
|
-
zoom={input.zoom}
|
|
82
|
-
minZoom={input.minZoom}
|
|
83
|
-
restriction={{
|
|
84
|
-
latLngBounds: input.latLngBounds,
|
|
85
|
-
strictBounds: true,
|
|
86
|
-
}}
|
|
87
|
-
center={input.value ? { lat: input.value.lat, lng: input.value.lng } : input.center}
|
|
88
|
-
gestureHandling={'greedy'}
|
|
89
|
-
disableDefaultUI={true}
|
|
90
|
-
>
|
|
91
|
-
{coords?.lat && coords?.lng ? (
|
|
92
|
-
<Marker position={{ lat: coords.lat, lng: coords.lng }} />
|
|
93
|
-
) : null}
|
|
94
|
-
</Map>
|
|
95
|
-
</APIProvider>
|
|
96
|
-
</div>
|
|
97
|
-
|
|
98
|
-
<div className='my-2 flex flex-wrap gap-2'>
|
|
99
|
-
<Button
|
|
100
|
-
type='button'
|
|
101
|
-
size={'sm'}
|
|
102
|
-
disabled={!coords?.lat || !coords?.lng}
|
|
103
|
-
variant='default'
|
|
104
|
-
onClick={(e) => {
|
|
105
|
-
e.preventDefault()
|
|
106
|
-
e.stopPropagation()
|
|
107
|
-
setCoords(undefined)
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
{t('removeMarker')}
|
|
111
|
-
</Button>
|
|
112
|
-
<TooltipComponent
|
|
113
|
-
delayDuration={100}
|
|
114
|
-
content={!(input.value?.lat && input.value?.lng) ? t('restoreMarkerTooltip') : null}
|
|
115
|
-
>
|
|
116
|
-
<Button
|
|
117
|
-
type='button'
|
|
118
|
-
size={'sm'}
|
|
119
|
-
disabled={!(input.value?.lat && input.value?.lng)}
|
|
120
|
-
variant='default'
|
|
121
|
-
onClick={(e) => {
|
|
122
|
-
e.preventDefault()
|
|
123
|
-
e.stopPropagation()
|
|
124
|
-
setCoords(() => {
|
|
125
|
-
if (input.value?.lat && input.value?.lng) {
|
|
126
|
-
return {
|
|
127
|
-
lat: input.value.lat,
|
|
128
|
-
lng: input.value.lng,
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
})
|
|
132
|
-
}}
|
|
133
|
-
>
|
|
134
|
-
{t('restoreMarker')}
|
|
135
|
-
</Button>
|
|
136
|
-
</TooltipComponent>
|
|
137
|
-
</div>
|
|
138
|
-
</ContainerBox>
|
|
139
|
-
</FormInputElement>
|
|
140
|
-
)
|
|
141
|
-
}
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
|
+
import { APIProvider, Map, Marker } from '@vis.gl/react-google-maps'
|
|
3
|
+
import ContainerBox from '@/components/container-box'
|
|
4
|
+
import { Button } from '@/components/ui/button'
|
|
5
|
+
import TooltipComponent from '@/components/feedback/tooltip-component'
|
|
6
|
+
import { useI18n } from 'nextjs-cms/translations/client'
|
|
7
|
+
import { MapFieldClientConfig } from 'nextjs-cms/core/fields'
|
|
8
|
+
import { useController, useFormContext } from 'react-hook-form'
|
|
9
|
+
import FormInputElement from '@/components/form/form-input-element'
|
|
10
|
+
import { env } from '@/env/env'
|
|
11
|
+
|
|
12
|
+
export default function MapFormInput({ input }: { input: MapFieldClientConfig }) {
|
|
13
|
+
const t = useI18n()
|
|
14
|
+
const { control } = useFormContext()
|
|
15
|
+
const {
|
|
16
|
+
field,
|
|
17
|
+
fieldState: { invalid, isTouched, isDirty, error },
|
|
18
|
+
} = useController({
|
|
19
|
+
name: input.name,
|
|
20
|
+
control,
|
|
21
|
+
defaultValue: input.value ?? undefined,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const [coords, setCoords] = React.useState<
|
|
25
|
+
| {
|
|
26
|
+
lat: number
|
|
27
|
+
lng: number
|
|
28
|
+
}
|
|
29
|
+
| undefined
|
|
30
|
+
>(() => {
|
|
31
|
+
if (input.value?.lat && input.value?.lng) {
|
|
32
|
+
return {
|
|
33
|
+
lat: input.value.lat,
|
|
34
|
+
lng: input.value.lng,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
field.onChange(coords ? `${coords.lat},${coords.lng}` : undefined)
|
|
41
|
+
}, [coords])
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<FormInputElement
|
|
45
|
+
validationError={error}
|
|
46
|
+
value={
|
|
47
|
+
<span>
|
|
48
|
+
{input.value?.lat}, {input.value?.lng}
|
|
49
|
+
</span>
|
|
50
|
+
}
|
|
51
|
+
readonly={input.readonly}
|
|
52
|
+
label={input.label}
|
|
53
|
+
required={input.required}
|
|
54
|
+
>
|
|
55
|
+
<ContainerBox>
|
|
56
|
+
<div className='relative h-[500px] w-full overflow-hidden rounded-xl outline-0'>
|
|
57
|
+
<input
|
|
58
|
+
type='hidden'
|
|
59
|
+
value={coords ? `${coords.lat},${coords.lng}` : ''}
|
|
60
|
+
disabled={field.disabled}
|
|
61
|
+
name={field.name}
|
|
62
|
+
onChange={field.onChange}
|
|
63
|
+
onBlur={field.onBlur}
|
|
64
|
+
ref={field.ref}
|
|
65
|
+
/>
|
|
66
|
+
<APIProvider apiKey={env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? ''}>
|
|
67
|
+
<Map
|
|
68
|
+
clickableIcons={false}
|
|
69
|
+
zoomControl={true}
|
|
70
|
+
onClick={(e) => {
|
|
71
|
+
e.stop()
|
|
72
|
+
setCoords(() => {
|
|
73
|
+
if (e.detail.latLng) {
|
|
74
|
+
return {
|
|
75
|
+
lat: e.detail.latLng.lat,
|
|
76
|
+
lng: e.detail.latLng.lng,
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
}}
|
|
81
|
+
zoom={input.zoom}
|
|
82
|
+
minZoom={input.minZoom}
|
|
83
|
+
restriction={{
|
|
84
|
+
latLngBounds: input.latLngBounds,
|
|
85
|
+
strictBounds: true,
|
|
86
|
+
}}
|
|
87
|
+
center={input.value ? { lat: input.value.lat, lng: input.value.lng } : input.center}
|
|
88
|
+
gestureHandling={'greedy'}
|
|
89
|
+
disableDefaultUI={true}
|
|
90
|
+
>
|
|
91
|
+
{coords?.lat && coords?.lng ? (
|
|
92
|
+
<Marker position={{ lat: coords.lat, lng: coords.lng }} />
|
|
93
|
+
) : null}
|
|
94
|
+
</Map>
|
|
95
|
+
</APIProvider>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<div className='my-2 flex flex-wrap gap-2'>
|
|
99
|
+
<Button
|
|
100
|
+
type='button'
|
|
101
|
+
size={'sm'}
|
|
102
|
+
disabled={!coords?.lat || !coords?.lng}
|
|
103
|
+
variant='default'
|
|
104
|
+
onClick={(e) => {
|
|
105
|
+
e.preventDefault()
|
|
106
|
+
e.stopPropagation()
|
|
107
|
+
setCoords(undefined)
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
{t('removeMarker')}
|
|
111
|
+
</Button>
|
|
112
|
+
<TooltipComponent
|
|
113
|
+
delayDuration={100}
|
|
114
|
+
content={!(input.value?.lat && input.value?.lng) ? t('restoreMarkerTooltip') : null}
|
|
115
|
+
>
|
|
116
|
+
<Button
|
|
117
|
+
type='button'
|
|
118
|
+
size={'sm'}
|
|
119
|
+
disabled={!(input.value?.lat && input.value?.lng)}
|
|
120
|
+
variant='default'
|
|
121
|
+
onClick={(e) => {
|
|
122
|
+
e.preventDefault()
|
|
123
|
+
e.stopPropagation()
|
|
124
|
+
setCoords(() => {
|
|
125
|
+
if (input.value?.lat && input.value?.lng) {
|
|
126
|
+
return {
|
|
127
|
+
lat: input.value.lat,
|
|
128
|
+
lng: input.value.lng,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}}
|
|
133
|
+
>
|
|
134
|
+
{t('restoreMarker')}
|
|
135
|
+
</Button>
|
|
136
|
+
</TooltipComponent>
|
|
137
|
+
</div>
|
|
138
|
+
</ContainerBox>
|
|
139
|
+
</FormInputElement>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import FormInputElement from '@/components/form/form-input-element'
|
|
2
|
-
import { useEffect, useState } from 'react'
|
|
3
|
-
import { SelectMultipleFieldClientConfig, SelectOption } from 'nextjs-cms/core/fields'
|
|
4
|
-
import { useController, useFormContext } from 'react-hook-form'
|
|
5
|
-
import { MultiSelect, MultiSelectOption } from '@/components/multi-select'
|
|
6
|
-
import { useI18n } from 'nextjs-cms/translations/client'
|
|
7
|
-
|
|
8
|
-
export default function MultipleSelectFormInput({ input }: { input: SelectMultipleFieldClientConfig }) {
|
|
9
|
-
const t = useI18n()
|
|
10
|
-
const { control } = useFormContext()
|
|
11
|
-
const {
|
|
12
|
-
field,
|
|
13
|
-
fieldState: { invalid, isTouched, isDirty, error },
|
|
14
|
-
} = useController({
|
|
15
|
-
name: input.name,
|
|
16
|
-
control,
|
|
17
|
-
defaultValue: input.value,
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const [value, setValue] = useState<SelectOption[] | undefined>([])
|
|
21
|
-
|
|
22
|
-
// Convert SelectOption[] to MultiSelectOption[]
|
|
23
|
-
const convertToMultiSelectOptions = (options: SelectOption[] | undefined): MultiSelectOption[] => {
|
|
24
|
-
if (!options) return []
|
|
25
|
-
return options.map((option) => ({
|
|
26
|
-
label: option.label.toString(),
|
|
27
|
-
value: option.value.toString(),
|
|
28
|
-
}))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Convert string[] to SelectOption[]
|
|
32
|
-
const convertFromStringArray = (values: string[], options: SelectOption[] | undefined): SelectOption[] => {
|
|
33
|
-
if (!options || !values) return []
|
|
34
|
-
return values
|
|
35
|
-
.map((value) => options.find((option) => option.value.toString() === value))
|
|
36
|
-
.filter(Boolean) as SelectOption[]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Convert SelectOption[] to string[]
|
|
40
|
-
const convertToStringArray = (options: SelectOption[] | undefined): string[] => {
|
|
41
|
-
if (!options) return []
|
|
42
|
-
return options.map((option) => option.value.toString())
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
if (input.value && input.value?.length > 0) {
|
|
47
|
-
setValue(input.value)
|
|
48
|
-
}
|
|
49
|
-
}, [input.value])
|
|
50
|
-
|
|
51
|
-
const multiSelectOptions = convertToMultiSelectOptions(input.options)
|
|
52
|
-
const currentValue = convertToStringArray(field.value || [])
|
|
53
|
-
|
|
54
|
-
const handleValueChange = (newValues: string[]) => {
|
|
55
|
-
const selectOptions = convertFromStringArray(newValues, input.options)
|
|
56
|
-
field.onChange(selectOptions)
|
|
57
|
-
setValue(selectOptions)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<FormInputElement validationError={error} label={input.label} required={input.required}>
|
|
62
|
-
<input
|
|
63
|
-
type='hidden'
|
|
64
|
-
className='hidden'
|
|
65
|
-
disabled={field.disabled}
|
|
66
|
-
name={field.name}
|
|
67
|
-
onBlur={field.onBlur}
|
|
68
|
-
ref={field.ref}
|
|
69
|
-
value={JSON.stringify(field.value)}
|
|
70
|
-
/>
|
|
71
|
-
|
|
72
|
-
<MultiSelect
|
|
73
|
-
hideSelectAll={true}
|
|
74
|
-
variant='default'
|
|
75
|
-
maxCount={100}
|
|
76
|
-
options={multiSelectOptions}
|
|
77
|
-
onValueChange={handleValueChange}
|
|
78
|
-
defaultValue={currentValue}
|
|
79
|
-
placeholder={t('selectOptions') as string}
|
|
80
|
-
disabled={field.disabled}
|
|
81
|
-
className='w-full py-3 ring-2 ring-gray-300'
|
|
82
|
-
/>
|
|
83
|
-
</FormInputElement>
|
|
84
|
-
)
|
|
85
|
-
}
|
|
1
|
+
import FormInputElement from '@/components/form/form-input-element'
|
|
2
|
+
import { useEffect, useState } from 'react'
|
|
3
|
+
import { SelectMultipleFieldClientConfig, SelectOption } from 'nextjs-cms/core/fields'
|
|
4
|
+
import { useController, useFormContext } from 'react-hook-form'
|
|
5
|
+
import { MultiSelect, MultiSelectOption } from '@/components/multi-select'
|
|
6
|
+
import { useI18n } from 'nextjs-cms/translations/client'
|
|
7
|
+
|
|
8
|
+
export default function MultipleSelectFormInput({ input }: { input: SelectMultipleFieldClientConfig }) {
|
|
9
|
+
const t = useI18n()
|
|
10
|
+
const { control } = useFormContext()
|
|
11
|
+
const {
|
|
12
|
+
field,
|
|
13
|
+
fieldState: { invalid, isTouched, isDirty, error },
|
|
14
|
+
} = useController({
|
|
15
|
+
name: input.name,
|
|
16
|
+
control,
|
|
17
|
+
defaultValue: input.value,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const [value, setValue] = useState<SelectOption[] | undefined>([])
|
|
21
|
+
|
|
22
|
+
// Convert SelectOption[] to MultiSelectOption[]
|
|
23
|
+
const convertToMultiSelectOptions = (options: SelectOption[] | undefined): MultiSelectOption[] => {
|
|
24
|
+
if (!options) return []
|
|
25
|
+
return options.map((option) => ({
|
|
26
|
+
label: option.label.toString(),
|
|
27
|
+
value: option.value.toString(),
|
|
28
|
+
}))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Convert string[] to SelectOption[]
|
|
32
|
+
const convertFromStringArray = (values: string[], options: SelectOption[] | undefined): SelectOption[] => {
|
|
33
|
+
if (!options || !values) return []
|
|
34
|
+
return values
|
|
35
|
+
.map((value) => options.find((option) => option.value.toString() === value))
|
|
36
|
+
.filter(Boolean) as SelectOption[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Convert SelectOption[] to string[]
|
|
40
|
+
const convertToStringArray = (options: SelectOption[] | undefined): string[] => {
|
|
41
|
+
if (!options) return []
|
|
42
|
+
return options.map((option) => option.value.toString())
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (input.value && input.value?.length > 0) {
|
|
47
|
+
setValue(input.value)
|
|
48
|
+
}
|
|
49
|
+
}, [input.value])
|
|
50
|
+
|
|
51
|
+
const multiSelectOptions = convertToMultiSelectOptions(input.options)
|
|
52
|
+
const currentValue = convertToStringArray(field.value || [])
|
|
53
|
+
|
|
54
|
+
const handleValueChange = (newValues: string[]) => {
|
|
55
|
+
const selectOptions = convertFromStringArray(newValues, input.options)
|
|
56
|
+
field.onChange(selectOptions)
|
|
57
|
+
setValue(selectOptions)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<FormInputElement validationError={error} label={input.label} required={input.required}>
|
|
62
|
+
<input
|
|
63
|
+
type='hidden'
|
|
64
|
+
className='hidden'
|
|
65
|
+
disabled={field.disabled}
|
|
66
|
+
name={field.name}
|
|
67
|
+
onBlur={field.onBlur}
|
|
68
|
+
ref={field.ref}
|
|
69
|
+
value={JSON.stringify(field.value)}
|
|
70
|
+
/>
|
|
71
|
+
|
|
72
|
+
<MultiSelect
|
|
73
|
+
hideSelectAll={true}
|
|
74
|
+
variant='default'
|
|
75
|
+
maxCount={100}
|
|
76
|
+
options={multiSelectOptions}
|
|
77
|
+
onValueChange={handleValueChange}
|
|
78
|
+
defaultValue={currentValue}
|
|
79
|
+
placeholder={t('selectOptions') as string}
|
|
80
|
+
disabled={field.disabled}
|
|
81
|
+
className='w-full py-3 ring-2 ring-gray-300'
|
|
82
|
+
/>
|
|
83
|
+
</FormInputElement>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import FormInputElement from '@/components/form/form-input-element'
|
|
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
|
-
dir={input.rtl !== undefined ? (input.rtl ? 'rtl' : 'ltr') : undefined}
|
|
30
|
-
readOnly={field.disabled}
|
|
31
|
-
disabled={field.disabled}
|
|
32
|
-
name={field.name}
|
|
33
|
-
onChange={(event) =>
|
|
34
|
-
event.target.value ? field.onChange(toNumber(event.target.value)) : field.onChange(NaN)
|
|
35
|
-
}
|
|
36
|
-
onBlur={field.onBlur}
|
|
37
|
-
value={field.value ?? ''}
|
|
38
|
-
ref={field.ref}
|
|
39
|
-
className='w-full rounded bg-input p-3 text-foreground shadow-xs outline-0 ring-2 ring-gray-300 hover:ring-gray-400 focus:ring-blue-500'
|
|
40
|
-
/>
|
|
41
|
-
</FormInputElement>
|
|
42
|
-
)
|
|
43
|
-
}
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import FormInputElement from '@/components/form/form-input-element'
|
|
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
|
+
dir={input.rtl !== undefined ? (input.rtl ? 'rtl' : 'ltr') : undefined}
|
|
30
|
+
readOnly={field.disabled}
|
|
31
|
+
disabled={field.disabled}
|
|
32
|
+
name={field.name}
|
|
33
|
+
onChange={(event) =>
|
|
34
|
+
event.target.value ? field.onChange(toNumber(event.target.value)) : field.onChange(NaN)
|
|
35
|
+
}
|
|
36
|
+
onBlur={field.onBlur}
|
|
37
|
+
value={field.value ?? ''}
|
|
38
|
+
ref={field.ref}
|
|
39
|
+
className='w-full rounded bg-input p-3 text-foreground shadow-xs outline-0 ring-2 ring-gray-300 hover:ring-gray-400 focus:ring-blue-500'
|
|
40
|
+
/>
|
|
41
|
+
</FormInputElement>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import FormInputElement from '@/components/form/form-input-element'
|
|
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-xs outline-0 ring-2 ring-gray-300 hover:ring-gray-400 focus:ring-blue-500'
|
|
44
|
-
/>
|
|
45
|
-
</FormInputElement>
|
|
46
|
-
)
|
|
47
|
-
}
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import FormInputElement from '@/components/form/form-input-element'
|
|
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-xs outline-0 ring-2 ring-gray-300 hover:ring-gray-400 focus:ring-blue-500'
|
|
44
|
+
/>
|
|
45
|
+
</FormInputElement>
|
|
46
|
+
)
|
|
47
|
+
}
|