Skip to content

Commit

Permalink
feat: get active employees for most cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ngolapnguyen committed Feb 28, 2024
1 parent 5d160dd commit d7734f8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/components/common/FormAccountWithRateList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Icon } from '@iconify/react'
import { Form, FormInstance, Input, SelectProps } from 'antd'
import { Rule } from 'antd/lib/form'
import { Permission } from 'constants/permission'
import { client, GET_PATHS } from 'libs/apis'
import { EmployeeStatus } from 'constants/status'
import { GET_PATHS, client } from 'libs/apis'
import { useEffect } from 'react'
import { NumericFormat } from 'react-number-format'
import { fullListPagination } from 'types/filters/Pagination'
Expand All @@ -23,6 +24,10 @@ interface Props {
const employeeOptionGetter = async () => {
const { data } = await client.getEmployees({
...fullListPagination,
// Only get active employees
workingStatuses: Object.values(EmployeeStatus).filter(
(status) => status !== EmployeeStatus.LEFT,
),
})
return (data || []).map(transformEmployeeDataToSelectOption)
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/pages/employees/EmployeeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { renderEmployeeOption } from 'components/common/Select/renderers/employe
import { renderStatusOption } from 'components/common/Select/renderers/statusOption'
import { SELECT_BOX_DATE_FORMAT, SERVER_DATE_FORMAT } from 'constants/date'
import { ROUTES } from 'constants/routes'
import { employeeStatuses } from 'constants/status'
import { EmployeeStatus, employeeStatuses } from 'constants/status'
import { client, GET_PATHS } from 'libs/apis'
import { useRouter } from 'next/router'
import { useState, useEffect } from 'react'
Expand Down Expand Up @@ -320,6 +320,10 @@ export const EmployeeForm = (props: Props) => {
optionGetter={async () => {
const { data } = await client.getEmployees({
...fullListPagination,
// Only get active employees
workingStatuses: Object.values(EmployeeStatus).filter(
(status) => status !== EmployeeStatus.LEFT,
),
})
return data?.map(transformEmployeeDataToSelectOption) || []
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { SELECT_BOX_DATE_FORMAT, SERVER_DATE_FORMAT } from 'constants/date'
import { renderOrganizationOption } from 'components/common/Select/renderers/organizationOption'
import { useFetchWithCache } from 'hooks/useFetchWithCache'
import { theme } from 'styles'
import { EmployeeStatus } from 'constants/status'

type FormValues = Partial<
Omit<RequestUpdateEmployeeGeneralInfoInput, 'joinedDate' | 'leftDate'>
Expand Down Expand Up @@ -212,6 +213,10 @@ export const EditGeneralInfoModal = (props: Props) => {
optionGetter={async () => {
const { data } = await client.getEmployees({
...fullListPagination,
// Only get active employees
workingStatuses: Object.values(EmployeeStatus).filter(
(status) => status !== EmployeeStatus.LEFT,
),
})
return (data || []).map(transformEmployeeDataToSelectOption)
}}
Expand Down Expand Up @@ -267,6 +272,10 @@ export const EditGeneralInfoModal = (props: Props) => {
optionGetter={async () => {
const { data } = await client.getEmployees({
...fullListPagination,
// Only get active employees
workingStatuses: Object.values(EmployeeStatus).filter(
(status) => status !== EmployeeStatus.LEFT,
),
})
return data?.map(transformEmployeeDataToSelectOption) || []
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
transformMetadataToSelectOption,
} from 'utils/select'
import { DeploymentType, deploymentTypes } from 'constants/deploymentTypes'
import { ProjectMemberStatus, projectMemberStatuses } from 'constants/status'
import {
EmployeeStatus,
ProjectMemberStatus,
projectMemberStatuses,
} from 'constants/status'
import { renderEmployeeOption } from 'components/common/Select/renderers/employeeOption'
import { FormInstance } from 'antd/es/form/Form'
import { useEffect } from 'react'
Expand Down Expand Up @@ -71,6 +75,10 @@ export const MemberForm = (props: Props) => {
() =>
client.getEmployees({
...fullListPagination,
// Only get active employees
workingStatuses: Object.values(EmployeeStatus).filter(
(status) => status !== EmployeeStatus.LEFT,
),
}),
)

Expand Down
8 changes: 5 additions & 3 deletions src/pages/employees/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Default = () => {
const queryFilter = query.filter ? JSON.parse(query.filter as string) : {}

const { permissions } = useAuthContext()
const canFilterStatus = permissions.includes(
const canFilterAllStatuses = permissions.includes(
Permission.EMPLOYEES_READ_FILTERBYALLSTATUSES,
)

Expand Down Expand Up @@ -159,7 +159,9 @@ const Default = () => {
filteredValue: filter.workingStatuses,
filters: Object.keys(employeeStatuses)
.filter(
(key) => canFilterStatus || (!canFilterStatus && key !== 'left'),
(key) =>
canFilterAllStatuses ||
(!canFilterAllStatuses && key !== EmployeeStatus.LEFT),
)
.map((key) => {
return {
Expand Down Expand Up @@ -431,7 +433,7 @@ const Default = () => {
permission && !permissions.includes(permission) ? [] : [col],
)
}, [
canFilterStatus,
canFilterAllStatuses,
filter,
positions,
projects,
Expand Down

0 comments on commit d7734f8

Please sign in to comment.