-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filter and search in key documents
- Loading branch information
1 parent
15cd641
commit 35c06a1
Showing
5 changed files
with
162 additions
and
3 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/views/CountryNsOverviewContextAndStructure/NationalSocietyKeyDocuments/i18n.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"namespace": "nationalSocietyKeyDocuments", | ||
"strings": { | ||
"nSSocietyKeyDocumentsTitle": "Key Documents" | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
src/views/CountryNsOverviewContextAndStructure/NationalSocietyKeyDocuments/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { useOutletContext } from 'react-router-dom'; | ||
import { DownloadFillIcon, SearchLineIcon } from '@ifrc-go/icons'; | ||
import { listToGroupList, mapToList } from '@togglecorp/fujs'; | ||
|
||
import Container from '#components/Container'; | ||
import DateInput from '#components/DateInput'; | ||
import TextInput from '#components/TextInput'; | ||
import Link from '#components/Link'; | ||
import useTranslation from '#hooks/useTranslation'; | ||
import useFilterState from '#hooks/useFilterState'; | ||
import { GoApiResponse, useRequest } from '#utils/restRequest'; | ||
import { CountryOutletContext } from '#utils/outletContext'; | ||
|
||
import i18n from './i18n.json'; | ||
import styles from './styles.module.css'; | ||
|
||
type GetKeyDocumentResponse = GoApiResponse<'/api/v2/country-document/'>; | ||
export type KeyDocumentItem = NonNullable<GetKeyDocumentResponse['results']>[number]; | ||
|
||
function NationalSocietyKeyDocuments() { | ||
const strings = useTranslation(i18n); | ||
|
||
const { countryId } = useOutletContext<CountryOutletContext>(); | ||
const { | ||
filter, | ||
rawFilter, | ||
setFilterField, | ||
} = useFilterState<{ | ||
searchText?: string, | ||
startDateAfter?: string, | ||
startDateBefore?: string, | ||
}>({ | ||
filter: {}, | ||
}); | ||
const { | ||
response: documentResponse, | ||
} = useRequest({ | ||
url: '/api/v2/country-document/', | ||
query: { | ||
country: Number(countryId), | ||
search: filter.searchText, | ||
year__lte: filter.startDateAfter, | ||
year__gte: filter.startDateBefore, | ||
}, | ||
preserveResponse: true, | ||
}); | ||
|
||
const documents = documentResponse?.results ?? []; | ||
|
||
const groupedDocumentsByType = ( | ||
listToGroupList( | ||
documents, | ||
(item) => item.document_type, | ||
(item) => item, | ||
) ?? {} | ||
); | ||
const documentsMapList = mapToList( | ||
groupedDocumentsByType, | ||
(d, k) => ({ label: k, value: d }), | ||
); | ||
|
||
return ( | ||
<Container | ||
className={styles.nationalSocietyDocuments} | ||
childrenContainerClassName={styles.nsKey} | ||
heading={strings.nSSocietyKeyDocumentsTitle} | ||
withHeaderBorder | ||
withGridViewInFilter | ||
filters={( | ||
<> | ||
<TextInput | ||
name="searchText" | ||
label="Search" | ||
placeholder="Search" | ||
value={rawFilter.searchText} | ||
onChange={setFilterField} | ||
icons={<SearchLineIcon />} | ||
/> | ||
<DateInput | ||
name="startDateAfter" | ||
label="Start" | ||
onChange={setFilterField} | ||
value={rawFilter.startDateAfter} | ||
/> | ||
<DateInput | ||
name="startDateBefore" | ||
label="End" | ||
onChange={setFilterField} | ||
value={rawFilter.startDateBefore} | ||
/> | ||
</> | ||
)} | ||
> | ||
{documentsMapList.map((document) => ( | ||
<Container | ||
className={styles.nsKeyDocuments} | ||
childrenContainerClassName={styles.nsDocuments} | ||
key={document.label} | ||
heading={document.label} | ||
withHeaderBorder | ||
> | ||
{document.value.map((doc) => ( | ||
<div className={styles.document}> | ||
<div>{doc?.name}</div> | ||
<div>{doc?.year}</div> | ||
<Link | ||
className={styles.downloadLink} | ||
href={doc?.url} | ||
external | ||
variant="tertiary" | ||
> | ||
<DownloadFillIcon className={styles.icon} /> | ||
</Link> | ||
</div> | ||
))} | ||
</Container> | ||
))} | ||
</Container> | ||
); | ||
} | ||
|
||
export default NationalSocietyKeyDocuments; |
29 changes: 29 additions & 0 deletions
29
src/views/CountryNsOverviewContextAndStructure/NationalSocietyKeyDocuments/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.national-society-documents { | ||
width: 100%; | ||
min-height: var(--go-ui-content-min-height); | ||
|
||
.ns-key { | ||
display: grid; | ||
grid-gap: var(--go-ui-spacing-lg); | ||
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); | ||
|
||
.ns-key-documents { | ||
border-radius: var(--go-ui-border-radius-lg); | ||
box-shadow: var(--go-ui-box-shadow-md); | ||
padding: var(--go-ui-spacing-lg); | ||
|
||
.ns-documents{ | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--go-ui-spacing-sm); | ||
|
||
.document { | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: space-between; | ||
gap: var(--go-ui-spacing-md); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters