Skip to content

Commit e44e52c

Browse files
committed
♻️(frontend) make room pattern validation rules reusable
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.
1 parent d72e0f6 commit e44e52c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/frontend/src/features/home/components/PersonalizeMeetingDialog.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import {
1313
TextField,
1414
} from 'react-aria-components'
1515
import { css } from '@/styled-system/css'
16+
import {
17+
MIN_ROOM_LENGTH,
18+
ALPHANUMERIC_LOWERCASE,
19+
} from '@/features/rooms/utils/isRoomValid'
1620

1721
export const PersonalizeMeetingDialog = ({
1822
isOpen,
@@ -43,10 +47,10 @@ export const PersonalizeMeetingDialog = ({
4347
}
4448

4549
const validationErrors = []
46-
if (roomSlug.length < 5) {
50+
if (roomSlug.length < MIN_ROOM_LENGTH) {
4751
validationErrors.push(t('errors.validation.length'))
4852
}
49-
if (!roomSlug.match(/^[a-z0-9]+$/)) {
53+
if (!new RegExp(`^${ALPHANUMERIC_LOWERCASE}+$`).test(roomSlug)) {
5054
validationErrors.push(t('errors.validation.spaceOrSpecialCharacter'))
5155
}
5256

src/frontend/src/features/rooms/utils/isRoomValid.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
*/
77
export const generatedRoomPattern = '[a-z]{3}-[a-z]{4}-[a-z]{3}'
88

9+
export const ALPHANUMERIC_LOWERCASE = '[a-z0-9]'
10+
11+
// Minimum length requirement for personalized rooms
12+
export const MIN_ROOM_LENGTH = 5
13+
914
/**
1015
* Pattern for user-defined custom room IDs
1116
* Format: Minimum 5 lowercase alphanumeric characters
1217
* This pattern allows users to create memorable, personalized room names
1318
* while maintaining basic validation rules (e.g., myroom123, teamspace, project2024)
1419
*/
15-
export const personalizedRoomPattern = '[a-z0-9]{5,}'
20+
export const personalizedRoomPattern = `${ALPHANUMERIC_LOWERCASE}{${MIN_ROOM_LENGTH},}`
1621

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

0 commit comments

Comments
 (0)