-
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.
fix: use table to show key documents for country
- Loading branch information
Showing
4 changed files
with
142 additions
and
70 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...untryNsOverviewContextAndStructure/NationalSocietyKeyDocuments/DocumentListCard/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,82 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import Container from '#components/Container'; | ||
import Table from '#components/Table'; | ||
import { DownloadFillIcon } from '@ifrc-go/icons'; | ||
import { GoApiResponse } from '#utils/restRequest'; | ||
import { | ||
createLinkColumn, | ||
createStringColumn, | ||
createDateColumn, | ||
} from '#components/Table/ColumnShortcuts'; | ||
|
||
import styles from './styles.module.css'; | ||
|
||
type GetKeyDocumentResponse = GoApiResponse<'/api/v2/country-document/'>; | ||
type KeyDocumentItem = NonNullable<GetKeyDocumentResponse['results']>[number]; | ||
|
||
interface Props { | ||
label: string; | ||
documents: KeyDocumentItem[]; | ||
} | ||
|
||
function documentKeySelector(document: KeyDocumentItem) { | ||
return document.id; | ||
} | ||
|
||
function DocumentListCard(props: Props) { | ||
const { | ||
label, | ||
documents, | ||
} = props; | ||
|
||
const columns = useMemo( | ||
() => ([ | ||
createStringColumn<KeyDocumentItem, number>( | ||
'name', | ||
'', | ||
(item) => item.name, | ||
), | ||
createDateColumn<KeyDocumentItem, number>( | ||
'date', | ||
'', | ||
(item) => item.year, | ||
{ | ||
columnClassName: styles.date, | ||
}, | ||
), | ||
createLinkColumn<KeyDocumentItem, number>( | ||
'url', | ||
'', | ||
() => <DownloadFillIcon />, | ||
(item) => ({ | ||
external: true, | ||
href: item.url, | ||
}), | ||
), | ||
]), | ||
[ | ||
], | ||
); | ||
|
||
return ( | ||
<Container | ||
className={styles.documentListCard} | ||
heading={label} | ||
headingLevel={4} | ||
withHeaderBorder | ||
withInternalPadding | ||
> | ||
<Table | ||
data={documents} | ||
pending={false} | ||
filtered={false} | ||
columns={columns} | ||
keySelector={documentKeySelector} | ||
headersHidden | ||
/> | ||
</Container> | ||
); | ||
} | ||
|
||
export default DocumentListCard; |
12 changes: 12 additions & 0 deletions
12
...verviewContextAndStructure/NationalSocietyKeyDocuments/DocumentListCard/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,12 @@ | ||
.document-list-card { | ||
border-radius: var(--go-ui-border-radius-sm); | ||
box-shadow: var(--go-ui-box-shadow-md); | ||
|
||
.document { | ||
.date { | ||
width: 0%; | ||
min-width: 9rem; | ||
} | ||
} | ||
} | ||
|
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
29 changes: 0 additions & 29 deletions
29
src/views/CountryNsOverviewContextAndStructure/NationalSocietyKeyDocuments/styles.module.css
This file was deleted.
Oops, something went wrong.