-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
135 additions
and
116 deletions.
There are no files selected for viewing
This file contains 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
84 changes: 2 additions & 82 deletions
84
frontend/src/app/(app)/(peopleFlow)/people/add-new/personal-details/page.tsx
This file contains 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 |
---|---|---|
@@ -1,83 +1,3 @@ | ||
'use client'; | ||
import { Button } from '@app/components/common/Button'; | ||
import { FormProvider } from '@app/components/common/FormProvider'; | ||
import { Input } from '@app/components/common/Input'; | ||
import { Typography } from '@app/components/common/Typography'; | ||
import { routes } from '@app/constants'; | ||
import { usePeopleStore } from '@app/store/peopleStore'; | ||
import { useEffect, useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { PersonalDetails } from '@app/components/pages/PersonalDetails/PersonalDetails'; | ||
|
||
enum PersonalDetailsFormNames { | ||
firstName = 'firstName', | ||
lastName = 'lastName', | ||
email = 'email', | ||
} | ||
interface PersonalDetailsForm { | ||
[PersonalDetailsFormNames.firstName]: string; | ||
[PersonalDetailsFormNames.lastName]: string; | ||
[PersonalDetailsFormNames.email]: string; | ||
} | ||
|
||
export default function PersonalDetails() { | ||
const form = useForm<PersonalDetailsForm>({ | ||
mode: 'onChange', | ||
defaultValues: { | ||
[PersonalDetailsFormNames.firstName]: '', | ||
[PersonalDetailsFormNames.lastName]: '', | ||
[PersonalDetailsFormNames.email]: '', | ||
}, | ||
}); | ||
const { isDirty, isValid } = form.formState; | ||
const [formValid, setFormValid] = useState(false); | ||
const updateProgress = usePeopleStore((state) => state.updateProgress); | ||
|
||
useEffect(() => { | ||
setFormValid(isDirty && isValid); | ||
}, [isDirty, isValid]); | ||
|
||
// INFO: update progress in sidebar stepper | ||
useEffect(() => { | ||
if (formValid) updateProgress({ [routes.people.addNew.personalDetails]: 'completed' }); | ||
else updateProgress({ [routes.people.addNew.personalDetails]: 'inProgress' }); | ||
}, [formValid, updateProgress]); | ||
|
||
return ( | ||
<FormProvider<PersonalDetailsForm> form={form}> | ||
<Typography variant="head-m/semibold" className="mb-6"> | ||
Personal details | ||
</Typography> | ||
<div className="mb-6 grid w-full grid-cols-2 gap-x-8 gap-y-6 rounded-[20px] border border-navy-200 bg-white p-8"> | ||
<Input | ||
name={PersonalDetailsFormNames.firstName} | ||
label="First name" | ||
options={{ | ||
minLength: { value: 2, message: 'First name must contain at least 2 characters' }, | ||
required: { value: true, message: 'First Name is required' }, | ||
}} | ||
/> | ||
<Input | ||
name={PersonalDetailsFormNames.lastName} | ||
label="Last name" | ||
options={{ | ||
minLength: { value: 2, message: 'Last name must contain at least 2 characters' }, | ||
required: { value: true, message: 'Last name is required' }, | ||
}} | ||
/> | ||
<Input | ||
name={PersonalDetailsFormNames.email} | ||
label="Email" | ||
options={{ | ||
pattern: { value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i, message: 'invalid email address' }, | ||
required: { value: true, message: 'Email is required' }, | ||
}} | ||
/> | ||
</div> | ||
<div className="flex justify-end"> | ||
<Button styleType="primary" variant="border" onClick={(e) => e.preventDefault()} disabled={!formValid}> | ||
Continue | ||
</Button> | ||
</div> | ||
</FormProvider> | ||
); | ||
} | ||
export default PersonalDetails; |
This file contains 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
2 changes: 1 addition & 1 deletion
2
frontend/src/components/modules/EmployeeSideStepper/EmployeeSideStepper.tsx
This file contains 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
31 changes: 31 additions & 0 deletions
31
frontend/src/components/pages/PersonalDetails/PersonalDetails.hooks.ts
This file contains 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,31 @@ | ||
import { routes } from '@app/constants'; | ||
import { useEffect, useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { PersonalDetailsForm, PersonalDetailsFormNames } from './PersonalDetails.interface'; | ||
import { usePeopleStore } from '@app/store/people/store'; | ||
|
||
export const usePersonalDetails = () => { | ||
const form = useForm<PersonalDetailsForm>({ | ||
mode: 'onChange', | ||
defaultValues: { | ||
[PersonalDetailsFormNames.firstName]: '', | ||
[PersonalDetailsFormNames.lastName]: '', | ||
[PersonalDetailsFormNames.email]: '', | ||
}, | ||
}); | ||
const { isDirty, isValid } = form.formState; | ||
const [formValid, setFormValid] = useState(false); | ||
const updateProgress = usePeopleStore((state) => state.updateProgress); | ||
|
||
useEffect(() => { | ||
setFormValid(isDirty && isValid); | ||
}, [isDirty, isValid]); | ||
|
||
// INFO: update progress in sidebar stepper | ||
useEffect(() => { | ||
if (formValid) updateProgress({ [routes.people.addNew.personalDetails]: 'completed' }); | ||
else updateProgress({ [routes.people.addNew.personalDetails]: 'inProgress' }); | ||
}, [formValid, updateProgress]); | ||
|
||
return { form, formValid }; | ||
}; |
11 changes: 11 additions & 0 deletions
11
frontend/src/components/pages/PersonalDetails/PersonalDetails.interface.ts
This file contains 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,11 @@ | ||
export const PersonalDetailsFormNames = { | ||
firstName: 'firstName', | ||
lastName: 'lastName', | ||
email: 'email', | ||
} as const; | ||
|
||
export interface PersonalDetailsForm { | ||
[PersonalDetailsFormNames.firstName]: string; | ||
[PersonalDetailsFormNames.lastName]: string; | ||
[PersonalDetailsFormNames.email]: string; | ||
} |
50 changes: 50 additions & 0 deletions
50
frontend/src/components/pages/PersonalDetails/PersonalDetails.tsx
This file contains 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,50 @@ | ||
'use client'; | ||
import { Button } from '@app/components/common/Button'; | ||
import { FormProvider } from '@app/components/common/FormProvider'; | ||
import { Input } from '@app/components/common/Input'; | ||
import { Typography } from '@app/components/common/Typography'; | ||
import { PersonalDetailsForm, PersonalDetailsFormNames } from './PersonalDetails.interface'; | ||
import { usePersonalDetails } from './PersonalDetails.hooks'; | ||
|
||
export const PersonalDetails = () => { | ||
const { form, formValid } = usePersonalDetails(); | ||
|
||
return ( | ||
<FormProvider<PersonalDetailsForm> form={form}> | ||
<Typography variant="head-m/semibold" className="mb-6"> | ||
Personal details | ||
</Typography> | ||
<div className="mb-6 grid w-full grid-cols-2 gap-x-8 gap-y-6 rounded-[20px] border border-navy-200 bg-white p-8"> | ||
<Input | ||
name={PersonalDetailsFormNames.firstName} | ||
label="First name" | ||
options={{ | ||
minLength: { value: 2, message: 'First name must contain at least 2 characters' }, | ||
required: { value: true, message: 'First Name is required' }, | ||
}} | ||
/> | ||
<Input | ||
name={PersonalDetailsFormNames.lastName} | ||
label="Last name" | ||
options={{ | ||
minLength: { value: 2, message: 'Last name must contain at least 2 characters' }, | ||
required: { value: true, message: 'Last name is required' }, | ||
}} | ||
/> | ||
<Input | ||
name={PersonalDetailsFormNames.email} | ||
label="Email" | ||
options={{ | ||
pattern: { value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i, message: 'invalid email address' }, | ||
required: { value: true, message: 'Email is required' }, | ||
}} | ||
/> | ||
</div> | ||
<div className="flex justify-end"> | ||
<Button styleType="primary" variant="border" onClick={(e) => e.preventDefault()} disabled={!formValid}> | ||
Continue | ||
</Button> | ||
</div> | ||
</FormProvider> | ||
); | ||
}; |
This file contains 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 @@ | ||
export { PersonalDetails } from './PersonalDetails'; |
This file contains 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 @@ | ||
export { usePeopleStore } from './store'; |
This file contains 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,9 @@ | ||
import { AddNewPersonRouteKeys } from '@app/components/modules/EmployeeSideStepper'; | ||
import { StepStates } from '@app/components/modules/SideStepper'; | ||
|
||
export type Progress = Record<AddNewPersonRouteKeys, StepStates>; | ||
|
||
export interface PeopleState { | ||
progress: Progress; | ||
updateProgress: (newProgress: Partial<Progress>) => void; | ||
} |
This file contains 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,18 @@ | ||
import { routes } from '@app/constants'; | ||
import { create } from 'zustand'; | ||
import { PeopleState } from './interfaces'; | ||
|
||
const initialState: PeopleState = { | ||
progress: { | ||
[routes.people.addNew.personalDetails]: 'notStarted', | ||
[routes.people.addNew.mainLadder]: 'notStarted', | ||
}, | ||
updateProgress: () => {}, | ||
}; | ||
|
||
const usePeopleStore = create<PeopleState>()((set) => ({ | ||
...initialState, | ||
updateProgress: (newProgress) => set((state) => ({ progress: { ...state.progress, ...newProgress } })), | ||
})); | ||
|
||
export { usePeopleStore }; |
This file was deleted.
Oops, something went wrong.
This file contains 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