dify/web/app/components/datasets/metadata/hooks/use-check-metadata-name.ts
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

35 lines
742 B
TypeScript

import { useTranslation } from 'react-i18next'
const i18nPrefix = 'metadata.checkName'
const useCheckMetadataName = () => {
const { t } = useTranslation()
return {
checkName: (name: string) => {
if (!name) {
return {
errorMsg: t(($) => $[`${i18nPrefix}.empty`], { ns: 'dataset' }),
}
}
if (!/^[a-z][a-z0-9_]*$/.test(name)) {
return {
errorMsg: t(($) => $[`${i18nPrefix}.invalid`], { ns: 'dataset' }),
}
}
if (name.length > 255) {
return {
errorMsg: t(($) => $[`${i18nPrefix}.tooLong`], { ns: 'dataset', max: 255 }),
}
}
return {
errorMsg: '',
}
},
}
}
export default useCheckMetadataName