Skip to content

Commit 10d6ce7

Browse files
committed
fix: type errors after rebase
1 parent e66f596 commit 10d6ce7

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

src/containers/Tenant/TableFormDialog/validation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ function validateSettings(
413413
export function buildTableValidationSchema({
414414
mode,
415415
originalInfo,
416-
}: SchemaContext): z.ZodType<FormValues> {
416+
}: SchemaContext): z.ZodType<FormValues, FormValues> {
417417
return baseSchema.superRefine((raw, ctx) => {
418418
const data = raw as FormValues;
419419
validateName(data, ctx, mode);
@@ -424,5 +424,5 @@ export function buildTableValidationSchema({
424424
validateSecondaryIndexes(data, ctx, originalInfo);
425425
validatePartitioning(data, ctx, mode);
426426
validateSettings(data, ctx, mode, originalInfo);
427-
}) as z.ZodType<FormValues>;
427+
}) as z.ZodType<FormValues, FormValues>;
428428
}

src/containers/Tenant/TopicFormDialog/validation.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import i18n from './i18n';
77

88
const MIN_ONE_MESSAGE = i18n('error_min-number', {count: 1});
99
const MAX_HUNDRED_MESSAGE = i18n('error_max-number', {count: 100});
10+
const REQUIRED_MESSAGE = i18n('error_required');
11+
const NUMBER_MESSAGE = i18n('error_number');
12+
13+
const getRequiredNumberError = (issue: {input?: unknown}) => {
14+
return issue.input === undefined ? REQUIRED_MESSAGE : NUMBER_MESSAGE;
15+
};
1016

1117
const addIssue = (ctx: z.RefinementCtx, path: Array<string | number>, message: string) => {
1218
ctx.addIssue({
@@ -21,8 +27,7 @@ const requiredNumber = (schema?: z.ZodNumber) =>
2127
(val) => (typeof val === 'number' && Number.isNaN(val) ? undefined : val),
2228
schema ??
2329
z.number({
24-
required_error: i18n('error_required'),
25-
invalid_type_error: i18n('error_number'),
30+
error: getRequiredNumberError,
2631
}),
2732
);
2833

@@ -32,14 +37,14 @@ const optionalNumber = (schema?: z.ZodNumber) =>
3237
(
3338
schema ??
3439
z.number({
35-
invalid_type_error: i18n('error_number'),
40+
error: NUMBER_MESSAGE,
3641
})
3742
).optional(),
3843
);
3944

4045
const topicNameSchema = z
41-
.string({required_error: i18n('error_required'), invalid_type_error: i18n('error_required')})
42-
.min(1, i18n('error_required'))
46+
.string({error: REQUIRED_MESSAGE})
47+
.min(1, REQUIRED_MESSAGE)
4348
.superRefine((value, ctx) => {
4449
if (!isValidEntityPath(value)) {
4550
addIssue(ctx, [], i18n('error_name-regex'));
@@ -67,26 +72,23 @@ export function getTopicFormValidationSchema(minPartitions: number) {
6772
shards: requiredNumber(
6873
z
6974
.number({
70-
required_error: i18n('error_required'),
71-
invalid_type_error: i18n('error_number'),
75+
error: getRequiredNumberError,
7276
})
7377
.min(1, MIN_ONE_MESSAGE),
7478
),
7579
writeQuotaBytes: requiredNumber(),
7680
autoPartitioning: z.object({
7781
enabled: z.boolean(),
78-
mode: z.string().min(1, i18n('error_required')),
82+
mode: z.string({error: REQUIRED_MESSAGE}).min(1, REQUIRED_MESSAGE),
7983
minPartitions: optionalNumber(
80-
z.number({invalid_type_error: i18n('error_number')}).min(1, MIN_ONE_MESSAGE),
84+
z.number({error: NUMBER_MESSAGE}).min(1, MIN_ONE_MESSAGE),
8185
),
8286
maxPartitions: optionalNumber(
83-
z.number({invalid_type_error: i18n('error_number')}).min(1, MIN_ONE_MESSAGE),
87+
z.number({error: NUMBER_MESSAGE}).min(1, MIN_ONE_MESSAGE),
8488
),
8589
stabilizationWindow: optionalNumber(),
8690
upUtilization: optionalNumber(
87-
z
88-
.number({invalid_type_error: i18n('error_number')})
89-
.max(100, MAX_HUNDRED_MESSAGE),
91+
z.number({error: NUMBER_MESSAGE}).max(100, MAX_HUNDRED_MESSAGE),
9092
),
9193
}),
9294
})
@@ -128,5 +130,5 @@ export function getTopicFormValidationSchema(minPartitions: number) {
128130
validateRequiredNumber(ctx, stabilizationPath, autoPartitioning.stabilizationWindow);
129131

130132
validateRequiredNumber(ctx, upUtilizationPath, autoPartitioning.upUtilization);
131-
}) as z.ZodType<TopicFormValues>;
133+
}) as z.ZodType<TopicFormValues, TopicFormValues>;
132134
}

0 commit comments

Comments
 (0)