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

feat: Add archived filter to the campagin application list #1993

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 public/locales/bg/campaign-application.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
"cta": {
"next": "Запазете и продължете",
"back": "Назад",
"submit": "Заявете кампания"
"submit": "Заявете кампания",
"hideArchived": "Скрий архивирани",
"showArchived": "Покажи архивирани"
},
"remark": {
"part-one": "*Допълнителна информация за процеса на кандидатстване и неговите етапи можете да намерите в нашите ",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/en/campaign-application.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
"cta": {
"next": "Save and continue",
"back": "Back",
"submit": "Submit campaign"
"submit": "Submit campaign",
"hideArchived": "Hide archived",
"showArchived": "Show archived"
},
"remark": {
"part-one": "*Additional information about the application process and its stages can be found in our ",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react'
import { useTranslation } from 'next-i18next'

import { DataGrid, GridColDef, GridRenderCellParams } from '@mui/x-data-grid'
import { useQuery } from '@tanstack/react-query'
import { routes } from 'common/routes'
Expand All @@ -9,10 +9,16 @@ import { useSession } from 'next-auth/react'
import Link from 'next/link'
import { endpoints } from 'service/apiEndpoints'
import { authQueryFnFactory } from 'service/restRequests'
import { Toolbar, Typography, Button } from '@mui/material'

export default function CampaignApplicationsGrid() {
const { t } = useTranslation('campaign-application')
const { list } = useCampaignsList()
const [showArchived, setShowArchived] = useState(false)
const { list } = useCampaignsList(showArchived)

const toggleArchivedFilter = () => {
setShowArchived((prev) => !prev)
}

const commonProps: Partial<GridColDef> = {
align: 'left',
Expand Down Expand Up @@ -79,23 +85,37 @@ export default function CampaignApplicationsGrid() {
]

return (
<DataGrid
style={{
background: theme.palette.common.white,
position: 'absolute',
height: 'calc(100vh - 299px)',
border: 'none',
width: 'calc(100% - 48px)',
left: '24px',
overflowY: 'auto',
overflowX: 'hidden',
borderRadius: '0 0 13px 13px',
}}
rows={list || []}
columns={columns}
editMode="row"
pageSizeOptions={[20, 50, 100]}
/>
<>
<Toolbar
sx={{
background: theme.palette.common.white,
borderTop: '1px solid lightgrey',
display: 'flex',
justifyContent: 'space-between',
height: '64px',
}}>
<Button variant="outlined" onClick={toggleArchivedFilter}>
<Typography>{showArchived ? t('cta.showArchived') : t('cta.hideArchived')}</Typography>
</Button>
</Toolbar>
<DataGrid
style={{
background: theme.palette.common.white,
position: 'absolute',
height: 'calc(100vh - 299px)',
border: 'none',
width: 'calc(100% - 48px)',
left: '24px',
overflowY: 'auto',
overflowX: 'hidden',
borderRadius: '0 0 13px 13px',
}}
rows={list || []}
columns={columns}
editMode="row"
pageSizeOptions={[20, 50, 100]}
/>
</>
)
}

Expand All @@ -111,12 +131,14 @@ function fetchMutation() {
)
}

export const useCampaignsList = () => {
export const useCampaignsList = (filterArchived = false) => {
const { data, isLoading } = fetchMutation()

return {
// the data array is strict mode (sometimes) it throws a Readonly array error on the sort so create a shallow copy
list: [...(data ?? [])].sort((a, b) => b?.updatedAt?.localeCompare(a?.updatedAt ?? '') ?? 0),
list: [...(data ?? [])]
.filter((campaign) => (filterArchived ? !campaign.archived : true))
.sort((a, b) => b?.updatedAt?.localeCompare(a?.updatedAt ?? '') ?? 0),
isLoading,
}
}
Loading