refactor: improve code readability and validation structure

- Added a new line for better readability in the BankAccountsPage component when showing alert messages.
- Refactored the test case for isRequestHostAllowed to enhance clarity.
- Improved formatting in the CreateBankAccountFormValidation schema for the nationalCode field.
This commit is contained in:
alisaza 2026-09-05 16:31:02 +03:30
parent 871176ba92
commit 76e65f4f79
3 changed files with 11 additions and 8 deletions

View File

@ -128,6 +128,7 @@ const BankAccountsPage = () => {
}
const userName = formatPersonName(row.user?.firstName, row.user?.lastName) || row.iban
showAlert(`حساب «${userName}» تأیید شود؟`, () =>
runAction(row.id, () => axiosInstance.patch(API_ROUTES.BANK_ACCOUNTS.ADMIN_APPROVE(row.id)), 'حساب بانکی تأیید شد')
)

View File

@ -3,13 +3,12 @@ import { describe, expect, it } from 'vitest'
import { isRequestHostAllowed } from '@/lib/security/requestHost'
describe('isRequestHostAllowed', () => {
it.each([
'backoffice.ghabilee.ir',
'backoffice.ghabilee.ir:443',
'BACKOFFICE.GHABILEE.IR',
])('allows a canonical production host: %s', (host) => {
it.each(['backoffice.ghabilee.ir', 'backoffice.ghabilee.ir:443', 'BACKOFFICE.GHABILEE.IR'])(
'allows a canonical production host: %s',
(host) => {
expect(isRequestHostAllowed(host, 'production')).toBe(true)
})
}
)
it.each([
null,

View File

@ -16,7 +16,10 @@ export const CreateBankAccountFormValidation = (requiresNationalCode: boolean) =
.trim()
.transform((value) => toEnglishDigits(value).toUpperCase().replace(/\s+/g, ''))
.refine((value) => /^IR\d{24}$/.test(value), v.ibanInvalid),
nationalCode: z.string().trim().transform((value) => toEnglishDigits(value)),
nationalCode: z
.string()
.trim()
.transform((value) => toEnglishDigits(value)),
})
.superRefine((value, ctx) => {
if (!requiresNationalCode) return