-
Notifications
You must be signed in to change notification settings - Fork 9
PR for company registration form for admin user #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: react-ts
Are you sure you want to change the base?
Conversation
Naman-56-56
commented
Oct 23, 2025
- Added company addition form for admin at the 'http://127.0.0.1:5173/admin/companies/add' endpoint
- Used RHF wrappers for consistency
- Implemented the form similarly to the form at 'http://127.0.0.1:5173/register/company' endpoint for consistency
- Added necessary url endpoints to router
| <Typography variant="h4">Add New Company</Typography> | ||
|
|
||
| <FormProvider {...methods}> | ||
| <Paper sx={{ p: 3 }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Wrap fields in a
<form>and submit properly
(handleSubmit on a button onClick skips native form submit) - add noValidate -- as we are validating via zod -- may give inconsistency
| <Paper sx={{ p: 3 }}> | |
| <Paper sx={{ p: 3 }} component="form" noValidate onSubmit={methods.handleSubmit(onSubmit)}> |
| <Button | ||
| variant="contained" | ||
| onClick={methods.handleSubmit(onSubmit)} | ||
| disabled={addCompany.isPending} | ||
| > | ||
| {addCompany.isPending ? 'Adding...' : 'Add Company'} | ||
| </Button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <Button | |
| variant="contained" | |
| onClick={methods.handleSubmit(onSubmit)} | |
| disabled={addCompany.isPending} | |
| > | |
| {addCompany.isPending ? 'Adding...' : 'Add Company'} | |
| </Button> | |
| <Button type="submit" variant="contained" disabled={loadingMeta || addCompany.isPending || methods.formState.isSubmitting}> |
| export const adminCompanySchema = z.object({ | ||
| name: z.string().min(2, 'Required'), | ||
| website: z.url('Invalid URL').optional().or(z.literal('')), | ||
| domain: z.string().min(1, 'Required'), | ||
| state: z.string().min(1, 'Required'), | ||
| city: z.string().min(2, 'Required'), | ||
| address: z.string().min(5, 'Required'), | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve Zod messages and empty-string handling for URL
| export const adminCompanySchema = z.object({ | |
| name: z.string().min(2, 'Required'), | |
| website: z.url('Invalid URL').optional().or(z.literal('')), | |
| domain: z.string().min(1, 'Required'), | |
| state: z.string().min(1, 'Required'), | |
| city: z.string().min(2, 'Required'), | |
| address: z.string().min(5, 'Required'), | |
| }) | |
| const emptyToUndefined = <T extends z.ZodTypeAny>(schema: T) => | |
| z.preprocess((v) => (v === '' ? undefined : v), schema) | |
| export const adminCompanySchema = z.object({ | |
| name: z.string().min(5, 'Must be at least 5 characters'), | |
| website: emptyToUndefined(z.string().url('Invalid URL')).optional(), | |
| domain: z.string().min(1, 'Required'), | |
| state: z.string().min(1, 'Required'), | |
| city: z.string().min(2, 'Must be at least 2 characters'), | |
| address: z.string().min(5, 'Must be at least 5 characters'), | |
| }) | |
| <FormProvider {...methods}> | ||
| <Paper sx={{ p: 3 }}> | ||
| {loadingMeta ? ( | ||
| <Typography>Loading options…</Typography> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ux polish : Add a Skeleton instead of plain “Loading options…”.
https://mui.com/material-ui/react-skeleton/
| }: { domains: string[]; states: { code: string; name: string }[] }) { | ||
| return ( | ||
| <Stack spacing={2}> | ||
| <RHFTextField name="name" label="Company Name" fullWidth /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ux polish :
Autofocus first field
| <RHFTextField name="name" label="Company Name" fullWidth /> | |
| <RHFTextField name="name" label="Company Name" fullWidth autoFocus /> | |