Skip to content

Commit

Permalink
innsending av personhendelser tar en fraOgMed måned
Browse files Browse the repository at this point in the history
  • Loading branch information
RamziAbuQassim committed Apr 4, 2024
1 parent 95448c3 commit 6e6de6f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/api/driftApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ export async function sendUtbetalingsIder(args: {
});
}

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

return apiClient({
Expand All @@ -137,8 +141,12 @@ export async function sendPersonhendelser(args: { hendelser: File }): Promise<Ap
});
}

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

return apiClient({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
.panelInnholdContainer {
display: flex;
flex-direction: column;
gap: @spacing-s;
gap: @spacing;
}
19 changes: 17 additions & 2 deletions src/pages/drift/components/personhendelser/Personhendelser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { useState } from 'react';

import * as driftApi from '~src/api/driftApi';
import ApiErrorAlert from '~src/components/apiErrorAlert/ApiErrorAlert';
import { MonthPicker } from '~src/components/inputs/datePicker/DatePicker';
import { useApiCall } from '~src/lib/hooks';
import { Nullable } from '~src/lib/types';
import { toIsoDateOnlyString } from '~src/utils/date/dateUtils';

import styles from './Personhendelser.module.less';

Expand All @@ -31,6 +33,7 @@ const Personhendelser = () => {
const PersonhendelserModal = (props: { visModal: boolean; onClose: () => void }) => {
const [sendPersonhendelserStatus, sendPersonHendelser] = useApiCall(driftApi.sendPersonhendelser);
const [dryRunStatus, dryRun] = useApiCall(driftApi.dryRunPersonhendelser);
const [fraOgMed, setFraOgMed] = useState<Nullable<Date>>(null);
const [personhendelserCSV, setPersonhendelserCSV] = useState<Nullable<File>>(null);
const [personhendelserCSVDry, setPersonhendelserCSVDry] = useState<Nullable<File>>(null);

Expand All @@ -39,14 +42,22 @@ const PersonhendelserModal = (props: { visModal: boolean; onClose: () => void })
console.log('No file selected');
return;
}
sendPersonHendelser({ hendelser: personhendelserCSV });
if (!fraOgMed) {
console.log('No date selected');
return;
}
sendPersonHendelser({ fraOgMed: toIsoDateOnlyString(fraOgMed), hendelser: personhendelserCSV });
};
const handleDryRun = () => {
if (!personhendelserCSVDry) {
console.log('No file selected');
return;
}
dryRun({ hendelser: personhendelserCSVDry });
if (!fraOgMed) {
console.log('No date selected');
return;
}
dryRun({ fraOgMed: toIsoDateOnlyString(fraOgMed), hendelser: personhendelserCSVDry });
};

return (
Expand All @@ -60,10 +71,12 @@ const PersonhendelserModal = (props: { visModal: boolean; onClose: () => void })
<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}>
<MonthPicker label="Fra og med" value={fraOgMed} onChange={setFraOgMed} />
<input
type="file"
onChange={(e) => (e.target.files ? setPersonhendelserCSVDry(e.target.files[0]) : null)}
Expand All @@ -78,8 +91,10 @@ const PersonhendelserModal = (props: { visModal: boolean; onClose: () => void })
</Button>
</div>
</Tabs.Panel>

<Tabs.Panel value="personhendelser" className={styles.tabPanel}>
<div className={styles.panelInnholdContainer}>
<MonthPicker label="Fra og med" value={fraOgMed} onChange={setFraOgMed} />
<input
type="file"
onChange={(e) => (e.target.files ? setPersonhendelserCSV(e.target.files[0]) : null)}
Expand Down

0 comments on commit 6e6de6f

Please sign in to comment.