-
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
20 changed files
with
196 additions
and
178 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
3 changes: 3 additions & 0 deletions
3
frontend/src/app/(app)/(addEmployee)/people/add-new/main-ladder/[[...id]]/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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { MainLadder } from '@app/components/pages/addEmployee/MainLadder'; | ||
|
||
export default MainLadder; |
3 changes: 3 additions & 0 deletions
3
frontend/src/app/(app)/(addEmployee)/people/add-new/personal-details/[[...id]]/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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { PersonalDetails } from '@app/components/pages/addEmployee/PersonalDetails'; | ||
|
||
export default PersonalDetails; |
3 changes: 0 additions & 3 deletions
3
frontend/src/app/(app)/(peopleFlow)/people/add-new/main-ladder/page.tsx
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
frontend/src/app/(app)/(peopleFlow)/people/add-new/personal-details/page.tsx
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
38 changes: 0 additions & 38 deletions
38
frontend/src/components/pages/MainLadder/MainLadder.hooks.ts
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
frontend/src/components/pages/MainLadder/MainLadder.interface.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
frontend/src/components/pages/PersonalDetails/PersonalDetails.interface.ts
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
...end/src/components/pages/addEmployee/AddEmployeeFormProvider/AddEmployeeForm.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,17 @@ | ||
import { Option } from '@app/components/common/Combobox'; | ||
|
||
export const addEmployeeFormNames = { | ||
firstName: 'firstName', | ||
lastName: 'lastName', | ||
email: 'email', | ||
ladder: 'ladder', | ||
technology: 'technology', | ||
} as const; | ||
|
||
export interface AddEmployeeForm { | ||
[addEmployeeFormNames.firstName]: string; | ||
[addEmployeeFormNames.lastName]: string; | ||
[addEmployeeFormNames.email]: string; | ||
[addEmployeeFormNames.ladder]: Option; | ||
[addEmployeeFormNames.technology]: Option[]; | ||
} |
19 changes: 19 additions & 0 deletions
19
frontend/src/components/pages/addEmployee/AddEmployeeFormProvider/AddEmployeeForm.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,19 @@ | ||
import { FC, PropsWithChildren } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
import { FormProvider } from '@app/components/common/FormProvider'; | ||
import { AddEmployeeForm, addEmployeeFormNames } from './AddEmployeeForm.interface'; | ||
|
||
export const AddEmployeeFormProvider: FC<PropsWithChildren> = ({ children }) => { | ||
const form = useForm<AddEmployeeForm>({ | ||
mode: 'onChange', | ||
defaultValues: { | ||
[addEmployeeFormNames.firstName]: '', | ||
[addEmployeeFormNames.lastName]: '', | ||
[addEmployeeFormNames.email]: '', | ||
[addEmployeeFormNames.ladder]: {}, | ||
[addEmployeeFormNames.technology]: [], | ||
}, | ||
}); | ||
return <FormProvider<AddEmployeeForm> form={form}>{children}</FormProvider>; | ||
}; |
3 changes: 3 additions & 0 deletions
3
frontend/src/components/pages/addEmployee/AddEmployeeFormProvider/index.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,3 @@ | ||
export { AddEmployeeFormProvider } from './AddEmployeeForm'; | ||
export type { AddEmployeeForm } from './AddEmployeeForm.interface'; | ||
export { addEmployeeFormNames } from './AddEmployeeForm.interface'; |
37 changes: 37 additions & 0 deletions
37
frontend/src/components/pages/addEmployee/MainLadder/MainLadder.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,37 @@ | ||
import { useFieldArray, useFormContext } from 'react-hook-form'; | ||
import { useEffect, useState } from 'react'; | ||
import { AddEmployeeForm, addEmployeeFormNames } from '../AddEmployeeFormProvider'; | ||
import { usePeopleStore } from '@app/store/people'; | ||
import { routes } from '@app/constants'; | ||
|
||
export const useMainLadder = () => { | ||
const form = useFormContext<AddEmployeeForm>(); | ||
const updateProgress = usePeopleStore((state) => state.updateProgress); | ||
|
||
const technologyFields = useFieldArray({ | ||
name: addEmployeeFormNames.technology, | ||
control: form.control, | ||
}); | ||
|
||
const [open, setOpen] = useState(true); | ||
const [formValid, setFormValid] = useState(false); | ||
|
||
const handleSubmit = form.handleSubmit((data) => console.log('data', data)); | ||
const values = form.watch(); | ||
const ladderSelected = values?.[addEmployeeFormNames.ladder]?.name?.length > 0; | ||
const firstTechnology = values?.[addEmployeeFormNames.technology]?.[0]; | ||
|
||
useEffect(() => { | ||
const technologySelected = firstTechnology && firstTechnology.name?.length > 0; | ||
|
||
setFormValid(ladderSelected && technologySelected); | ||
}, [values, ladderSelected, firstTechnology]); | ||
|
||
// INFO: update progress in sidebar stepper | ||
useEffect(() => { | ||
if (formValid) updateProgress({ [routes.people.addNew.mainLadder]: 'completed' }); | ||
else updateProgress({ [routes.people.addNew.mainLadder]: 'inProgress' }); | ||
}, [formValid, updateProgress]); | ||
|
||
return { firstTechnology, form, handleSubmit, technologyFields, open, setOpen, ladderSelected, formValid }; | ||
}; |
86 changes: 86 additions & 0 deletions
86
frontend/src/components/pages/addEmployee/MainLadder/MainLadder.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,86 @@ | ||
'use client'; | ||
import { Button } from '@app/components/common/Button'; | ||
import { Combobox } from '@app/components/common/Combobox'; | ||
import { Typography } from '@app/components/common/Typography'; | ||
import { stepComponentsMap } from '@app/components/modules/SideStepper'; | ||
import { useMainLadder } from './MainLadder.hooks'; | ||
import { DeleteIcon } from '@app/static/icons/DeleteIcon'; | ||
import { generateClassNames } from '@app/utils'; | ||
import { ChevronUpIcon } from '@app/static/icons/ChevronUpIcon'; | ||
import { Spacer, ladders, technologies } from './MainLadder.utils'; | ||
import { addEmployeeFormNames } from '../AddEmployeeFormProvider'; | ||
|
||
export const MainLadder = () => { | ||
const { form, technologyFields, open, setOpen, ladderSelected, formValid, firstTechnology } = useMainLadder(); | ||
const values = form.watch(); | ||
|
||
return ( | ||
<div className="flex flex-col gap-y-10 rounded-[20px] border-navy-200 bg-white p-8"> | ||
<div className="flex items-center justify-between"> | ||
<div className="flex items-center gap-x-4"> | ||
<div>{formValid ? stepComponentsMap.completed : stepComponentsMap.inProgress}</div> | ||
<Typography variant="head-s/medium">1. Select Ladder</Typography> | ||
</div> | ||
<Button | ||
variant="link" | ||
className={generateClassNames(`flex h-8 w-8 duration-150 ${open ? 'rotate-0' : 'rotate-180'} items-center`)} | ||
onClick={() => setOpen((prev) => !prev)} | ||
> | ||
{<ChevronUpIcon className="text-navy-600" />} | ||
</Button> | ||
</div> | ||
{open && ( | ||
<div className="flex flex-col gap-y-6"> | ||
<div className="flex w-1/2 flex-col gap-y-6"> | ||
<Combobox | ||
label="Ladder" | ||
options={ladders} | ||
name={addEmployeeFormNames.ladder} | ||
renderRightContent={() => <Spacer />} | ||
/> | ||
{values?.[addEmployeeFormNames.technology].map((tech, i) => { | ||
return ( | ||
<Combobox | ||
label="Technology" | ||
key={`${tech.id}-${i}`} | ||
options={technologies} | ||
name={`${addEmployeeFormNames.technology}.${i}`} | ||
renderRightContent={() => | ||
i !== 0 ? ( | ||
<Button | ||
variant="link" | ||
styleType="natural" | ||
className="flex h-8 w-8 items-center" | ||
onClick={() => technologyFields.remove(i)} | ||
> | ||
<DeleteIcon /> | ||
</Button> | ||
) : ( | ||
<Spacer /> | ||
) | ||
} | ||
/> | ||
); | ||
})} | ||
{ladderSelected && ( | ||
<Button | ||
styleType="primary" | ||
variant="link" | ||
className="w-fit" | ||
onClick={() => technologyFields.append({ id: '', name: '' })} | ||
disabled={firstTechnology && !firstTechnology.name} | ||
> | ||
+ Technology | ||
</Button> | ||
)} | ||
</div> | ||
<div className="self-end"> | ||
<Button styleType="primary" variant="solid" disabled={!formValid}> | ||
Confirm and continue | ||
</Button> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.