Skip to content

Commit

Permalink
Merge pull request #41 from LerianStudio/feat/add-validation-into-cod…
Browse files Browse the repository at this point in the history
…e-field

✨ feat: add validation into field code
  • Loading branch information
gabrielcastr0 authored Nov 21, 2024
2 parents 6e978ac + 093e593 commit 519e352
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions locales/extracted/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"errors.custom.one_uppercase_letter": "Field must contain at least 1 uppercase letter",
"errors.custom.only_numbers": "Field must contain only numbers",
"errors.custom.special_characters": "Field must not contain special characters",
"errors.custom.uppercase_required": "Field must be in uppercase and consist of letters only",
"errors.invalid_type": "",
"errors.invalid_type_received_undefined": "Required field",
"errors.too_big.date.exact": "Date must be exactly {maximum}",
Expand Down
3 changes: 2 additions & 1 deletion locales/extracted/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,6 @@
"account.sheet.type.loans": "Empréstimos",
"account.sheet.type.marketplace": "Mercado",
"account.sheet.type.savings": "Poupança",
"ledgers.account.field.type.tooltip": "O tipo de conta"
"ledgers.account.field.type.tooltip": "O tipo de conta",
"errors.custom.uppercase_required": "O campo deve estar em maiúsculas e conter apenas letras"
}
1 change: 0 additions & 1 deletion src/app/(routes)/ledgers/[id]/assets/assets-sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ export const AssetsSheet = ({
<LoadingButton
size="lg"
type="submit"
disabled={!(form.formState.isDirty && form.formState.isValid)}
fullWidth
loading={createPending || updatePending}
>
Expand Down
4 changes: 4 additions & 0 deletions src/lib/zod/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ const messages = defineMessages({
custom_date_invalid: {
id: 'errors.custom.date.invalid',
defaultMessage: 'Invalid date'
},
custom_uppercase_required: {
id: 'errors.custom.uppercase_required',
defaultMessage: 'Field must be in uppercase and consist of letters only'
}
})

Expand Down
9 changes: 8 additions & 1 deletion src/schema/assets.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { z } from 'zod'
import { metadata } from './metadata'
import { uppercaseLettersOnly, regex } from './regex'

const type = z.string().min(1).max(255)
const name = z.string().min(1).max(255)
const code = z.string().min(1).max(255)
const code = z
.string()
.min(1)
.max(255)
.refine(regex(uppercaseLettersOnly), {
params: { id: 'custom_uppercase_required' }
})

export const assets = { type, name, code, metadata }
2 changes: 2 additions & 0 deletions src/schema/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export const oneLowerCaseLetter = /[a-z]/
export const oneNumber = /[0-9]/

export const onlyNumbers = /^[0-9]*$/

export const uppercaseLettersOnly = /^[A-Z]+$/

0 comments on commit 519e352

Please sign in to comment.