This commit is contained in:
Owen 2025-06-09 11:13:58 -04:00
parent 57315a36ee
commit c409266954
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD

View file

@ -82,7 +82,14 @@ export default function StepperForm() {
); );
const generateId = (name: string) => { const generateId = (name: string) => {
return name.toLowerCase().replace(/\s+/g, "-"); // Replace any character that is not a letter, number, space, or hyphen with a hyphen
// Also collapse multiple hyphens and trim
return name
.toLowerCase()
.replace(/[^a-z0-9\s-]/g, "-")
.replace(/\s+/g, "-")
.replace(/-+/g, "-")
.replace(/^-+|-+$/g, "");
}; };
async function orgSubmit(values: z.infer<typeof orgSchema>) { async function orgSubmit(values: z.infer<typeof orgSchema>) {
@ -207,23 +214,22 @@ export default function StepperForm() {
type="text" type="text"
{...field} {...field}
onChange={(e) => { onChange={(e) => {
const orgId = // Prevent "/" in orgName input
generateId( const sanitizedValue = e.target.value.replace(/\//g, "-");
e.target const orgId = generateId(sanitizedValue);
.value
);
orgForm.setValue( orgForm.setValue(
"orgId", "orgId",
orgId orgId
); );
orgForm.setValue( orgForm.setValue(
"orgName", "orgName",
e.target.value sanitizedValue
); );
debouncedCheckOrgIdAvailability( debouncedCheckOrgIdAvailability(
orgId orgId
); );
}} }}
value={field.value.replace(/\//g, "-")}
/> />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />