Skip to content

Commit

Permalink
Add dry run functionality for personhendelser
Browse files Browse the repository at this point in the history
  • Loading branch information
ramnav990 committed Mar 27, 2024
1 parent 37d3efc commit 95448c3
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/api/driftApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,14 @@ export async function sendPersonhendelser(args: { hendelser: File }): Promise<Ap
body: formData,
});
}

export async function dryRunPersonhendelser(args: { hendelser: File }): Promise<ApiClientResult<{ status: string }>> {
const formData = new FormData();
formData.append('file', args.hendelser);

return apiClient({
url: `/drift/personhendelser/dry`,
method: 'POST',
body: formData,
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
@import '@styles/variables.less';

.modalBody {
> :not(:last-child) {
margin-bottom: @spacing;
}
}

.tabPanel {
padding: @spacing-s 0;
}

.panelInnholdContainer {
display: flex;
flex-direction: column;
gap: @spacing-s;
Expand Down
61 changes: 49 additions & 12 deletions src/pages/drift/components/personhendelser/Personhendelser.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as RemoteData from '@devexperts/remote-data-ts';
import { Alert, Button, Modal } from '@navikt/ds-react';
import { Alert, Button, Modal, Tabs } from '@navikt/ds-react';
import { useState } from 'react';

import * as driftApi from '~src/api/driftApi';
Expand Down Expand Up @@ -30,7 +30,9 @@ const Personhendelser = () => {

const PersonhendelserModal = (props: { visModal: boolean; onClose: () => void }) => {
const [sendPersonhendelserStatus, sendPersonHendelser] = useApiCall(driftApi.sendPersonhendelser);
const [dryRunStatus, dryRun] = useApiCall(driftApi.dryRunPersonhendelser);
const [personhendelserCSV, setPersonhendelserCSV] = useState<Nullable<File>>(null);
const [personhendelserCSVDry, setPersonhendelserCSVDry] = useState<Nullable<File>>(null);

const handleSubmit = () => {
if (!personhendelserCSV) {
Expand All @@ -39,6 +41,13 @@ const PersonhendelserModal = (props: { visModal: boolean; onClose: () => void })
}
sendPersonHendelser({ hendelser: personhendelserCSV });
};
const handleDryRun = () => {
if (!personhendelserCSVDry) {
console.log('No file selected');
return;
}
dryRun({ hendelser: personhendelserCSVDry });
};

return (
<Modal
Expand All @@ -48,18 +57,46 @@ const PersonhendelserModal = (props: { visModal: boolean; onClose: () => void })
header={{ heading: 'Personhendelser' }}
>
<Modal.Body className={styles.modalBody}>
<input
type="file"
onChange={(e) => (e.target.files ? setPersonhendelserCSV(e.target.files[0]) : null)}
/>
<Tabs defaultValue="dry-run">
<Tabs.List>
<Tabs.Tab value="dry-run" label="Dry-run" />
<Tabs.Tab value="personhendelser" label="Innsending av personhendelser" />
</Tabs.List>
<Tabs.Panel value="dry-run" className={styles.tabPanel}>
<div className={styles.panelInnholdContainer}>
<input
type="file"
onChange={(e) => (e.target.files ? setPersonhendelserCSVDry(e.target.files[0]) : null)}
/>

{RemoteData.isFailure(dryRunStatus) && <ApiErrorAlert error={dryRunStatus.error} />}
{RemoteData.isSuccess(dryRunStatus) && (
<Alert variant="success">Dry run av personhendelser OK 👍🤌</Alert>
)}
<Button onClick={handleDryRun} loading={RemoteData.isPending(dryRunStatus)}>
Dry run personhendelser
</Button>
</div>
</Tabs.Panel>
<Tabs.Panel value="personhendelser" className={styles.tabPanel}>
<div className={styles.panelInnholdContainer}>
<input
type="file"
onChange={(e) => (e.target.files ? setPersonhendelserCSV(e.target.files[0]) : null)}
/>

{RemoteData.isFailure(sendPersonhendelserStatus) && (
<ApiErrorAlert error={sendPersonhendelserStatus.error} />
)}
{RemoteData.isSuccess(sendPersonhendelserStatus) && (
<Alert variant="success">Oppdatering av personhendelser OK 👍🤌</Alert>
)}
<Button onClick={handleSubmit}>Oppdater personhendelser</Button>
{RemoteData.isFailure(sendPersonhendelserStatus) && (
<ApiErrorAlert error={sendPersonhendelserStatus.error} />
)}
{RemoteData.isSuccess(sendPersonhendelserStatus) && (
<Alert variant="success">Oppdatering av personhendelser OK 👍🤌</Alert>
)}
<Button onClick={handleSubmit} loading={RemoteData.isPending(sendPersonhendelserStatus)}>
Oppdater personhendelser
</Button>
</div>
</Tabs.Panel>
</Tabs>
</Modal.Body>
</Modal>
);
Expand Down

0 comments on commit 95448c3

Please sign in to comment.