Skip to content

Commit

Permalink
feat: Add archived filter to the campagin application list
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkotev committed Dec 8, 2024
1 parent 11ea027 commit 4d8964d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
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,
}
}

0 comments on commit 4d8964d

Please sign in to comment.