stuff done
This commit is contained in:
43
lib/schemas/admin/entity.ts
Normal file
43
lib/schemas/admin/entity.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import {Entity, EntityLocale, EntityType} from '@prisma/client'
|
||||
import {z} from 'zod'
|
||||
|
||||
import {i18nLocalesCodes} from '@/i18n-config'
|
||||
import {metaFormSchema} from '@/lib/schemas/meta'
|
||||
|
||||
interface Map {
|
||||
[key: string]: string | undefined
|
||||
}
|
||||
|
||||
export const EntityTypeDescription: Map = {
|
||||
article: 'Стаття',
|
||||
page: 'Сторінка',
|
||||
block: 'Блок'
|
||||
}
|
||||
//
|
||||
export type EntityTerm = Entity & {locales: EntityLocale}
|
||||
|
||||
export const entityLocaleSchema = z.object({
|
||||
lang: z.enum(i18nLocalesCodes),
|
||||
title: z.coerce.string().trim().min(1).max(384),
|
||||
annotation: z.coerce.string().trim().optional(),
|
||||
body: z.coerce.string().trim().optional()
|
||||
})
|
||||
|
||||
export const createEntityFormSchema = z.object({
|
||||
type: z.enum(Object.keys(EntityType) as [string, ...string[]], {
|
||||
message: "Обов'язкове до вибору"
|
||||
}), // ProductToStore
|
||||
published: z.coerce.boolean().default(false).optional(), // ProductToStore
|
||||
scopes: z.coerce.string().trim().optional(),
|
||||
slug: z.coerce
|
||||
.string()
|
||||
.trim()
|
||||
.max(512)
|
||||
.regex(/^[a-z0-9-]+$/, {
|
||||
message: 'тільки латинські символи, цифри та дефіс'
|
||||
})
|
||||
.optional(),
|
||||
media: z.coerce.string().trim().max(512).optional(),
|
||||
locales: z.array(entityLocaleSchema),
|
||||
meta: z.array(metaFormSchema)
|
||||
})
|
||||
Reference in New Issue
Block a user