-
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
Open
Naman-56-56
wants to merge
2
commits into
Spoken-tutorial:react-ts
Choose a base branch
from
Naman-56-56:react-ts
base: react-ts
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
frontend/src/features/company/components/AdminCompanyForm.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import RHFTextField from '@shared/RHF/RHFTextField' | ||
| import RHFAutocomplete from '@shared/RHF/RHFAutocomplete'; | ||
| import { Stack } from '@mui/material' | ||
|
|
||
| export default function AdminCompanyForm({ | ||
| domains, states | ||
| }: { domains: string[]; states: { code: string; name: string }[] }) { | ||
| return ( | ||
| <Stack spacing={2}> | ||
| <RHFTextField name="name" label="Company Name" fullWidth autoFocus /> | ||
| <RHFTextField name="website" label="Website" placeholder="https://example.com" fullWidth /> | ||
| <RHFAutocomplete | ||
| name="domain" | ||
| label="Domain" | ||
| options={domains} | ||
| fullWidth | ||
| /> | ||
| <RHFAutocomplete | ||
| name="state" | ||
| label="State" | ||
| options={states.map((s) => ({ label: s.name, value: s.name }))} | ||
| fullWidth | ||
| /> | ||
| <RHFTextField name="city" label="City" fullWidth /> | ||
| <RHFTextField name="address" label="Address" multiline rows={3} fullWidth /> | ||
| </Stack> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
frontend/src/features/company/pages/AdminCompanyAddPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // src/features/company/pages/AdminCompanyAddPage.tsx | ||
| import { useState } from 'react' | ||
| import { | ||
| Box, Button, Stack, Typography, Paper, Divider, Skeleton | ||
| } from '@mui/material' | ||
| import { FormProvider, useForm } from 'react-hook-form' | ||
| import { zodResolver } from '@hookform/resolvers/zod' | ||
| import { useNavigate } from 'react-router-dom' | ||
|
|
||
| import AdminCompanyForm from '../components/AdminCompanyForm' | ||
| import { adminCompanySchema, type AdminCompanyForm as AdminCompanyFormType } from '../schema' | ||
| import { useMetaOptions } from '../queries' | ||
| import { useAddCompany } from '../mutations' | ||
|
|
||
| export default function AdminCompanyAddPage() { | ||
| const navigate = useNavigate() | ||
| const { data: options, isLoading: loadingMeta } = useMetaOptions() | ||
| const addCompany = useAddCompany() | ||
|
|
||
| const methods = useForm<AdminCompanyFormType>({ | ||
| resolver: zodResolver(adminCompanySchema), | ||
| defaultValues: { | ||
| name: '', | ||
| website: '', | ||
| domain: '', | ||
| state: '', | ||
| city: '', | ||
| address: '' | ||
| }, | ||
| mode: 'onTouched' | ||
| }) | ||
|
|
||
| const [submitted, setSubmitted] = useState<null | { success: boolean; companyId?: number }>(null) | ||
|
|
||
| const onSubmit = async (data: AdminCompanyFormType) => { | ||
| try { | ||
| const result = await addCompany.mutateAsync(data) | ||
| setSubmitted({ success: true, companyId: result.company_id }) | ||
| } catch (e) { | ||
| setSubmitted({ success: false }) | ||
| } | ||
| } | ||
|
|
||
| // Success screen | ||
| if (submitted?.success) { | ||
| return ( | ||
| <Paper sx={{ p: 4 }}> | ||
| <Typography variant="h5" gutterBottom> | ||
| ✅ Company added successfully! | ||
| </Typography> | ||
| <Typography> | ||
| Company ID: <b>{submitted.companyId}</b> | ||
| </Typography> | ||
| <Divider sx={{ my: 3 }} /> | ||
| <Stack direction="row" spacing={2}> | ||
| <Button variant="contained" onClick={() => navigate('/admin/companies')}> | ||
| Back to Companies | ||
| </Button> | ||
| <Button variant="outlined" onClick={() => setSubmitted(null)}> | ||
| Add Another | ||
| </Button> | ||
| </Stack> | ||
| </Paper> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <Stack spacing={3}> | ||
| <Typography variant="h4">Add New Company</Typography> | ||
|
|
||
| <FormProvider {...methods}> | ||
| <Paper component="form" noValidate onSubmit={methods.handleSubmit(onSubmit)} sx={{ p: 3 }}> | ||
| {loadingMeta ? ( | ||
| <Stack spacing={3}> | ||
| <Skeleton variant="text" width="40%" height={32} /> | ||
| <Skeleton variant="rectangular" height={56} /> | ||
| <Skeleton variant="text" width="40%" height={32} /> | ||
| <Skeleton variant="rectangular" height={56} /> | ||
| <Stack direction="row" spacing={2}> | ||
| <Skeleton variant="rectangular" width="50%" height={56} /> | ||
| <Skeleton variant="rectangular" width="50%" height={56} /> | ||
| </Stack> | ||
| <Skeleton variant="text" width="40%" height={32} /> | ||
| <Skeleton variant="rectangular" height={56} /> | ||
| <Skeleton variant="rectangular" height={120} /> | ||
| </Stack> | ||
| ) : ( | ||
| <AdminCompanyForm | ||
| domains={options?.domains ?? ['Software', 'EdTech', 'Finance']} | ||
| states={options?.states ?? [{ code: 'MH', name: 'Maharashtra' }, { code: 'DL', name: 'Delhi' }]} | ||
| /> | ||
| )} | ||
|
|
||
| <Stack direction="row" spacing={2} sx={{ mt: 3 }} justifyContent="space-between"> | ||
| <Button variant="outlined" onClick={() => navigate('/admin/companies')}> | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
| type="submit" | ||
| variant="contained" | ||
| disabled={loadingMeta || addCompany.isPending || methods.formState.isSubmitting} | ||
| > | ||
| {addCompany.isPending ? 'Adding...' : 'Add Company'} | ||
| </Button> | ||
| </Stack> | ||
| </Paper> | ||
| </FormProvider> | ||
|
|
||
| {addCompany.isError && ( | ||
| <Typography color="error">Something went wrong. Please try again.</Typography> | ||
| )} | ||
| </Stack> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,29 +2,35 @@ | |||||||||||||||||||||||||||||||||||||||||||
| import { domain } from 'node_modules/zod/v4/core/regexes.cjs'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { z } from 'zod'; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Helper function to convert empty strings to undefined | ||||||||||||||||||||||||||||||||||||||||||||
| const emptyToUndefined = (val: string) => (val === '' ? undefined : val); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Company Details | ||||||||||||||||||||||||||||||||||||||||||||
| export const companySchema = z.object({ | ||||||||||||||||||||||||||||||||||||||||||||
| name: z.string().min(2, 'Required'), | ||||||||||||||||||||||||||||||||||||||||||||
| website: z.url('Invalid URL').optional().or(z.literal('')), | ||||||||||||||||||||||||||||||||||||||||||||
| domain: z.string().min(1, 'Required'), // e.g., "Software", "Edu" | ||||||||||||||||||||||||||||||||||||||||||||
| name: z.string().min(2, 'Company name must be at least 2 characters'), | ||||||||||||||||||||||||||||||||||||||||||||
| website: z.preprocess( | ||||||||||||||||||||||||||||||||||||||||||||
| emptyToUndefined, | ||||||||||||||||||||||||||||||||||||||||||||
| z.string().url('Please enter a valid URL').optional() | ||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||
| domain: z.string().min(1, 'Please select a domain'), // e.g., "Software", "Edu" | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export type CompanyForm = z.infer<typeof companySchema> | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Employer Details | ||||||||||||||||||||||||||||||||||||||||||||
| export const employerSchema = z.object({ | ||||||||||||||||||||||||||||||||||||||||||||
| first_name: z.string().min(2, 'Required'), | ||||||||||||||||||||||||||||||||||||||||||||
| last_name: z.string().min(2, 'Required'), | ||||||||||||||||||||||||||||||||||||||||||||
| email: z.email('Invalid Email'), | ||||||||||||||||||||||||||||||||||||||||||||
| phone: z.string().min(8, 'Invalid Phone') | ||||||||||||||||||||||||||||||||||||||||||||
| first_name: z.string().min(2, 'First name must be at least 2 characters'), | ||||||||||||||||||||||||||||||||||||||||||||
| last_name: z.string().min(2, 'Last name must be at least 2 characters'), | ||||||||||||||||||||||||||||||||||||||||||||
| email: z.string().email('Please enter a valid email address'), | ||||||||||||||||||||||||||||||||||||||||||||
| phone: z.string().min(8, 'Phone number must be at least 8 digits') | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export type EmployerForm = z.infer<typeof employerSchema> | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Job Details | ||||||||||||||||||||||||||||||||||||||||||||
| export const jobSchema = z.object({ | ||||||||||||||||||||||||||||||||||||||||||||
| title: z.string().min(2, 'Required'), | ||||||||||||||||||||||||||||||||||||||||||||
| description: z.string().min(10, 'Required'), | ||||||||||||||||||||||||||||||||||||||||||||
| title: z.string().min(2, 'Job title must be at least 2 characters'), | ||||||||||||||||||||||||||||||||||||||||||||
| description: z.string().min(10, 'Job description must be at least 10 characters'), | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export type JobForm = z.infer<typeof jobSchema> | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -36,4 +42,16 @@ export const registrationSchema = z.object({ | |||||||||||||||||||||||||||||||||||||||||||
| job: jobSchema.optional() // present if not skipped | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export type RegistrationPayload = z.infer<typeof registrationSchema> | ||||||||||||||||||||||||||||||||||||||||||||
| export type RegistrationPayload = z.infer<typeof registrationSchema> | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Admin Company Addition (simplified, just company details) | ||||||||||||||||||||||||||||||||||||||||||||
| export const adminCompanySchema = z.object({ | ||||||||||||||||||||||||||||||||||||||||||||
| name: z.string().min(5, 'Must be at least 5 characters'), | ||||||||||||||||||||||||||||||||||||||||||||
| website: z.string().url('Please enter a valid URL'), | ||||||||||||||||||||||||||||||||||||||||||||
| domain: z.string().min(1, 'Please select a domain'), | ||||||||||||||||||||||||||||||||||||||||||||
| state: z.string().min(1, 'Please select a state'), | ||||||||||||||||||||||||||||||||||||||||||||
| city: z.string().min(2, 'City name must be at least 2 characters'), | ||||||||||||||||||||||||||||||||||||||||||||
| address: z.string().min(5, 'Address must be at least 5 characters'), | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
48
to
55
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve Zod messages and empty-string handling for URL
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export type AdminCompanyForm = z.infer<typeof adminCompanySchema> | ||||||||||||||||||||||||||||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.