Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
frozenhelium committed Apr 3, 2024
1 parent 5a2c3bb commit 7125663
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/src/views/AccountMyFormsDref/ActiveDrefTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,19 @@ function ActiveDrefTable(props: Props) {
'country',
strings.activeDrefTableCountryHeading,
(item) => item.country_details?.name,
{ columnClassName: styles.country },
),
createStringColumn<LatestDref, Key>(
'type_of_dref',
strings.activeDrefTableTypeOfDrefHeading,
(item) => item.type_of_dref_display,
{ columnClassName: styles.type },
),
createStringColumn<LatestDref, Key>(
'status',
strings.activeDrefTableStatusHeading,
(item) => item.status_display,
{ columnClassName: styles.status },
),
createElementColumn<LatestDref, Key, DrefTableActionsProps>(
'actions',
Expand Down Expand Up @@ -259,6 +262,7 @@ function ActiveDrefTable(props: Props) {
onPublishSuccess: refetchActiveDref,
};
},
{ columnClassName: styles.actions },
),
]),
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
}

.table {
.date {
width: 7rem;
}

.country,
.appeal-code {
width: 8rem;
}
Expand All @@ -19,8 +16,15 @@
min-width: 8rem;
}

.actions,
.stage {
width: 8rem;
width: 9rem;
}

.date,
.type,
.status {
width: 7rem;
}

.sub-cell {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import {
useCallback,
useState,
} from 'react';
import { Button } from '@ifrc-go/ui';
import xlsx from 'exceljs';
import FileSaver from 'file-saver';

import ifrcLogoFile from '#assets/icons/ifrc-square.png';
import useNationalSociety from '#hooks/domain/useNationalSociety';
import { COLOR_RED } from '#utils/constants';

const fieldNameToCellAddressMap = {

Check warning on line 13 in app/src/views/AccountMyFormsDref/DownloadImportTemplateButton/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

'fieldNameToCellAddressMap' is assigned a value but never used
national_society: {
row: 6,
},
};

function DownloadImportTemplateButton() {
const [generationPending, setGenerationPending] = useState(false);
const nationalSocieties = useNationalSociety();

const handleClick = useCallback(
() => {
async function generateTemplate() {
const workbook = new xlsx.Workbook();
const now = new Date();
workbook.created = now;
const response = await fetch(ifrcLogoFile);
const buffer = await response.arrayBuffer();

const ifrcLogo = workbook.addImage({
buffer,
extension: 'png',
});

const coverWorksheet = workbook.addWorksheet('DREF Import');

const overviewWorksheet = workbook.addWorksheet('Operation Overview');
const eventDetailsWorksheet = workbook.addWorksheet('Event Detail');

Check warning on line 40 in app/src/views/AccountMyFormsDref/DownloadImportTemplateButton/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

'eventDetailsWorksheet' is assigned a value but never used
const actionsNeedsWorksheet = workbook.addWorksheet('Actions-Needs');

Check warning on line 41 in app/src/views/AccountMyFormsDref/DownloadImportTemplateButton/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

'actionsNeedsWorksheet' is assigned a value but never used
const operationWorksheet = workbook.addWorksheet('Operation');

Check warning on line 42 in app/src/views/AccountMyFormsDref/DownloadImportTemplateButton/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

'operationWorksheet' is assigned a value but never used
const timeframeAndContactsWorksheet = workbook.addWorksheet('Operational timeframes and contacts');

Check warning on line 43 in app/src/views/AccountMyFormsDref/DownloadImportTemplateButton/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

'timeframeAndContactsWorksheet' is assigned a value but never used

coverWorksheet.addImage(ifrcLogo, 'A1:B6');
coverWorksheet.getCell('C1').value = 'DISASTER RESPONSE EMERGENCY FUND';
coverWorksheet.mergeCells('C1:L3');
coverWorksheet.getCell('C1:L3').style = {
font: {
name: 'Montserrat',
family: 2,
bold: true,
size: 20,
color: { argb: COLOR_RED },
},
alignment: { horizontal: 'center', vertical: 'middle' },
};
coverWorksheet.addRow('');
coverWorksheet.addRow('');
coverWorksheet.addRow('');
coverWorksheet.addRow('');
coverWorksheet.mergeCells('C4:L6');
coverWorksheet.getCell('C4').value = 'Import template';
coverWorksheet.getCell('C4').style = {
font: {
bold: true, size: 18, name: 'Montserrat', family: 2,
},
alignment: { horizontal: 'center', vertical: 'middle' },
};

overviewWorksheet.columns = [
{ header: 'ID', key: 'id' },
{ header: 'Field', key: 'field' },
{ header: 'Value', key: 'value' },
];

const idColumn = overviewWorksheet.getColumn('id');
const fieldColumn = overviewWorksheet.getColumn('field');
idColumn.protection = {
locked: true,
hidden: true,
};
fieldColumn.protection = { locked: true };
overviewWorksheet.addRow({
values: {
id: 'country',
field: 'Country',
},
});

await workbook.xlsx.writeBuffer().then((sheet) => FileSaver.saveAs(
new Blob([sheet], { type: 'application/vnd.ms-excel;charset=utf-8' }),
`DREF import template ${now.toLocaleString()}.xlsx`,
));

setGenerationPending(false);
}

setGenerationPending((alreadyGenerating) => {
if (!alreadyGenerating) {
generateTemplate();
}

return true;
});
},
[nationalSocieties],

Check warning on line 107 in app/src/views/AccountMyFormsDref/DownloadImportTemplateButton/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

React Hook useCallback has an unnecessary dependency: 'nationalSocieties'. Either exclude it or remove the dependency array
);

return (
<Button
onClick={handleClick}
name={undefined}
disabled={generationPending}
>
Download Import Template
</Button>
);
}

export default DownloadImportTemplateButton;
Empty file.
4 changes: 4 additions & 0 deletions app/src/views/AccountMyFormsDref/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Link from '#components/Link';

import ActiveDrefTable from './ActiveDrefTable';
import CompletedDrefTable from './CompletedDrefTable';
import DownloadImportTemplateButton from './DownloadImportTemplateButton';

import i18n from './i18n.json';
import styles from './styles.module.css';
Expand All @@ -32,6 +33,9 @@ export function Component() {
{strings.drefFeedbackForm}
</Link>
</div>
<div className={styles.actions}>
<DownloadImportTemplateButton />
</div>
{currentView === 'active' && (
<ActiveDrefTable
actions={(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

.name {
display: flex;
word-break: break-all;
word-break: break-word;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.cell {
padding: var(--go-ui-spacing-sm);
overflow: hidden;
word-break: break-all;
word-break: break-word;
}

&:hover {
Expand Down

0 comments on commit 7125663

Please sign in to comment.