Skip to content
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

[FE][CPF-65] Add employee - personal details #77

Merged
merged 15 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# hooks start from the project root directory

cd frontend

yarn lint:fix && yarn format
yarn lint:fix
yarn format
yarn compile
5 changes: 4 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
},
"dependencies": {
"@headlessui/react": "^2.0.4",
"@hookform/error-message": "^2.0.1",
"clsx": "^2.1.0",
"next": "14.1.3",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.52.0",
"react-easy-crop": "^5.0.7",
"react-markdown": "^9.0.1",
"react-tooltip": "^5.26.3",
"remark-gfm": "^4.0.0",
"tailwind-merge": "^2.2.2"
"tailwind-merge": "^2.2.2",
"zustand": "^4.5.4"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.13",
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/app/(app)/(peopleFlow)/people/add-new/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { EmployeeSideStepper } from '@app/components/modules/EmployeeSideStepper';
import { WorkflowTopbar } from '@app/components/modules/WorkflowTopbar';

export default function PeopleLayout({ children }: Readonly<{ children: React.ReactNode }>) {
return (
<div className="flex">
<div className="w-full">
<WorkflowTopbar />
<main className="p-8">
<div className="grid grid-cols-workflow">
<EmployeeSideStepper />
<div className="col-span-1 px-8">{children}</div>
</div>
</main>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { PersonalDetails } from '@app/components/pages/PersonalDetails/PersonalDetails';

export default PersonalDetails;
14 changes: 14 additions & 0 deletions frontend/src/app/(app)/(root)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Sidebar } from '@app/components/modules/Sidebar';
import { Topbar } from '@app/components/modules/Topbar';

export default function AppLayout({ children }: Readonly<{ children: React.ReactNode }>) {
return (
<div className="flex">
<Sidebar />
<div className="w-full">
<Topbar />
<main className="p-8">{children}</main>
</div>
</div>
);
}
File renamed without changes.
16 changes: 16 additions & 0 deletions frontend/src/app/(app)/(root)/people/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Button } from '@app/components/common/Button';
import { routes } from '@app/constants';
import Link from 'next/link';

export default function People() {
return (
<div>
<div className="mb-6 flex items-center justify-between">
<h1 className="text-lg font-semibold leading-6 text-navy-900">People</h1>
<Button>
<Link href={routes.people.addNew.personalDetails}>+ Employee</Link>
</Button>
</div>
</div>
);
}
33 changes: 0 additions & 33 deletions frontend/src/app/(app)/layout.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions frontend/src/app/(app)/people/page.tsx

This file was deleted.

19 changes: 19 additions & 0 deletions frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';

import './globals.css';

const inter = Inter({ subsets: ['latin'] });

export const metadata: Metadata = {
title: 'CPF - Career Progression Framework',
description: 'Career Progression Framework Application',
};

export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="en">
<body className={`${inter.className} h-full bg-navy-50`}>{children}</body>
</html>
);
}
5 changes: 2 additions & 3 deletions frontend/src/components/common/Button/Button.interface.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ButtonHTMLAttributes, ReactNode } from 'react';
import { ButtonHTMLAttributes } from 'react';

export interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
styleType?: StyleTypes;
variant?: Variants;
disabled?: boolean;
className?: string;
children: ReactNode;
}

export type StyleTypes = 'primary' | 'natural' | 'warning';
Expand Down
25 changes: 16 additions & 9 deletions frontend/src/components/common/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateClassNames } from '@app/utils';
import React from 'react';
import { Props, StyleTypes, Variants } from './Button.interface';
import React, { FC } from 'react';
import { ButtonProps, StyleTypes, Variants } from './Button.interface';

const types: {
[key in StyleTypes]: {
Expand All @@ -10,38 +10,45 @@ const types: {
primary: {
solid: 'bg-blue-600 text-white hover:bg-blue-900',
border:
'bg-white text-blue-800 border border-blue-800 hover:bg-navy-100 active:bg-white active:text-blue-900 active:border-blue-900',
borderless: 'px-2 bg-transparent text-blue-800 hover:bg-navy-100 active:bg-white active:text-blue-900',
'bg-transparent text-blue-800 border border-blue-800 hover:bg-navy-100 active:text-blue-900 active:border-blue-900',
borderless: 'px-2 bg-transparent text-blue-800 hover:bg-navy-100 active:text-blue-900',
link: 'px-0 bg-transparent text-blue-800 hover:underline hover:text-blue-900 active:text-blue-900 active:no-underline',
},
natural: {
solid: 'bg-navy-600 text-white hover:bg-navy-700',
border: 'bg-white text-navy-600 border border-navy-300 hover:bg-navy-100',
border: 'bg-transparent text-navy-600 border border-navy-300 hover:bg-navy-100',
borderless: 'px-2 bg-transparent text-navy-600 hover:bg-navy-50 active:bg-navy-100',
link: 'px-0 bg-transparent text-navy-600 hover:underline hover:text-navy-700 active:no-underline',
},
warning: {
solid: 'bg-red-600 text-white hover:bg-red-700',
border: 'bg-white text-red-600 border border-red-600 hover:bg-navy-100 hover:text-red-700',
border: 'bg-transparent text-red-600 border border-red-600 hover:bg-navy-100 hover:text-red-700',
borderless:
'px-2 bg-transparent text-red-600 hover:bg-navy-50 hover:border-[1.5px] hover:border-red-700 hover:text-red-700',
link: 'px-0 bg-transparent text-red-600 hover:underline hover:text-red-700 active:no-underline',
},
};

export const Button = ({
const disabledStyles = {
solid: 'bg-navy-200',
border: 'bg-transparent border-navy-200 border',
borderless: 'px-2 border-none',
link: 'px-0 border-none',
};

export const Button: FC<ButtonProps> = ({
styleType = 'primary',
variant = 'solid',
disabled = false,
className,
children,
...props
}: Props) => {
}) => {
const buttonClass = generateClassNames(
'h-11 px-5 items-center justify-center rounded-full transition duration-200',
{
[types[styleType][variant]]: !disabled,
'bg-navy-200 border-navy-200 text-navy-300 cursor-not-allowed': disabled,
[`text-navy-300 cursor-not-allowed ${disabledStyles[variant]}`]: disabled,
},
className,
);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/common/Button/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { Button } from './Button';
export type { StyleTypes, Variants, Props } from './Button.interface';
15 changes: 15 additions & 0 deletions frontend/src/components/common/FormProvider/FormProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PropsWithChildren } from 'react';
import { FieldValues, FormProvider as RHFFormProvider, UseFormReturn } from 'react-hook-form';

interface Props<T extends FieldValues> extends PropsWithChildren {
form: UseFormReturn<T>;
onSubmit?: (values: T) => void;
}

export const FormProvider = <T extends FieldValues>({ form, onSubmit, children }: Props<T>) => {
return (
<RHFFormProvider {...form}>
<form {...(onSubmit && { onSubmit: form.handleSubmit(onSubmit) })}>{children}</form>
</RHFFormProvider>
);
};
1 change: 1 addition & 0 deletions frontend/src/components/common/FormProvider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { FormProvider } from './FormProvider';
8 changes: 8 additions & 0 deletions frontend/src/components/common/Input/Input.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { FieldValues, RegisterOptions } from 'react-hook-form';

export interface InputProps {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some props for the icon at the beginning/end of the field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add input styles from Figma styleguide in the next PR. I didn't want to make this PR too big with all the extras.

label?: string;
placeholder?: string;
name: string;
options?: RegisterOptions<FieldValues, string>;
}
43 changes: 43 additions & 0 deletions frontend/src/components/common/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { FC, memo } from 'react';
import { InputProps } from './Input.interface';
import { useFormContext } from 'react-hook-form';
import { generateClassNames } from '@app/utils';
import { ErrorMessage } from '@hookform/error-message';
import { CheckMarkIcon } from '@app/static/icons/AlertTriangleIcon';

export const Input: FC<InputProps> = memo(({ label, name, placeholder, options = {}, ...otherProps }) => {
const { formState, register, getFieldState } = useFormContext();
const error = getFieldState(name).error;

return (
<div className="flex flex-col gap-y-3">
{label && (
<label className="text-navy-900" htmlFor={`input-${name}`}>
{label}
</label>
)}
<input
className={generateClassNames(
'outline-black h-12 w-full rounded-xl border border-navy-200 px-4 outline-none focus:border-navy-700',
{ 'border-red-600 focus:border-red-600': !!error },
)}
placeholder={placeholder}
id={`input-${name}`}
{...register(name, options)}
{...otherProps}
/>
<ErrorMessage
errors={formState.errors}
name={name}
render={({ message }) => (
<div className="flex items-center gap-x-2">
<CheckMarkIcon />
<div className="text-sm text-red-600 first-letter:uppercase">{message}</div>
</div>
)}
/>
</div>
);
});

Input.displayName = 'Input';
2 changes: 2 additions & 0 deletions frontend/src/components/common/Input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Input } from './Input';
export type { InputProps } from './Input.interface';
2 changes: 1 addition & 1 deletion frontend/src/components/common/Typography/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const Typography = ({
case 'h5':
return <h5 className={classnames}>{children}</h5>;
case 'h6':
return <p className={classnames}>{children}</p>;
return <h6 className={classnames}>{children}</h6>;
case 'p':
default:
return <p className={classnames}>{children}</p>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { routes } from '@app/constants';
import { Step } from '../SideStepper';
import { AddNewPersonRouteKeys } from './EmployeeSideStepper.interface';

export const addEmployeeInitialSteps: Step<AddNewPersonRouteKeys>[] = [
{ label: '1. Personal details', state: 'notStarted', current: true, href: routes.people.addNew.personalDetails },
{ label: '2. Main ladder', state: 'notStarted', current: false, href: routes.people.addNew.mainLadder },
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { routes } from '@app/constants';

type AddNewPersonRoutes = typeof routes.people.addNew;
export type AddNewPersonRouteKeys = AddNewPersonRoutes[keyof AddNewPersonRoutes];
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client';
import { SideStepper, StepStates } from '../SideStepper';
import { useEffect, useState } from 'react';
import { usePathname } from 'next/navigation';
import { AddNewPersonRouteKeys } from './EmployeeSideStepper.interface';
import { addEmployeeInitialSteps } from './EmployeeSideStepper.const';
import { usePeopleStore } from '@app/store/people/store';

export const EmployeeSideStepper = () => {
const progress = usePeopleStore((state) => state.progress);
const pathname = usePathname();
const [addEmployeeSteps, setAddEmployeeSteps] = useState(addEmployeeInitialSteps);

// INFO: If current step is not 'completed', then set 'inProgress' state to the current path
useEffect(() => {
setAddEmployeeSteps((prevState) =>
prevState.map((step) => {
const state: StepStates =
progress[step.href] !== 'completed' && pathname.endsWith(step.href) ? 'inProgress' : progress[step.href];

return {
...step,
state: state,
};
}),
);
}, [pathname, progress]);

return <SideStepper<AddNewPersonRouteKeys> steps={addEmployeeSteps} />;
};
2 changes: 2 additions & 0 deletions frontend/src/components/modules/EmployeeSideStepper/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { EmployeeSideStepper } from './EmployeeSideStepper';
export type { AddNewPersonRouteKeys } from './EmployeeSideStepper.interface';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type StepStates = 'completed' | 'inProgress' | 'notStarted';

export interface Step<T> {
label: string;
state: StepStates;
current: boolean;
href: T;
}

export interface SideStepperProps<T> {
steps: Step<T>[];
}
Loading