Skip to content

Commit

Permalink
♻️(frontend) make room pattern validation rules reusable
Browse files Browse the repository at this point in the history
Make the validation rules more maintainable and reusable across the codebase.
Particularly useful when these values need to be referenced in multiple
validation contexts.

The personalize room's link modal needs a step-by-step validation.
  • Loading branch information
lebaudantoine committed Jan 21, 2025
1 parent 9b60404 commit 69457a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
TextField,
} from 'react-aria-components'
import { css } from '@/styled-system/css'
import {
MIN_ROOM_LENGTH,
ALPHANUMERIC_LOWERCASE,
} from '@/features/rooms/utils/isRoomValid'

export const PersonalizeMeetingDialog = ({
isOpen,
Expand Down Expand Up @@ -43,10 +47,10 @@ export const PersonalizeMeetingDialog = ({
}

const validationErrors = []
if (roomSlug.length < 5) {
if (roomSlug.length < MIN_ROOM_LENGTH) {
validationErrors.push(t('errors.validation.length'))
}
if (!roomSlug.match(/^[a-z0-9]+$/)) {
if (!new RegExp(`^${ALPHANUMERIC_LOWERCASE}+$`).test(roomSlug)) {
validationErrors.push(t('errors.validation.spaceOrSpecialCharacter'))
}

Expand Down
7 changes: 6 additions & 1 deletion src/frontend/src/features/rooms/utils/isRoomValid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
*/
export const generatedRoomPattern = '[a-z]{3}-[a-z]{4}-[a-z]{3}'

export const ALPHANUMERIC_LOWERCASE = '[a-z0-9]'

// Minimum length requirement for personalized rooms
export const MIN_ROOM_LENGTH = 5

/**
* Pattern for user-defined custom room IDs
* Format: Minimum 5 lowercase alphanumeric characters
* This pattern allows users to create memorable, personalized room names
* while maintaining basic validation rules (e.g., myroom123, teamspace, project2024)
*/
export const personalizedRoomPattern = '[a-z0-9]{5,}'
export const personalizedRoomPattern = `${ALPHANUMERIC_LOWERCASE}{${MIN_ROOM_LENGTH},}`

// Combined pattern that accepts both system-generated and personalized room IDs
// This allows flexibility in room creation while maintaining consistent validation
Expand Down

0 comments on commit 69457a0

Please sign in to comment.