Skip to content

Commit fa320a1

Browse files
committed
feat: Sync validation with CM and core
https://harperdb.atlassian.net/browse/STUDIO-13
1 parent 3a71fbd commit fa320a1

File tree

6 files changed

+33
-27
lines changed

6 files changed

+33
-27
lines changed

src/features/auth/SignUp.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,26 @@ import { toast } from 'sonner';
1414
import { z } from 'zod';
1515

1616
const SignInSchema = z.object({
17+
email: z
18+
.email({
19+
error: 'Please enter a valid email address.',
20+
})
21+
.trim()
22+
.toLowerCase()
23+
.max(80, { error: 'Email cannot be longer than 80 characters.' }),
1724
firstname: z
1825
.string()
26+
.trim()
1927
.min(2, { error: 'Please enter your first name.' })
20-
.max(50, { error: 'First name cannot be longer than 50 characters.' }),
28+
.max(40, { error: 'First name cannot be longer than 40 characters.' }),
2129
lastname: z
2230
.string()
31+
.trim()
2332
.min(2, { error: 'Please enter your last name.' })
24-
.max(50, { error: 'Last name cannot be longer than 50 characters.' }),
25-
email: z
26-
.email({
27-
error: 'Please enter a valid email address.',
28-
})
29-
.max(75, { error: 'Email cannot be longer than 75 characters.' }),
33+
.max(80, { error: 'Last name cannot be longer than 80 characters.' }),
3034
password: z
3135
.string()
32-
.min(8, { error: 'Password must be at least 8 characters long.' })
33-
.max(50, { error: 'Password cannot be longer than 50 characters.' }),
36+
.min(8, { error: 'Password must be at least 8 characters long.' }),
3437
});
3538

3639
export function SignUp() {

src/features/clusters/upsert/upsertClusterSchema.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const UpsertClusterSchema = z.object({
88
.max(255, 'System name cannot be longer than 255 characters long.'),
99
abbreviatedName: z
1010
.string()
11-
.max(10, 'Must be at most 10 characters long.')
11+
.max(20, 'Must be at most 20 characters long.')
1212
.regex(/^[a-zA-Z0-9-]*$/, 'Can only contain letters, numbers and dashes'),
1313
fqdn: z
1414
.string()
@@ -23,7 +23,7 @@ export const UpsertClusterSchema = z.object({
2323
regionName: z.string().nonempty('Please select a region.'),
2424
latencyDescription: z.string().nonempty('Please select a latency tier.'),
2525
}),
26-
),
26+
).max(50, { error: 'A maximum of 50 regions can be selected for each cluster. ' }),
2727

2828
instances: z.array(
2929
z.object({
@@ -36,5 +36,5 @@ export const UpsertClusterSchema = z.object({
3636
.max(maxPortNumber, 'That port number is too high.')
3737
.optional(),
3838
}),
39-
),
39+
).max(100, { error: 'A maximum of 100 instances can be added to each cluster.' }),
4040
});

src/features/instance/databases/modals/CreateNewTableModal.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,33 @@ import { useForm } from 'react-hook-form';
2626
import { toast } from 'sonner';
2727
import { z } from 'zod';
2828

29+
const schemaRegex = /^[\x20-\x2E|\x30-\x5F|\x61-\x7E]*$/;
30+
2931
const CreateTableSchema = z.object({
3032
databaseName: z
3133
.string()
32-
.regex(/^[a-zA-Z0-9_]*$/, {
33-
error: 'Database name can only contain letters, numbers, and underscores.',
34+
.regex(schemaRegex, {
35+
error: 'Database name cannot include backticks or forward slashes.',
3436
})
3537
.max(75, { error: 'Database name cannot be longer than 75 characters.' }),
3638
tableName: z
3739
.string()
3840
.nonempty({
3941
error: 'Table name is required.',
4042
})
41-
.regex(/^[a-zA-Z0-9_]*$/, {
42-
error: 'Table name can only contain letters, numbers, and underscores.',
43+
.regex(schemaRegex, {
44+
error: 'Table name cannot include backticks or forward slashes.',
4345
})
44-
.max(30, {
45-
error: 'Table name cannot be longer than 30 characters.',
46+
.max(250, {
47+
error: 'Table name cannot be longer than 250 characters.',
4648
}),
4749
primaryKey: z
4850
.string()
49-
.regex(/^[a-zA-Z0-9_]*$/, {
50-
error: 'Primary key can only contain letters, numbers, and underscores.',
51+
.regex(schemaRegex, {
52+
error: 'Primary key cannot include backticks or forward slashes.',
5153
})
52-
.max(14, {
53-
error: 'Primary key cannot be longer than 14 characters.',
54+
.max(250, {
55+
error: 'Primary key cannot be longer than 250 characters.',
5456
}),
5557
});
5658

src/features/instance/operations/schemas/addUserFormSchema.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export const AddUserFormSchema = z
44
.object({
55
username: z
66
.string()
7+
.trim()
8+
.toLowerCase()
79
.nonempty({ error: 'Please enter a username.' }),
810
role: z
911
.string()
@@ -12,8 +14,7 @@ export const AddUserFormSchema = z
1214
}),
1315
password: z
1416
.string()
15-
.min(8, { error: 'Password must be at least 8 characters long.' })
16-
.max(50, { error: 'Password cannot be longer than 50 characters.' }),
17+
.min(8, { error: 'Password must be at least 8 characters long.' }),
1718
confirmPassword: z.string(),
1819
})
1920
.refine((data) => data.password === data.confirmPassword, {

src/features/organizations/hooks/useCreateNewOrganization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { apiClient } from '@/config/apiClient';
22
import { useMutation } from '@tanstack/react-query';
33
import { SchemaOrganization } from '@/lib/api.gen';
44

5-
export async function onNewOrganizationSubmit(newOrg: Omit<SchemaOrganization, 'id' | 'type'>): Promise<SchemaOrganization> {
5+
async function onNewOrganizationSubmit(newOrg: Omit<SchemaOrganization, 'id' | 'type'>): Promise<SchemaOrganization> {
66
const { data } = await apiClient.post('/Organization/', {
77
...newOrg,
88
});

src/features/organizations/modals/newOrganizationSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const NewOrganizationSchema = z.object({
1111
}),
1212
subdomain: z
1313
.string()
14-
.max(10, {
15-
error: 'The subdomain cannot be longer than 10 characters.',
14+
.max(62, {
15+
error: 'The subdomain cannot be longer than 62 characters.',
1616
})
1717
.regex(/^[a-zA-Z0-9-]*$/, {
1818
error: 'Please only use letters, digits and dashes (-) in the subdomain.',

0 commit comments

Comments
 (0)