feat: hook up validators with input fields

This commit is contained in:
tdgao
2026-08-24 16:07:11 -06:00
parent 1ec4c6cef8
commit a23df8a355
12 changed files with 156 additions and 23 deletions
@@ -0,0 +1,42 @@
import { validateNonStandardText, validateProfanity } from '@modrinth/moderation'
import { defineMessages, type MessageDescriptor } from '@modrinth/ui'
export interface ProjectTextValidationResult {
severity: 'error'
message: MessageDescriptor
}
const messages = defineMessages({
slur: {
id: 'project.text-validation.slur',
defaultMessage: 'Slurs are not allowed.',
},
profanity: {
id: 'project.text-validation.profanity',
defaultMessage: 'Profanity is not allowed.',
},
nonStandardText: {
id: 'project.text-validation.non-standard-text',
defaultMessage: 'Non-standard text characters are not allowed.',
},
})
export function validateProjectText(
text: string | null | undefined,
): ProjectTextValidationResult | null {
if (!text) return null
const profanity = validateProfanity(text)
if (profanity.slurCount > 0) {
return { severity: 'error', message: messages.slur }
}
if (profanity.profanityCount > 0) {
return { severity: 'error', message: messages.profanity }
}
if (!validateNonStandardText(text).valid) {
return { severity: 'error', message: messages.nonStandardText }
}
return null
}