Skip to content

Commit

Permalink
feat: query projects with status array
Browse files Browse the repository at this point in the history
  • Loading branch information
ngolapnguyen committed Mar 11, 2024
1 parent d7734f8 commit b89fd87
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
BASE_URL='https://develop-api.fortress.d.foundation/api/v1'
# BASE_URL='https://develop-api.fortress.d.foundation/api/v1'
BASE_URL='https://api.fortress.d.foundation/api/v1'
GOOGLE_CLIENT_ID='180094408893-s17eot91hbmqa5lp6gsgjglan9et20sp.apps.googleusercontent.com'
16 changes: 10 additions & 6 deletions src/components/pages/feedbacks/work/ToggleAllowSendSurveyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import {
Switch,
Typography,
} from 'antd'
import { useCallback, useMemo, useState } from 'react'
import debounce from 'lodash.debounce'
import { ProjectStatus } from 'constants/status'
import { useFetchWithCache } from 'hooks/useFetchWithCache'
import { GET_PATHS, client } from 'libs/apis'
import { ProjectListFilter } from 'types/filters/ProjectListFilter'
import { useFilter } from 'hooks/useFilter'
import { client, GET_PATHS } from 'libs/apis'
import debounce from 'lodash.debounce'
import { useCallback, useMemo, useState } from 'react'
import { theme } from 'styles'
import { ProjectListFilter } from 'types/filters/ProjectListFilter'
import { ViewProjectData } from 'types/schema'
import { getErrorMessage } from 'utils/string'
import { theme } from 'styles'

interface Props {
isOpen: boolean
Expand All @@ -27,7 +28,10 @@ interface Props {
export const ToggleAllowSendSurveyModal = (props: Props) => {
const { isOpen, onClose } = props
const { filter } = useFilter(
new ProjectListFilter({ sort: '-start_date, -name', status: 'active' }),
new ProjectListFilter({
sort: '-start_date, -name',
status: [ProjectStatus.ACTIVE],
}),
)

const { data: projectsData, mutate } = useFetchWithCache(
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/invoice/new/InvoiceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const InvoiceForm = () => {
const { data: projectData } = useFetchWithCache(GET_PATHS.getProjects, () =>
client.getProjects({
...new ProjectListFilter({
status: ProjectStatus.ACTIVE,
status: [ProjectStatus.ACTIVE],
type: [ProjectType.FIXED_COST, ProjectType.TIME_MATERIAL],
}),
...fullListPagination,
Expand Down
4 changes: 3 additions & 1 deletion src/libs/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ class Client {
}

public getProjects(filter: ProjectListFilter) {
const queryString = qs.stringify(filter)
const queryString = qs.stringify(filter, {
arrayFormat: 'repeat',
})

return fetcher<ViewProjectListDataResponse & Meta>(
`${BASE_URL}/projects?${queryString}`,
Expand Down
8 changes: 4 additions & 4 deletions src/pages/projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ const columns = ({
key: 'status',
dataIndex: 'status',
filterSearch: true,
filterMultiple: false,
filteredValue: filter.status ? [filter.status].flat() : [],
filterMultiple: true,
filteredValue: filter.status,
filters: projectStatusData
.map(transformMetadataToFilterOption)
.map(({ text, value = '' }) => ({
Expand Down Expand Up @@ -270,7 +270,7 @@ const Default = () => {

const { filter, setFilter } = useFilter(
new ProjectListFilter({
status: ProjectStatus.ACTIVE,
status: [ProjectStatus.ONBOARDING, ProjectStatus.ACTIVE],
...queryFilter,
}),
{ shouldUpdateToQuery: true },
Expand Down Expand Up @@ -365,7 +365,7 @@ const Default = () => {
)
.join(',')
setFilter({
status: (filters.status?.[0] as string) || '',
status: (filters.status as string[]) || [],
sort,
})
}}
Expand Down
4 changes: 2 additions & 2 deletions src/types/filters/ProjectListFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Nullable } from 'types/common'
import { Pagination } from './Pagination'

interface RequestGetListProjectInput {
status?: string | string[]
status?: string[]
name?: string
type?: string | string[]
sort?: string
Expand All @@ -18,7 +18,7 @@ export class ProjectListFilter
sort

constructor({
status = null,
status = [],
name = null,
type = null,
sort = null,
Expand Down

0 comments on commit b89fd87

Please sign in to comment.