create-nextjs-cms 0.9.28 → 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 +2 -2
- 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,140 +1,140 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react'
|
|
2
|
-
import FormInputElement from '@/components/form/form-input-element'
|
|
3
|
-
import SelectBox from '@/components/select-box'
|
|
4
|
-
import LoadingSpinners from '@/components/feedback/loading-spinners'
|
|
5
|
-
import { useAutoAnimate } from '@formkit/auto-animate/react'
|
|
6
|
-
import SelectInputButtons from '@/components/sections/select-input-buttons'
|
|
7
|
-
import { useI18n } from 'nextjs-cms/translations/client'
|
|
8
|
-
import { trpc } from '@/app/_trpc/client'
|
|
9
|
-
import { SelectOption } from 'nextjs-cms/core/fields'
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
|
+
import FormInputElement from '@/components/form/form-input-element'
|
|
3
|
+
import SelectBox from '@/components/select-box'
|
|
4
|
+
import LoadingSpinners from '@/components/feedback/loading-spinners'
|
|
5
|
+
import { useAutoAnimate } from '@formkit/auto-animate/react'
|
|
6
|
+
import SelectInputButtons from '@/components/sections/select-input-buttons'
|
|
7
|
+
import { useI18n } from 'nextjs-cms/translations/client'
|
|
8
|
+
import { trpc } from '@/app/_trpc/client'
|
|
9
|
+
import { SelectOption } from 'nextjs-cms/core/fields'
|
|
10
10
|
import type { RouterOutputs } from '@/app/_trpc/types'
|
|
11
|
-
import { nanoid } from 'nanoid'
|
|
12
|
-
|
|
13
|
-
type CategorySelect = RouterOutputs['categorySections']['get']['data']
|
|
14
|
-
|
|
15
|
-
export default function CategorySectionSelectInput({
|
|
16
|
-
input,
|
|
17
|
-
refetch,
|
|
18
|
-
isChild = false,
|
|
19
|
-
}: {
|
|
20
|
-
input: CategorySelect
|
|
21
|
-
refetch?: any
|
|
22
|
-
isChild?: boolean
|
|
23
|
-
}) {
|
|
24
|
-
const t = useI18n()
|
|
25
|
-
/**
|
|
26
|
-
* Check and add the select option if it does not exist, the select option has a value of undefined
|
|
27
|
-
*/
|
|
28
|
-
const exists = input?.options?.filter((option) => option.value === undefined)
|
|
29
|
-
if (!exists || exists.length === 0) {
|
|
30
|
-
if (input?.options) {
|
|
31
|
-
// @ts-ignore - This is a type-hack to add the placeholder `select` option to the options array
|
|
32
|
-
input.options.unshift({ value: undefined, label: t('select') })
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const [parent, enableAnimations] = useAutoAnimate(/* optional config */)
|
|
37
|
-
const [isLoading, setIsLoading] = useState<boolean>(false)
|
|
38
|
-
const [hasMounted, setHasMounted] = useState<boolean>(false)
|
|
39
|
-
const [value, setValue] = useState<string | number | undefined>(/*getValue(input?.value)*/)
|
|
40
|
-
const [child, setChild] = useState<CategorySelect | null>(null)
|
|
41
|
-
const [randomKey, setRandomKey] = useState<string>(nanoid())
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (input) {
|
|
45
|
-
setChild(null)
|
|
46
|
-
if (input.depth && input.depth <= 1) return
|
|
47
|
-
if (value === undefined) {
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
setIsLoading(true)
|
|
51
|
-
childrenMutation.mutate({
|
|
52
|
-
parentId: value,
|
|
53
|
-
sectionName: input.sectionName,
|
|
54
|
-
level: input.level,
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
}, [value])
|
|
58
|
-
|
|
59
|
-
if (!input) return null
|
|
60
|
-
|
|
61
|
-
const childrenMutation = trpc.categorySections.getChildren.useMutation({
|
|
62
|
-
onSuccess: (data) => {
|
|
63
|
-
if (data && data.options) {
|
|
64
|
-
const childInput: CategorySelect = {
|
|
65
|
-
parentId: data.parentId,
|
|
66
|
-
sectionName: input.sectionName,
|
|
67
|
-
required: input.required,
|
|
68
|
-
label: input.label,
|
|
69
|
-
name: input.name,
|
|
70
|
-
options: data.options,
|
|
71
|
-
level: data.level,
|
|
72
|
-
depth: input.depth,
|
|
73
|
-
value: hasMounted ? undefined : input.value,
|
|
74
|
-
allowRecursiveDelete: input.allowRecursiveDelete,
|
|
75
|
-
}
|
|
76
|
-
setChild(childInput)
|
|
77
|
-
} else {
|
|
78
|
-
setChild(null)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
setIsLoading(false)
|
|
82
|
-
setHasMounted(true)
|
|
83
|
-
},
|
|
84
|
-
onError: (error) => {},
|
|
85
|
-
// console.log('Error', error)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<>
|
|
90
|
-
{/* @ts-ignore no need for validations in this case */}
|
|
91
|
-
<FormInputElement label={isChild ? '|->' : input.label} required={input.required}>
|
|
92
|
-
<SelectBox
|
|
93
|
-
// The key is to tell react to re-render the select
|
|
94
|
-
// box whenever we change the randomKey value
|
|
95
|
-
// (we're doing this after deleting an item from the select)
|
|
96
|
-
key={randomKey}
|
|
97
|
-
items={input.options ? input.options : []}
|
|
98
|
-
onChange={(value: SelectOption | undefined) => {
|
|
99
|
-
setValue(value?.value)
|
|
100
|
-
}}
|
|
101
|
-
classname='w-full shadow-xs'
|
|
102
|
-
/>
|
|
103
|
-
|
|
104
|
-
<SelectInputButtons
|
|
105
|
-
value={value}
|
|
106
|
-
level={input.level}
|
|
107
|
-
sectionTitle={input.label}
|
|
108
|
-
section={input.name}
|
|
109
|
-
parentId={input.parentId}
|
|
110
|
-
refetch={() => {
|
|
111
|
-
refetch()
|
|
112
|
-
}}
|
|
113
|
-
reset={() => {
|
|
114
|
-
setValue(undefined)
|
|
115
|
-
setRandomKey(nanoid())
|
|
116
|
-
}}
|
|
117
|
-
allowRecursiveDelete={input.allowRecursiveDelete ?? false}
|
|
118
|
-
/>
|
|
119
|
-
</FormInputElement>
|
|
120
|
-
<div ref={parent}>
|
|
121
|
-
{isLoading && <LoadingSpinners />}
|
|
122
|
-
{child && (
|
|
123
|
-
<div className='ps-4'>
|
|
124
|
-
<CategorySectionSelectInput
|
|
125
|
-
refetch={() => {
|
|
126
|
-
childrenMutation.mutate({
|
|
127
|
-
parentId: value,
|
|
128
|
-
sectionName: input.sectionName,
|
|
129
|
-
level: input.level,
|
|
130
|
-
})
|
|
131
|
-
}}
|
|
132
|
-
isChild={true}
|
|
133
|
-
input={child}
|
|
134
|
-
/>
|
|
135
|
-
</div>
|
|
136
|
-
)}
|
|
137
|
-
</div>
|
|
138
|
-
</>
|
|
139
|
-
)
|
|
140
|
-
}
|
|
11
|
+
import { nanoid } from 'nanoid'
|
|
12
|
+
|
|
13
|
+
type CategorySelect = RouterOutputs['categorySections']['get']['data']
|
|
14
|
+
|
|
15
|
+
export default function CategorySectionSelectInput({
|
|
16
|
+
input,
|
|
17
|
+
refetch,
|
|
18
|
+
isChild = false,
|
|
19
|
+
}: {
|
|
20
|
+
input: CategorySelect
|
|
21
|
+
refetch?: any
|
|
22
|
+
isChild?: boolean
|
|
23
|
+
}) {
|
|
24
|
+
const t = useI18n()
|
|
25
|
+
/**
|
|
26
|
+
* Check and add the select option if it does not exist, the select option has a value of undefined
|
|
27
|
+
*/
|
|
28
|
+
const exists = input?.options?.filter((option) => option.value === undefined)
|
|
29
|
+
if (!exists || exists.length === 0) {
|
|
30
|
+
if (input?.options) {
|
|
31
|
+
// @ts-ignore - This is a type-hack to add the placeholder `select` option to the options array
|
|
32
|
+
input.options.unshift({ value: undefined, label: t('select') })
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const [parent, enableAnimations] = useAutoAnimate(/* optional config */)
|
|
37
|
+
const [isLoading, setIsLoading] = useState<boolean>(false)
|
|
38
|
+
const [hasMounted, setHasMounted] = useState<boolean>(false)
|
|
39
|
+
const [value, setValue] = useState<string | number | undefined>(/*getValue(input?.value)*/)
|
|
40
|
+
const [child, setChild] = useState<CategorySelect | null>(null)
|
|
41
|
+
const [randomKey, setRandomKey] = useState<string>(nanoid())
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (input) {
|
|
45
|
+
setChild(null)
|
|
46
|
+
if (input.depth && input.depth <= 1) return
|
|
47
|
+
if (value === undefined) {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
setIsLoading(true)
|
|
51
|
+
childrenMutation.mutate({
|
|
52
|
+
parentId: value,
|
|
53
|
+
sectionName: input.sectionName,
|
|
54
|
+
level: input.level,
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
}, [value])
|
|
58
|
+
|
|
59
|
+
if (!input) return null
|
|
60
|
+
|
|
61
|
+
const childrenMutation = trpc.categorySections.getChildren.useMutation({
|
|
62
|
+
onSuccess: (data) => {
|
|
63
|
+
if (data && data.options) {
|
|
64
|
+
const childInput: CategorySelect = {
|
|
65
|
+
parentId: data.parentId,
|
|
66
|
+
sectionName: input.sectionName,
|
|
67
|
+
required: input.required,
|
|
68
|
+
label: input.label,
|
|
69
|
+
name: input.name,
|
|
70
|
+
options: data.options,
|
|
71
|
+
level: data.level,
|
|
72
|
+
depth: input.depth,
|
|
73
|
+
value: hasMounted ? undefined : input.value,
|
|
74
|
+
allowRecursiveDelete: input.allowRecursiveDelete,
|
|
75
|
+
}
|
|
76
|
+
setChild(childInput)
|
|
77
|
+
} else {
|
|
78
|
+
setChild(null)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
setIsLoading(false)
|
|
82
|
+
setHasMounted(true)
|
|
83
|
+
},
|
|
84
|
+
onError: (error) => {},
|
|
85
|
+
// console.log('Error', error)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
{/* @ts-ignore no need for validations in this case */}
|
|
91
|
+
<FormInputElement label={isChild ? '|->' : input.label} required={input.required}>
|
|
92
|
+
<SelectBox
|
|
93
|
+
// The key is to tell react to re-render the select
|
|
94
|
+
// box whenever we change the randomKey value
|
|
95
|
+
// (we're doing this after deleting an item from the select)
|
|
96
|
+
key={randomKey}
|
|
97
|
+
items={input.options ? input.options : []}
|
|
98
|
+
onChange={(value: SelectOption | undefined) => {
|
|
99
|
+
setValue(value?.value)
|
|
100
|
+
}}
|
|
101
|
+
classname='w-full shadow-xs'
|
|
102
|
+
/>
|
|
103
|
+
|
|
104
|
+
<SelectInputButtons
|
|
105
|
+
value={value}
|
|
106
|
+
level={input.level}
|
|
107
|
+
sectionTitle={input.label}
|
|
108
|
+
section={input.name}
|
|
109
|
+
parentId={input.parentId}
|
|
110
|
+
refetch={() => {
|
|
111
|
+
refetch()
|
|
112
|
+
}}
|
|
113
|
+
reset={() => {
|
|
114
|
+
setValue(undefined)
|
|
115
|
+
setRandomKey(nanoid())
|
|
116
|
+
}}
|
|
117
|
+
allowRecursiveDelete={input.allowRecursiveDelete ?? false}
|
|
118
|
+
/>
|
|
119
|
+
</FormInputElement>
|
|
120
|
+
<div ref={parent}>
|
|
121
|
+
{isLoading && <LoadingSpinners />}
|
|
122
|
+
{child && (
|
|
123
|
+
<div className='ps-4'>
|
|
124
|
+
<CategorySectionSelectInput
|
|
125
|
+
refetch={() => {
|
|
126
|
+
childrenMutation.mutate({
|
|
127
|
+
parentId: value,
|
|
128
|
+
sectionName: input.sectionName,
|
|
129
|
+
level: input.level,
|
|
130
|
+
})
|
|
131
|
+
}}
|
|
132
|
+
isChild={true}
|
|
133
|
+
input={child}
|
|
134
|
+
/>
|
|
135
|
+
</div>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
</>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { FieldClientConfig } from 'nextjs-cms/core/fields'
|
|
2
|
-
import React, { useEffect, useState } from 'react'
|
|
3
|
-
import FormInputs from '@/components/form/form-inputs'
|
|
4
|
-
import { ConditionalField } from 'nextjs-cms/core/types'
|
|
5
|
-
|
|
6
|
-
export function ConditionalFields({
|
|
7
|
-
sectionName,
|
|
8
|
-
conditionalFields,
|
|
9
|
-
value,
|
|
10
|
-
}: {
|
|
11
|
-
sectionName: string
|
|
12
|
-
conditionalFields: ConditionalField[]
|
|
13
|
-
value: string | number | undefined
|
|
14
|
-
}) {
|
|
15
|
-
const [conditionalInputs, setConditionalInputs] = useState<FieldClientConfig[]>([])
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
if (!value) setConditionalInputs([])
|
|
19
|
-
// Check if the value is in the conditional inputs
|
|
20
|
-
const _conditionalFields: FieldClientConfig[] = []
|
|
21
|
-
conditionalFields.filter((conditionalField) => {
|
|
22
|
-
switch (conditionalField.rule.condition) {
|
|
23
|
-
case 'equals':
|
|
24
|
-
if (value?.toString() === conditionalField.rule.value.toString()) {
|
|
25
|
-
// Add the input to the conditional inputs
|
|
26
|
-
_conditionalFields.push(conditionalField.field)
|
|
27
|
-
}
|
|
28
|
-
break
|
|
29
|
-
case 'notEquals':
|
|
30
|
-
if (value?.toString() !== conditionalField.rule.value.toString()) {
|
|
31
|
-
// Add the input to the conditional inputs
|
|
32
|
-
_conditionalFields.push(conditionalField.field)
|
|
33
|
-
}
|
|
34
|
-
break
|
|
35
|
-
default:
|
|
36
|
-
return null
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
if (_conditionalFields && _conditionalFields.length > 0) {
|
|
40
|
-
setConditionalInputs(_conditionalFields)
|
|
41
|
-
} else {
|
|
42
|
-
setConditionalInputs([])
|
|
43
|
-
}
|
|
44
|
-
}, [value])
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<>{conditionalInputs.length > 0 ? <FormInputs inputs={conditionalInputs} sectionName={sectionName} /> : null}</>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
1
|
+
import { FieldClientConfig } from 'nextjs-cms/core/fields'
|
|
2
|
+
import React, { useEffect, useState } from 'react'
|
|
3
|
+
import FormInputs from '@/components/form/form-inputs'
|
|
4
|
+
import { ConditionalField } from 'nextjs-cms/core/types'
|
|
5
|
+
|
|
6
|
+
export function ConditionalFields({
|
|
7
|
+
sectionName,
|
|
8
|
+
conditionalFields,
|
|
9
|
+
value,
|
|
10
|
+
}: {
|
|
11
|
+
sectionName: string
|
|
12
|
+
conditionalFields: ConditionalField[]
|
|
13
|
+
value: string | number | undefined
|
|
14
|
+
}) {
|
|
15
|
+
const [conditionalInputs, setConditionalInputs] = useState<FieldClientConfig[]>([])
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!value) setConditionalInputs([])
|
|
19
|
+
// Check if the value is in the conditional inputs
|
|
20
|
+
const _conditionalFields: FieldClientConfig[] = []
|
|
21
|
+
conditionalFields.filter((conditionalField) => {
|
|
22
|
+
switch (conditionalField.rule.condition) {
|
|
23
|
+
case 'equals':
|
|
24
|
+
if (value?.toString() === conditionalField.rule.value.toString()) {
|
|
25
|
+
// Add the input to the conditional inputs
|
|
26
|
+
_conditionalFields.push(conditionalField.field)
|
|
27
|
+
}
|
|
28
|
+
break
|
|
29
|
+
case 'notEquals':
|
|
30
|
+
if (value?.toString() !== conditionalField.rule.value.toString()) {
|
|
31
|
+
// Add the input to the conditional inputs
|
|
32
|
+
_conditionalFields.push(conditionalField.field)
|
|
33
|
+
}
|
|
34
|
+
break
|
|
35
|
+
default:
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
if (_conditionalFields && _conditionalFields.length > 0) {
|
|
40
|
+
setConditionalInputs(_conditionalFields)
|
|
41
|
+
} else {
|
|
42
|
+
setConditionalInputs([])
|
|
43
|
+
}
|
|
44
|
+
}, [value])
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<>{conditionalInputs.length > 0 ? <FormInputs inputs={conditionalInputs} sectionName={sectionName} /> : null}</>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import {DynamicIcon} from 'lucide-react/dynamic'
|
|
4
|
-
import type { IconName } from 'lucide-react/dynamic'
|
|
5
|
-
|
|
6
|
-
export default function SectionIcon({ name, className }: { name: string; className?: string }) {
|
|
7
|
-
return <DynamicIcon name={name as IconName} className={className} />
|
|
8
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {DynamicIcon} from 'lucide-react/dynamic'
|
|
4
|
+
import type { IconName } from 'lucide-react/dynamic'
|
|
5
|
+
|
|
6
|
+
export default function SectionIcon({ name, className }: { name: string; className?: string }) {
|
|
7
|
+
return <DynamicIcon name={name as IconName} className={className} />
|
|
8
|
+
}
|