Files
supabase/apps/studio/components/ui/Forms/Form.constants.ts
Joshen Lim a458977e2d Support for Dedicated Pooler in Connection Pooling (#33817)
* Init

* Initial set up for hooking up supavisor and pgbouncer

* Hook up pgbouncer status check after swapping pooler type

* Add check for nano compute for switching to pg bouncer

* Add check for ipv4 addon

* Remove expect error tag

* Add badge to select options for pooler types

* Remove statement mode

* Resolve undefined problem with react hook form

* Fix

* Update UI texts from PgBouncer to Dedicated Pooler

* Feex

* FEEX

* Fix

* Small update to UI

* Smol update
2025-02-28 11:14:42 +08:00

18 lines
734 B
TypeScript

import * as z from 'zod'
export const StringNumberOrNull = z
.string()
.transform((v) => (v === '' ? null : v))
.nullable()
.refine((value) => value === null || !isNaN(Number(value)), {
message: 'Invalid number',
})
.transform((value) => (value === null ? null : Number(value)))
/**
* [Joshen] After wrangling with RHF I think this is the easiest way to handle nullable number fields
* - Declare the field normally as you would in the zod form schema (e.g field: z.number().nullable())
* - In the InputField, add a form.register call `{...form.register('field_name', { setValueAs: setValueAsNullableNumber })}`
*/
export const setValueAsNullableNumber = (v: any) => (v === '' || v === null ? null : parseInt(v))